X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=plugins%2Fafm-main-plugin%2Fafm-main-plugin.c;h=553cffc3253d0c9fa1f22450cb31274e47b3a905;hb=4644264333b29d58bc50085a9d97c74770b8b86a;hp=2d350df2214dfcd7ad3dafaf1eed702e21223115;hpb=86b1d3c36dc486c0721fc319a63cef4839b617b5;p=src%2Fapp-framework-binder.git diff --git a/plugins/afm-main-plugin/afm-main-plugin.c b/plugins/afm-main-plugin/afm-main-plugin.c index 2d350df2..553cffc3 100644 --- a/plugins/afm-main-plugin/afm-main-plugin.c +++ b/plugins/afm-main-plugin/afm-main-plugin.c @@ -18,17 +18,18 @@ #define _GNU_SOURCE /* See feature_test_macros(7) */ #include #include +#include #include #include "afb-plugin.h" -#include "afb-req-itf.h" -#include "afb-poll-itf.h" #include "utils-sbus.h" #include "utils-jbus.h" +static const char _added_[] = "added"; static const char _auto_[] = "auto"; static const char _continue_[] = "continue"; +static const char _changed_[] = "changed"; static const char _detail_[] = "detail"; static const char _id_[] = "id"; static const char _install_[] = "install"; @@ -46,9 +47,15 @@ static const char _uninstall_[] = "uninstall"; static const char _uri_[] = "uri"; static const struct AFB_interface *interface; +static struct afb_evmgr evmgr; static struct jbus *jbus; +static void application_list_changed(const char *data, void *closure) +{ + afb_evmgr_push(evmgr, "application-list-changed", NULL); +} + static struct json_object *embed(const char *tag, struct json_object *obj) { struct json_object *result; @@ -81,6 +88,7 @@ static void embed_call_void(struct afb_req request, const char *method) afb_req_fail(request, "failed", "framework daemon failure"); return; } + obj = json_object_get(obj); obj = embed(method, obj); if (obj == NULL) { afb_req_fail(request, "failed", "framework daemon failure"); @@ -111,6 +119,7 @@ static void call_appid(struct afb_req request, const char *method) afb_req_fail(request, "failed", "framework daemon failure"); return; } + obj = json_object_get(obj); afb_req_success(request, obj, NULL); } @@ -130,6 +139,7 @@ static void call_runid(struct afb_req request, const char *method) afb_req_fail(request, "failed", "framework daemon failure"); return; } + obj = json_object_get(obj); afb_req_success(request, obj, NULL); } @@ -180,6 +190,7 @@ static void start(struct afb_req request) free(query); /* check status */ + obj = json_object_get(obj); if (obj == NULL) { afb_req_fail(request, "failed", "framework daemon failure"); return; @@ -218,7 +229,7 @@ static void state(struct afb_req request) static void install(struct afb_req request) { - struct json_object *obj; + struct json_object *obj, *added; char *query; const char *filename; struct afb_arg arg; @@ -239,6 +250,7 @@ static void install(struct afb_req request) obj = jbus_call_sj_sync(jbus, _install_, query); if (interface->verbosity) +; fprintf(stderr, "(afm-main-plugin) install(%s) -> %s\n", query, obj ? json_object_to_json_string(obj) : "NULL"); free(query); @@ -250,6 +262,9 @@ static void install(struct afb_req request) } /* embed if needed */ + if (json_object_object_get_ex(obj, _added_, &added)) + obj = added; + obj = json_object_get(obj); obj = embed(_id_, obj); afb_req_success(request, obj, NULL); } @@ -285,19 +300,24 @@ static struct sbus_itf sbusitf; const struct AFB_plugin *pluginRegister(const struct AFB_interface *itf) { + int rc; + struct afb_pollmgr pollmgr; struct sbus *sbus; /* records the interface */ assert (interface == NULL); + interface = itf; + evmgr = afb_daemon_get_evmgr(itf->daemon); /* creates the sbus for session */ - sbusitf.wait = itf->pollitf->wait; - sbusitf.open = itf->pollitf->open; - sbusitf.on_readable = itf->pollitf->on_readable; - sbusitf.on_writable = itf->pollitf->on_writable; - sbusitf.on_hangup = itf->pollitf->on_hangup; - sbusitf.close = itf->pollitf->close; - sbus = sbus_session(&sbusitf, itf->pollclosure); + pollmgr = afb_daemon_get_pollmgr(itf->daemon); + sbusitf.wait = pollmgr.itf->wait; + sbusitf.open = pollmgr.itf->open; + sbusitf.on_readable = pollmgr.itf->on_readable; + sbusitf.on_writable = pollmgr.itf->on_writable; + sbusitf.on_hangup = pollmgr.itf->on_hangup; + sbusitf.close = pollmgr.itf->close; + sbus = sbus_session(&sbusitf, pollmgr.closure); if (sbus == NULL) { fprintf(stderr, "ERROR: %s:%d: can't connect to DBUS session\n", __FILE__, __LINE__); return NULL; @@ -310,7 +330,13 @@ const struct AFB_plugin *pluginRegister(const struct AFB_interface *itf) return NULL; } - + /* records the signal handler */ + rc = jbus_on_signal_s(jbus, _changed_, application_list_changed, NULL); + if (rc < 0) { + jbus_unref(jbus); + return NULL; + } + return &plug_desc; }