X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-apiset.c;h=18104a93de571fa0b66437e725cbfaf78b4affef;hb=197626868aaf84e9a68e8e7e5397ef1c6883a0f1;hp=f41c88c00496c0ac49654c6fa7e79991e4b99f10;hpb=9b2c70bf87bb3272cb325f3a9ecf69cd0bd53ba8;p=src%2Fapp-framework-binder.git diff --git a/src/afb-apiset.c b/src/afb-apiset.c index f41c88c0..18104a93 100644 --- a/src/afb-apiset.c +++ b/src/afb-apiset.c @@ -31,8 +31,6 @@ #include "afb-xreq.h" #include "jobs.h" -#include - #define INCR 8 /* CAUTION: must be a power of 2 */ /** @@ -251,7 +249,7 @@ int afb_apiset_add(struct afb_apiset *set, const char *name, struct afb_api api) apis->name = name; set->count++; - NOTICE("API %s added", name); + INFO("API %s added", name); return 0; @@ -308,6 +306,17 @@ int afb_apiset_lookup(struct afb_apiset *set, const char *name, struct afb_api * return -1; } +/** + * Check whether the 'set' has the API of 'name' + * @param set the set of API + * @param name the name of the API to get + * @return 1 if the api exist or 0 otherwise + */ +int afb_apiset_has(struct afb_apiset *set, const char *name) +{ + return !!search(set, name); +} + /** * Get from the 'set' the API of 'name' in 'api' with fallback to subset or default api * @param set the set of API @@ -352,6 +361,8 @@ int afb_apiset_get(struct afb_apiset *set, const char *name, struct afb_api *api */ static int start_api(struct afb_apiset *set, struct api_desc *api, int share_session, int onneed) { + int rc; + if (api->status == 0) return 0; else if (api->status > 0) { @@ -359,22 +370,24 @@ static int start_api(struct afb_apiset *set, struct api_desc *api, int share_ses return -1; } + INFO("API %s starting...", api->name); if (api->api.itf->service_start) { api->status = EBUSY; - if (api->api.itf->service_start(api->api.closure, share_session, onneed, set) >= 0) - api->status = 0; - else if (errno) + rc = api->api.itf->service_start(api->api.closure, share_session, onneed, set); + if (rc < 0) { api->status = errno ?: ECANCELED; - } else { - if (onneed) - api->status = 0; - else { - /* already started: it is an error */ - ERROR("The api %s is not a startable service", api->name); - api->status = EINVAL; + ERROR("The api %s failed to start (%d)", api->name, rc); + return -1; } + } else if (!onneed) { + /* already started: it is an error */ + ERROR("The api %s is not a startable service", api->name); + api->status = EINVAL; + return -1; } - return -!!api->status; + NOTICE("API %s started", api->name); + api->status = 0; + return 0; } /** @@ -492,9 +505,10 @@ void afb_apiset_set_verbosity(struct afb_apiset *set, const char *name, int leve } /** - * Set the verbosity level of the 'api' + * Get the verbosity level of the 'api' * @param set the api set - * @param name the api to set (NULL set all) + * @param name the api to get + * @return the verbosity level or -1 in case of error */ int afb_apiset_get_verbosity(struct afb_apiset *set, const char *name) { @@ -505,12 +519,27 @@ int afb_apiset_get_verbosity(struct afb_apiset *set, const char *name) errno = ENOENT; return -1; } + if (!i->api.itf->get_verbosity) return verbosity; return i->api.itf->get_verbosity(i->api.closure); } +/** + * Get the description of the API of 'name' + * @param set the api set + * @param name the api whose description is required + * @return the description or NULL + */ +struct json_object *afb_apiset_describe(struct afb_apiset *set, const char *name) +{ + const struct api_desc *i; + + i = name ? search(set, name) : NULL; + return i && i->api.itf->describe ? i->api.itf->describe(i->api.closure) : NULL; +} + /** * Get the list of api names * @param set the api set