summaryrefslogtreecommitdiffstats
path: root/ctl-lib
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-09-13 15:01:13 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-09-14 10:42:24 +0200
commitbc13eeff8c7fd9af8c6a7ab16ba924f1f942353e (patch)
tree81b92b5e1bef596434b45406421c5793ed0c0cda /ctl-lib
parent0176d185790649daad4384d1712ca1c7070ac561 (diff)
Add ctlPlugins array to the ctlConfig structure
This lets you add new actions to a section from a plugin, typically at its init step. Change-Id: I33a61c6162d25332d680d8a0e2d1841a457e0e80 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'ctl-lib')
-rw-r--r--ctl-lib/ctl-action.c5
-rw-r--r--ctl-lib/ctl-config.c5
-rw-r--r--ctl-lib/ctl-config.h2
3 files changed, 10 insertions, 2 deletions
diff --git a/ctl-lib/ctl-action.c b/ctl-lib/ctl-action.c
index a42e8b5..4c72105 100644
--- a/ctl-lib/ctl-action.c
+++ b/ctl-lib/ctl-action.c
@@ -407,3 +407,8 @@ int AddActionsToSection(AFB_ApiT apiHandle, CtlSectionT *section, json_object *a
}
return 0;
}
+
+int AddActionsToSectionFromPlugin(AFB_ApiT apiHandle, CtlPluginT *externalCtlPlugins, CtlSectionT *section, json_object *actionsJ, int exportApi) {
+ ctlPlugins = externalCtlPlugins;
+ return AddActionsToSection(apiHandle, section, actionsJ, exportApi);
+}
diff --git a/ctl-lib/ctl-config.c b/ctl-lib/ctl-config.c
index 339b14c..e815f2c 100644
--- a/ctl-lib/ctl-config.c
+++ b/ctl-lib/ctl-config.c
@@ -151,10 +151,9 @@ int CtlConfigExec(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) {
// Loop on every section and process config
int errcount=0;
for (int idx = 0; ctlConfig->sections[idx].key != NULL; idx++) {
-
if (!ctlConfig->sections[idx].loadCB)
AFB_ApiNotice(apiHandle, "CtlConfigLoad: notice empty section '%s'", ctlConfig->sections[idx].key);
- else if (json_object_object_get_ex(ctlConfig->configJ, ctlConfig->sections[idx].key, NULL))
+ else if (ctlConfig->sections[idx].actions)
errcount += ctlConfig->sections[idx].loadCB(apiHandle, &ctlConfig->sections[idx], NULL);
}
@@ -186,6 +185,8 @@ CtlConfigT *CtlLoadMetaDataJson(AFB_ApiT apiHandle, json_object *ctlConfigJ, con
ctlHandle->configJ = ctlConfigJ;
ctlHandle->prefix = prefix;
+ ctlHandle->ctlPlugins = &ctlPlugins;
+
return ctlHandle;
}
diff --git a/ctl-lib/ctl-config.h b/ctl-lib/ctl-config.h
index 1e9837c..4216aa8 100644
--- a/ctl-lib/ctl-config.h
+++ b/ctl-lib/ctl-config.h
@@ -75,6 +75,7 @@ typedef struct {
json_object *configJ;
json_object *requireJ;
CtlSectionT *sections;
+ CtlPluginT **ctlPlugins;
void *external;
} CtlConfigT;
@@ -91,6 +92,7 @@ typedef enum {
// ctl-action.c
extern int AddActionsToSection(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ, int exportApi);
+extern int AddActionsToSectionFromPlugin(AFB_ApiT apiHandle, CtlPluginT *externalCtlPlugins, CtlSectionT *section, json_object *actionsJ, int exportApi);
extern CtlActionT *ActionConfig(AFB_ApiT apiHandle, json_object *actionsJ, int exportApi);
extern void ActionExecUID(AFB_ReqT request, CtlConfigT *ctlConfig, const char *uid, json_object *queryJ);
extern int ActionExecOne( CtlSourceT *source, CtlActionT* action, json_object *queryJ);