X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafm-main-binding.c;h=a24d992d89e1392a2ef402ea1eaaea4c51a8f330;hb=f551ac4966543b360e3458a61615626d71f55a6e;hp=1af3d8a0ec6e6fd7f883de1c947ab87051286c0d;hpb=d432d8e6918e2e665f1c1179915fed3e0647380a;p=src%2Fapp-framework-main.git diff --git a/src/afm-main-binding.c b/src/afm-main-binding.c index 1af3d8a..a24d992 100644 --- a/src/afm-main-binding.c +++ b/src/afm-main-binding.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015, 2016 "IoT.bzh" + * Copyright (C) 2015, 2016, 2017 IoT.bzh * Author "Fulup Ar Foll" * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,20 +21,20 @@ #include #include +#define AFB_BINDING_VERSION 2 #include #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"; -static const char _local_[] = "local"; -static const char _mode_[] = "mode"; -static const char _remote_[] = "remote"; +static const char _once_[] = "once"; +static const char _pause_[] = "pause"; +static const char _resume_[] = "resume"; static const char _runid_[] = "runid"; static const char _runnables_[] = "runnables"; static const char _runners_[] = "runners"; @@ -43,9 +43,6 @@ static const char _state_[] = "state"; static const char _stop_[] = "stop"; static const char _terminate_[] = "terminate"; static const char _uninstall_[] = "uninstall"; -static const char _uri_[] = "uri"; - -static const struct afb_binding_interface *binder; static struct jbus *jbus; @@ -104,7 +101,7 @@ static void memo_success(struct memo *memo, struct json_object *obj, const char */ static void application_list_changed(const char *data, void *closure) { - afb_daemon_broadcast_event(binder->daemon, "application-list-changed", NULL); + afb_daemon_broadcast_event("application-list-changed", NULL); } /* @@ -136,13 +133,13 @@ static struct json_object *embed(const char *tag, struct json_object *obj) /* * Callback for replies made by 'embed_call_void'. */ -static void embed_call_void_callback(int status, struct json_object *obj, struct memo *memo) +static void embed_call_void_callback(int iserror, struct json_object *obj, struct memo *memo) { - DEBUG(binder, "(afm-main-binding) %s(true) -> %s\n", memo->method, + AFB_DEBUG("(afm-main-binding) %s(true) -> %s\n", memo->method, obj ? json_object_to_json_string(obj) : "NULL"); - if (obj == NULL) { - memo_fail(memo, "framework daemon failure"); + if (iserror) { + memo_fail(memo, obj ? json_object_get_string(obj) : "framework daemon failure"); } else { memo_success(memo, embed(memo->method, json_object_get(obj)), NULL); } @@ -167,13 +164,13 @@ static void embed_call_void(struct afb_req request, const char *method) /* * Callback for replies made by 'call_appid' and 'call_runid'. */ -static void call_xxxid_callback(int status, struct json_object *obj, struct memo *memo) +static void call_xxxid_callback(int iserror, struct json_object *obj, struct memo *memo) { - DEBUG(binder, "(afm-main-binding) %s -> %s\n", memo->method, + AFB_DEBUG("(afm-main-binding) %s -> %s\n", memo->method, obj ? json_object_to_json_string(obj) : "NULL"); - if (obj == NULL) { - memo_fail(memo, "framework daemon failure"); + if (iserror) { + memo_fail(memo, obj ? json_object_get_string(obj) : "framework daemon failure"); } else { memo_success(memo, json_object_get(obj), NULL); } @@ -240,13 +237,13 @@ static void detail(struct afb_req request) call_appid(request, _detail_); } -static void start_callback(int status, struct json_object *obj, struct memo *memo) +static void start_callback(int iserror, struct json_object *obj, struct memo *memo) { - DEBUG(binder, "(afm-main-binding) %s -> %s\n", memo->method, + AFB_DEBUG("(afm-main-binding) %s -> %s\n", memo->method, obj ? json_object_to_json_string(obj) : "NULL"); - if (obj == NULL) { - memo_fail(memo, "framework daemon failure"); + if (iserror) { + memo_fail(memo, obj ? json_object_get_string(obj) : "framework daemon failure"); } else { obj = json_object_get(obj); if (json_object_get_type(obj) == json_type_int) @@ -258,7 +255,7 @@ static void start_callback(int status, struct json_object *obj, struct memo *mem static void start(struct afb_req request) { struct memo *memo; - const char *id, *mode; + const char *id; char *query; int rc; @@ -269,19 +266,13 @@ static void start(struct afb_req request) return; } - /* get the mode */ - mode = afb_req_value(request, _mode_); - if (mode == NULL || !strcmp(mode, _auto_)) { - mode = binder->mode == AFB_MODE_REMOTE ? _remote_ : _local_; - } - /* prepares asynchronous request */ memo = memo_create(request, _start_); if (memo == NULL) return; /* create the query */ - rc = asprintf(&query, "{\"id\":\"%s\",\"mode\":\"%s\"}", id, mode); + rc = asprintf(&query, "{\"id\":\"%s\"}", id); if (rc < 0) { memo_fail(memo, "out of memory"); return; @@ -293,19 +284,24 @@ static void start(struct afb_req request) free(query); } +static void once(struct afb_req request) +{ + call_appid(request, _once_); +} + static void terminate(struct afb_req request) { call_runid(request, _terminate_); } -static void stop(struct afb_req request) +static void pause(struct afb_req request) { - call_runid(request, _stop_); + call_runid(request, _pause_); } -static void continue_(struct afb_req request) +static void resume(struct afb_req request) { - call_runid(request, _continue_); + call_runid(request, _resume_); } static void runners(struct afb_req request) @@ -318,12 +314,12 @@ static void state(struct afb_req request) call_runid(request, _state_); } -static void install_callback(int status, struct json_object *obj, struct memo *memo) +static void install_callback(int iserror, struct json_object *obj, struct memo *memo) { struct json_object *added; - if (obj == NULL) { - memo_fail(memo, "framework daemon failure"); + if (iserror) { + memo_fail(memo, obj ? json_object_get_string(obj) : "framework daemon failure"); } else { if (json_object_object_get_ex(obj, _added_, &added)) obj = added; @@ -369,54 +365,55 @@ static void uninstall(struct afb_req request) call_appid(request, _uninstall_); } -static const struct afb_verb_desc_v1 verbs[] = -{ - {_runnables_, AFB_SESSION_CHECK, runnables, "Get list of runnable applications"}, - {_detail_ , AFB_SESSION_CHECK, detail, "Get the details for one application"}, - {_start_ , AFB_SESSION_CHECK, start, "Start an application"}, - {_terminate_, AFB_SESSION_CHECK, terminate, "Terminate a running application"}, - {_stop_ , AFB_SESSION_CHECK, stop, "Stop (pause) a running application"}, - {_continue_ , AFB_SESSION_CHECK, continue_, "Continue (resume) a stopped application"}, - {_runners_ , AFB_SESSION_CHECK, runners, "Get the list of running applications"}, - {_state_ , AFB_SESSION_CHECK, state, "Get the state of a running application"}, - {_install_ , AFB_SESSION_CHECK, install, "Install an application using a widget file"}, - {_uninstall_, AFB_SESSION_CHECK, uninstall, "Uninstall an application"}, - { NULL, 0, NULL, NULL } -}; - -static const struct afb_binding plug_desc = { - .type = AFB_BINDING_VERSION_1, - .v1 = { - .info = "Application Framework Master Service", - .prefix = "afm-main", - .verbs = verbs - } -}; - -const struct afb_binding *afbBindingV1Register(const struct afb_binding_interface *itf) +static int init() { int rc; struct sd_bus *sbus; - /* records the interface */ - assert (binder == NULL); - binder = itf; - /* creates the jbus for accessing afm-user-daemon */ - sbus = afb_daemon_get_user_bus(itf->daemon); + sbus = afb_daemon_get_user_bus(); if (sbus == NULL) - return NULL; + return -1; jbus = create_jbus(sbus, "/org/AGL/afm/user"); if (jbus == NULL) - return NULL; + return -1; /* records the signal handler */ rc = jbus_on_signal_s(jbus, _changed_, application_list_changed, NULL); if (rc < 0) { jbus_unref(jbus); - return NULL; + return -1; } - return &plug_desc; + return 0; } +static const struct afb_verb_v2 verbs[] = +{ + {_runnables_, runnables, NULL, "Get list of runnable applications", AFB_SESSION_CHECK }, + {_detail_ , detail, NULL, "Get the details for one application", AFB_SESSION_CHECK }, + {_start_ , start, NULL, "Start an application", AFB_SESSION_CHECK }, + {_once_ , once, NULL, "Start once an application", AFB_SESSION_CHECK }, + {_terminate_, terminate, NULL, "Terminate a running application", AFB_SESSION_CHECK }, + {_pause_ , pause, NULL, "Pause a running application", AFB_SESSION_CHECK }, + {_resume_ , resume, NULL, "Resume a paused application", AFB_SESSION_CHECK }, + {_stop_ , pause, NULL, "Obsolete since 2016/11/08, use 'pause' instead", AFB_SESSION_CHECK }, + {_continue_ , resume, NULL, "Obsolete since 2016/11/08, use 'resume' instead", AFB_SESSION_CHECK }, + {_runners_ , runners, NULL, "Get the list of running applications", AFB_SESSION_CHECK }, + {_state_ , state, NULL, "Get the state of a running application", AFB_SESSION_CHECK }, + {_install_ , install, NULL, "Install an application using a widget file", AFB_SESSION_CHECK }, + {_uninstall_, uninstall, NULL, "Uninstall an application", AFB_SESSION_CHECK }, + { NULL, NULL, NULL, NULL, 0 } +}; + +const struct afb_binding_v2 afbBindingV2 = { + .api = "afm-main", + .specification = NULL, + .info = "Application Framework Master Service", + .verbs = verbs, + .preinit = NULL, + .init = init, + .onevent = NULL, + .noconcurrency = 0 +}; +