X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-api-so-v2.c;h=9d4caeeb2f933dac8103e3040eac4bad2150cd5f;hb=34fa1fb6de1c449b81b9a19fda21c2963eb57f3f;hp=dcefc76934c919ec5e10b2ee39616f06ce1e3898;hpb=5659246230cef16abae4b1edda9791a1f25fc03d;p=src%2Fapp-framework-binder.git diff --git a/src/afb-api-so-v2.c b/src/afb-api-so-v2.c index dcefc769..9d4caeeb 100644 --- a/src/afb-api-so-v2.c +++ b/src/afb-api-so-v2.c @@ -73,53 +73,8 @@ static void call_cb(void *closure, struct afb_xreq *xreq) static int service_start_cb(void *closure, int share_session, int onneed, struct afb_apiset *apiset) { - int rc; - int (*start)(); - void (*onevent)(const char *event, struct json_object *object); - struct api_so_v2 *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 */ - start = desc->binding->init; - onevent = desc->binding->onevent; - - /* 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_v2(desc->export, start); - 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) @@ -286,7 +241,7 @@ int afb_api_so_v2_add_binding(const struct afb_binding_v2 *binding, void *handle assert(data); /* allocates the description */ - export = afb_export_create_v2(binding->api, data); + export = afb_export_create_v2(binding->api, data, binding->init, binding->onevent); desc = calloc(1, sizeof *desc); if (desc == NULL) { ERROR("out of memory"); @@ -309,7 +264,7 @@ int afb_api_so_v2_add_binding(const struct afb_binding_v2 *binding, void *handle /* records the binding */ afb_api.closure = desc; afb_api.itf = &so_v2_api_itf; - afb_api.noconcurrency = binding->noconcurrency; + afb_api.group = binding->noconcurrency ? export : NULL; if (afb_apiset_add(apiset, afb_export_apiname(desc->export), afb_api) < 0) { ERROR("binding %s can't be registered to set %s...", afb_export_apiname(desc->export), afb_apiset_name(apiset)); goto error;