X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafm-user-daemon.c;h=a180be616c0dec90a313a44d077acb2864115ff6;hb=a1ae7c362b0b7a65cad813a8def6c8eae72f33b2;hp=e71e011278d8a98abcc36a9553da34b0bd2f6fd8;hpb=011a41f695cbc7aa5deca2dcee77ccf9d21f5823;p=src%2Fapp-framework-main.git diff --git a/src/afm-user-daemon.c b/src/afm-user-daemon.c index e71e011..a180be6 100644 --- a/src/afm-user-daemon.c +++ b/src/afm-user-daemon.c @@ -1,5 +1,5 @@ /* - Copyright 2015, 2016 IoT.bzh + Copyright 2015, 2016, 2017 IoT.bzh author: José Bollo @@ -185,7 +185,6 @@ static void on_detail(struct sd_bus_message *smsg, struct json_object *obj, void json_object_put(resp); } - /* * On query "start" from 'smsg' with parameters of 'obj'. */ @@ -253,6 +252,42 @@ static void on_start(struct sd_bus_message *smsg, struct json_object *obj, void free(uri); } +/* + * On query "once" from 'smsg' with parameters of 'obj'. + */ +static void on_once(struct sd_bus_message *smsg, struct json_object *obj, void *unused) +{ + const char *appid; + struct json_object *appli, *resp; + int runid; + + /* get the parameters */ + if (!j_read_string(obj, &appid) && !j_read_string_at(obj, "id", &appid)) { + jbus_reply_error_s(smsg, error_bad_request); + return; + } + + /* get the application */ + INFO("method once called for %s", appid); + appli = afm_db_get_application(afdb, appid); + if (appli == NULL) { + jbus_reply_error_s(smsg, error_not_found); + return; + } + + /* launch the application */ + runid = afm_run_once(appli); + if (runid <= 0) { + jbus_reply_error_s(smsg, error_cant_start); + return; + } + + /* returns the state */ + resp = afm_run_state(runid); + reply(smsg, resp, error_not_found); + json_object_put(resp); +} + /* * On query "pause" from 'smsg' with parameters of 'obj'. */ @@ -416,7 +451,7 @@ static int open_bus(sd_bus **ret, int isuser, const char *address) int rc; if (address == NULL) - return (isuser ? sd_bus_open_user : sd_bus_open_system)(ret); + return (isuser ? sd_bus_default_user : sd_bus_default_system)(ret); rc = sd_bus_new(&b); if (rc < 0) @@ -600,6 +635,7 @@ int main(int ac, char **av) if (jbus_add_service_j(user_bus, "runnables", on_runnables, NULL) || jbus_add_service_j(user_bus, "detail", on_detail, NULL) || jbus_add_service_j(user_bus, "start", on_start, NULL) + || jbus_add_service_j(user_bus, "once", on_once, NULL) || jbus_add_service_j(user_bus, "terminate", on_terminate, NULL) || jbus_add_service_j(user_bus, "pause", on_pause, NULL) || jbus_add_service_j(user_bus, "resume", on_resume, NULL)