+/*
+ * On query "state" from 'smsg' with parameters of 'obj'.
+ */
+static void on_state(struct sd_bus_message *smsg, struct json_object *obj, void *unused)
+{
+ int runid;
+ struct json_object *resp;
+ if (onrunid(smsg, obj, "state", &runid)) {
+ resp = afm_run_state(runid);
+ reply(smsg, resp, error_not_found);
+ json_object_put(resp);
+ }
+}
+
+/*
+ * Calls the system daemon to achieve application management of
+ * the 'method' gotten from 'smsg' with the parameter's string 'msg'.
+ *
+ * The principle is very simple: call the corresponding system method
+ * and reply its response to the caller.
+ *
+ * The request and reply is synchronous and is blocking.
+ * It is possible to implment it in an asynchrounous way but it
+ * would brake the common behaviour. It would be a call like
+ * jbus_call_ss(system_bus, method, msg, callback, smsg)
+ */
+static void propagate(struct sd_bus_message *smsg, const char *msg, const char *method)
+{
+ char *reply;
+ INFO("method %s propagated with %s", method, msg);
+ reply = jbus_call_ss_sync(system_bus, method, msg);
+ if (reply) {
+ jbus_reply_s(smsg, reply);
+ free(reply);
+ }
+ else
+ jbus_reply_error_s(smsg, error_system);
+}
+
+#if defined(EXPLICIT_CALL)
+/*
+ * On query "install" from 'smsg' with parameters of 'msg'.
+ */
+static void on_install(struct sd_bus_message *smsg, const char *msg, void *unused)
+{
+ return propagate(smsg, msg, "install");
+}
+
+/*
+ * On query "uninstall" from 'smsg' with parameters of 'msg'.
+ */
+static void on_uninstall(struct sd_bus_message *smsg, const char *msg, void *unused)
+{
+ return propagate(smsg, msg, "uninstall");
+}
+#endif
+
+/*
+ * On system signaling that applications list changed
+ */
+static void on_signal_changed(struct json_object *obj, void *unused)