summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-01-26 12:08:11 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2016-02-04 15:47:01 +0100
commitc9c0f8989ec6cdd55a8e584e8c93041ae2126282 (patch)
tree2b782a34825bdef12295bbe9603bfaa3b5e38aa2
parent7fc272e5a9afc922f14c47b4c27d0a564e2de4ca (diff)
user-daemon: propagate install/uninstall
The propagation to system bus is less efficient than the direct call but it consumes less resources for a feature that is not frequent. Change-Id: I08c075229648dad4b17878dbb3af93e0e4851de5 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afm-user-daemon.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/afm-user-daemon.c b/src/afm-user-daemon.c
index f6d2aef..ff58e03 100644
--- a/src/afm-user-daemon.c
+++ b/src/afm-user-daemon.c
@@ -63,6 +63,7 @@ const char error_nothing[] = "[]";
const char error_bad_request[] = "\"bad request\"";
const char error_not_found[] = "\"not found\"";
const char error_cant_start[] = "\"can't start\"";
+const char error_system[] = "\"system error\"";
static const char *getappid(struct json_object *obj)
{
@@ -168,6 +169,25 @@ static void on_state(struct jreq *jreq, struct json_object *obj)
json_object_put(resp);
}
+static void propagate(struct jreq *jreq, const char *msg, const char *method)
+{
+ char *reply = jbus_call_ss_sync(jbuses[0], method, msg);
+ if (reply)
+ jbus_reply_s(jreq, reply);
+ else
+ jbus_reply_error_s(jreq, error_system);
+}
+
+static void on_install(struct jreq *jreq, const char *msg)
+{
+ return propagate(jreq, msg, "install");
+}
+
+static void on_uninstall(struct jreq *jreq, const char *msg)
+{
+ return propagate(jreq, msg, "uninstall");
+}
+
static void on_signal_changed(struct json_object *obj)
{
/* update the database */
@@ -295,7 +315,9 @@ int main(int ac, char **av)
|| jbus_add_service_j(jbuses[1], "stop", on_stop)
|| jbus_add_service_j(jbuses[1], "continue", on_continue)
|| jbus_add_service_j(jbuses[1], "runners", on_runners)
- || jbus_add_service_j(jbuses[1], "state", on_state)) {
+ || jbus_add_service_j(jbuses[1], "state", on_state)
+ || jbus_add_service_s(jbuses[1], "install", on_install)
+ || jbus_add_service_s(jbuses[1], "uninstall", on_uninstall)) {
ERROR("adding services failed");
return 1;
}