X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-api-so-v1.c;h=ad7a0cdd3c5451ca166ca622289a32eff1ce6801;hb=e51d68ddc998f558507217e3c849b16ce94c068f;hp=7e987c22aca39c1a1aacdcdf1b8e32fa5e2a64a0;hpb=e48b6fb595d90509d70f850244fc962f8440a14b;p=src%2Fapp-framework-binder.git diff --git a/src/afb-api-so-v1.c b/src/afb-api-so-v1.c index 7e987c22..ad7a0cdd 100644 --- a/src/afb-api-so-v1.c +++ b/src/afb-api-so-v1.c @@ -16,7 +16,6 @@ */ #define _GNU_SOURCE -#define AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO #include #include @@ -78,6 +77,7 @@ 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 (*init)(struct afb_service service); void (*onevent)(const char *event, struct json_object *object); @@ -87,7 +87,7 @@ static int service_start_cb(void *closure, int share_session, int onneed, struct if (desc->service != NULL) { /* not an error when onneed */ if (onneed != 0) - return 0; + goto done; /* already started: it is an error */ ERROR("Service %s already started", desc->binding->v1.prefix); @@ -100,7 +100,7 @@ static int service_start_cb(void *closure, int share_session, int onneed, struct if (init == NULL && onevent == NULL) { /* not an error when onneed */ if (onneed != 0) - return 0; + goto done; /* no initialisation method */ ERROR("Binding %s is not a service", desc->binding->v1.prefix); @@ -108,13 +108,25 @@ static int service_start_cb(void *closure, int share_session, int onneed, struct } /* get the event handler if any */ - desc->service = afb_svc_create_v1(desc->binding->v1.prefix, apiset, share_session, init, onevent); + desc->service = afb_svc_create(desc->binding->v1.prefix, apiset, share_session, onevent, NULL); if (desc->service == NULL) { - /* starting error */ - ERROR("Starting service %s failed", desc->binding->v1.prefix); + ERROR("Creation of service %s failed", desc->binding->v1.prefix); return -1; } + /* Starts the service */ + desc->ditf.state = Daemon_Init; + rc = afb_svc_start_v1(desc->service, init); + if (rc < 0) { + /* initialisation error */ + ERROR("Initialisation of service %s failed (%d): %m", desc->binding->v1.prefix, rc); + afb_svc_destroy(desc->service, NULL); + desc->service = NULL; + return rc; + } + +done: + desc->ditf.state = Daemon_Run; return 0; } @@ -294,6 +306,7 @@ int afb_api_so_v1_add(const char *path, void *handle, struct afb_apiset *apiset) afb_ditf_rename(&desc->ditf, desc->binding->v1.prefix); afb_api.closure = desc; afb_api.itf = &so_v1_api_itf; + afb_api.noconcurrency = 0; if (afb_apiset_add(apiset, desc->binding->v1.prefix, afb_api) < 0) { ERROR("binding [%s] can't be registered...", path); goto error2;