diff options
-rw-r--r-- | ctl-lib/afb-definitions.h | 105 | ||||
-rw-r--r-- | ctl-lib/ctl-action.c | 10 | ||||
-rw-r--r-- | ctl-lib/ctl-config.h | 3 | ||||
-rw-r--r-- | ctl-lib/ctl-event.c | 9 | ||||
-rw-r--r-- | ctl-lib/ctl-lua.c | 23 | ||||
-rw-r--r-- | ctl-lib/ctl-plugin.c | 2 |
6 files changed, 119 insertions, 33 deletions
diff --git a/ctl-lib/afb-definitions.h b/ctl-lib/afb-definitions.h index 4b0f35c..1f4495f 100644 --- a/ctl-lib/afb-definitions.h +++ b/ctl-lib/afb-definitions.h @@ -20,8 +20,8 @@ #ifndef _AFB_DEFINITIONS_INCLUDE_ #define _AFB_DEFINITIONS_INCLUDE_ -// Waiting for a clean AppFW-V3 API -#if((AFB_BINDING_VERSION == 0 || AFB_BINDING_VERSION == 3) && defined(AFB_BINDING_WANT_DYNAPI)) +// Legacy DYNAPI support. Deprecated and will be removed. +#if((AFB_BINDING_VERSION == 0) && defined(AFB_BINDING_WANT_DYNAPI)) #include <afb/afb-binding.h> #define AFB_BINDING_PREV3 @@ -55,11 +55,7 @@ #define AFB_ApiError(api, ...) AFB_DYNAPI_ERROR (api, __VA_ARGS__) #define AFB_ApiInfo(api, ...) AFB_DYNAPI_INFO (api, __VA_ARGS__) -#if(AFB_BINDING_VERSION == 3) - #define AFB_GetApiSettings afb_api_settings -#else #define AFB_GetApiSettings(api) json_object_new_object() -#endif #define AFB_ReqIsValid(request) request #define AFB_EvtIsValid(evtHandle) evtHandle @@ -72,12 +68,104 @@ #define AFB_GetEventLoop(api) afb_dynapi_get_event_loop(api) #define AFB_RootDirGetFD(api) afb_dynapi_rootdir_get_fd(api) + #define AFB_ReqVCBData afb_request_get_vcbdata + #define AFB_ReqGetApi afb_request_get_dynapi #define AFB_ClientCtxSet(request, replace, createCB, freeCB, handle) afb_request_context(request, replace, createCB, freeCB, handle) #define AFB_ClientCtxClear(request) afb_request_context_clear(request) #define AFB_ReqSetLOA(request, level) afb_request_session_set_LOA(request, level) + #define AFB_NewApi afb_dynapi_new_api + + #define AFB_ApiAddVerb(a,b,c,d,e,f,g,h) afb_dynapi_add_verb(a,b,c,d,e,f,g) + + #define AFB_ApiSetUserData afb_dynapi_set_userdata + #define AFB_ApiGetUserData afb_dynapi_get_userdata + + #define AFB_ApiOnEvent afb_dynapi_on_event + #define AFB_ApiOnInit afb_dynapi_on_init + #define AFB_ApiSeal afb_dynapi_seal + + typedef struct { + const char *verb; /* name of the verb, NULL only at end of the array */ + void (*callback)(AFB_ReqT req); /* callback function implementing the verb */ + const struct afb_auth *auth; /* required authorisation, can be NULL */ + const char *info; /* some info about the verb, can be NULL */ + uint32_t session; + } AFB_ApiVerbs; +#elif(AFB_BINDING_VERSION == 3) + #include <afb/afb-binding.h> + + #define AFB_ReqNone NULL + typedef afb_req_t AFB_ReqT; + typedef afb_api_t AFB_ApiT; + + typedef afb_event_t AFB_EventT; + #define AFB_EventIsValid(eventid) eventid + #define AFB_EventPush afb_event_push + #define AFB_ReqSubscribe afb_req_subscribe + #define AFB_EventMake(api, name) afb_api_make_event(api, name) + + #define AFB_ReqJson(request) afb_req_json(request) + + #define AFB_ReqSuccess afb_req_success + #define AFB_ReqSuccessF afb_req_success_f + #define AFB_ReqFail afb_req_fail + #define AFB_ReqFailF afb_req_fail_f + + #define AFB_ReqNotice(request, ...) AFB_REQ_NOTICE (request, __VA_ARGS__) + #define AFB_ReqWarning(request, ...) AFB_REQ_WARNING (request, __VA_ARGS__) + #define AFB_ReqDebug(request, ...) AFB_REQ_DEBUG (request, __VA_ARGS__) + #define AFB_ReqError(request, ...) AFB_REQ_ERROR (request, __VA_ARGS__) + #define AFB_ReqInfo(request, ...) AFB_REQ_INFO (request, __VA_ARGS__) + + #define AFB_ApiVerbose(api, level, ...) afb_api_verbose(api, level, __VA_ARGS__) + #define AFB_ApiNotice(api, ...) AFB_API_NOTICE (api, __VA_ARGS__) + #define AFB_ApiWarning(api, ...) AFB_API_WARNING (api, __VA_ARGS__) + #define AFB_ApiDebug(api, ...) AFB_API_DEBUG (api, __VA_ARGS__) + #define AFB_ApiError(api, ...) AFB_API_ERROR (api, __VA_ARGS__) + #define AFB_ApiInfo(api, ...) AFB_API_INFO (api, __VA_ARGS__) + + #define AFB_GetApiSettings afb_api_settings + + #define AFB_ReqIsValid(request) request + #define AFB_EvtIsValid(evtHandle) evtHandle + +#if ! defined(afb_service_call_legacy) || ! defined(afb_service_call_sync_legacy) + #define afb_service_call_legacy afb_api_x3_call_legacy + #define afb_service_call_sync_legacy afb_api_x3_call_sync_legacy +#endif + + #define AFB_ServiceCall(api, ...) afb_service_call_legacy(api,__VA_ARGS__) + #define AFB_ServiceSync(api, ...) afb_service_call_sync_legacy(api, __VA_ARGS__) + + #define AFB_ApiCall(api, ...) afb_api_call(api, __VA_ARGS__) + #define AFB_ApiSync(api, ...) afb_api_call_sync(api, __VA_ARGS__) + + #define AFB_RequireApi(api, ...) afb_api_require_api(api, __VA_ARGS__) + + #define AFB_GetEventLoop(api) afb_api_get_event_loop(api) + #define AFB_RootDirGetFD(api) afb_api_rootdir_get_fd(api) + #define AFB_ReqVCBData afb_req_get_vcbdata + #define AFB_ReqGetApi afb_req_get_api + + #define AFB_ClientCtxSet(request, replace, createCB, freeCB, handle) afb_req_context(request, replace, createCB, freeCB, handle) + #define AFB_ClientCtxClear(request) afb_req_context_clear(request) + + #define AFB_ReqSetLOA(request, level) afb_req_session_set_LOA(request, level) + + #define AFB_NewApi afb_api_new_api + + #define AFB_ApiAddVerb afb_api_add_verb + + #define AFB_ApiSetUserData afb_api_set_userdata + #define AFB_ApiGetUserData afb_api_get_userdata + + #define AFB_ApiOnEvent afb_api_on_event + #define AFB_ApiOnInit afb_api_on_init + #define AFB_ApiSeal afb_api_seal + typedef struct { const char *verb; /* name of the verb, NULL only at end of the array */ void (*callback)(AFB_ReqT req); /* callback function implementing the verb */ @@ -86,7 +174,7 @@ uint32_t session; } AFB_ApiVerbs; -#elif(AFB_BINDING_VERSION == 2) +#else #include <afb/afb-binding.h> typedef struct afb_req AFB_ReqT; @@ -118,7 +206,7 @@ #define AFB_ApiError(api, ...) AFB_ERROR (__VA_ARGS__) #define AFB_ApiInfo(api, ...) AFB_INFO (__VA_ARGS__) - #define AFB_GetApiSettings(api) json_object_new_object() + #define AFB_GetApiSettings(api) json_object_new_object() #define AFB_ReqIsValid(request) afb_req_is_valid(request) #define AFB_EvtIsValid(evtHandle) afb_event_is_valid(evtHandle) @@ -130,6 +218,7 @@ #define AFB_GetEventLoop(api) afb_daemon_get_event_loop() #define AFB_RootDirGetFD(api) afb_daemon_rootdir_get_fd() + #define AFB_ReqVCBData afb_req_get_vcbdata #define AFB_ReqSetLOA(request, level) afb_req_session_set_LOA(request, level) diff --git a/ctl-lib/ctl-action.c b/ctl-lib/ctl-action.c index 55e810e..bb9ac66 100644 --- a/ctl-lib/ctl-action.c +++ b/ctl-lib/ctl-action.c @@ -124,13 +124,13 @@ int ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *queryJ) { // Direct Request Call in APIV3 -#ifdef AFB_BINDING_PREV3 +#if (defined(AFB_BINDING_PREV3) || (AFB_BINDING_VERSION == 3)) static void ActionDynRequest(AFB_ReqT request) { // retrieve action handle from request and execute the request - json_object *queryJ = afb_request_json(request); - CtlActionT* action = (CtlActionT*) afb_request_get_vcbdata(request); + json_object *queryJ = AFB_ReqJson(request); + CtlActionT* action = (CtlActionT*) AFB_ReqVCBData(request); CtlSourceT source; source.uid = action->uid; @@ -312,12 +312,12 @@ int ActionLoadOne(AFB_ApiT apiHandle, CtlActionT *action, json_object *actionJ, "args", &action->argsJ); if (!err) { // in API V3 each control is optionally map to a verb -#ifdef AFB_BINDING_PREV3 +#if (defined(AFB_BINDING_PREV3) || (AFB_BINDING_VERSION == 3)) if(!apiHandle) return -1; action->api = apiHandle; if (exportApi) { - err = afb_dynapi_add_verb(apiHandle, action->uid, action->info, ActionDynRequest, action, NULL, 0); + err = AFB_ApiAddVerb(apiHandle, action->uid, action->info, ActionDynRequest, action, NULL, 0, 0); if (err) { AFB_ApiError(apiHandle, "ACTION-LOAD-ONE fail to register API verb=%s", action->uid); return -1; diff --git a/ctl-lib/ctl-config.h b/ctl-lib/ctl-config.h index 914b8e5..b2f1e2f 100644 --- a/ctl-lib/ctl-config.h +++ b/ctl-lib/ctl-config.h @@ -110,11 +110,8 @@ extern int CtlLoadSections(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, CtlSection // ctl-event.c extern int EventConfig(AFB_ApiT apihandle, CtlSectionT *section, json_object *actionsJ); -#ifdef AFB_BINDING_PREV3 extern void CtrlDispatchApiEvent (AFB_ApiT apiHandle, const char *evtLabel, struct json_object *eventJ); -#else extern void CtrlDispatchV2Event(const char *evtLabel, json_object *eventJ); -#endif // ctl-control.c extern int ControlConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ); diff --git a/ctl-lib/ctl-event.c b/ctl-lib/ctl-event.c index 235be28..4174000 100644 --- a/ctl-lib/ctl-event.c +++ b/ctl-lib/ctl-event.c @@ -22,16 +22,19 @@ #include "ctl-config.h" - // Event dynamic API-V3 mode -#ifdef AFB_BINDING_PREV3 +#if defined AFB_BINDING_PREV3 || AFB_BINDING_VERSION == 3 void CtrlDispatchApiEvent (AFB_ApiT apiHandle, const char *evtLabel, struct json_object *eventJ) { int idx = 0; CtlActionT* actions = NULL; AFB_ApiDebug (apiHandle, "Received event=%s, query=%s", evtLabel, json_object_get_string(eventJ)); // retrieve section config from api handle + #ifdef AFB_BINDING_PREV3 CtlConfigT *ctrlConfig = (CtlConfigT*) afb_dynapi_get_userdata(apiHandle); + #elif AFB_BINDING_VERSION == 3 + CtlConfigT *ctrlConfig = (CtlConfigT*) afb_api_get_userdata(apiHandle); + #endif for (idx = 0; ctrlConfig->sections[idx].key != NULL; ++idx) { @@ -67,7 +70,7 @@ void CtrlDispatchV2Event(const char *evtLabel, json_object *eventJ) { int index= ActionLabelToIndex(actions, evtLabel); if (index < 0) { - AFB_WARNING ("CtlDispatchEvent: fail to find uid=%s in action event section", evtLabel); + AFB_WARNING_V2("CtlDispatchEvent: fail to find uid=%s in action event section", evtLabel); return; } diff --git a/ctl-lib/ctl-lua.c b/ctl-lib/ctl-lua.c index 9194d75..87e27d0 100644 --- a/ctl-lib/ctl-lua.c +++ b/ctl-lib/ctl-lua.c @@ -370,27 +370,27 @@ PrintMessage: } static int LuaPrintInfo(lua_State* luaState) { - int err = LuaFormatMessage(luaState, AFB_VERBOSITY_LEVEL_INFO, _AFB_SYSLOG_LEVEL_INFO_); + int err = LuaFormatMessage(luaState, AFB_VERBOSITY_LEVEL_INFO, AFB_SYSLOG_LEVEL_INFO); return err; } static int LuaPrintError(lua_State* luaState) { - int err = LuaFormatMessage(luaState, AFB_VERBOSITY_LEVEL_ERROR, _AFB_SYSLOG_LEVEL_ERROR_); + int err = LuaFormatMessage(luaState, AFB_VERBOSITY_LEVEL_ERROR, AFB_SYSLOG_LEVEL_ERROR); return err; // no value return } static int LuaPrintWarning(lua_State* luaState) { - int err = LuaFormatMessage(luaState, AFB_VERBOSITY_LEVEL_WARNING, _AFB_SYSLOG_LEVEL_WARNING_); + int err = LuaFormatMessage(luaState, AFB_VERBOSITY_LEVEL_WARNING, AFB_SYSLOG_LEVEL_WARNING); return err; } static int LuaPrintNotice(lua_State* luaState) { - int err = LuaFormatMessage(luaState, AFB_VERBOSITY_LEVEL_NOTICE, _AFB_SYSLOG_LEVEL_NOTICE_); + int err = LuaFormatMessage(luaState, AFB_VERBOSITY_LEVEL_NOTICE, AFB_SYSLOG_LEVEL_NOTICE); return err; } static int LuaPrintDebug(lua_State* luaState) { - int err = LuaFormatMessage(luaState, AFB_VERBOSITY_LEVEL_DEBUG, _AFB_SYSLOG_LEVEL_DEBUG_); + int err = LuaFormatMessage(luaState, AFB_VERBOSITY_LEVEL_DEBUG, AFB_SYSLOG_LEVEL_DEBUG); return err; } @@ -426,13 +426,7 @@ static int LuaAfbFail(lua_State* luaState) { return 0; } -#ifdef AFB_BINDING_PREV3 - static void LuaAfbServiceCB(void *handle, int iserror, struct json_object *responseJ, AFB_ApiT apiHandle) { -#else - -static void LuaAfbServiceCB(void *handle, int iserror, struct json_object *responseJ) { -#endif LuaCbHandleT *handleCb = (LuaCbHandleT*) handle; int count = 1; @@ -991,11 +985,14 @@ static int LuaTimerClear(lua_State* luaState) { if (!timerHandle) return 1; -#ifdef AFB_BINDING_PREV3 +#if(AFB_BINDING_VERSION == 3) || ((AFB_BINDING_VERSION == 0) && defined(AFB_BINDING_WANT_DYNAPI)) // API handle does not exit in API-V2 LuaCbHandleT *luaCbHandle = (LuaCbHandleT*) timerHandle->context; -#endif AFB_ApiNotice(luaCbHandle->source->api, "LuaTimerClear timer=%s", timerHandle->uid); +#else + AFB_NOTICE("LuaTimerClear timer=%s", timerHandle->uid); +#endif + TimerEvtStop(timerHandle); return 0; //happy end diff --git a/ctl-lib/ctl-plugin.c b/ctl-lib/ctl-plugin.c index cefd593..d27b71d 100644 --- a/ctl-lib/ctl-plugin.c +++ b/ctl-lib/ctl-plugin.c @@ -94,7 +94,7 @@ static int PluginLoadCOne(AFB_ApiT apiHandle, const char *pluginpath, json_objec // store dlopen handle to enable onload action at exec time ctlPlugin->dlHandle = dlHandle; -#ifndef AFB_BINDING_PREV3 +#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; |