afb-export: record apiset at creation
authorJosé Bollo <jose.bollo@iot.bzh>
Thu, 21 Sep 2017 16:17:39 +0000 (18:17 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Mon, 9 Oct 2017 12:08:32 +0000 (14:08 +0200)
Change-Id: I058eaee990e34990d0860a316ba8c348c23eff5f
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afb-api-so-v1.c
src/afb-api-so-v2.c
src/afb-export.c
src/afb-export.h

index c69f294..d7429ef 100644 (file)
@@ -212,7 +212,7 @@ int afb_api_so_v1_add(const char *path, void *handle, struct afb_apiset *apiset)
        /* allocates the description */
        init = dlsym(handle, afb_api_so_v1_service_init);
        onevent = dlsym(handle, afb_api_so_v1_service_event);
-       export = afb_export_create_v1(path, init, onevent);
+       export = afb_export_create_v1(apiset, path, init, onevent);
        desc = calloc(1, sizeof *desc);
        if (desc == NULL || export == NULL) {
                ERROR("out of memory");
index fef6eb2..edc31d5 100644 (file)
@@ -168,7 +168,7 @@ int afb_api_so_v2_add_binding(const struct afb_binding_v2 *binding, void *handle
        assert(data);
 
        /* allocates the description */
-       export = afb_export_create_v2(binding->api, data, binding->init, binding->onevent);
+       export = afb_export_create_v2(apiset, binding->api, data, binding->init, binding->onevent);
        desc = calloc(1, sizeof *desc);
        if (!desc || !export) {
                ERROR("out of memory");
index 2f16b37..90507b6 100644 (file)
@@ -39,7 +39,6 @@
 #include "jobs.h"
 #include "verbose.h"
 
-extern struct afb_apiset *main_apiset;
 
 /*************************************************************************
  * internal types and structures
@@ -206,7 +205,7 @@ static int require_api_cb(void *closure, const char *name, int initialized)
                errno = EINVAL;
                return -1;
        }
-       return -!(initialized ? afb_apiset_lookup_started : afb_apiset_lookup)(main_apiset, name, 1);
+       return -!(initialized ? afb_apiset_lookup_started : afb_apiset_lookup)(export->apiset, name, 1);
 }
 
 static int rename_api_cb(void *closure, const char *name)
@@ -687,7 +686,7 @@ static const struct afb_evt_itf evt_v12_itf = {
  *************************************************************************************************************
  *************************************************************************************************************/
 
-static struct afb_export *create(const char *apiname, enum afb_api_version version)
+static struct afb_export *create(struct afb_apiset *apiset, const char *apiname, enum afb_api_version version)
 {
        struct afb_export *export;
 
@@ -706,7 +705,7 @@ static struct afb_export *create(const char *apiname, enum afb_api_version versi
                export->version = version;
                export->state = Api_State_Pre_Init;
                export->session = afb_session_addref(common_session);
-               export->apiset = afb_apiset_addref(main_apiset);
+               export->apiset = afb_apiset_addref(apiset);
        }
        return export;
 }
@@ -723,9 +722,9 @@ void afb_export_destroy(struct afb_export *export)
        }
 }
 
-struct afb_export *afb_export_create_v1(const char *apiname, int (*init)(struct afb_service), void (*onevent)(const char*, struct json_object*))
+struct afb_export *afb_export_create_v1(struct afb_apiset *apiset, const char *apiname, int (*init)(struct afb_service), void (*onevent)(const char*, struct json_object*))
 {
-       struct afb_export *export = create(apiname, Api_Version_1);
+       struct afb_export *export = create(apiset, apiname, Api_Version_1);
        if (export) {
                export->init.v1 = init;
                export->on_event.v12 = onevent;
@@ -737,9 +736,9 @@ struct afb_export *afb_export_create_v1(const char *apiname, int (*init)(struct
        return export;
 }
 
-struct afb_export *afb_export_create_v2(const char *apiname, struct afb_binding_data_v2 *data, int (*init)(), void (*onevent)(const char*, struct json_object*))
+struct afb_export *afb_export_create_v2(struct afb_apiset *apiset, const char *apiname, struct afb_binding_data_v2 *data, int (*init)(), void (*onevent)(const char*, struct json_object*))
 {
-       struct afb_export *export = create(apiname, Api_Version_2);
+       struct afb_export *export = create(apiset, apiname, Api_Version_2);
        if (export) {
                export->init.v2 = init;
                export->on_event.v12 = onevent;
index 853fc5d..9bd0820 100644 (file)
@@ -24,8 +24,9 @@ struct afb_service;
 struct afb_binding_data_v2;
 struct afb_binding_interface_v1;
 
-extern struct afb_export *afb_export_create_v1(const char *apiname, int (*init)(struct afb_service), void (*onevent)(const char*, struct json_object*));
-extern struct afb_export *afb_export_create_v2(const char *apiname, struct afb_binding_data_v2 *data, int (*init)(), void (*onevent)(const char*, struct json_object*));
+extern struct afb_export *afb_export_create_v1(struct afb_apiset *apiset, const char *apiname, int (*init)(struct afb_service), void (*onevent)(const char*, struct json_object*));
+extern struct afb_export *afb_export_create_v2(struct afb_apiset *apiset, const char *apiname, struct afb_binding_data_v2 *data, int (*init)(), void (*onevent)(const char*, struct json_object*));
+
 extern void afb_export_destroy(struct afb_export *export);
 
 extern const char *afb_export_apiname(const struct afb_export *export);