afb-api-so-v2: split the declaration in two parts
authorJosé Bollo <jose.bollo@iot.bzh>
Fri, 21 Apr 2017 17:01:31 +0000 (19:01 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Fri, 21 Apr 2017 17:01:31 +0000 (19:01 +0200)
Having a part not linked to an existing opened shared library
might be useful for internal APIS.

Change-Id: I56348f07c87f6844682e3ea56dc07d7ee296bfbf
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afb-api-so-v2.c
src/afb-api-so-v2.h

index 6038d96..6ac1fa7 100644 (file)
@@ -141,37 +141,16 @@ static struct afb_api_itf so_v2_api_itf = {
        .set_verbosity = set_verbosity_cb
 };
 
-int afb_api_so_v2_add(const char *path, void *handle, struct afb_apiset *apiset)
+int afb_api_so_v2_add_binding(struct afb_binding_v2 *binding, void *handle, struct afb_apiset *apiset)
 {
        int rc;
        struct api_so_v2 *desc;
-       struct afb_binding_v2 *binding;
        struct afb_api afb_api;
 
-       /* retrieves the register function */
-       binding = dlsym(handle, afb_api_so_v2_descriptor);
-       if (!binding)
-               return 0;
-
-       INFO("binding [%s] looks like an AFB binding V2", path);
-
        /* basic checks */
-       if (binding->api == NULL || *binding->api == 0) {
-               ERROR("binding [%s] bad api name...", path);
-               goto error;
-       }
-       if (!afb_api_is_valid_name(binding->api)) {
-               ERROR("binding [%s] invalid api name...", path);
-               goto error;
-       }
-       if (binding->specification == NULL || *binding->specification == 0) {
-               ERROR("binding [%s] bad specification...", path);
-               goto error;
-       }
-       if (binding->verbs == NULL) {
-               ERROR("binding [%s] no verbs...", path);
-               goto error;
-       }
+       assert(binding->api);
+       assert(binding->specification);
+       assert(binding->verbs);
 
        /* allocates the description */
        desc = calloc(1, sizeof *desc);
@@ -185,14 +164,12 @@ int afb_api_so_v2_add(const char *path, void *handle, struct afb_apiset *apiset)
        /* init the interface */
        afb_ditf_init(&desc->ditf, binding->api);
 
-       /* for log purpose, a fake binding is needed here */
-
        /* init the binding */
        if (binding->init) {
-               NOTICE("binding %s [%s] calling init function", binding->api, path);
+               INFO("binding %s calling init function", binding->api);
                rc = binding->init(&desc->ditf.interface);
                if (rc < 0) {
-                       ERROR("binding %s [%s] initialisation function failed...", binding->api, path);
+                       ERROR("binding %s initialisation function failed...", binding->api);
                        goto error2;
                }
        }
@@ -201,10 +178,10 @@ int afb_api_so_v2_add(const char *path, void *handle, struct afb_apiset *apiset)
        afb_api.closure = desc;
        afb_api.itf = &so_v2_api_itf;
        if (afb_apiset_add(apiset, binding->api, afb_api) < 0) {
-               ERROR("binding [%s] can't be registered...", path);
+               ERROR("binding %s can't be registered to set %s...", binding->api, afb_apiset_name(apiset));
                goto error2;
        }
-       NOTICE("binding %s loaded with API prefix %s", path, binding->api);
+       NOTICE("binding %s added to set %s", binding->api, afb_apiset_name(apiset));
        return 1;
 
 error2:
@@ -213,3 +190,38 @@ error:
        return -1;
 }
 
+int afb_api_so_v2_add(const char *path, void *handle, struct afb_apiset *apiset)
+{
+       struct afb_binding_v2 *binding;
+
+       /* retrieves the register function */
+       binding = dlsym(handle, afb_api_so_v2_descriptor);
+       if (!binding)
+               return 0;
+
+       INFO("binding [%s] looks like an AFB binding V2", path);
+
+       /* basic checks */
+       if (binding->api == NULL || *binding->api == 0) {
+               ERROR("binding [%s] bad api name...", path);
+               goto error;
+       }
+       if (!afb_api_is_valid_name(binding->api)) {
+               ERROR("binding [%s] invalid api name...", path);
+               goto error;
+       }
+       if (binding->specification == NULL || *binding->specification == 0) {
+               ERROR("binding [%s] bad specification...", path);
+               goto error;
+       }
+       if (binding->verbs == NULL) {
+               ERROR("binding [%s] no verbs...", path);
+               goto error;
+       }
+
+       return afb_api_so_v2_add_binding(binding, handle, apiset);
+
+ error:
+       return -1;
+}
+
index 2807897..180e61a 100644 (file)
@@ -18,4 +18,8 @@
 
 #pragma once
 
+struct afb_apiset;
+struct afb_binding_v2;
+
 extern int afb_api_so_v2_add(const char *path, void *handle, struct afb_apiset *apiset);
+extern int afb_api_so_v2_add_binding(struct afb_binding_v2 *binding, void *handle, struct afb_apiset *apiset);