Record API names in service descriptors
authorJosé Bollo <jose.bollo@iot.bzh>
Tue, 30 May 2017 08:41:56 +0000 (10:41 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Tue, 30 May 2017 08:41:56 +0000 (10:41 +0200)
Change-Id: Ie437a6987df7f27a4a68b9c022d8cad8ab4f2cfe
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afb-api-so-v1.c
src/afb-api-so-v2.c
src/afb-svc.c
src/afb-svc.h

index f367820..b7b29e4 100644 (file)
@@ -108,7 +108,7 @@ 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(apiset, share_session, init, onevent);
+       desc->service = afb_svc_create_v1(desc->binding->v1.prefix, apiset, share_session, init, onevent);
        if (desc->service == NULL) {
                /* starting error */
                ERROR("Starting service %s failed", desc->binding->v1.prefix);
index 1c5fe52..11fa334 100644 (file)
@@ -133,7 +133,7 @@ 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(apiset, share_session, start, onevent, desc->data);
+       desc->service = afb_svc_create_v2(desc->binding->api, apiset, share_session, start, onevent, desc->data);
        if (desc->service == NULL) {
                /* starting error */
                ERROR("Starting service %s failed", desc->binding->api);
index b492520..fad1328 100644 (file)
@@ -42,6 +42,9 @@
  */
 struct afb_svc
 {
+       /* api/prefix */
+       const char *api;
+
        /* session of the service */
        struct afb_session *session;
 
@@ -128,6 +131,7 @@ static void svc_free(struct afb_svc *svc)
  * Allocates a new service
  */
 static struct afb_svc *afb_svc_alloc(
+                       const char *api,
                        struct afb_apiset *apiset,
                        int share_session
 )
@@ -142,6 +146,7 @@ static struct afb_svc *afb_svc_alloc(
        }
 
        /* instanciate the apiset */
+       svc->api = api;
        svc->apiset = afb_apiset_addref(apiset);
 
        /* instanciate the session */
@@ -171,17 +176,18 @@ error:
  * Creates a new service
  */
 struct afb_svc *afb_svc_create_v1(
-               struct afb_apiset *apiset,
-               int share_session,
-               int (*start)(struct afb_service service),
-               void (*on_event)(const char *event, struct json_object *object)
+                       const char *api,
+                       struct afb_apiset *apiset,
+                       int share_session,
+                       int (*start)(struct afb_service service),
+                       void (*on_event)(const char *event, struct json_object *object)
 )
 {
        int rc;
        struct afb_svc *svc;
 
        /* allocates the svc handler */
-       svc = afb_svc_alloc(apiset, share_session);
+       svc = afb_svc_alloc(api, apiset, share_session);
        if (svc == NULL)
                goto error;
 
@@ -211,6 +217,7 @@ error:
  * Creates a new service
  */
 struct afb_svc *afb_svc_create_v2(
+                       const char *api,
                        struct afb_apiset *apiset,
                        int share_session,
                        int (*start)(),
@@ -222,7 +229,7 @@ struct afb_svc *afb_svc_create_v2(
        struct afb_svc *svc;
 
        /* allocates the svc handler */
-       svc = afb_svc_alloc(apiset, share_session);
+       svc = afb_svc_alloc(api, apiset, share_session);
        if (svc == NULL)
                goto error;
        data->service = to_afb_service(svc);
index 347716d..84b03d8 100644 (file)
@@ -23,12 +23,14 @@ struct afb_apiset;
 struct afb_binding_data_v2;
 
 extern struct afb_svc *afb_svc_create_v1(
+                       const char *api,
                        struct afb_apiset *apiset,
                        int share_session,
                        int (*start)(struct afb_service service),
                        void (*on_event)(const char *event, struct json_object *object));
 
 extern struct afb_svc *afb_svc_create_v2(
+                       const char *api,
                        struct afb_apiset *apiset,
                        int share_session,
                        int (*start)(),