X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-api-so-v1.c;h=c77ab72487ea4a123969d1215a83356e85ccdb82;hb=ac7a95223a6314cca6250495ea59c3cf7e46e89e;hp=ef73b343583709fc39f92ac37f3d920d9baf31bb;hpb=5659246230cef16abae4b1edda9791a1f25fc03d;p=src%2Fapp-framework-binder.git diff --git a/src/afb-api-so-v1.c b/src/afb-api-so-v1.c index ef73b343..c77ab724 100644 --- a/src/afb-api-so-v1.c +++ b/src/afb-api-so-v1.c @@ -67,59 +67,15 @@ static void call_cb(void *closure, struct afb_xreq *xreq) const struct afb_verb_desc_v1 *verb; struct api_so_v1 *desc = closure; - verb = search(desc, xreq->verb); + xreq->request.dynapi = (void*)desc->export; /* hack: this avoids to export afb_export structure */ + verb = search(desc, xreq->request.verb); afb_xreq_call_verb_v1(xreq, verb); } static int service_start_cb(void *closure, int share_session, int onneed, struct afb_apiset *apiset) { - int rc; - int (*init)(struct afb_service service); - void (*onevent)(const char *event, struct json_object *object); - struct api_so_v1 *desc = closure; - - /* check state */ - if (afb_export_is_started(desc->export)) { - /* not an error when onneed */ - if (onneed != 0) - goto done; - - /* already started: it is an error */ - ERROR("Service %s already started", afb_export_apiname(desc->export)); - return -1; - } - - /* get the initialisation */ - init = dlsym(desc->handle, afb_api_so_v1_service_init); - onevent = dlsym(desc->handle, afb_api_so_v1_service_event); - - /* unshare the session if asked */ - if (!share_session) { - rc = afb_export_unshare_session(desc->export); - if (rc < 0) { - ERROR("Can't unshare the session for %s", afb_export_apiname(desc->export)); - return -1; - } - } - - /* set event handling */ - rc = afb_export_handle_events(desc->export, onevent); - if (rc < 0) { - ERROR("Can't set event handler for %s", afb_export_apiname(desc->export)); - return -1; - } - - /* Starts the service */ - rc = afb_export_start_v1(desc->export, init); - if (rc < 0) { - /* initialisation error */ - ERROR("Initialisation of service %s failed (%d): %m", afb_export_apiname(desc->export), rc); - return rc; - } - -done: - return 0; + return afb_export_start(desc->export, share_session, onneed, apiset); } static void update_hooks_cb(void *closure) @@ -243,6 +199,8 @@ int afb_api_so_v1_add(const char *path, void *handle, struct afb_apiset *apiset) { struct api_so_v1 *desc; struct afb_binding_v1 *(*register_function) (const struct afb_binding_interface_v1 *interface); + int (*init)(struct afb_service service); + void (*onevent)(const char *event, struct json_object *object); struct afb_api afb_api; struct afb_export *export; @@ -253,7 +211,9 @@ int afb_api_so_v1_add(const char *path, void *handle, struct afb_apiset *apiset) INFO("binding [%s] is a valid AFB binding V1", path); /* allocates the description */ - export = afb_export_create_v1(path); + init = dlsym(handle, afb_api_so_v1_service_init); + onevent = dlsym(handle, afb_api_so_v1_service_event); + export = afb_export_create_v1(apiset, path, init, onevent); desc = calloc(1, sizeof *desc); if (desc == NULL || export == NULL) { ERROR("out of memory"); @@ -279,7 +239,7 @@ int afb_api_so_v1_add(const char *path, void *handle, struct afb_apiset *apiset) ERROR("binding [%s] bad prefix...", path); goto error; } - if (!afb_api_is_valid_name(desc->binding->v1.prefix)) { + if (!afb_api_is_valid_name(desc->binding->v1.prefix, 1)) { ERROR("binding [%s] invalid prefix...", path); goto error; } @@ -297,7 +257,7 @@ int afb_api_so_v1_add(const char *path, void *handle, struct afb_apiset *apiset) afb_export_rename(desc->export, desc->binding->v1.prefix); afb_api.closure = desc; afb_api.itf = &so_v1_api_itf; - afb_api.noconcurrency = 0; + afb_api.group = NULL; if (afb_apiset_add(apiset, afb_export_apiname(desc->export), afb_api) < 0) { ERROR("binding [%s] can't be registered...", path); goto error;