summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-04-21 19:01:31 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-04-21 19:01:31 +0200
commita289811d452020de3aa03cd2d9c1d21e4386c241 (patch)
treee9c3e7713b325eaf21d4843e09709acebdb6855d
parentc6046d8d5fda932fa61e3396fdbdfc1614fbe028 (diff)
afb-api-so-v2: split the declaration in two parts
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>
-rw-r--r--src/afb-api-so-v2.c74
-rw-r--r--src/afb-api-so-v2.h4
2 files changed, 47 insertions, 31 deletions
diff --git a/src/afb-api-so-v2.c b/src/afb-api-so-v2.c
index 6038d964..6ac1fa70 100644
--- a/src/afb-api-so-v2.c
+++ b/src/afb-api-so-v2.c
@@ -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;
+}
+
diff --git a/src/afb-api-so-v2.h b/src/afb-api-so-v2.h
index 28078973..180e61ae 100644
--- a/src/afb-api-so-v2.h
+++ b/src/afb-api-so-v2.h
@@ -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);