From c9c0f8989ec6cdd55a8e584e8c93041ae2126282 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Tue, 26 Jan 2016 12:08:11 +0100 Subject: [PATCH] user-daemon: propagate install/uninstall MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- src/afm-user-daemon.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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; } -- 2.16.6