X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafm-binding.c;h=34880fc78f6c3da2ba239fb92f46401034900388;hb=refs%2Fheads%2Fguppy;hp=5fb1f73d32e66bb3468089b34459bfc410862af4;hpb=bceaf2cc403176fd808d4e00be893671be3f4bb0;p=src%2Fapp-framework-main.git diff --git a/src/afm-binding.c b/src/afm-binding.c index 5fb1f73..34880fc 100644 --- a/src/afm-binding.c +++ b/src/afm-binding.c @@ -41,6 +41,7 @@ * constant strings */ static const char _added_[] = "added"; +static const char _all_[] = "all"; static const char _a_l_c_[] = "application-list-changed"; static const char _bad_request_[] = "bad-request"; static const char _cannot_start_[] = "cannot-start"; @@ -49,6 +50,7 @@ static const char _id_[] = "id"; static const char _install_[] = "install"; static const char _lang_[] = "lang"; static const char _not_found_[] = "not-found"; +static const char _not_running_[] = "not-running"; static const char _once_[] = "once"; static const char _pause_[] = "pause"; static const char _resume_[] = "resume"; @@ -187,6 +189,12 @@ static void not_found(afb_req_t req) afb_req_fail(req, _not_found_, NULL); } +/* common not running reply */ +static void not_running(afb_req_t req) +{ + afb_req_fail(req, _not_running_, NULL); +} + /* common can't start reply */ static void cant_start(afb_req_t req) { @@ -219,6 +227,18 @@ static const char *get_lang(afb_req_t req) return lang; } +/* + * Retrieve whether all is required from 'req'. + */ +static int get_all(afb_req_t req) +{ + struct json_object *val; + + /* get the optional language */ + return json_object_object_get_ex(afb_req_json(req), _all_, &val) + && json_object_get_boolean(val); +} + /* * retrieves the 'appid' in parameters received with the @@ -237,7 +257,7 @@ static int onappid(afb_req_t req, const char *method, const char **appid) /* get the appid if any */ if (!wrap_json_unpack(json, "s", appid) - || !wrap_json_unpack(json, "{si}", _id_, appid)) { + || !wrap_json_unpack(json, "{ss}", _id_, appid)) { /* found */ INFO("method %s called for %s", method, *appid); return 1; @@ -283,7 +303,10 @@ static int onrunid(afb_req_t req, const char *method, int *runid) /* nothing appropriate */ INFO("method %s can't get runid for %s: %m", method, appid); - not_found(req); + if (errno == ESRCH) + not_running(req); + else + not_found(req); return 0; } @@ -318,14 +341,18 @@ static void reply_status(afb_req_t req, int status) */ static void runnables(afb_req_t req) { + int all; const char *lang; struct json_object *resp; /* get the language */ lang = get_lang(req); + /* get the all */ + all = get_all(req); + /* get the details */ - resp = afm_udb_applications_public(afudb, afb_req_get_uid(req), lang); + resp = afm_udb_applications_public(afudb, all, afb_req_get_uid(req), lang); afb_req_success(req, resp, NULL); } @@ -463,8 +490,10 @@ static void terminate(afb_req_t req) */ static void runners(afb_req_t req) { + int all; struct json_object *resp; - resp = afm_urun_list(afudb, afb_req_get_uid(req)); + all = get_all(req); + resp = afm_urun_list(afudb, all, afb_req_get_uid(req)); afb_req_success(req, resp, NULL); } @@ -575,7 +604,7 @@ static int init(afb_api_t api) json_true = json_object_new_boolean(1); /* init database */ - afudb = afm_udb_create(1, 0, "afm-appli-"); + afudb = afm_udb_create(1, 0, "afm-"); if (!afudb) { ERROR("afm_udb_create failed"); return -1;