aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-09-11 11:09:15 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-09-14 10:42:24 +0200
commit0176d185790649daad4384d1712ca1c7070ac561 (patch)
tree6a242b614e373d51a4f79fd438422b6cc31717e8
parentd6eb01e14f2340c950ff8476d7b112f91297aae2 (diff)
Add an Init step to the plugins load
The onload step could be considered as a preinit step. Init stage happens once all plugins are loaded and so you can refer to them to add new actions or configuration elements. Change-Id: I7986265bb1227208d0648bb2c56a1172b164faf1 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--ctl-lib/ctl-plugin.c11
-rw-r--r--ctl-lib/ctl-plugin.h1
2 files changed, 11 insertions, 1 deletions
diff --git a/ctl-lib/ctl-plugin.c b/ctl-lib/ctl-plugin.c
index d27b71d..3dfecd9 100644
--- a/ctl-lib/ctl-plugin.c
+++ b/ctl-lib/ctl-plugin.c
@@ -438,8 +438,17 @@ int PluginConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pluginsJ
{
// Jose hack to make verbosity visible from sharedlib and
// be able to call verb from others api inside the binder
- struct afb_binding_data_v2 *afbHidenData = dlsym(ctlPlugins[idx++].dlHandle, "afbBindingV2data");
+ struct afb_binding_data_v2 *afbHidenData = dlsym(ctlPlugins[idx].dlHandle, "afbBindingV2data");
if (afbHidenData) *afbHidenData = afbBindingV2data;
+
+ DispatchPluginInstallCbT ctlPluginInit = dlsym(ctlPlugins[idx].dlHandle, "CtlPluginInit");
+ if (ctlPluginInit) {
+ if((*ctlPluginInit) (&ctlPlugins[idx], ctlPlugins[idx].context)) {
+ AFB_ApiError(apiHandle, "Plugin Init function hasn't finish well. Abort initialization");
+ return -1;
+ }
+ }
+ idx++;
}
return 0;
}
diff --git a/ctl-lib/ctl-plugin.h b/ctl-lib/ctl-plugin.h
index e4b8ccb..8d9b083 100644
--- a/ctl-lib/ctl-plugin.h
+++ b/ctl-lib/ctl-plugin.h
@@ -122,6 +122,7 @@ typedef int(*DispatchPluginInstallCbT)(CtlPluginT *plugin, void* handle);
#define MACRO_STR_VALUE(arg) #arg
#define CTLP_CAPI_REGISTER(pluglabel) CtlPluginMagicT CtlPluginMagic={.uid=pluglabel,.magic=CTL_PLUGIN_MAGIC}; struct afb_binding_data_v2;
#define CTLP_ONLOAD(plugin, handle) int CtlPluginOnload(CtlPluginT *plugin, void* handle)
+#define CTLP_INIT(plugin, handle) int CtlPluginInit(CtlPluginT *plugin, void* handle)
#define CTLP_CAPI(funcname, source, argsJ, queryJ) int funcname(CtlSourceT *source, json_object* argsJ, json_object* queryJ)
// LUA2c Wrapper macro. Allows to call C code from Lua script