aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-06-29 19:34:06 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-06-29 19:38:23 +0200
commitcf1a7ea2bba1e0f2cc0d958148a1d488508c1a03 (patch)
tree80e192865e1339b8f554664b5f6900550d54adc7
parent974e868702e875fd9d9bdea63fd62ac26bc408db (diff)
Ability to add a plugin after the initial load
Plugins normally lie in a dedicated section and loaded once for all. With this function we are able to load a plugin after the initial load. Change-Id: Iebacdfce836767089f164ebe5cff72c7e45803be Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--ctl-lib/ctl-config.h1
-rw-r--r--ctl-lib/ctl-plugin.c60
2 files changed, 48 insertions, 13 deletions
diff --git a/ctl-lib/ctl-config.h b/ctl-lib/ctl-config.h
index 8d1a770..f86a96f 100644
--- a/ctl-lib/ctl-config.h
+++ b/ctl-lib/ctl-config.h
@@ -131,6 +131,7 @@ int ControlConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actions
int OnloadConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ);
// ctl-plugin.c
+int PluginAdd(AFB_ApiT apiHandle, CtlSectionT *section, json_object *newPluginsJ);
int PluginConfig(AFB_ApiT UNUSED_ARG(apiHandle), CtlSectionT *section, json_object *pluginsJ);
int PluginGetCB (AFB_ApiT apiHandle, CtlActionT *action , json_object *callbackJ);
diff --git a/ctl-lib/ctl-plugin.c b/ctl-lib/ctl-plugin.c
index 7458852..2bbae73 100644
--- a/ctl-lib/ctl-plugin.c
+++ b/ctl-lib/ctl-plugin.c
@@ -362,14 +362,58 @@ static int PluginLoad (AFB_ApiT apiHandle, CtlPluginT *ctlPlugin, json_object *p
return 0;
}
+static int PluginParse(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pluginsJ, int *pluginNb) {
+ int idx = 0, err = 0;
+
+ if (json_object_get_type(pluginsJ) == json_type_array) {
+ *pluginNb = (int)json_object_array_length(pluginsJ);
+ ctlPlugins = calloc (*pluginNb + 1, sizeof(CtlPluginT));
+ for (idx=0; idx < *pluginNb; idx++) {
+ json_object *pluginJ = json_object_array_get_idx(pluginsJ, idx);
+ err += PluginLoad(apiHandle, &ctlPlugins[idx], pluginJ, section->handle);
+ }
+ } else {
+ ctlPlugins = calloc (2, sizeof(CtlPluginT));
+ err += PluginLoad(apiHandle, &ctlPlugins[0], pluginsJ, section->handle);
+ (*pluginNb)++;
+ }
+
+ return err;
+}
int PluginConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pluginsJ) {
int err = 0;
- int idx = 0;
- int length = 0;
+ int idx = 0, jdx = 0;
+ int pluginNb = 0, newPluginsNb = 0, totalPluginNb = 0;
if (ctlPlugins)
{
+ // There is something to add let that happens
+ if(pluginsJ) {
+ CtlPluginT *ctlPluginsNew = NULL, *ctlPluginsOrig = ctlPlugins;
+ err = PluginParse(apiHandle, section, pluginsJ, &newPluginsNb);
+ ctlPluginsNew = ctlPlugins;
+
+ while(ctlPlugins[pluginNb].uid != NULL) {
+ pluginNb++;
+ }
+
+ totalPluginNb = pluginNb + newPluginsNb;
+ ctlPlugins = calloc(totalPluginNb + 1, sizeof(CtlPluginT));
+ while(ctlPluginsOrig[idx].uid != NULL) {
+ ctlPlugins[idx] = ctlPluginsOrig[idx];
+ idx++;
+ }
+ while(ctlPluginsNew[jdx].uid != NULL && idx <= totalPluginNb) {
+ ctlPlugins[idx] = ctlPluginsNew[jdx];
+ idx++;
+ jdx++;
+ }
+
+ free(ctlPluginsOrig);
+ free(ctlPluginsNew);
+ }
+
while(ctlPlugins[idx].uid != NULL)
{
// Jose hack to make verbosity visible from sharedlib and
@@ -381,17 +425,7 @@ int PluginConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pluginsJ
}
else
{
- if (json_object_get_type(pluginsJ) == json_type_array) {
- length = (int)json_object_array_length(pluginsJ);
- ctlPlugins = calloc (length+1, sizeof(CtlPluginT));
- for (idx=0; idx < length; idx++) {
- json_object *pluginJ = json_object_array_get_idx(pluginsJ, idx);
- err += PluginLoad(apiHandle, &ctlPlugins[idx], pluginJ, section->handle);
- }
- } else {
- ctlPlugins = calloc (2, sizeof(CtlPluginT));
- err += PluginLoad(apiHandle, &ctlPlugins[0], pluginsJ, section->handle);
- }
+ err = PluginParse(apiHandle, section, pluginsJ, &pluginNb);
}
return err;