aboutsummaryrefslogtreecommitdiffstats
path: root/src/afb-api-so-v2.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-08-31 09:30:19 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-08-31 09:30:19 +0200
commit11e2d4395056c7bd2a618b4fa7ffdd70af05d14e (patch)
tree12088d06154a0f5f27b77a7eef2c131173964877 /src/afb-api-so-v2.c
parentbfffa28ba0483b49770326c4f567950ea80d0fb6 (diff)
afb-svc: make service existing during its initialisation
The initialisation of services is splitted in two parts: - the creation and allocation of the structure for the service. - the initialisation once the structure is ready and recorded. Change-Id: I05c89fb513869d45e6b8413699fba234f00ce6b1 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/afb-api-so-v2.c')
-rw-r--r--src/afb-api-so-v2.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/afb-api-so-v2.c b/src/afb-api-so-v2.c
index bc5ecdf7..038f1ce2 100644
--- a/src/afb-api-so-v2.c
+++ b/src/afb-api-so-v2.c
@@ -103,6 +103,7 @@ static void call_sync_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);
@@ -133,13 +134,24 @@ static int service_start_cb(void *closure, int share_session, int onneed, struct
}
/* get the event handler if any */
- desc->service = afb_svc_create_v2(desc->binding->api, apiset, share_session, start, onevent, desc->data);
+ desc->service = afb_svc_create(desc->binding->api, apiset, share_session, onevent, &desc->data->service);
if (desc->service == NULL) {
/* starting error */
ERROR("Starting service %s failed", desc->binding->api);
return -1;
}
+ /* Starts the service */
+ rc = afb_svc_start_v2(desc->service, start);
+ if (rc < 0) {
+ /* initialisation error */
+ ERROR("Initialisation of service %s failed (%d): %m", desc->binding->api, rc);
+ afb_svc_destroy(desc->service, &desc->data->service);
+ desc->service = NULL;
+ return rc;
+ }
+
+
return 0;
}