diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2018-10-02 14:59:25 +0200 |
---|---|---|
committer | Clément Bénier <clement.benier@iot.bzh> | 2018-10-05 14:36:45 +0200 |
commit | 1d757228d9acb1d09ce966fe68b87fc067b9d9af (patch) | |
tree | f8efe1d90b570f6dd10ff6e09634fc58a4d3e527 /ctl-lib/ctl-plugin.c | |
parent | 625ce776e0e9ed869da90659eb988ee32de4cf3b (diff) |
Get rid of the support of API version 2 and DYNAPI
Change-Id: I24d99de6fe5d1d639392315926ca23f60a137fc4
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'ctl-lib/ctl-plugin.c')
-rw-r--r-- | ctl-lib/ctl-plugin.c | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/ctl-lib/ctl-plugin.c b/ctl-lib/ctl-plugin.c index 5d3ae1f..0a41c7f 100644 --- a/ctl-lib/ctl-plugin.c +++ b/ctl-lib/ctl-plugin.c @@ -24,13 +24,13 @@ #include "ctl-config.h" -int PluginGetCB (AFB_ApiT apiHandle, CtlActionT *action , json_object *callbackJ) { +int PluginGetCB (afb_api_t apiHandle, CtlActionT *action , json_object *callbackJ) { const char *plugin=NULL, *function=NULL; json_object *argsJ; int idx; if (!ctlPlugins) { - AFB_ApiError(apiHandle, "PluginGetCB plugin section missing cannot call '%s'", json_object_get_string(callbackJ)); + AFB_API_ERROR(apiHandle, "PluginGetCB plugin section missing cannot call '%s'", json_object_get_string(callbackJ)); return 1; } @@ -39,7 +39,7 @@ int PluginGetCB (AFB_ApiT apiHandle, CtlActionT *action , json_object *callbackJ "function", &function, "args", &argsJ); if (err) { - AFB_ApiError(apiHandle, "PluginGet missing plugin|function|[args] in %s", json_object_get_string(callbackJ)); + AFB_API_ERROR(apiHandle, "PluginGet missing plugin|function|[args] in %s", json_object_get_string(callbackJ)); return 1; } @@ -48,7 +48,7 @@ int PluginGetCB (AFB_ApiT apiHandle, CtlActionT *action , json_object *callbackJ } if (!ctlPlugins[idx].uid) { - AFB_ApiError(apiHandle, "PluginGetCB no plugin with uid=%s", plugin); + AFB_API_ERROR(apiHandle, "PluginGetCB no plugin with uid=%s", plugin); return 1; } @@ -57,7 +57,7 @@ int PluginGetCB (AFB_ApiT apiHandle, CtlActionT *action , json_object *callbackJ action->exec.cb.plugin= &ctlPlugins[idx]; if (!action->exec.cb.callback) { - AFB_ApiError(apiHandle, "PluginGetCB no plugin=%s no function=%s", plugin, function); + AFB_API_ERROR(apiHandle, "PluginGetCB no plugin=%s no function=%s", plugin, function); return 1; } return 0; @@ -74,31 +74,29 @@ static int DispatchOneL2c(void* luaState, char *funcname, Lua2cFunctionT callbac #endif } -static int PluginLoadCOne(AFB_ApiT apiHandle, const char *pluginpath, json_object *lua2csJ, const char *lua2c_prefix, void * handle, CtlPluginT *ctlPlugin) +static int PluginLoadCOne(afb_api_t apiHandle, const char *pluginpath, json_object *lua2csJ, const char *lua2c_prefix, void * handle, CtlPluginT *ctlPlugin) { void *dlHandle = dlopen(pluginpath, RTLD_NOW); if (!dlHandle) { - AFB_ApiError(apiHandle, "CTL-PLUGIN-LOADONE Fail to load pluginpath=%s err= %s", pluginpath, dlerror()); + AFB_API_ERROR(apiHandle, "CTL-PLUGIN-LOADONE Fail to load pluginpath=%s err= %s", pluginpath, dlerror()); return -1; } CtlPluginMagicT *ctlPluginMagic = (CtlPluginMagicT*) dlsym(dlHandle, "CtlPluginMagic"); if (!ctlPluginMagic || ctlPluginMagic->magic != CTL_PLUGIN_MAGIC) { - AFB_ApiError(apiHandle, "CTL-PLUGIN-LOADONE symbol'CtlPluginMagic' missing or != CTL_PLUGIN_MAGIC plugin=%s", pluginpath); + AFB_API_ERROR(apiHandle, "CTL-PLUGIN-LOADONE symbol'CtlPluginMagic' missing or != CTL_PLUGIN_MAGIC plugin=%s", pluginpath); return -1; } else { - AFB_ApiNotice(apiHandle, "CTL-PLUGIN-LOADONE %s successfully registered", ctlPluginMagic->uid); + AFB_API_NOTICE(apiHandle, "CTL-PLUGIN-LOADONE %s successfully registered", ctlPluginMagic->uid); } // store dlopen handle to enable onload action at exec time ctlPlugin->dlHandle = dlHandle; -#if (defined(AFB_BINDING_PREV3) || (AFB_BINDING_VERSION == 3)) // Jose hack to make verbosity visible from sharelib with API-V2 struct afb_binding_data_v2 *afbHidenData = dlsym(dlHandle, "afbBindingV2data"); if (afbHidenData) *afbHidenData = afbBindingV2data; -#endif // Push lua2cWrapper @ into plugin Lua2cWrapperT *lua2cInPlug = dlsym(dlHandle, "Lua2cWrap"); @@ -121,7 +119,7 @@ static int PluginLoadCOne(AFB_ApiT apiHandle, const char *pluginpath, json_objec Lua2cFunctionT l2cFunction = (Lua2cFunctionT) dlsym(dlHandle, funcName); if (!l2cFunction) { - AFB_ApiError(apiHandle, "CTL-PLUGIN-LOADONE symbol'%s' missing err=%s", funcName, dlerror()); + AFB_API_ERROR(apiHandle, "CTL-PLUGIN-LOADONE symbol'%s' missing err=%s", funcName, dlerror()); return 1; } l2cFunc[index].func = (void*) l2cFunction; @@ -157,7 +155,7 @@ static int PluginLoadCOne(AFB_ApiT apiHandle, const char *pluginpath, json_objec count++; } if (errCount) { - AFB_ApiError(apiHandle, "CTL-PLUGIN-LOADONE %d symbols not found in plugin='%s'", errCount, pluginpath); + AFB_API_ERROR(apiHandle, "CTL-PLUGIN-LOADONE %d symbols not found in plugin='%s'", errCount, pluginpath); return -1; } int total = ctlPlugin->ctlL2cFunc->l2cCount + count; @@ -179,7 +177,7 @@ static int PluginLoadCOne(AFB_ApiT apiHandle, const char *pluginpath, json_objec DispatchPluginInstallCbT ctlPluginOnload = dlsym(dlHandle, "CtlPluginOnload"); if (ctlPluginOnload) { if((*ctlPluginOnload) (ctlPlugin, handle)) { - AFB_ApiError(apiHandle, "Plugin Onload function hasn't finish well. Abort initialization"); + AFB_API_ERROR(apiHandle, "Plugin Onload function hasn't finish well. Abort initialization"); return -1; } } @@ -187,7 +185,7 @@ static int PluginLoadCOne(AFB_ApiT apiHandle, const char *pluginpath, json_objec return 0; } -static int LoadFoundPlugins(AFB_ApiT apiHandle, json_object *scanResult, json_object *lua2csJ, const char *lua2c_prefix, void *handle, CtlPluginT *ctlPlugin) +static int LoadFoundPlugins(afb_api_t apiHandle, json_object *scanResult, json_object *lua2csJ, const char *lua2c_prefix, void *handle, CtlPluginT *ctlPlugin) { char pluginpath[CONTROL_MAXPATH_LEN]; char *filename; @@ -211,7 +209,7 @@ static int LoadFoundPlugins(AFB_ApiT apiHandle, json_object *scanResult, json_ob "filename", &filename); if (err) { - AFB_ApiError(apiHandle, "HOOPs invalid plugin file path=\n-- %s", json_object_get_string(scanResult)); + AFB_API_ERROR(apiHandle, "HOOPs invalid plugin file path=\n-- %s", json_object_get_string(scanResult)); return -1; } @@ -232,18 +230,18 @@ static int LoadFoundPlugins(AFB_ApiT apiHandle, json_object *scanResult, json_ob } if(len > 1) - AFB_ApiWarning(apiHandle, "Plugin multiple instances in searchpath will use %s/%s", fullpath, filename); + AFB_API_WARNING(apiHandle, "Plugin multiple instances in searchpath will use %s/%s", fullpath, filename); return 0; } -char *GetDefaultPluginSearchPath(AFB_ApiT apiHandle, const char *prefix) +char *GetDefaultPluginSearchPath(afb_api_t apiHandle, const char *prefix) { char *searchPath, *rootDir, *path; const char *bindingPath; const char *envDirList; size_t envDirList_len; - json_object *settings = AFB_GetApiSettings(apiHandle); + json_object *settings = afb_api_settings(apiHandle); json_object *bpath; if(json_object_object_get_ex(settings, "binding-path", &bpath)) { @@ -282,18 +280,18 @@ char *GetDefaultPluginSearchPath(AFB_ApiT apiHandle, const char *prefix) return searchPath; } -static int FindPlugins(AFB_ApiT apiHandle, const char *searchPath, const char *file, json_object **pluginPathJ) +static int FindPlugins(afb_api_t apiHandle, const char *searchPath, const char *file, json_object **pluginPathJ) { *pluginPathJ = ScanForConfig(searchPath, CTL_SCAN_RECURSIVE, file, NULL); if (!*pluginPathJ || json_object_array_length(*pluginPathJ) == 0) { - AFB_ApiError(apiHandle, "CTL-PLUGIN-LOADONE Missing plugin=%s* (config ldpath?) search=\n-- %s", file, searchPath); + AFB_API_ERROR(apiHandle, "CTL-PLUGIN-LOADONE Missing plugin=%s* (config ldpath?) search=\n-- %s", file, searchPath); return -1; } return 0; } -static int PluginLoad (AFB_ApiT apiHandle, CtlPluginT *ctlPlugin, json_object *pluginJ, void *handle, const char *prefix) +static int PluginLoad (afb_api_t apiHandle, CtlPluginT *ctlPlugin, json_object *pluginJ, void *handle, const char *prefix) { int err = 0, i = 0; char *searchPath; @@ -312,7 +310,7 @@ static int PluginLoad (AFB_ApiT apiHandle, CtlPluginT *ctlPlugin, json_object *p "params", &ctlPlugin->paramsJ ); if (err) { - AFB_ApiError(apiHandle, "CTL-PLUGIN-LOADONE Plugin missing uid|[info]|libs|[spath]|[lua]|[params] in:\n-- %s", json_object_get_string(pluginJ)); + AFB_API_ERROR(apiHandle, "CTL-PLUGIN-LOADONE Plugin missing uid|[info]|libs|[spath]|[lua]|[params] in:\n-- %s", json_object_get_string(pluginJ)); return 1; } @@ -321,7 +319,7 @@ static int PluginLoad (AFB_ApiT apiHandle, CtlPluginT *ctlPlugin, json_object *p "prefix", &lua2c_prefix, "functions", &lua2csJ); if(err) { - AFB_ApiError(apiHandle, "CTL-PLUGIN-LOADONE Missing 'function' in:\n-- %s", json_object_get_string(pluginJ)); + AFB_API_ERROR(apiHandle, "CTL-PLUGIN-LOADONE Missing 'function' in:\n-- %s", json_object_get_string(pluginJ)); return 1; } } @@ -374,7 +372,7 @@ 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) { +static int PluginParse(afb_api_t apiHandle, CtlSectionT *section, json_object *pluginsJ, int *pluginNb) { int idx = 0, err = 0; switch (json_object_get_type(pluginsJ)) { @@ -394,7 +392,7 @@ static int PluginParse(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pl break; } default: { - AFB_ApiError(apiHandle, "Wrong JSON object passed: %s", json_object_get_string(pluginsJ)); + AFB_API_ERROR(apiHandle, "Wrong JSON object passed: %s", json_object_get_string(pluginsJ)); err = -1; } } @@ -402,7 +400,7 @@ static int PluginParse(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pl return err; } -int PluginConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pluginsJ) { +int PluginConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *pluginsJ) { int err = 0; int idx = 0, jdx = 0; int pluginNb = 0, newPluginsNb = 0, totalPluginNb = 0; @@ -445,7 +443,7 @@ int PluginConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pluginsJ 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"); + AFB_API_ERROR(apiHandle, "Plugin Init function hasn't finish well. Abort initialization"); return -1; } } |