diff options
Diffstat (limited to 'ctl-lib')
-rw-r--r-- | ctl-lib/CMakeLists.txt | 6 | ||||
-rw-r--r-- | ctl-lib/afb-definitions.h | 244 | ||||
-rw-r--r-- | ctl-lib/afb-definitions_v2.h | 85 | ||||
-rw-r--r-- | ctl-lib/ctl-action.c | 12 | ||||
-rw-r--r-- | ctl-lib/ctl-config.c | 14 | ||||
-rw-r--r-- | ctl-lib/ctl-config.h | 33 | ||||
-rw-r--r-- | ctl-lib/ctl-config_v2.h | 74 | ||||
-rw-r--r-- | ctl-lib/ctl-config_v3.h | 94 | ||||
-rw-r--r-- | ctl-lib/ctl-control.c | 4 | ||||
-rw-r--r-- | ctl-lib/ctl-event.c | 8 | ||||
-rw-r--r-- | ctl-lib/ctl-lua.c | 14 | ||||
-rw-r--r-- | ctl-lib/ctl-onload.c | 2 | ||||
-rw-r--r-- | ctl-lib/ctl-plugin.c | 6 | ||||
-rw-r--r-- | ctl-lib/ctl-plugin.h | 2 |
14 files changed, 355 insertions, 243 deletions
diff --git a/ctl-lib/CMakeLists.txt b/ctl-lib/CMakeLists.txt index 147cfb0..e066bbc 100644 --- a/ctl-lib/CMakeLists.txt +++ b/ctl-lib/CMakeLists.txt @@ -29,7 +29,7 @@ if(NOT CMAKE_INSTALL_PREFIX) endif() set(CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_PREFIX}/lib) set(CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/include) -add_definitions(-DAFB_BINDING_VERSION=3) +add_definitions(-DAFB_BINDING_VERSION=0) add_definitions(-DLUA_GLOB_PATTERN="/var/?.lua\\\;") add_definitions(-DSUSE_LUA_INCDIR) @@ -55,7 +55,9 @@ endforeach(PKG_CONFIG) set(CTL_LUA_SOURCE ctl-lua.c ctl-timer.c ctl-lua-utils.c) ADD_COMPILE_OPTIONS(-DCONTROL_SUPPORT_LUA) -set(CONTROLLER_HEADERS afb-definitions.h ctl-config.h ctl-lua.h +set(CONTROLLER_HEADERS afb-definitions.h afb-definitions_v2.h + ctl-config.h ctl-config_v2.h ctl-config_v3.h + ctl-lua.h ctl-plugin.h ctl-timer.h ) diff --git a/ctl-lib/afb-definitions.h b/ctl-lib/afb-definitions.h index 5a749c6..116be69 100644 --- a/ctl-lib/afb-definitions.h +++ b/ctl-lib/afb-definitions.h @@ -20,223 +20,97 @@ #ifndef _AFB_DEFINITIONS_INCLUDE_ #define _AFB_DEFINITIONS_INCLUDE_ -// 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 - #define AFB_ReqNone NULL - typedef struct afb_request* AFB_ReqT; - typedef struct afb_dynapi* AFB_ApiT; - typedef struct afb_eventid* AFB_EventT; - #define AFB_EventIsValid(eventid) eventid - #define AFB_EventPush afb_eventid_push - #define AFB_ReqSubscribe afb_request_subscribe - #define AFB_EventMake(api, name) afb_dynapi_make_eventid(api, name) +#if(AFB_BINDING_VERSION != 2) +#include <afb/afb-binding.h> +#define AFB_ReqNone NULL +typedef struct afb_req_x2* AFB_ReqT; +typedef struct afb_api_x3* AFB_ApiT; - #define AFB_ReqJson(request) afb_request_json(request) +typedef struct afb_event_x2* AFB_EventT; +#define AFB_EventIsValid(eventid) eventid +#define AFB_EventPush afb_event_x2_push +#define AFB_ReqSubscribe afb_req_x2_subscribe - #define AFB_ReqSuccess afb_request_success - #define AFB_ReqSuccessF afb_request_success_f - #define AFB_ReqFail afb_request_fail - #define AFB_ReqFailF afb_request_fail_f +#define AFB_ReqJson(request) afb_req_x2_json(request) - #define AFB_ReqNotice(request, ...) AFB_REQUEST_NOTICE (request, __VA_ARGS__) - #define AFB_ReqWarning(request, ...) AFB_REQUEST_WARNING (request, __VA_ARGS__) - #define AFB_ReqDebug(request, ...) AFB_REQUEST_DEBUG (request, __VA_ARGS__) - #define AFB_ReqError(request, ...) AFB_REQUEST_ERROR (request, __VA_ARGS__) - #define AFB_ReqInfo(request, ...) AFB_REQUEST_INFO (request, __VA_ARGS__) +#define AFB_ReqSuccess(r,o,i) afb_req_x2_reply(r,o,NULL,i) +#define AFB_ReqSuccessF(r,o,...) afb_req_x2_reply_f(r,o,NULL,__VA_ARGS__) +#define AFB_ReqFail(r,e,i) afb_req_x2_reply(r,NULL,e,i) +#define AFB_ReqFailF(r,e,...) afb_req_x2_reply_f(r,NULL,e,__VA_ARGS__) - #define AFB_ApiVerbose(api, level, ...) afb_dynapi_verbose(api, level, __VA_ARGS__) - #define AFB_ApiNotice(api, ...) AFB_DYNAPI_NOTICE (api, __VA_ARGS__) - #define AFB_ApiWarning(api, ...) AFB_DYNAPI_WARNING (api, __VA_ARGS__) - #define AFB_ApiDebug(api, ...) AFB_DYNAPI_DEBUG (api, __VA_ARGS__) - #define AFB_ApiError(api, ...) AFB_DYNAPI_ERROR (api, __VA_ARGS__) - #define AFB_ApiInfo(api, ...) AFB_DYNAPI_INFO (api, __VA_ARGS__) +#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_GetApiSettings(api) json_object_new_object() - #define AFB_ReqIsValid(request) request - #define AFB_EvtIsValid(evtHandle) evtHandle - - #define AFB_ServiceCall(api, ...) afb_dynapi_call(api, __VA_ARGS__) - #define AFB_ServiceSync(api, ...) afb_dynapi_call_sync(api, __VA_ARGS__) - - #define AFB_RequireApi(api, ...) afb_dynapi_require_api(api, __VA_ARGS__) - - - #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 +#define AFB_ReqIsValid(request) request +#define AFB_EvtIsValid(evtHandle) evtHandle /* * Binder version < FF.RC4, we miss two defined calls. * This is for compatibility purpose that we defined them here. */ #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 +#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_api_call_legacy(api, __VA_ARGS__) - #define AFB_ServiceSync(api, ...) afb_api_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_ClientCtxClear(request) afb_req_x2_context_clear(request) - #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_ReqSetLOA(request, level) afb_req_session_set_LOA(request, level) - #define AFB_NewApi afb_api_new_api +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; - #define AFB_ApiAddVerb afb_api_add_verb - #define AFB_ApiSetUserData afb_api_set_userdata - #define AFB_ApiGetUserData afb_api_get_userdata +#define AFB_EventMake(api, name) afb_api_x3_make_event_x2(api, name) +#define AFB_ApiVerbose(api, level, ...) afb_api_x3_verbose(api, level, __VA_ARGS__) +#define AFB_ApiNotice(api, ...) AFB_API_NOTICE_V3 (api, __VA_ARGS__) +#define AFB_ApiWarning(api, ...) AFB_API_WARNING_V3 (api, __VA_ARGS__) +#define AFB_ApiDebug(api, ...) AFB_API_DEBUG_V3 (api, __VA_ARGS__) +#define AFB_ApiError(api, ...) AFB_API_ERROR_V3 (api, __VA_ARGS__) +#define AFB_ApiInfo(api, ...) AFB_API_INFO_V3 (api, __VA_ARGS__) - #define AFB_ApiOnEvent afb_api_on_event - #define AFB_ApiOnInit afb_api_on_init - #define AFB_ApiSeal afb_api_seal +#define AFB_GetApiSettings afb_api_x3_settings - 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; +#define AFB_ServiceCall(api, ...) afb_api_x3_call_legacy(api, __VA_ARGS__) +#define AFB_ServiceSync(api, ...) afb_api_x3_call_sync_legacy(api, __VA_ARGS__) -#else - #include <afb/afb-binding.h> +#define AFB_ApiCall(api, ...) afb_api_x3_call(api, __VA_ARGS__) +#define AFB_ApiSync(api, ...) afb_api_x3_call_sync(api, __VA_ARGS__) - typedef struct afb_req AFB_ReqT; - typedef void* AFB_ApiT; - #define AFB_ReqNone (struct afb_req){0,0} +#define AFB_RequireApi(api, ...) afb_api_x3_require_api(api, __VA_ARGS__) - typedef struct afb_event AFB_EventT; - #define AFB_EventPush afb_event_push - #define AFB_ReqSubscribe afb_req_subscribe - #define AFB_EventIsValid(event) afb_event_is_valid(event) - #define AFB_EventMake(api, name) afb_daemon_make_event(name) +#define AFB_GetEventLoop(api) afb_api_x3_get_event_loop(api) +#define AFB_RootDirGetFD(api) afb_api_x3_rootdir_get_fd(api) +#define AFB_ReqVCBData afb_req_x2_get_vcbdata +#define AFB_ReqGetApi afb_req_get_api - #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_NewApi afb_api_x3_new_api - #define AFB_ReqNotice(request, ...) AFB_NOTICE (__VA_ARGS__) - #define AFB_ReqWarning(request, ...) AFB_WARNING (__VA_ARGS__) - #define AFB_ReqDebug(request, ...) AFB_DEBUG (__VA_ARGS__) - #define AFB_ReqError(request, ...) AFB_ERROR (__VA_ARGS__) - #define AFB_ReqInfo(request, ...) AFB_INFO (__VA_ARGS__) +#define AFB_ApiAddVerb afb_api_x3_add_verb - #define AFB_ApiVerbose(api, level, ...) afb_daemon_verbose_v2(level,__VA_ARGS__) - #define AFB_ApiNotice(api, ...) AFB_NOTICE (__VA_ARGS__) - #define AFB_ApiWarning(api, ...) AFB_WARNING (__VA_ARGS__) - #define AFB_ApiDebug(api, ...) AFB_DEBUG (__VA_ARGS__) - #define AFB_ApiError(api, ...) AFB_ERROR (__VA_ARGS__) - #define AFB_ApiInfo(api, ...) AFB_INFO (__VA_ARGS__) +#define AFB_ApiSetUserData afb_api_x3_set_userdata +#define AFB_ApiGetUserData afb_api_x3_get_userdata - #define AFB_GetApiSettings(api) json_object_new_object() +#define AFB_ApiOnEvent afb_api_x3_on_event +#define AFB_ApiOnInit afb_api_x3_on_init +#define AFB_ApiSeal afb_api_x3_seal - #define AFB_ReqIsValid(request) afb_req_is_valid(request) - #define AFB_EvtIsValid(evtHandle) afb_event_is_valid(evtHandle) +#define AFB_ClientCtxSet(request, replace, createCB, freeCB, handle) afb_req_x2_context(request, replace, createCB, freeCB, handle) - #define AFB_ServiceCall(api, ...) afb_service_call(__VA_ARGS__) - #define AFB_ServiceSync(api, ...) afb_service_call_sync(__VA_ARGS__) - - #define AFB_RequireApi(api, ...) afb_daemon_require_api(__VA_ARGS__) - - #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) - - static inline void* AFB_ClientCtxSet(afb_req request, int replace, void *(*create_context)(void *closure), void (*free_context)(void*), void *closure) - { - void *ctx = create_context(closure); - if(ctx) - {afb_req_context_set(request, ctx, free_context);} - return ctx; - } - - #define AFB_ClientCtxClear(request) afb_req_context_clear(request) - - #define AFB_ApiVerbs afb_verb_v2 #endif +#include "afb-definitions_v2.h" + #endif /* _AFB_DEFINITIONS_INCLUDE_ */ diff --git a/ctl-lib/afb-definitions_v2.h b/ctl-lib/afb-definitions_v2.h new file mode 100644 index 0000000..66c5ed2 --- /dev/null +++ b/ctl-lib/afb-definitions_v2.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2016-2018 "IoT.bzh" + * Author Fulup Ar Foll <fulup@iot.bzh> + * Contrib Jonathan Aillet <jonathan.aillet@iot.bzh> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, something express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef _AFB_DEFINITIONS_V2_INCLUDE_ +#define _AFB_DEFINITIONS_V2_INCLUDE_ + +// Legacy DYNAPI support. Deprecated and will be removed. +#if(AFB_BINDING_VERSION == 2) +#include <afb/afb-binding.h> + +typedef struct afb_req AFB_ReqT; +typedef void* AFB_ApiT; +#define AFB_ReqNone (struct afb_req){0,0} + +typedef struct afb_event AFB_EventT; +#define AFB_EventPush afb_event_push +#define AFB_ReqSubscribe afb_req_subscribe +#define AFB_EventIsValid(event) afb_event_is_valid(event) +#define AFB_EventMake(api, name) afb_daemon_make_event(name) + +#define AFB_ReqJson(request) afb_req_x1_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_NOTICE (__VA_ARGS__) +#define AFB_ReqWarning(request, ...) AFB_WARNING (__VA_ARGS__) +#define AFB_ReqDebug(request, ...) AFB_DEBUG (__VA_ARGS__) +#define AFB_ReqError(request, ...) AFB_ERROR (__VA_ARGS__) +#define AFB_ReqInfo(request, ...) AFB_INFO (__VA_ARGS__) + +#define AFB_ApiVerbose(api, level, ...) afb_daemon_verbose_v2(level,__VA_ARGS__) +#define AFB_ApiNotice(api, ...) AFB_NOTICE (__VA_ARGS__) +#define AFB_ApiWarning(api, ...) AFB_WARNING (__VA_ARGS__) +#define AFB_ApiDebug(api, ...) AFB_DEBUG (__VA_ARGS__) +#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_ReqIsValid(request) afb_req_is_valid(request) +#define AFB_EvtIsValid(evtHandle) afb_event_is_valid(evtHandle) + +#define AFB_ServiceCall(api, ...) afb_service_call(__VA_ARGS__) +#define AFB_ServiceSync(api, ...) afb_service_call_sync(__VA_ARGS__) + +#define AFB_RequireApi(api, ...) afb_daemon_require_api(__VA_ARGS__) + +#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) + +static inline void* AFB_ClientCtxSet(afb_req request, int replace, void *(*create_context)(void *closure), void (*free_context)(void*), void *closure) +{ + void *ctx = create_context(closure); + if(ctx) + {afb_req_context_set(request, ctx, free_context);} + return ctx; +} + +#define AFB_ClientCtxClear(request) afb_req_context_clear(request) + +#define AFB_ApiVerbs afb_verb_v2 + +#endif +#endif /* _AFB_DEFINITIONS_INCLUDE_ */ diff --git a/ctl-lib/ctl-action.c b/ctl-lib/ctl-action.c index 8aa5dc7..9d71160 100644 --- a/ctl-lib/ctl-action.c +++ b/ctl-lib/ctl-action.c @@ -124,7 +124,6 @@ int ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *queryJ) { // Direct Request Call in APIV3 -#if (defined(AFB_BINDING_PREV3) || (AFB_BINDING_VERSION == 3)) static void ActionDynRequest(AFB_ReqT request) { @@ -140,7 +139,6 @@ static void ActionDynRequest(AFB_ReqT request) { // provide request and execute the action ActionExecOne(&source, action, queryJ); } -#endif void ParseURI(const char *uri, char **first, char **second) { @@ -297,7 +295,7 @@ static int BuildOneAction(AFB_ApiT apiHandle, CtlActionT *action, const char *ur // unpack individual action object -int ActionLoadOne(AFB_ApiT apiHandle, CtlActionT *action, json_object *actionJ, int exportApi) { +int ActionLoadOne_V3(AFB_ApiT apiHandle, CtlActionT *action, json_object *actionJ, int exportApi) { int err = 0; const char *uri = NULL; @@ -312,7 +310,6 @@ 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 -#if (defined(AFB_BINDING_PREV3) || (AFB_BINDING_VERSION == 3)) if(!apiHandle) return -1; action->api = apiHandle; @@ -323,7 +320,6 @@ int ActionLoadOne(AFB_ApiT apiHandle, CtlActionT *action, json_object *actionJ, return -1; } } -#endif err = BuildOneAction(apiHandle, action, uri); } else { AFB_ApiError(apiHandle, "Fail to parse action JSON : (%s)", json_object_to_json_string(actionJ)); @@ -337,7 +333,7 @@ int ActionLoadOne(AFB_ApiT apiHandle, CtlActionT *action, json_object *actionJ, return err; } -CtlActionT *ActionConfig(AFB_ApiT apiHandle, json_object *actionsJ, int exportApi) { +CtlActionT *ActionConfig_V3(AFB_ApiT apiHandle, json_object *actionsJ, int exportApi) { int err; CtlActionT *actions; @@ -349,14 +345,14 @@ CtlActionT *ActionConfig(AFB_ApiT apiHandle, json_object *actionsJ, int exportAp for (int idx = 0; idx < count; idx++) { json_object *actionJ = json_object_array_get_idx(actionsJ, idx); - err = ActionLoadOne(apiHandle, &actions[idx], actionJ, exportApi); + err = ActionLoadOne_V3(apiHandle, &actions[idx], actionJ, exportApi); if (err) return NULL; } } else { actions = calloc(2, sizeof (CtlActionT)); - err = ActionLoadOne(apiHandle, &actions[0], actionsJ, exportApi); + err = ActionLoadOne_V3(apiHandle, &actions[0], actionsJ, exportApi); if (err) return NULL; } diff --git a/ctl-lib/ctl-config.c b/ctl-lib/ctl-config.c index d1fb4bb..d6749fc 100644 --- a/ctl-lib/ctl-config.c +++ b/ctl-lib/ctl-config.c @@ -62,7 +62,7 @@ json_object* CtlConfigScan(const char *dirList, const char *prefix) { return responseJ; } -char* ConfigSearch(AFB_ApiT apiHandle, json_object *responseJ) { +char* ConfigSearch_V3(AFB_ApiT apiHandle, json_object *responseJ) { // We load 1st file others are just warnings size_t p_length; char *filepath = NULL; @@ -94,7 +94,7 @@ char* ConfigSearch(AFB_ApiT apiHandle, json_object *responseJ) { return filepath; } -char* CtlConfigSearch(AFB_ApiT apiHandle, const char *dirList, const char *prefix) { +char* CtlConfigSearch_V3(AFB_ApiT apiHandle, const char *dirList, const char *prefix) { // search for default dispatch config file json_object* responseJ = CtlConfigScan (dirList, prefix); @@ -123,7 +123,7 @@ static int DispatchRequireOneApi(AFB_ApiT apiHandle, json_object * bindindJ) { * @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) { +void DispatchRequireApi_V3(AFB_ApiT apiHandle, json_object * requireJ) { static int init = 0, err = 0; int idx; @@ -140,7 +140,7 @@ void DispatchRequireApi(AFB_ApiT apiHandle, json_object * requireJ) { init = 1; } -int CtlConfigExec(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) { +int CtlConfigExec_V3(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) { DispatchRequireApi(apiHandle, ctlConfig->requireJ); #ifdef CONTROL_SUPPORT_LUA @@ -161,7 +161,7 @@ int CtlConfigExec(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) { return errcount; } -CtlConfigT *CtlLoadMetaDataJson(AFB_ApiT apiHandle, json_object *ctlConfigJ, const char *prefix) { +CtlConfigT *CtlLoadMetaDataJson_V3(AFB_ApiT apiHandle, json_object *ctlConfigJ, const char *prefix) { json_object *metadataJ; CtlConfigT *ctlHandle=NULL; int err; @@ -189,7 +189,7 @@ CtlConfigT *CtlLoadMetaDataJson(AFB_ApiT apiHandle, json_object *ctlConfigJ, con return ctlHandle; } -CtlConfigT *CtlLoadMetaDataUsingPrefix(AFB_ApiT apiHandle,const char* filepath, const char *prefix) { +CtlConfigT *CtlLoadMetaDataUsingPrefix_V3(AFB_ApiT apiHandle,const char* filepath, const char *prefix) { json_object *ctlConfigJ; @@ -303,7 +303,7 @@ json_object* LoadAdditionalsFiles(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, con return sectionJ; } -int CtlLoadSections(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, CtlSectionT *sections) { +int CtlLoadSections_V3(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, CtlSectionT *sections) { int err; #ifdef CONTROL_SUPPORT_LUA diff --git a/ctl-lib/ctl-config.h b/ctl-lib/ctl-config.h index b2f1e2f..3497d5a 100644 --- a/ctl-lib/ctl-config.h +++ b/ctl-lib/ctl-config.h @@ -90,38 +90,41 @@ typedef enum { } SectionEnumT; // ctl-action.c -extern CtlActionT *ActionConfig(AFB_ApiT apiHandle, json_object *actionsJ, int exportApi); +extern CtlActionT *ActionConfig_V3(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); -extern int ActionLoadOne(AFB_ApiT apiHandle, CtlActionT *action, json_object *, int exportApi); +extern int ActionLoadOne_V3(AFB_ApiT apiHandle, CtlActionT *action, json_object *, int exportApi); extern int ActionLabelToIndex(CtlActionT* actions, const char* actionLabel); // ctl-config.c extern int CtlConfigMagicNew(); extern json_object* CtlConfigScan(const char *dirList, const char *prefix) ; -extern char* ConfigSearch(AFB_ApiT apiHandle, json_object *responseJ); -extern char* CtlConfigSearch(AFB_ApiT apiHandle, const char *dirList, const char *prefix) ; -extern void DispatchRequireApi(AFB_ApiT apiHandle, json_object * requireJ); -extern int CtlConfigExec(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) ; -extern CtlConfigT *CtlLoadMetaDataJson(AFB_ApiT apiHandle,json_object *ctlConfigJ, const char *prefix) ; -extern CtlConfigT *CtlLoadMetaDataUsingPrefix(AFB_ApiT apiHandle,const char* filepath, const char *prefix) ; -extern int CtlLoadSections(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, CtlSectionT *sections); +extern char* ConfigSearch_V3(AFB_ApiT apiHandle, json_object *responseJ); +extern char* CtlConfigSearch_V3(AFB_ApiT apiHandle, const char *dirList, const char *prefix) ; +extern void DispatchRequireApi_V3(AFB_ApiT apiHandle, json_object * requireJ); +extern int CtlConfigExec_V3(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) ; +extern CtlConfigT *CtlLoadMetaDataJson_V3(AFB_ApiT apiHandle,json_object *ctlConfigJ, const char *prefix) ; +extern CtlConfigT *CtlLoadMetaDataUsingPrefix_V3(AFB_ApiT apiHandle,const char* filepath, const char *prefix) ; +extern int CtlLoadSections_V3(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, CtlSectionT *sections); #define CtlLoadMetaData(api, filepath) CtlLoadMetaDataUsingPrefix(api, filepath, NULL) // ctl-event.c -extern int EventConfig(AFB_ApiT apihandle, CtlSectionT *section, json_object *actionsJ); -extern void CtrlDispatchApiEvent (AFB_ApiT apiHandle, const char *evtLabel, struct json_object *eventJ); +extern int EventConfig_V3(AFB_ApiT apihandle, CtlSectionT *section, json_object *actionsJ); +extern void CtrlDispatchApiEvent(AFB_ApiT apiHandle, const char *evtLabel, struct json_object *eventJ); extern void CtrlDispatchV2Event(const char *evtLabel, json_object *eventJ); // ctl-control.c -extern int ControlConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ); +extern int ControlConfig_V3(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ); // ctl-onload.c -extern int OnloadConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ); +extern int OnloadConfig_V3(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ); // ctl-plugin.c -extern int PluginConfig(AFB_ApiT UNUSED_ARG(apiHandle), CtlSectionT *section, json_object *pluginsJ); -extern int PluginGetCB (AFB_ApiT apiHandle, CtlActionT *action , json_object *callbackJ); +extern int PluginConfig_V3(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pluginsJ); +extern int PluginGetCB_V3(AFB_ApiT apiHandle, CtlActionT *action , json_object *callbackJ); + +#include "ctl-config_v2.h" +#include "ctl-config_v3.h" #ifdef __cplusplus } diff --git a/ctl-lib/ctl-config_v2.h b/ctl-lib/ctl-config_v2.h new file mode 100644 index 0000000..a835cbd --- /dev/null +++ b/ctl-lib/ctl-config_v2.h @@ -0,0 +1,74 @@ +#ifndef _CTL_CONFIG_V2_INCLUDE_ +#define _CTL_CONFIG_V2_INCLUDE_ + +#if(AFB_BINDING_VERSION==2) +// ctl-action.c +static inline CtlActionT *ActionConfig(AFB_ApiT apiHandle, json_object *actionsJ, int exportApi) +{ + return ActionConfig_V3(afbBindingV2data.service.closure, actionsJ, exportApi); +} +static inline int ActionLoadOne(AFB_ApiT apiHandle, CtlActionT *action, json_object *obj, int exportApi) +{ + return ActionLoadOne_V3(afbBindingV2data.service.closure, action, obj, exportApi); +} + +// ctl-config.c +static inline char* ConfigSearch(AFB_ApiT apiHandle, json_object *responseJ) +{ + return ConfigSearch_V3(afbBindingV2data.service.closure, responseJ); +} +static inline char* CtlConfigSearch(AFB_ApiT apiHandle, const char *dirList, const char *prefix) +{ + return CtlConfigSearch_V3(afbBindingV2data.service.closure, dirList, prefix); +} +static inline void DispatchRequireApi(AFB_ApiT apiHandle, json_object * requireJ) +{ + DispatchRequireApi_V3(afbBindingV2data.service.closure, requireJ); +} +static inline int CtlConfigExec(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) +{ + return CtlConfigExec_V3(afbBindingV2data.service.closure, ctlConfig); +} +static inline CtlConfigT *CtlLoadMetaDataJson(AFB_ApiT apiHandle,json_object *ctlConfigJ, const char *prefix) +{ + return CtlLoadMetaDataJson_V3(afbBindingV2data.service.closure, ctlConfigJ, prefix); +} +static inline CtlConfigT *CtlLoadMetaDataUsingPrefix(AFB_ApiT apiHandle,const char* filepath, const char *prefix) +{ + return CtlLoadMetaDataUsingPrefix_V3(afbBindingV2data.service.closure, filepath, prefix); +} +static inline int CtlLoadSections(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, CtlSectionT *sections) +{ + return CtlLoadSections_V3(afbBindingV2data.service.closure, ctlHandle, sections); +} + +// ctl-event.c +static inline int EventConfig(AFB_ApiT apihandle, CtlSectionT *section, json_object *actionsJ) +{ + return EventConfig_V3(afbBindingV2data.service.closure, section, actionsJ); +} + +// ctl-control.c +static inline int ControlConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ) +{ + return ControlConfig_V3(afbBindingV2data.service.closure, section, actionsJ); +} + +// ctl-onload.c +static inline int OnloadConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ) +{ + return OnloadConfig_V3(afbBindingV2data.service.closure, section, actionsJ); +} + +// ctl-plugin.c +static inline int PluginConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pluginsJ) +{ + return PluginConfig_V3(afbBindingV2data.service.closure, section, pluginsJ); +} +static inline int PluginGetCB(AFB_ApiT apiHandle, CtlActionT *action , json_object *callbackJ) +{ + return PluginGetCB_V3(afbBindingV2data.service.closure, action, callbackJ); +} +#endif + +#endif /* _CTL_CONFIG_INCLUDE_ */ diff --git a/ctl-lib/ctl-config_v3.h b/ctl-lib/ctl-config_v3.h new file mode 100644 index 0000000..bdddedf --- /dev/null +++ b/ctl-lib/ctl-config_v3.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2016 "IoT.bzh" + * Author Fulup Ar Foll <fulup@iot.bzh> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, something express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Reference: + * Json load using json_unpack https://jansson.readthedocs.io/en/2.9/apiref.html#parsing-and-validating-values + */ + +#ifndef _CTL_CONFIG_V3_INCLUDE_ +#define _CTL_CONFIG_V3_INCLUDE_ + +#if(AFB_BINDING_VERSION!=2) +// ctl-action.c +static inline CtlActionT *ActionConfig(AFB_ApiT apiHandle, json_object *actionsJ, int exportApi) +{ + return ActionConfig_V3(apiHandle, actionsJ, exportApi); +} +static inline int ActionLoadOne(AFB_ApiT apiHandle, CtlActionT *action, json_object *obj, int exportApi) +{ + return ActionLoadOne_V3(apiHandle, action, obj, exportApi); +} + +// ctl-config.c +static inline char* ConfigSearch(AFB_ApiT apiHandle, json_object *responseJ) +{ + return ConfigSearch_V3(apiHandle, responseJ); +} +static inline char* CtlConfigSearch(AFB_ApiT apiHandle, const char *dirList, const char *prefix) +{ + return CtlConfigSearch_V3(apiHandle, dirList, prefix); +} +static inline void DispatchRequireApi(AFB_ApiT apiHandle, json_object * requireJ) +{ + DispatchRequireApi_V3(apiHandle, requireJ); +} +static inline int CtlConfigExec(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) +{ + return CtlConfigExec_V3(apiHandle, ctlConfig); +} +static inline CtlConfigT *CtlLoadMetaDataJson(AFB_ApiT apiHandle,json_object *ctlConfigJ, const char *prefix) +{ + return CtlLoadMetaDataJson_V3(apiHandle, ctlConfigJ, prefix); +} +static inline CtlConfigT *CtlLoadMetaDataUsingPrefix(AFB_ApiT apiHandle,const char* filepath, const char *prefix) +{ + return CtlLoadMetaDataUsingPrefix_V3(apiHandle, filepath, prefix); +} +static inline int CtlLoadSections(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, CtlSectionT *sections) +{ + return CtlLoadSections_V3(apiHandle, ctlHandle, sections); +} + +// ctl-event.c +static inline int EventConfig(AFB_ApiT apihandle, CtlSectionT *section, json_object *actionsJ) +{ + return EventConfig_V3(apihandle, section, actionsJ); +} + +// ctl-control.c +static inline int ControlConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ) +{ + return ControlConfig_V3(apiHandle, section, actionsJ); +} + +// ctl-onload.c +static inline int OnloadConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ) +{ + return OnloadConfig_V3(apiHandle, section, actionsJ); +} + +// ctl-plugin.c +static inline int PluginConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pluginsJ) +{ + return PluginConfig_V3(apiHandle, section, pluginsJ); +} +static inline int PluginGetCB(AFB_ApiT apiHandle, CtlActionT *action , json_object *callbackJ) +{ + return PluginGetCB_V3(apiHandle, action, callbackJ); +} + +#endif +#endif /* _CTL_CONFIG_INCLUDE_ */ diff --git a/ctl-lib/ctl-control.c b/ctl-lib/ctl-control.c index 0605d6b..8669d00 100644 --- a/ctl-lib/ctl-control.c +++ b/ctl-lib/ctl-control.c @@ -23,11 +23,11 @@ #include "ctl-config.h" // onload section receive one action or an array of actions -int ControlConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ) { +int ControlConfig_V3(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ) { // Load time parse actions in config file if (actionsJ != NULL) { - section->actions= ActionConfig(apiHandle, actionsJ, 1); + section->actions= ActionConfig_V3(apiHandle, actionsJ, 1); if (!section->actions) { AFB_ApiError (apiHandle, "ControlLoad config fail processing onload actions"); diff --git a/ctl-lib/ctl-event.c b/ctl-lib/ctl-event.c index bb847b5..6042d21 100644 --- a/ctl-lib/ctl-event.c +++ b/ctl-lib/ctl-event.c @@ -29,11 +29,7 @@ void CtrlDispatchApiEvent (AFB_ApiT apiHandle, const char *evtLabel, struct json 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 + CtlConfigT *ctrlConfig = (CtlConfigT*) AFB_ApiGetUserData(apiHandle); for (idx = 0; ctrlConfig->sections[idx].key != NULL; ++idx) { @@ -60,7 +56,7 @@ void CtrlDispatchApiEvent (AFB_ApiT apiHandle, const char *evtLabel, struct json } // onload section receive one action or an array of actions -int EventConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ) { +int EventConfig_V3(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ) { // Load time parse actions in config file if (actionsJ != NULL) { diff --git a/ctl-lib/ctl-lua.c b/ctl-lib/ctl-lua.c index 8d67ae4..c06b156 100644 --- a/ctl-lib/ctl-lua.c +++ b/ctl-lib/ctl-lua.c @@ -40,7 +40,7 @@ #endif static lua_State* luaState; -static CtlPluginT *ctlPlugins = NULL; +CtlPluginT *ctlPlugins = NULL; #if CTX_MAGIC_VALUE static int CTX_MAGIC = CTX_MAGIC_VALUE; @@ -285,13 +285,7 @@ static int LuaFormatMessage(lua_State* luaState, int verbosity, int level) { return 1; // if log level low then silently ignore message -#ifndef AFB_BINDING_PREV3 - if (afb_get_verbosity() < verbosity) return 0; -#elif !defined(AFB_BINDING_INTERFACE_VERSION) - if (source->api->verbosity < verbosity) return 0; -#else - if (!afb_dynapi_wants_log_level(source->api, level)) return 0; -#endif + if (!afb_api_x3_wants_log_level(source->api, level)) return 0; json_object *responseJ = LuaPopArgs(source, luaState, LUA_FIRST_ARG + 1); @@ -985,13 +979,9 @@ static int LuaTimerClear(lua_State* luaState) { if (!timerHandle) return 1; -#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; AFB_ApiNotice(luaCbHandle->source->api, "LuaTimerClear timer=%s", timerHandle->uid); -#else - AFB_NOTICE("LuaTimerClear timer=%s", timerHandle->uid); -#endif TimerEvtStop(timerHandle); diff --git a/ctl-lib/ctl-onload.c b/ctl-lib/ctl-onload.c index 9baa689..736048b 100644 --- a/ctl-lib/ctl-onload.c +++ b/ctl-lib/ctl-onload.c @@ -23,7 +23,7 @@ #include "ctl-config.h" // onload section receive one action or an array of actions -int OnloadConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ) { +int OnloadConfig_V3(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ) { int err = 0; // Load time parse actions in control file diff --git a/ctl-lib/ctl-plugin.c b/ctl-lib/ctl-plugin.c index e57fb8a..71931b8 100644 --- a/ctl-lib/ctl-plugin.c +++ b/ctl-lib/ctl-plugin.c @@ -24,7 +24,7 @@ #include "ctl-config.h" -int PluginGetCB (AFB_ApiT apiHandle, CtlActionT *action , json_object *callbackJ) { +int PluginGetCB_V3(AFB_ApiT apiHandle, CtlActionT *action , json_object *callbackJ) { const char *plugin=NULL, *function=NULL; json_object *argsJ; int idx; @@ -94,11 +94,9 @@ static int PluginLoadCOne(AFB_ApiT apiHandle, const char *pluginpath, json_objec // 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"); @@ -401,7 +399,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_V3(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pluginsJ) { int err = 0; int idx = 0, jdx = 0; int pluginNb = 0, newPluginsNb = 0, totalPluginNb = 0; diff --git a/ctl-lib/ctl-plugin.h b/ctl-lib/ctl-plugin.h index 6fff0c5..e4b8ccb 100644 --- a/ctl-lib/ctl-plugin.h +++ b/ctl-lib/ctl-plugin.h @@ -115,7 +115,7 @@ typedef struct { } exec; } CtlActionT; -static CtlPluginT *ctlPlugins; +extern CtlPluginT *ctlPlugins; typedef int(*DispatchPluginInstallCbT)(CtlPluginT *plugin, void* handle); |