aboutsummaryrefslogtreecommitdiffstats
path: root/ctl-lib/ctl-config.c
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-06-26 17:53:17 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-06-27 17:43:12 +0200
commit0f3063b70fc10311323fec6d4493a5316e51d439 (patch)
tree41ed03f5c2700e29e8f65aa0692f021fbd974d78 /ctl-lib/ctl-config.c
parent1ff524bc55b3ff10b7ab2a5f2cafbb41fce22949 (diff)
Be able to dispatch required api at the wanted timeflounder_5.99.1flounder/5.99.15.99.1
Separate the require api step from ConfigExec and if called from anywhere but CtlConfigExec function, take care that not already initialized or that the previous has failed, so this is a new try. Change-Id: Ic98ef09487f7f58c1b1cb6c417eba261a5a81b13 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'ctl-lib/ctl-config.c')
-rw-r--r--ctl-lib/ctl-config.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/ctl-lib/ctl-config.c b/ctl-lib/ctl-config.c
index 8ef9a85..fcd0e02 100644
--- a/ctl-lib/ctl-config.c
+++ b/ctl-lib/ctl-config.c
@@ -104,28 +104,45 @@ char* CtlConfigSearch(AFB_ApiT apiHandle, const char *dirList, const char *prefi
return NULL;
}
-static void DispatchRequireOneApi(AFB_ApiT apiHandle, json_object * bindindJ) {
+static int DispatchRequireOneApi(AFB_ApiT apiHandle, json_object * bindindJ) {
const char* requireBinding = json_object_get_string(bindindJ);
int err = AFB_RequireApi(apiHandle, requireBinding, 1);
if (err) {
AFB_ApiWarning(apiHandle, "CTL-LOAD-CONFIG:REQUIRE Fail to get=%s", requireBinding);
}
-}
-
-int CtlConfigExec(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) {
- // best effort to initialise everything before starting
- if (ctlConfig->requireJ) {
+ return err;
+}
- if (json_object_get_type(ctlConfig->requireJ) == json_type_array) {
- for (int idx = 0; idx < json_object_array_length(ctlConfig->requireJ); idx++) {
- DispatchRequireOneApi(apiHandle, json_object_array_get_idx(ctlConfig->requireJ, idx));
+/**
+ * @brief Best effort to initialise everything before starting
+ * Call afb_require_api at the first call or if there was an error because
+ * the CtlConfigExec could be called anywhere and not in binding init.
+ * So you could call this function at init time.
+ *
+ * @param apiHandle : a afb_daemon api handle, see AFB_ApiT in afb_definitions.h
+ * @param requireJ : json_object array of api name required.
+ */
+void DispatchRequireApi(AFB_ApiT apiHandle, json_object * requireJ) {
+ static int init = 0, err = 0;
+ int idx;
+
+ if ( (! init || err) && requireJ) {
+ if (json_object_get_type(requireJ) == json_type_array) {
+ for (idx = 0; idx < json_object_array_length(requireJ); idx++) {
+ err += DispatchRequireOneApi(apiHandle, json_object_array_get_idx(requireJ, idx));
}
} else {
- DispatchRequireOneApi(apiHandle, ctlConfig->requireJ);
+ err += DispatchRequireOneApi(apiHandle, requireJ);
}
}
+ init = 1;
+}
+
+int CtlConfigExec(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) {
+
+ DispatchRequireApi(apiHandle, ctlConfig->requireJ);
#ifdef CONTROL_SUPPORT_LUA
// load static LUA utilities
LuaConfigExec(apiHandle);