+
+int load_config(afb_api_t api)
+{
+ int ret = 0;
+ CtlConfigT *ctlConfig;
+ const char *dirList = getenv("CONTROL_CONFIG_PATH");
+ std::string bindingDirPath = GetBindingDirPath(api);
+ std::string filepath = bindingDirPath + "/etc";
+
+ if (!dirList)
+ dirList=CONTROL_CONFIG_PATH;
+
+ filepath.append(":");
+ filepath.append(dirList);
+ const char *configPath = CtlConfigSearch(api, filepath.c_str(), "control");
+
+ if (!configPath)
+ {
+ AFB_ERROR_V3("CtlPreInit: No control-* config found invalid JSON %s ", filepath.c_str());
+ return -1;
+ }
+
+ // create one API per file
+ ctlConfig = CtlLoadMetaData(api, configPath);
+ if (!ctlConfig)
+ {
+ AFB_ERROR_V3("CtrlPreInit No valid control config file in:\n-- %s", configPath);
+ return -1;
+ }
+
+ // Save the config in the api userdata field
+ afb_api_set_userdata(api, ctlConfig);
+
+ setExternalData(ctlConfig, (void*) &application_t::instance());
+ ret= CtlLoadSections(api, ctlConfig, ctlSections_);
+
+ return ret;
+}