From a289811d452020de3aa03cd2d9c1d21e4386c241 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Fri, 21 Apr 2017 19:01:31 +0200 Subject: [PATCH] afb-api-so-v2: split the declaration in two parts MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- src/afb-api-so-v2.c | 74 +++++++++++++++++++++++++++++++---------------------- src/afb-api-so-v2.h | 4 +++ 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); -- 2.16.6