summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-12-13 14:42:49 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-17 10:04:07 +0100
commiteaf644db7106061481710adb75023122ce4bc150 (patch)
tree9b06621a42861997b96a6f0921a0b33dc685d654
parenteaf8c0808d54d987a532254887919822438b7848 (diff)
Shared library: update to a v3 shared library
- AFB_BINDING_VERSION = 3 - remove preprocessor variables - mandatory lua - name of library is ctl-utilities - does not work with v2 versions - remove afb-definitions.h - use of the GNUinstalldirs module to set the destination directories. Change-Id: Ifdf12885ffad5003ecbbcf3639af63060f0ebc7e Signed-off-by: Clément Bénier <clement.benier@iot.bzh> Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--CMakeLists.txt2
-rw-r--r--ctl-lib/CMakeLists.txt93
-rw-r--r--ctl-lib/afb-definitions.h242
-rw-r--r--ctl-lib/ctl-action.c88
-rw-r--r--ctl-lib/ctl-config.c65
-rw-r--r--ctl-lib/ctl-config.h42
-rw-r--r--ctl-lib/ctl-control.c4
-rw-r--r--ctl-lib/ctl-event.c40
-rw-r--r--ctl-lib/ctl-lua.c127
-rw-r--r--ctl-lib/ctl-lua.h8
-rw-r--r--ctl-lib/ctl-onload.c10
-rw-r--r--ctl-lib/ctl-plugin.c170
-rw-r--r--ctl-lib/ctl-plugin.h12
-rw-r--r--ctl-lib/ctl-timer.c104
-rw-r--r--ctl-lib/ctl-timer.h54
-rw-r--r--ctl-lib/ctl-utilities.pc.in31
16 files changed, 355 insertions, 737 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a6c55d7..9804022 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,4 +17,6 @@
###########################################################################
# This component should be included as a submodule and wont compile as standalone
+CMAKE_MINIMUM_REQUIRED(VERSION 3.3)
+include(GNUInstallDirs)
add_subdirectory("ctl-lib")
diff --git a/ctl-lib/CMakeLists.txt b/ctl-lib/CMakeLists.txt
index 3ab0774..48684e0 100644
--- a/ctl-lib/CMakeLists.txt
+++ b/ctl-lib/CMakeLists.txt
@@ -15,29 +15,78 @@
# See the License for the specific language governing permissions and
# limitations under the License.
###########################################################################
+set(TARGET_NAME "ctl-utilities")
+set(PROJECT_PRETTY_NAME "Controller")
+set(PROJECT_DESCRIPTION "controller")
+set(PROJECT_URL "https://gerrit.automotivelinux.org:29418/apps/app-controller-submodule")
+set(PROJECT_AUTHOR "Ar Foll, Fulup")
+set(PROJECT_AUTHOR_MAIL "fulup@iot.bzh")
+set(PROJECT_LICENSE "APL2.0")
+set(PROJECT_LANGUAGES "C")
-# Include LUA only when requested
-if(CONTROL_SUPPORT_LUA)
- message(STATUS "Notice: LUA Controler Support Selected")
- set(CTL_LUA_SOURCE ctl-lua.c ctl-timer.c ctl-lua-utils.c)
- ADD_COMPILE_OPTIONS(-DCONTROL_SUPPORT_LUA)
-else(CONTROL_SUPPORT_LUA)
- message(STATUS "Warning: LUA Without Support ")
-endif(CONTROL_SUPPORT_LUA)
-
-# Add target to project dependency list
-PROJECT_TARGET_ADD(ctl-utilities)
-
- # Define project Targets
- ADD_LIBRARY(${TARGET_NAME} STATIC ctl-action.c ctl-config.c ctl-onload.c ctl-plugin.c ctl-control.c ctl-event.c ${CTL_LUA_SOURCE})
-
- # Library dependencies (include updates automatically)
- TARGET_LINK_LIBRARIES(${TARGET_NAME}
- afb-helpers
- ${link_libraries}
+if(NOT CMAKE_INSTALL_PREFIX)
+ set(CMAKE_INSTALL_PREFIX "/usr")
+endif()
+add_definitions(-DAFB_BINDING_VERSION=3)
+add_definitions(-DLUA_GLOB_PATTERN="/var/?.lua\\\;")
+add_definitions(-DSUSE_LUA_INCDIR)
+
+
+INCLUDE(FindPkgConfig)
+set (PKG_REQUIRED_LIST
+ afb-daemon
+ afb-helpers
+ lua
+ )
+
+# Loop on required package and add options
+foreach (PKG_CONFIG ${PKG_REQUIRED_LIST})
+ string(REGEX REPLACE "[<>]?=.*$" "" XPREFIX ${PKG_CONFIG})
+ PKG_CHECK_MODULES(${XPREFIX} REQUIRED ${PKG_CONFIG})
+
+ INCLUDE_DIRECTORIES(${${XPREFIX}_INCLUDE_DIRS})
+ list(APPEND link_libraries ${${XPREFIX}_LDFLAGS})
+ add_compile_options (${${XPREFIX}_CFLAGS})
+endforeach(PKG_CONFIG)
+
+
+set(CTL_LUA_SOURCE ctl-lua.c ctl-lua-utils.c)
+ADD_COMPILE_OPTIONS(-DCONTROL_SUPPORT_LUA)
+
+set(CONTROLLER_HEADERS
+ ctl-config.h
+ ctl-lua.h
+ ctl-plugin.h
)
- # Define target includes for this target client
- TARGET_INCLUDE_DIRECTORIES(${TARGET_NAME}
- PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
+# Define project Targets
+ADD_LIBRARY(${TARGET_NAME} SHARED ctl-action.c ctl-config.c ctl-onload.c ctl-plugin.c ctl-control.c ctl-event.c ${CTL_LUA_SOURCE})
+
+# Library dependencies (include updates automatically)
+TARGET_LINK_LIBRARIES(${TARGET_NAME}
+ afb-helpers
+ ${link_libraries}
+ )
+
+# Define target includes for this target client
+TARGET_INCLUDE_DIRECTORIES(${TARGET_NAME}
+ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
+ )
+
+CONFIGURE_FILE(${TARGET_NAME}.pc.in ${TARGET_NAME}.pc @ONLY)
+INSTALL(FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}.pc
+ DESTINATION
+ ${CMAKE_INSTALL_LIBDIR}/pkgconfig
+ )
+
+INSTALL(FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/lib${TARGET_NAME}.so
+ DESTINATION
+ ${CMAKE_INSTALL_LIBDIR}
+ )
+INSTALL(FILES
+ ${CONTROLLER_HEADERS}
+ DESTINATION
+ ${CMAKE_INSTALL_INCLUDEDIR}
)
diff --git a/ctl-lib/afb-definitions.h b/ctl-lib/afb-definitions.h
deleted file mode 100644
index 5a749c6..0000000
--- a/ctl-lib/afb-definitions.h
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * 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_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)
-
- #define AFB_ReqJson(request) afb_request_json(request)
-
- #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_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_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_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
-
-/*
- * 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
-#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_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 */
- 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;
-
-#else
- #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_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 0bd9c7b..735ade9 100644
--- a/ctl-lib/ctl-action.c
+++ b/ctl-lib/ctl-action.c
@@ -34,7 +34,7 @@ int ActionLabelToIndex(CtlActionT*actions, const char* actionLabel) {
return -1;
}
-void ActionExecUID(AFB_ReqT request, CtlConfigT *ctlConfig, const char *uid, json_object *queryJ) {
+void ActionExecUID(afb_req_t request, CtlConfigT *ctlConfig, const char *uid, json_object *queryJ) {
for (int i = 0; ctlConfig->sections[i].key != NULL; i++) {
if (ctlConfig->sections[i].actions) {
for (int j = 0; ctlConfig->sections[i].actions[j].uid != NULL; j++) {
@@ -73,7 +73,7 @@ int ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *queryJ) {
break;
default:
- AFB_ApiError(action->api, "ActionExecOne(queryJ should be an object) uid=%s args=%s", source->uid, json_object_get_string(queryJ));
+ AFB_API_ERROR(action->api, "ActionExecOne(queryJ should be an object) uid=%s args=%s", source->uid, json_object_get_string(queryJ));
return -1;
}
}
@@ -82,16 +82,16 @@ int ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *queryJ) {
}
/* AFB Subcall will release the json_object doing the json_object_put() call */
- err = AFB_ServiceSync(action->api, action->exec.subcall.api, action->exec.subcall.verb, extendedQueryJ, &returnJ);
- if(err && AFB_ReqIsValid(source->request))
- AFB_ReqFailF(source->request, "subcall-fail", "ActionExecOne(AppFw) uid=%s api=%s verb=%s args=%s", source->uid, action->exec.subcall.api, action->exec.subcall.verb, json_object_get_string(action->argsJ));
- else if(err && ! AFB_ReqIsValid(source->request))
- AFB_ApiError(action->api, "ActionExecOne(AppFw) uid=%s api=%s verb=%s args=%s", source->uid, action->exec.subcall.api, action->exec.subcall.verb, json_object_get_string(action->argsJ));
- else if(AFB_ReqIsValid(source->request)) {
+ err = afb_api_call_sync_legacy(action->api, action->exec.subcall.api, action->exec.subcall.verb, extendedQueryJ, &returnJ);
+ if(err && afb_req_is_valid(source->request))
+ afb_req_fail_f(source->request, "subcall-fail", "ActionExecOne(AppFw) uid=%s api=%s verb=%s args=%s", source->uid, action->exec.subcall.api, action->exec.subcall.verb, json_object_get_string(action->argsJ));
+ else if(err && ! afb_req_is_valid(source->request))
+ AFB_API_ERROR(action->api, "ActionExecOne(AppFw) uid=%s api=%s verb=%s args=%s", source->uid, action->exec.subcall.api, action->exec.subcall.verb, json_object_get_string(action->argsJ));
+ else if(afb_req_is_valid(source->request)) {
if(wrap_json_unpack(returnJ, "{s:o}", "response", &toReturnJ))
- AFB_ApiError(action->api, "ActionExecOne(Can't unpack response) uid=%s api=%s verb=%s args=%s", source->uid, action->exec.subcall.api, action->exec.subcall.verb, json_object_get_string(action->argsJ));
+ AFB_API_ERROR(action->api, "ActionExecOne(Can't unpack response) uid=%s api=%s verb=%s args=%s", source->uid, action->exec.subcall.api, action->exec.subcall.verb, json_object_get_string(action->argsJ));
else
- AFB_ReqSuccess(source->request, toReturnJ, NULL);
+ afb_req_success(source->request, toReturnJ, NULL);
}
break;
}
@@ -100,7 +100,7 @@ int ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *queryJ) {
case CTL_TYPE_LUA:
err = LuaCallFunc(source, action, queryJ);
if (err) {
- AFB_ApiError(action->api, "ActionExecOne(Lua) uid=%s func=%s args=%s", source->uid, action->exec.lua.funcname, json_object_get_string(action->argsJ));
+ AFB_API_ERROR(action->api, "ActionExecOne(Lua) uid=%s func=%s args=%s", source->uid, action->exec.lua.funcname, json_object_get_string(action->argsJ));
}
break;
#endif
@@ -109,13 +109,13 @@ int ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *queryJ) {
source->plugin = action->exec.cb.plugin;
err = (*action->exec.cb.callback) (source, action->argsJ, queryJ);
if (err) {
- AFB_ApiError(action->api, "ActionExecOne(Callback) uid%s plugin=%s function=%s args=%s", source->uid, action->exec.cb.plugin->uid, action->exec.cb.funcname, json_object_get_string(action->argsJ));
+ AFB_API_ERROR(action->api, "ActionExecOne(Callback) uid%s plugin=%s function=%s args=%s", source->uid, action->exec.cb.plugin->uid, action->exec.cb.funcname, json_object_get_string(action->argsJ));
}
break;
default:
{
- AFB_ApiError(action->api, "ActionExecOne(unknown) API type uid=%s", source->uid);
+ AFB_API_ERROR(action->api, "ActionExecOne(unknown) API type uid=%s", source->uid);
break;
}
}
@@ -125,13 +125,10 @@ 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) {
-
+static void ActionDynRequest(afb_req_t request) {
// retrieve action handle from request and execute the request
- json_object *queryJ = AFB_ReqJson(request);
- CtlActionT* action = (CtlActionT*) AFB_ReqVCBData(request);
+ json_object *queryJ = afb_req_json(request);
+ CtlActionT* action = (CtlActionT*) afb_req_get_vcbdata(request);
CtlSourceT source;
source.uid = action->uid;
@@ -141,10 +138,8 @@ 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)
-{
+void ParseURI(const char *uri, char **first, char **second) {
char *tmp;
if(! uri || ! first || ! second) {
@@ -175,12 +170,12 @@ void ParseURI(const char *uri, char **first, char **second)
* the function
*
*/
-static int BuildPluginAction(AFB_ApiT apiHandle, const char *uri, CtlActionT *action) {
+static int BuildPluginAction(afb_api_t apiHandle, const char *uri, CtlActionT *action) {
char *plugin = NULL, *function = NULL;
json_object *callbackJ = NULL;
if (!action) {
- AFB_ApiError(apiHandle, "Action not valid");
+ AFB_API_ERROR(apiHandle, "Action not valid");
return -1;
}
@@ -193,13 +188,13 @@ static int BuildPluginAction(AFB_ApiT apiHandle, const char *uri, CtlActionT *ac
"plugin", plugin,
"function", function,
"args", action->argsJ)) {
- AFB_ApiError(apiHandle, "Error packing Callback JSON object for plugin %s and function %s", uri, function);
+ AFB_API_ERROR(apiHandle, "Error packing Callback JSON object for plugin %s and function %s", uri, function);
return -1;
} else {
return PluginGetCB(apiHandle, action, callbackJ);
}
} else {
- AFB_ApiError(apiHandle, "Miss something uri or function.");
+ AFB_API_ERROR(apiHandle, "Miss something uri or function.");
return -1;
}
@@ -214,18 +209,18 @@ static int BuildPluginAction(AFB_ApiT apiHandle, const char *uri, CtlActionT *ac
* unexpected result.
*
*/
-static int BuildApiAction(AFB_ApiT apiHandle, const char *uri, CtlActionT *action) {
+static int BuildApiAction(afb_api_t apiHandle, const char *uri, CtlActionT *action) {
char *api = NULL, *verb = NULL;
if (!action) {
- AFB_ApiError(apiHandle, "Action not valid");
+ AFB_API_ERROR(apiHandle, "Action not valid");
return -1;
}
ParseURI(uri, &api, &verb);
if(!api || !verb) {
- AFB_ApiError(apiHandle, "Error parsing the action string");
+ AFB_API_ERROR(apiHandle, "Error parsing the action string");
return -1;
}
@@ -246,18 +241,18 @@ static int BuildApiAction(AFB_ApiT apiHandle, const char *uri, CtlActionT *actio
*/
#ifdef CONTROL_SUPPORT_LUA
-static int BuildLuaAction(AFB_ApiT apiHandle, const char *uri, CtlActionT *action) {
+static int BuildLuaAction(afb_api_t apiHandle, const char *uri, CtlActionT *action) {
char *plugin = NULL, *function = NULL;
if (!action) {
- AFB_ApiError(apiHandle, "Action not valid");
+ AFB_API_ERROR(apiHandle, "Action not valid");
return -1;
}
ParseURI(uri, &plugin, &function);
if(!plugin || !function) {
- AFB_ApiError(apiHandle, "Error parsing the action string");
+ AFB_API_ERROR(apiHandle, "Error parsing the action string");
return -1;
}
@@ -269,7 +264,7 @@ static int BuildLuaAction(AFB_ApiT apiHandle, const char *uri, CtlActionT *actio
}
#endif
-static int BuildOneAction(AFB_ApiT apiHandle, CtlActionT *action, const char *uri) {
+static int BuildOneAction(afb_api_t apiHandle, CtlActionT *action, const char *uri) {
size_t lua_pre_len = strlen(LUA_ACTION_PREFIX);
size_t api_pre_len = strlen(API_ACTION_PREFIX);
size_t plugin_pre_len = strlen(PLUGIN_ACTION_PREFIX);
@@ -279,7 +274,7 @@ static int BuildOneAction(AFB_ApiT apiHandle, CtlActionT *action, const char *ur
#ifdef CONTROL_SUPPORT_LUA
return BuildLuaAction(apiHandle, &uri[lua_pre_len], action);
#else
- AFB_ApiError(apiHandle, "LUA support not selected at build. Feature disabled");
+ AFB_API_ERROR(apiHandle, "LUA support not selected at build. Feature disabled");
return -1;
#endif
} else if (!strncasecmp(uri, API_ACTION_PREFIX, api_pre_len)) {
@@ -287,18 +282,18 @@ static int BuildOneAction(AFB_ApiT apiHandle, CtlActionT *action, const char *ur
} else if (!strncasecmp(uri, PLUGIN_ACTION_PREFIX, plugin_pre_len)) {
return BuildPluginAction(apiHandle, &uri[plugin_pre_len], action);
} else {
- AFB_ApiError(apiHandle, "Wrong uri specified. You have to specified 'lua://', 'plugin://' or 'api://'.");
+ AFB_API_ERROR(apiHandle, "Wrong uri specified. You have to specified 'lua://', 'plugin://' or 'api://'.");
return -1;
}
}
- AFB_ApiError(apiHandle, "Uri, Action or function not valid");
+ AFB_API_ERROR(apiHandle, "Uri, Action or function not valid");
return -1;
}
// unpack individual action object
-int ActionLoadOne(AFB_ApiT apiHandle, CtlActionT *action, json_object *actionJ, int exportApi) {
+int ActionLoadOne(afb_api_t apiHandle, CtlActionT *action, json_object *actionJ, int exportApi) {
int err = 0;
const char *uri = NULL;
@@ -312,33 +307,30 @@ int ActionLoadOne(AFB_ApiT apiHandle, CtlActionT *action, json_object *actionJ,
"privileges", &action->privileges,
"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;
if (exportApi) {
- err = AFB_ApiAddVerb(apiHandle, action->uid, action->info, ActionDynRequest, action, NULL, 0, 0);
+ err = afb_api_add_verb(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);
+ AFB_API_ERROR(apiHandle, "ACTION-LOAD-ONE fail to register API verb=%s", action->uid);
return -1;
}
}
-#endif
err = BuildOneAction(apiHandle, action, uri);
} else {
- AFB_ApiError(apiHandle, "Fail to parse action JSON : (%s)", json_object_to_json_string(actionJ));
+ AFB_API_ERROR(apiHandle, "Fail to parse action JSON : (%s)", json_object_to_json_string(actionJ));
err = -1;
}
} else {
- AFB_ApiError(apiHandle, "Wrong action JSON object parameter: (%s)", json_object_to_json_string(actionJ));
+ AFB_API_ERROR(apiHandle, "Wrong action JSON object parameter: (%s)", json_object_to_json_string(actionJ));
err = -1;
}
return err;
}
-CtlActionT *ActionConfig(AFB_ApiT apiHandle, json_object *actionsJ, int exportApi) {
+CtlActionT *ActionConfig(afb_api_t apiHandle, json_object *actionsJ, int exportApi) {
int err;
CtlActionT *actions;
@@ -365,7 +357,7 @@ CtlActionT *ActionConfig(AFB_ApiT apiHandle, json_object *actionsJ, int exportAp
return actions;
}
-int AddActionsToSection(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ, int exportApi) {
+int AddActionsToSection(afb_api_t apiHandle, CtlSectionT *section, json_object *actionsJ, int exportApi) {
if (actionsJ || section) {
CtlActionT *actions = NULL;
if(section->actions) {
@@ -398,12 +390,12 @@ int AddActionsToSection(AFB_ApiT apiHandle, CtlSectionT *section, json_object *a
section->actions = actions;
}
else {
- AFB_ApiError (apiHandle, "Missing actions to add or the section object");
+ AFB_API_ERROR (apiHandle, "Missing actions to add or the section object");
return 1;
}
if (!section->actions) {
- AFB_ApiError (apiHandle, "Adding '%s' fails to section %s", json_object_get_string(actionsJ), section->uid);
+ AFB_API_ERROR (apiHandle, "Adding '%s' fails to section %s", json_object_get_string(actionsJ), section->uid);
return 1;
}
return 0;
diff --git a/ctl-lib/ctl-config.c b/ctl-lib/ctl-config.c
index 532a2e8..42391db 100644
--- a/ctl-lib/ctl-config.c
+++ b/ctl-lib/ctl-config.c
@@ -26,13 +26,8 @@
#include "filescan-utils.h"
#include "ctl-config.h"
-extern void* getExternalData(CtlConfigT *ctlConfig) {
- return ctlConfig->external;
-}
-extern void setExternalData(CtlConfigT *ctlConfig, void *data) {
- ctlConfig->external = data;
-}
+// Load control config file
int CtlConfigMagicNew() {
static int InitRandomDone=0;
@@ -67,7 +62,7 @@ json_object* CtlConfigScan(const char *dirList, const char *prefix) {
return responseJ;
}
-char* ConfigSearch(AFB_ApiT apiHandle, json_object *responseJ) {
+char* ConfigSearch(afb_api_t apiHandle, json_object *responseJ) {
// We load 1st file others are just warnings
size_t p_length;
char *filepath = NULL;
@@ -79,7 +74,7 @@ char* ConfigSearch(AFB_ApiT apiHandle, json_object *responseJ) {
int err = wrap_json_unpack(entryJ, "{s:s, s:s !}", "fullpath", &fullpath, "filename", &filename);
if (err) {
- AFB_ApiError(apiHandle, "CTL-INIT HOOPs invalid JSON entry= %s", json_object_get_string(entryJ));
+ AFB_API_ERROR(apiHandle, "CTL-INIT HOOPs invalid JSON entry= %s", json_object_get_string(entryJ));
}
if (index == 0) {
@@ -91,7 +86,7 @@ char* ConfigSearch(AFB_ApiT apiHandle, json_object *responseJ) {
strncat(filepath, filename, p_length - strlen(filepath));
}
else {
- AFB_ApiWarning(apiHandle, "CTL-INIT JSON file found but not used : %s/%s", fullpath, filename);
+ AFB_API_WARNING(apiHandle, "CTL-INIT JSON file found but not used : %s/%s", fullpath, filename);
}
}
@@ -99,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(afb_api_t apiHandle, const char *dirList, const char *prefix) {
// search for default dispatch config file
json_object* responseJ = CtlConfigScan (dirList, prefix);
@@ -109,12 +104,11 @@ char* CtlConfigSearch(AFB_ApiT apiHandle, const char *dirList, const char *prefi
return NULL;
}
-static int DispatchRequireOneApi(AFB_ApiT apiHandle, json_object * bindindJ) {
+static int DispatchRequireOneApi(afb_api_t apiHandle, json_object * bindindJ) {
const char* requireBinding = json_object_get_string(bindindJ);
- int err = AFB_RequireApi(apiHandle, requireBinding, 1);
+ int err = afb_api_require_api(apiHandle, requireBinding, 1);
if (err) {
- AFB_ApiError(apiHandle, "CTL-LOAD-CONFIG:REQUIRE Fail to get=%s. Aborting.", requireBinding);
- exit(1);
+ AFB_API_WARNING(apiHandle, "CTL-LOAD-CONFIG:REQUIRE Fail to get=%s", requireBinding);
}
return err;
@@ -126,10 +120,10 @@ static int DispatchRequireOneApi(AFB_ApiT apiHandle, json_object * bindindJ) {
* 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 apiHandle : a afb_daemon api handle, see afb_api_t in afb_definitions.h
* @param requireJ : json_object array of api name required.
*/
-void DispatchRequireApi(AFB_ApiT apiHandle, json_object * requireJ) {
+void DispatchRequireApi(afb_api_t apiHandle, json_object * requireJ) {
static int init = 0, err = 0;
int idx;
@@ -146,7 +140,7 @@ void DispatchRequireApi(AFB_ApiT apiHandle, json_object * requireJ) {
init = 1;
}
-int CtlConfigExec(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) {
+int CtlConfigExec(afb_api_t apiHandle, CtlConfigT *ctlConfig) {
DispatchRequireApi(apiHandle, ctlConfig->requireJ);
#ifdef CONTROL_SUPPORT_LUA
@@ -158,7 +152,7 @@ int CtlConfigExec(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) {
int errcount=0;
for (int idx = 0; ctlConfig->sections[idx].key != NULL; idx++) {
if (!ctlConfig->sections[idx].loadCB)
- AFB_ApiNotice(apiHandle, "CtlConfigLoad: notice empty section '%s'", ctlConfig->sections[idx].key);
+ AFB_API_NOTICE(apiHandle, "CtlConfigLoad: notice empty section '%s'", ctlConfig->sections[idx].key);
else
errcount += ctlConfig->sections[idx].loadCB(apiHandle, &ctlConfig->sections[idx], NULL);
}
@@ -166,7 +160,7 @@ int CtlConfigExec(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) {
return errcount;
}
-CtlConfigT *CtlLoadMetaDataJson(AFB_ApiT apiHandle, json_object *ctlConfigJ, const char *prefix) {
+CtlConfigT *CtlLoadMetaDataJson(afb_api_t apiHandle, json_object *ctlConfigJ, const char *prefix) {
json_object *metadataJ;
CtlConfigT *ctlHandle=NULL;
int err;
@@ -183,30 +177,31 @@ CtlConfigT *CtlLoadMetaDataJson(AFB_ApiT apiHandle, json_object *ctlConfigJ, con
"author", &ctlHandle->author,
"date", &ctlHandle->date);
if (err) {
- AFB_ApiError(apiHandle, "CTL-LOAD-CONFIG:METADATA Missing something uid|api|version|[info]|[require]|[author]|[date] in:\n-- %s", json_object_get_string(metadataJ));
+ AFB_API_ERROR(apiHandle, "CTL-LOAD-CONFIG:METADATA Missing something uid|api|version|[info]|[require]|[author]|[date] in:\n-- %s", json_object_get_string(metadataJ));
free(ctlHandle);
return NULL;
}
-
- ctlHandle->configJ = ctlConfigJ;
- ctlHandle->prefix = prefix;
}
+ ctlHandle->configJ = ctlConfigJ;
+ ctlHandle->prefix = prefix;
+ ctlHandle->ctlPlugins = &ctlPlugins;
+
return ctlHandle;
}
-CtlConfigT *CtlLoadMetaDataUsingPrefix(AFB_ApiT apiHandle,const char* filepath, const char *prefix) {
+CtlConfigT *CtlLoadMetaDataUsingPrefix(afb_api_t apiHandle,const char* filepath, const char *prefix) {
json_object *ctlConfigJ;
// Load JSON file
ctlConfigJ = json_object_from_file(filepath);
if (!ctlConfigJ) {
- AFB_ApiError(apiHandle, "CTL-LOAD-CONFIG Not invalid JSON %s ", filepath);
+ AFB_API_ERROR(apiHandle, "CTL-LOAD-CONFIG Not invalid JSON %s ", filepath);
return NULL;
}
- AFB_ApiInfo(apiHandle, "CTL-LOAD-CONFIG: loading config filepath=%s", filepath);
+ AFB_API_INFO(apiHandle, "CTL-LOAD-CONFIG: loading config filepath=%s", filepath);
return CtlLoadMetaDataJson(apiHandle, ctlConfigJ, prefix);
}
@@ -215,9 +210,9 @@ void wrap_json_array_add(void* array, json_object *val) {
json_object_array_add(array, (json_object*)val);
}
-json_object* LoadAdditionalsFiles(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, const char *key, json_object *sectionJ);
+json_object* LoadAdditionalsFiles(afb_api_t apiHandle, CtlConfigT *ctlHandle, const char *key, json_object *sectionJ);
-json_object* CtlUpdateSectionConfig(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, const char *key, json_object *sectionJ, json_object *filesJ) {
+json_object* CtlUpdateSectionConfig(afb_api_t apiHandle, CtlConfigT *ctlHandle, const char *key, json_object *sectionJ, json_object *filesJ) {
json_object *sectionArrayJ;
char *oneFile = NULL;
@@ -238,11 +233,10 @@ json_object* CtlUpdateSectionConfig(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, c
int length = (int)json_object_array_length(filesJ);
for (int idx=0; idx < length; idx++) {
json_object *oneFileJ = json_object_array_get_idx(filesJ, idx);
- json_object *responseJ = ScanForConfig(CONTROL_CONFIG_PATH ,CTL_SCAN_RECURSIVE, json_object_get_string(oneFileJ), ".json");
- responseJ = responseJ ? responseJ:
+ json_object *responseJ =
ScanForConfig(bindingPath, CTL_SCAN_RECURSIVE, json_object_get_string(oneFileJ), ".json");
if(!responseJ) {
- AFB_ApiError(apiHandle, "No config files found in search path. No changes has been made\n -- %s\n -- %s", CONTROL_CONFIG_PATH, bindingPath);
+ AFB_API_ERROR(apiHandle, "No config files found in search path. No changes has been made\n -- %s", bindingPath);
return sectionArrayJ;
}
oneFile = ConfigSearch(apiHandle, responseJ);
@@ -257,11 +251,10 @@ json_object* CtlUpdateSectionConfig(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, c
}
}
} else {
- json_object *responseJ = ScanForConfig(CONTROL_CONFIG_PATH ,CTL_SCAN_RECURSIVE, json_object_get_string(filesJ), ".json");
- responseJ = responseJ ? responseJ:
+ json_object *responseJ =
ScanForConfig(bindingPath, CTL_SCAN_RECURSIVE, json_object_get_string(filesJ), ".json");
if(!responseJ) {
- AFB_ApiError(apiHandle, "No config files found in search path. No changes has been made\n -- %s\n -- %s", CONTROL_CONFIG_PATH, bindingPath);
+ AFB_API_ERROR(apiHandle, "No config files found in search path. No changes has been made\n -- %s", bindingPath);
return sectionArrayJ;
}
oneFile = ConfigSearch(apiHandle, responseJ);
@@ -274,7 +267,7 @@ json_object* CtlUpdateSectionConfig(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, c
return sectionArrayJ;
}
-json_object* LoadAdditionalsFiles(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, const char *key, json_object *sectionJ)
+json_object* LoadAdditionalsFiles(afb_api_t apiHandle, CtlConfigT *ctlHandle, const char *key, json_object *sectionJ)
{
json_object *filesJ, *filesArrayJ = json_object_new_array();
if (json_object_get_type(sectionJ) == json_type_array) {
@@ -311,7 +304,7 @@ json_object* LoadAdditionalsFiles(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, con
return sectionJ;
}
-int CtlLoadSections(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, CtlSectionT *sections) {
+int CtlLoadSections(afb_api_t 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 1facf39..285de7d 100644
--- a/ctl-lib/ctl-config.h
+++ b/ctl-lib/ctl-config.h
@@ -59,7 +59,7 @@ typedef struct ConfigSectionS {
const char *uid;
const char *info;
const char *prefix;
- int (*loadCB)(AFB_ApiT apihandle, struct ConfigSectionS *section, json_object *sectionJ);
+ int (*loadCB)(afb_api_t apihandle, struct ConfigSectionS *section, json_object *sectionJ);
void *handle;
CtlActionT *actions;
} CtlSectionT;
@@ -75,7 +75,7 @@ typedef struct {
json_object *configJ;
json_object *requireJ;
CtlSectionT *sections;
- CtlPluginT *ctlPlugins;
+ CtlPluginT **ctlPlugins;
void *external;
} CtlConfigT;
@@ -91,43 +91,39 @@ typedef enum {
} SectionEnumT;
// ctl-action.c
-extern int AddActionsToSection(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ, int exportApi);
-extern CtlActionT *ActionConfig(AFB_ApiT apiHandle, json_object *actionsJ, int exportApi);
-extern void ActionExecUID(AFB_ReqT request, CtlConfigT *ctlConfig, const char *uid, json_object *queryJ);
+extern int AddActionsToSection(afb_api_t apiHandle, CtlSectionT *section, json_object *actionsJ, int exportApi);
+extern CtlActionT *ActionConfig(afb_api_t apiHandle, json_object *actionsJ, int exportApi);
+extern void ActionExecUID(afb_req_t 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(afb_api_t apiHandle, CtlActionT *action, json_object *, int exportApi);
extern int ActionLabelToIndex(CtlActionT* actions, const char* actionLabel);
// ctl-config.c
extern int CtlConfigMagicNew();
-extern void* getExternalData(CtlConfigT *ctlConfig);
-extern void setExternalData(CtlConfigT *ctlConfig, void *data);
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(afb_api_t apiHandle, json_object *responseJ);
+extern char* CtlConfigSearch(afb_api_t apiHandle, const char *dirList, const char *prefix) ;
+extern void DispatchRequireApi(afb_api_t apiHandle, json_object * requireJ);
+extern int CtlConfigExec(afb_api_t apiHandle, CtlConfigT *ctlConfig) ;
+extern CtlConfigT *CtlLoadMetaDataJson(afb_api_t apiHandle,json_object *ctlConfigJ, const char *prefix) ;
+extern CtlConfigT *CtlLoadMetaDataUsingPrefix(afb_api_t apiHandle,const char* filepath, const char *prefix) ;
+extern int CtlLoadSections(afb_api_t 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(afb_api_t apihandle, CtlSectionT *section, json_object *actionsJ);
+extern void CtrlDispatchApiEvent (afb_api_t 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(afb_api_t apiHandle, CtlSectionT *section, json_object *actionsJ);
// ctl-onload.c
-extern int OnloadConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ);
+extern int OnloadConfig(afb_api_t 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 void* getPluginContext(CtlPluginT *plugin);
-extern void setPluginContext(CtlPluginT *plugin, void *context);
+extern int PluginConfig(afb_api_t UNUSED_ARG(apiHandle), CtlSectionT *section, json_object *pluginsJ);
+extern int PluginGetCB (afb_api_t apiHandle, CtlActionT *action , json_object *callbackJ);
#ifdef __cplusplus
}
#endif
diff --git a/ctl-lib/ctl-control.c b/ctl-lib/ctl-control.c
index b28ff4c..43d3e2e 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(afb_api_t apiHandle, CtlSectionT *section, json_object *actionsJ) {
int err = 0;
if (actionsJ) {
if ( (err= AddActionsToSection(apiHandle, section, actionsJ, 1)) ) {
- AFB_ApiError (apiHandle, "ControlLoad config fail processing actions for section %s", section->uid);
+ AFB_API_ERROR (apiHandle, "ControlLoad config fail processing actions for section %s", section->uid);
return err;
}
}
diff --git a/ctl-lib/ctl-event.c b/ctl-lib/ctl-event.c
index d17bd3c..37590b2 100644
--- a/ctl-lib/ctl-event.c
+++ b/ctl-lib/ctl-event.c
@@ -23,18 +23,13 @@
#include "ctl-config.h"
// Event dynamic API-V3 mode
-#if defined AFB_BINDING_PREV3 || AFB_BINDING_VERSION == 3
-void CtrlDispatchApiEvent (AFB_ApiT apiHandle, const char *evtLabel, struct json_object *eventJ) {
+void CtrlDispatchApiEvent (afb_api_t 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));
+ AFB_API_DEBUG (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)
{
@@ -46,7 +41,7 @@ void CtrlDispatchApiEvent (AFB_ApiT apiHandle, const char *evtLabel, struct json
idx = ActionLabelToIndex(actions, evtLabel);
if (idx < 0) {
- AFB_ApiWarning(apiHandle, "CtlDispatchEvent: fail to find uid=%s in action event section", evtLabel);
+ AFB_API_WARNING(apiHandle, "CtlDispatchEvent: fail to find uid=%s in action event section", evtLabel);
return;
}
@@ -57,40 +52,17 @@ void CtrlDispatchApiEvent (AFB_ApiT apiHandle, const char *evtLabel, struct json
source.request = NULL;
// Best effort ignoring error to exec corresponding action
- (void) ActionExecOne (&source, &actions[idx], eventJ);
+ (void) ActionExecOne (&source, &actions[idx], json_object_get(eventJ));
}
-#else
-// In API-V2 controller config is unique and static
-extern CtlConfigT *ctrlConfig;
-
-// call action attached to even name if any
-void CtrlDispatchV2Event(const char *evtLabel, json_object *eventJ) {
- CtlActionT* actions = ctrlConfig->sections[CTL_SECTION_EVENT].actions;
-
- int index= ActionLabelToIndex(actions, evtLabel);
- if (index < 0) {
- AFB_WARNING_V2("CtlDispatchEvent: fail to find uid=%s in action event section", evtLabel);
- return;
- }
-
- CtlSourceT source;
- source.uid = actions[index].uid;
- source.api = actions[index].api;
- source.request = AFB_ReqNone;
-
- // Best effort ignoring error to exec corresponding action
- (void) ActionExecOne (&source, &actions[index], eventJ);
-}
-#endif
// onload section receive one action or an array of actions
-int EventConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ) {
+int EventConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *actionsJ) {
int err = 0;
// Load time parse actions in config file
if (actionsJ != NULL) {
if ( (err= AddActionsToSection(apiHandle, section, actionsJ, 0)) ) {
- AFB_ApiError (apiHandle, "EventLoad config fail processing actions for section %s", section->uid);
+ AFB_API_ERROR (apiHandle, "EventLoad config fail processing actions for section %s", section->uid);
return err;
}
}
diff --git a/ctl-lib/ctl-lua.c b/ctl-lib/ctl-lua.c
index 4a32f26..9b0d572 100644
--- a/ctl-lib/ctl-lua.c
+++ b/ctl-lib/ctl-lua.c
@@ -57,7 +57,7 @@ static int TIMER_MAGIC;
typedef struct {
char *name;
int count;
- AFB_EventT event;
+ afb_event_t event;
} LuaAfbEvent;
typedef struct {
@@ -90,7 +90,7 @@ static CtlSourceT *LuaSourcePop(lua_State *luaState, int index) {
static LuaAfbSourceT *LuaSourcePush(lua_State *luaState, CtlSourceT *source) {
LuaAfbSourceT *afbSource = (LuaAfbSourceT *) calloc(1, sizeof (LuaAfbSourceT));
if (!afbSource) {
- AFB_ApiError(source->api, "LuaSourcePush fail to allocate user data context");
+ AFB_API_ERROR(source->api, "LuaSourcePush fail to allocate user data context");
return NULL;
}
@@ -144,12 +144,12 @@ static int LuaPushArgument(CtlSourceT *source, json_object *argsJ) {
lua_pushnumber(luaState, json_object_get_double(argsJ));
break;
case json_type_null:
- AFB_ApiNotice(source->api, "LuaPushArgument: NULL object type %s", json_object_to_json_string(argsJ));
+ AFB_API_NOTICE(source->api, "LuaPushArgument: NULL object type %s", json_object_to_json_string(argsJ));
lua_pushnil(luaState);
break;
default:
- AFB_ApiError(source->api, "LuaPushArgument: unsupported Json object type %s", json_object_to_json_string(argsJ));
+ AFB_API_ERROR(source->api, "LuaPushArgument: unsupported Json object type %s", json_object_to_json_string(argsJ));
return 0;
}
return 1;
@@ -180,7 +180,7 @@ static json_object *LuaTableToJson(CtlSourceT *source, lua_State* luaState, int
tableJ = json_object_new_object();
tableType = LUA_TSTRING;
} else if (tableType != LUA_TSTRING) {
- AFB_ApiError(source->api, "MIX Lua Table with key string/numeric not supported");
+ AFB_API_ERROR(source->api, "MIX Lua Table with key string/numeric not supported");
return NULL;
}
@@ -193,15 +193,13 @@ static json_object *LuaTableToJson(CtlSourceT *source, lua_State* luaState, int
tableJ = json_object_new_array();
tableType = LUA_TNUMBER;
} else if (tableType != LUA_TNUMBER) {
- AFB_ApiError(source->api, "MIX Lua Table with key numeric/string not supported");
+ AFB_API_ERROR(source->api, "MIX Lua Table with key numeric/string not supported");
return NULL;
}
json_object *argJ = LuaPopOneArg(source, luaState, LUA_VALUE_INDEX);
json_object_array_add(tableJ, argJ);
}
-
-
lua_pop(luaState, 1); // removes 'value'; keeps 'key' for next iteration
}
@@ -247,7 +245,7 @@ static json_object *LuaPopOneArg(CtlSourceT *source, lua_State* luaState, int id
break;
default:
- AFB_ApiNotice(source->api, "LuaPopOneArg: script returned Unknown/Unsupported idx=%d type:%d/%s", idx, luaType, lua_typename(luaState, luaType));
+ AFB_API_NOTICE(source->api, "LuaPopOneArg: script returned Unknown/Unsupported idx=%d type:%d/%s", idx, luaType, lua_typename(luaState, luaType));
value = NULL;
}
@@ -285,13 +283,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);
@@ -351,7 +343,7 @@ static int LuaFormatMessage(lua_State* luaState, int verbosity, int level) {
if (uidIdx >= LUA_MSG_MAX_LENGTH) {
const char *trunc = "... <truncated> ";
- AFB_ApiWarning(source->api, "LuaFormatMessage: message[%s] overflow LUA_MSG_MAX_LENGTH=%d\n", format, LUA_MSG_MAX_LENGTH);
+ AFB_API_WARNING(source->api, "LuaFormatMessage: message[%s] overflow LUA_MSG_MAX_LENGTH=%d\n", format, LUA_MSG_MAX_LENGTH);
uidIdx = LUA_MSG_MAX_LENGTH - 1;
memcpy(&message[uidIdx - strlen(trunc)], trunc, strlen(trunc));
break;
@@ -364,7 +356,7 @@ static int LuaFormatMessage(lua_State* luaState, int verbosity, int level) {
PrintMessage:
// TBD: __file__ and __line__ should match LUA source code
- AFB_ApiVerbose(source->api, level, __FILE__, __LINE__, source->uid, "%s", message);
+ afb_api_verbose(source->api, level, __FILE__, __LINE__, source->uid, "%s", message);
json_object_put(responseJ);
return 0; // nothing return to lua
}
@@ -405,7 +397,7 @@ static int LuaAfbSuccess(lua_State* luaState) {
json_object *responseJ = LuaPopArgs(source, luaState, LUA_FIRST_ARG + 1);
if (responseJ == JSON_ERROR) return 1;
- AFB_ReqSuccess(source->request, responseJ, NULL);
+ afb_req_success(source->request, responseJ, NULL);
return 0;
}
@@ -420,13 +412,13 @@ static int LuaAfbFail(lua_State* luaState) {
json_object *responseJ = LuaPopArgs(source, luaState, LUA_FIRST_ARG + 1);
if (responseJ == JSON_ERROR) return 1;
- AFB_ReqFail(source->request, source->uid, json_object_get_string(responseJ));
+ afb_req_success(source->request, json_object_new_string(source->uid), json_object_get_string(responseJ));
json_object_put(responseJ);
return 0;
}
-static void LuaAfbServiceCB(void *handle, int iserror, struct json_object *responseJ, AFB_ApiT apiHandle) {
+static void LuaAfbServiceCB(void *handle, int iserror, struct json_object *responseJ, afb_api_t apiHandle) {
LuaCbHandleT *handleCb = (LuaCbHandleT*) handle;
int count = 1;
@@ -443,7 +435,7 @@ static void LuaAfbServiceCB(void *handle, int iserror, struct json_object *respo
int err = lua_pcall(luaState, count, LUA_MULTRET, 0);
if (err) {
- AFB_ApiError(apiHandle, "LUA-SERVICE-CB:FAIL response=%s err=%s", json_object_to_json_string(responseJ), lua_tostring(luaState, -1));
+ AFB_API_ERROR(apiHandle, "LUA-SERVICE-CB:FAIL response=%s err=%s", json_object_to_json_string(responseJ), lua_tostring(luaState, -1));
}
free(handleCb->source);
@@ -481,7 +473,7 @@ static int LuaAfbService(lua_State* luaState) {
handleCb->source = malloc(sizeof (CtlSourceT));
handleCb->source = memcpy(handleCb->source, source, sizeof (CtlSourceT));
- AFB_ServiceCall(source->api, api, verb, queryJ, LuaAfbServiceCB, handleCb);
+ afb_api_call_legacy(source->api, api, verb, queryJ, LuaAfbServiceCB, handleCb);
return 0; // no value return
}
@@ -514,7 +506,7 @@ static int LuaAfbServiceSync(lua_State* luaState) {
json_object *queryJ = LuaPopOneArg(source, luaState, LUA_FIRST_ARG + 3);
if (queryJ == JSON_ERROR) return 1;
- int iserror = AFB_ServiceSync(source->api, api, verb, queryJ, &responseJ);
+ int iserror = afb_api_call_sync_legacy(source->api, api, verb, queryJ, &responseJ);
// push error status & response
count = 1;
@@ -544,7 +536,7 @@ static int LuaAfbEventPush(lua_State* luaState) {
afbevt = (LuaAfbEvent*) lua_touserdata(luaState, LUA_FIRST_ARG + 1);
- if (!AFB_EventIsValid(afbevt->event)) {
+ if (!afb_event_is_valid(afbevt->event)) {
lua_pushliteral(luaState, "LuaAfbMakePush-Fail invalid event");
lua_error(luaState);
return 1;
@@ -557,10 +549,10 @@ static int LuaAfbEventPush(lua_State* luaState) {
return 1;
}
- int done = AFB_EventPush(afbevt->event, ctlEventJ);
+ int done = afb_event_push(afbevt->event, ctlEventJ);
if (!done) {
lua_pushliteral(luaState, "LuaAfbEventPush-Fail No Subscriber to event");
- AFB_ApiError(source->api, "LuaAfbEventPush-Fail name subscriber event=%s count=%d", afbevt->name, afbevt->count);
+ AFB_API_ERROR(source->api, "LuaAfbEventPush-Fail name subscriber event=%s count=%d", afbevt->name, afbevt->count);
lua_error(luaState);
return 1;
}
@@ -587,16 +579,16 @@ static int LuaAfbEventSubscribe(lua_State* luaState) {
afbevt = (LuaAfbEvent*) lua_touserdata(luaState, LUA_FIRST_ARG + 1);
- if (!AFB_EventIsValid(afbevt->event)) {
+ if (!afb_event_is_valid(afbevt->event)) {
lua_pushliteral(luaState, "LuaAfbMakePush-Fail invalid event handle");
lua_error(luaState);
return 1;
}
- int err = AFB_ReqSubscribe(source->request, afbevt->event);
+ int err = afb_req_subscribe(source->request, afbevt->event);
if (err) {
lua_pushliteral(luaState, "LuaAfbEventSubscribe-Fail No Subscriber to event");
- AFB_ApiError(source->api, "LuaAfbEventPush-Fail name subscriber event=%s count=%d", afbevt->name, afbevt->count);
+ AFB_API_ERROR(source->api, "LuaAfbEventPush-Fail name subscriber event=%s count=%d", afbevt->name, afbevt->count);
lua_error(luaState);
return 1;
}
@@ -642,9 +634,9 @@ static int LuaAfbEventMake(lua_State* luaState) {
afbevt->name = strdupa(lua_tostring(luaState, LUA_FIRST_ARG + 1));
// create a new binder event
- afbevt->event = AFB_EventMake(source->api, afbevt->name);
- if (!AFB_EventIsValid(afbevt->event)) {
- AFB_ApiError(source->api, "Fail to CreateEvent evtname=%s", afbevt->name);
+ afbevt->event = afb_api_make_event(source->api, afbevt->name);
+ if (!afb_event_is_valid(afbevt->event)) {
+ AFB_API_ERROR(source->api, "Fail to CreateEvent evtname=%s", afbevt->name);
lua_pushliteral(luaState, "LuaAfbEventMake-Fail to Create Binder event");
lua_error(luaState);
return 1;
@@ -768,7 +760,7 @@ int LuaCallFunc(CtlSourceT *source, CtlActionT *action, json_object *queryJ) {
// effectively exec LUA script code
err = lua_pcall(luaState, count, 1, 0);
if (err) {
- AFB_ApiError(source->api, "LuaCallFunc Fail calling %s error=%s", func, lua_tostring(luaState, -1));
+ AFB_API_ERROR(source->api, "LuaCallFunc Fail calling %s error=%s", func, lua_tostring(luaState, -1));
return -1;
}
@@ -777,24 +769,24 @@ int LuaCallFunc(CtlSourceT *source, CtlActionT *action, json_object *queryJ) {
return rc;
}
-int LuaLoadScript(AFB_ApiT apiHandle, const char *luaScriptPath) {
+int LuaLoadScript(afb_api_t apiHandle, const char *luaScriptPath) {
int err = 0;
if (!luaScriptPath) {
- AFB_ApiError(apiHandle, "Error: provided path is NULL");
+ AFB_API_ERROR(apiHandle, "Error: provided path is NULL");
return -1;
}
err = luaL_loadfile(luaState, luaScriptPath);
if (err) {
- AFB_ApiError(apiHandle, "Error at load for %s: %s", luaScriptPath, lua_tostring(luaState, -1));
+ AFB_API_ERROR(apiHandle, "Error at load for %s: %s", luaScriptPath, lua_tostring(luaState, -1));
return err;
}
// Script was loaded we need to parse to make it executable
err = lua_pcall(luaState, 0, 0, 0);
if (err) {
- AFB_ApiError(apiHandle, "Error at execution for %s: %s", luaScriptPath, lua_tostring(luaState, -1));
+ AFB_API_ERROR(apiHandle, "Error at execution for %s: %s", luaScriptPath, lua_tostring(luaState, -1));
return err;
}
return err;
@@ -819,7 +811,7 @@ static int LuaDoScript(json_object *queryJ, CtlSourceT *source) {
"args", &argsJ);
if (err) {
- AFB_ApiError(source->api, "LUA-DOSCRIPT-SCAN: Miss something in JSON object uid|[spath]|action|[args]: %s", json_object_to_json_string(queryJ));
+ AFB_API_ERROR(source->api, "LUA-DOSCRIPT-SCAN: Miss something in JSON object uid|[spath]|action|[args]: %s", json_object_to_json_string(queryJ));
return -1;
}
@@ -831,7 +823,7 @@ static int LuaDoScript(json_object *queryJ, CtlSourceT *source) {
}
if(!luaScriptPathJ) {
- AFB_ApiError(source->api, "LUA-DOSCRIPT-SCAN: No script found");
+ AFB_API_ERROR(source->api, "LUA-DOSCRIPT-SCAN: No script found");
return -1;
}
@@ -840,7 +832,7 @@ static int LuaDoScript(json_object *queryJ, CtlSourceT *source) {
err = wrap_json_unpack(entryJ, "{s:s, s:s !}", "fullpath", &fullpath, "filename", &filename);
if (err) {
- AFB_ApiError(source->api, "LUA-DOSCRIPT-SCAN:HOOPs invalid config file path = %s", json_object_to_json_string(entryJ));
+ AFB_API_ERROR(source->api, "LUA-DOSCRIPT-SCAN:HOOPs invalid config file path = %s", json_object_to_json_string(entryJ));
return -1;
}
@@ -921,12 +913,12 @@ static int LuaDoString(const char *script, CtlSourceT *source) {
// Execute LUA code from received API request
-static void LuaDoAction(LuaDoActionT action, AFB_ReqT request) {
+static void LuaDoAction(LuaDoActionT action, afb_req_t request) {
int err = 0, count = 0;
CtlSourceT *source = alloca(sizeof (CtlSourceT));
source->request = request;
- json_object* queryJ = AFB_ReqJson(request);
+ json_object* queryJ = afb_req_json(request);
switch (action) {
@@ -935,7 +927,7 @@ static void LuaDoAction(LuaDoActionT action, AFB_ReqT request) {
const char *script = json_object_get_string(queryJ);
count = LuaDoString(script, source);
if (count)
- AFB_ApiError(source->api, "DOSTRING goes wrong err=%d, String=%s ", count, script);
+ AFB_API_ERROR(source->api, "DOSTRING goes wrong err=%d, String=%s ", count, script);
break;
}
@@ -943,7 +935,7 @@ static void LuaDoAction(LuaDoActionT action, AFB_ReqT request) {
{
count = LuaDoCall(queryJ, source);
if (count)
- AFB_ApiError(source->api, "DOCALL goes wrong, error = %d, query=%s", count, json_object_get_string(queryJ));
+ AFB_API_ERROR(source->api, "DOCALL goes wrong, error = %d, query=%s", count, json_object_get_string(queryJ));
break;
}
@@ -951,35 +943,35 @@ static void LuaDoAction(LuaDoActionT action, AFB_ReqT request) {
{ // Fulup need to fix argument passing
count = LuaDoScript(queryJ, source);
if (count)
- AFB_ApiError(source->api, "DOSCRIPT goes wrong error=%d query=%s", count, json_object_to_json_string(queryJ));
+ AFB_API_ERROR(source->api, "DOSCRIPT goes wrong error=%d query=%s", count, json_object_to_json_string(queryJ));
break;
}
default:
- AFB_ApiError(source->api, "LUA-DOSCRIPT-ACTION unknown query=%s", json_object_to_json_string(queryJ));
- AFB_ReqFail(request, "LUA:ERROR", lua_tostring(luaState, -1));
+ AFB_API_ERROR(source->api, "LUA-DOSCRIPT-ACTION unknown query=%s", json_object_to_json_string(queryJ));
+ afb_req_success(request, json_object_new_string("LUA:ERROR"), lua_tostring(luaState, -1));
return;
}
if (count >= 0)
err = lua_pcall(luaState, count + 1, 0, 0);
if (err) {
- AFB_ApiError(source->api, "LUA-DO-EXEC:FAIL query=%s err=%s", json_object_to_json_string(queryJ), lua_tostring(luaState, -1));
- AFB_ReqFail(request, "LUA:ERROR", lua_tostring(luaState, -1));
+ AFB_API_ERROR(source->api, "LUA-DO-EXEC:FAIL query=%s err=%s", json_object_to_json_string(queryJ), lua_tostring(luaState, -1));
+ afb_req_success(request, json_object_new_string("LUA:ERROR"), lua_tostring(luaState, -1));
return;
}
return;
}
-void ctlapi_execlua(AFB_ReqT request) {
+void ctlapi_execlua(afb_req_t request) {
LuaDoAction(LUA_DOSTRING, request);
}
-void ctlapi_request(AFB_ReqT request) {
+void ctlapi_request(afb_req_t request) {
LuaDoAction(LUA_DOCALL, request);
}
-void ctlapi_debuglua(AFB_ReqT request) {
+void ctlapi_debuglua(afb_req_t request) {
LuaDoAction(LUA_DOSCRIPT, request);
}
@@ -1004,13 +996,8 @@ 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
+ AFB_API_NOTICE(luaCbHandle->source->api, "LuaTimerClear timer=%s", timerHandle->uid);
TimerEvtStop(timerHandle);
@@ -1068,7 +1055,7 @@ static int LuaTimerSetCB(TimerHandleT *timer) {
int err = lua_pcall(luaState, count, LUA_MULTRET, 0);
if (err) {
- AFB_ApiError(LuaCbHandle->source->api, "LUA-TIMER-CB:FAIL response=%s err=%s", json_object_to_json_string(LuaCbHandle->context), lua_tostring(luaState, -1));
+ AFB_API_ERROR(LuaCbHandle->source->api, "LUA-TIMER-CB:FAIL response=%s err=%s", json_object_to_json_string(LuaCbHandle->context), lua_tostring(luaState, -1));
return 1;
}
@@ -1177,7 +1164,7 @@ static void *LuaClientCtxNew(void * handle) {
int err = lua_pcall(luaState, count, 1, 0);
if (err) {
- AFB_ApiError(clientCtx->source->api, "LuaClientCtxNew:FAIL response=%s err=%s", json_object_to_json_string(clientCtx->clientCtxJ), lua_tostring(luaState, -1));
+ AFB_API_ERROR(clientCtx->source->api, "LuaClientCtxNew:FAIL response=%s err=%s", json_object_to_json_string(clientCtx->clientCtxJ), lua_tostring(luaState, -1));
return NULL;
}
@@ -1213,7 +1200,7 @@ static void LuaClientCtxFree(void * handle) {
int err = lua_pcall(luaState, count, LUA_MULTRET, 0);
if (err) {
- AFB_ApiError(clientCtx->source->api, "LuaClientCtxFree:FAIL response=%s err=%s", json_object_to_json_string(clientCtx->clientCtxJ), lua_tostring(luaState, -1));
+ AFB_API_ERROR(clientCtx->source->api, "LuaClientCtxFree:FAIL response=%s err=%s", json_object_to_json_string(clientCtx->clientCtxJ), lua_tostring(luaState, -1));
return;
}
@@ -1236,7 +1223,7 @@ static int LuaClientCtx(lua_State* luaState) {
return 1; // return error code
}
- if (!AFB_ReqIsValid(source->request)) {
+ if (!afb_req_is_valid(source->request)) {
lua_pushliteral(luaState, "LuaSessionSet-Syntax should be called within client request context");
lua_error(luaState);
return 1; // return error code
@@ -1244,7 +1231,7 @@ static int LuaClientCtx(lua_State* luaState) {
// in only one arg then we should free the clientCtx
if (lua_gettop(luaState) == LUA_FIRST_ARG) {
- AFB_ClientCtxClear(source->request);
+ afb_req_context_clear(source->request);
lua_pushnil(luaState);
return 1;
}
@@ -1266,7 +1253,7 @@ static int LuaClientCtx(lua_State* luaState) {
memcpy(clientCtx->source, source, sizeof (CtlSourceT)); // source if free when command return
// push client context within session
- void *done = AFB_ClientCtxSet(source->request, 1, LuaClientCtxNew, LuaClientCtxFree, clientCtx);
+ void *done = afb_req_context(source->request, 1, LuaClientCtxNew, LuaClientCtxFree, clientCtx);
if (!done) {
lua_pushliteral(luaState, "LuaClientCtx-Fail to allocate client context)");
lua_error(luaState);
@@ -1314,19 +1301,19 @@ static const luaL_Reg afbFunction[] = {
// Load Lua Interpreter
-int LuaConfigExec(AFB_ApiT apiHandle) {
+int LuaConfigExec(afb_api_t apiHandle) {
int err;
// Load LUA utils functions.
err = LuaDoString(lua_utils, NULL);
if (err) {
- AFB_ApiError(apiHandle, "Error loading lua_utils default functions.%s, %d", lua_utils, err);
+ AFB_API_ERROR(apiHandle, "Error loading lua_utils default functions.%s, %d", lua_utils, err);
return -1;
}
err = lua_pcall(luaState, 0, 0, 0);
if (err) {
- AFB_ApiError(apiHandle, "Error loading lua_utils default functions at pcall.%s, %d", lua_tostring(luaState, 0), err);
+ AFB_API_ERROR(apiHandle, "Error loading lua_utils default functions at pcall.%s, %d", lua_tostring(luaState, 0), err);
return -1;
}
return 0;
@@ -1334,7 +1321,7 @@ int LuaConfigExec(AFB_ApiT apiHandle) {
// Load Lua Interpreter
-int LuaConfigLoad(AFB_ApiT apiHandle, const char *prefix) {
+int LuaConfigLoad(afb_api_t apiHandle, const char *prefix) {
size_t total_len = 0, base_len = 0, spath_len = 0;
static int luaLoaded = 0;
int token_nb = 0, i = 0;
@@ -1347,7 +1334,7 @@ int LuaConfigLoad(AFB_ApiT apiHandle, const char *prefix) {
// open a new LUA interpretor
luaState = luaL_newstate();
if (!luaState) {
- AFB_ApiError(apiHandle, "LUA_INIT: Fail to open lua interpretor");
+ AFB_API_ERROR(apiHandle, "LUA_INIT: Fail to open lua interpretor");
free(luaState);
return 1;
}
diff --git a/ctl-lib/ctl-lua.h b/ctl-lib/ctl-lua.h
index a02c6e1..5107108 100644
--- a/ctl-lib/ctl-lua.h
+++ b/ctl-lib/ctl-lua.h
@@ -41,7 +41,7 @@ extern "C" {
#include "lualib.h"
#endif
-#include "ctl-timer.h"
+#include <afb-timer.h>
int LuaLibInit ();
@@ -52,12 +52,12 @@ typedef enum {
} LuaDoActionT;
extern const char *lua_utils;
-extern int LuaLoadScript(AFB_ApiT apiHandle, const char *luaScriptPath);
-extern int LuaConfigLoad (AFB_ApiT apiHandle, const char *prefix);
+extern int LuaLoadScript(afb_api_t apiHandle, const char *luaScriptPath);
+extern int LuaConfigLoad (afb_api_t apiHandle, const char *prefix);
extern void LuaL2cNewLib(luaL_Reg *l2cFunc, int count, const char *prefix);
extern int Lua2cWrapper(void* luaHandle, char *funcname, Lua2cFunctionT callback);
extern int LuaCallFunc (CtlSourceT *source, CtlActionT *action, json_object *queryJ) ;
-extern int LuaConfigExec(AFB_ApiT apiHandle);
+extern int LuaConfigExec(afb_api_t apiHandle);
#ifdef __cplusplus
}
diff --git a/ctl-lib/ctl-onload.c b/ctl-lib/ctl-onload.c
index 6100f2a..c631e4c 100644
--- a/ctl-lib/ctl-onload.c
+++ b/ctl-lib/ctl-onload.c
@@ -23,19 +23,19 @@
#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(afb_api_t apiHandle, CtlSectionT *section, json_object *actionsJ) {
int err = 0;
// Load time parse actions in control file
if (actionsJ != NULL) {
if ( (err= AddActionsToSection(apiHandle, section, actionsJ, 0)) ) {
- AFB_ApiError (apiHandle, "OnloadConfig control fail processing actions for section %s", section->uid);
+ AFB_API_ERROR (apiHandle, "OnloadConfig control fail processing actions for section %s", section->uid);
return err;
}
} else {
// Exec time process onload action now
if (!section->actions) {
- AFB_ApiWarning (apiHandle, "OnloadConfig Cannot Exec Non Existing Onload Action");
+ AFB_API_WARNING (apiHandle, "OnloadConfig Cannot Exec Non Existing Onload Action");
return 1;
}
@@ -43,12 +43,12 @@ int OnloadConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ
CtlSourceT source;
source.uid = section->actions[idx].uid;
source.api = section->actions[idx].api;
- source.request = AFB_ReqNone;
+ source.request = NULL;
if(!err)
err = ActionExecOne(&source, &section->actions[idx], NULL);
else {
- AFB_ApiError(apiHandle, "Onload action execution failed on: %s", source.uid);
+ AFB_API_ERROR(apiHandle, "Onload action execution failed on: %s", source.uid);
return err;
}
}
diff --git a/ctl-lib/ctl-plugin.c b/ctl-lib/ctl-plugin.c
index 48b79d1..c65cee8 100644
--- a/ctl-lib/ctl-plugin.c
+++ b/ctl-lib/ctl-plugin.c
@@ -24,24 +24,13 @@
#include "ctl-config.h"
-void* getPluginContext(CtlPluginT *plugin) {
- return plugin->context;
-}
-
-void setPluginContext(CtlPluginT *plugin, void *context) {
- plugin->context = context;
-}
-
-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;
- CtlConfigT *ctlConfig = (CtlConfigT *) AFB_ApiGetUserData(apiHandle);
- CtlPluginT *ctlPlugins = ctlConfig ? ctlConfig->ctlPlugins : NULL;
-
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;
}
@@ -50,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;
}
@@ -59,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;
}
@@ -68,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;
@@ -85,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);
+ if (!ctlPluginMagic) {
+ AFB_API_ERROR(apiHandle, "CTL-PLUGIN-LOADONE symbol'CtlPluginMagic' missing %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");
@@ -132,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;
@@ -168,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;
@@ -190,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;
}
}
@@ -198,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;
@@ -222,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;
}
@@ -235,31 +222,26 @@ static int LoadFoundPlugins(AFB_ApiT apiHandle, json_object *scanResult, json_ob
return -1;
}
else if(ext && !strcasecmp(ext, CTL_SCRIPT_EXT)) {
-#ifndef CONTROL_SUPPORT_LUA
- AFB_ApiError(apiHandle, "LUA support not selected (cf:CONTROL_SUPPORT_LUA) in config.cmake");
- return -1;
-#else
ctlPlugin->api = apiHandle;
ctlPlugin->context = handle;
if(LuaLoadScript(apiHandle, pluginpath))
return -1;
-#endif
}
}
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)) {
@@ -284,32 +266,32 @@ char *GetDefaultPluginSearchPath(AFB_ApiT apiHandle, const char *prefix)
* between bindingPath and envDirList concatenation.
*/
if(envDirList) {
- envDirList_len = strlen(CONTROL_PLUGIN_PATH) + strlen(envDirList) + strlen(bindingPath) + strlen(rootDir) + 3;
+ envDirList_len = strlen(envDirList) + strlen(bindingPath) + strlen(rootDir) + 3;
searchPath = malloc(envDirList_len + 1);
- snprintf(searchPath, envDirList_len + 1, "%s:%s:%s:%s", rootDir, bindingPath, envDirList, CONTROL_PLUGIN_PATH);
+ snprintf(searchPath, envDirList_len + 1, "%s:%s:%s", rootDir, bindingPath, envDirList);
}
else {
- envDirList_len = strlen(CONTROL_PLUGIN_PATH) + strlen(bindingPath) + strlen(rootDir) + 2;
+ envDirList_len = strlen(bindingPath) + strlen(rootDir) + 2;
searchPath = malloc(envDirList_len + 1);
- snprintf(searchPath, envDirList_len + 1, "%s:%s:%s", rootDir, bindingPath, CONTROL_PLUGIN_PATH);
+ snprintf(searchPath, envDirList_len + 1, "%s:%s", rootDir, bindingPath);
}
free(rootDir);
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;
@@ -328,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;
}
@@ -337,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;
}
}
@@ -390,74 +372,88 @@ 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 err = 0, idx = 0, pluginToAddNumber, totalPluginNumber;
-
- CtlConfigT *ctlConfig = (CtlConfigT *) AFB_ApiGetUserData(apiHandle);
- CtlPluginT *ctlPluginsNew, *ctlPluginsOrig = ctlConfig ? ctlConfig->ctlPlugins : NULL;
-
- while(ctlPluginsOrig && ctlPluginsOrig[idx].uid != NULL)
- idx++;
-
- totalPluginNumber = idx;
+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)) {
case json_type_array: {
- pluginToAddNumber = (int) json_object_array_length(pluginsJ);
+ *pluginNb = (int)json_object_array_length(pluginsJ);
+ ctlPlugins = calloc (*pluginNb + 1, sizeof(CtlPluginT));
+ for (idx=0; idx < *pluginNb; idx++) {
+ json_object *pluginJ = json_object_array_get_idx(pluginsJ, idx);
+ err += PluginLoad(apiHandle, &ctlPlugins[idx], pluginJ, section->handle, section->prefix);
+ }
break;
}
case json_type_object: {
- pluginToAddNumber = 1;
+ ctlPlugins = calloc (2, sizeof(CtlPluginT));
+ err += PluginLoad(apiHandle, &ctlPlugins[0], pluginsJ, section->handle, section->prefix);
+ (*pluginNb)++;
break;
}
default: {
- AFB_ApiError(apiHandle, "Wrong JSON object passed: %s", json_object_get_string(pluginsJ));
- return -1;
+ AFB_API_ERROR(apiHandle, "Wrong JSON object passed: %s", json_object_get_string(pluginsJ));
+ err = -1;
}
}
- totalPluginNumber += pluginToAddNumber;
-
- ctlPluginsNew = calloc (totalPluginNumber + 1, sizeof(CtlPluginT));
- memcpy(ctlPluginsNew, ctlPluginsOrig, idx * sizeof(CtlPluginT));
-
- while(idx < totalPluginNumber) {
- json_object *pluginJ = json_object_is_type(pluginsJ, json_type_array) ?
- json_object_array_get_idx(pluginsJ, idx) : pluginsJ;
- err += PluginLoad(apiHandle, &ctlPluginsNew[idx], pluginJ, section->handle, section->prefix);
- idx++;
- }
-
- ctlConfig->ctlPlugins = ctlPluginsNew;
- free(ctlPluginsOrig);
-
- return err;
+ return err;
}
-int PluginConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pluginsJ) {
- int err = 0, idx = 0;
+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;
+
+ if (ctlPlugins)
+ {
+ // There is something to add let that happens
+ if(pluginsJ) {
+ CtlPluginT *ctlPluginsNew = NULL, *ctlPluginsOrig = ctlPlugins;
+ err = PluginParse(apiHandle, section, pluginsJ, &newPluginsNb);
+ ctlPluginsNew = ctlPlugins;
+
+ while(ctlPlugins[pluginNb].uid != NULL) {
+ pluginNb++;
+ }
+
+ totalPluginNb = pluginNb + newPluginsNb;
+ ctlPlugins = calloc(totalPluginNb + 1, sizeof(CtlPluginT));
+ while(ctlPluginsOrig[idx].uid != NULL) {
+ ctlPlugins[idx] = ctlPluginsOrig[idx];
+ idx++;
+ }
+ while(ctlPluginsNew[jdx].uid != NULL && idx <= totalPluginNb) {
+ ctlPlugins[idx] = ctlPluginsNew[jdx];
+ idx++;
+ jdx++;
+ }
- CtlConfigT *ctlConfig = (CtlConfigT *) AFB_ApiGetUserData(apiHandle);
- CtlPluginT *ctlPlugins = ctlConfig ? ctlConfig->ctlPlugins : NULL;
+ free(ctlPluginsOrig);
+ free(ctlPluginsNew);
+ }
- // First plugins load
- if(pluginsJ) {
- err = PluginParse(apiHandle, section, pluginsJ);
- }
- // Code executed executed at Controller ConfigExec step
- else if (ctlPlugins) {
while(ctlPlugins[idx].uid != NULL)
{
- // Calling plugin Init function
+ // Jose hack to make verbosity visible from sharedlib and
+ // be able to call verb from others api inside the binder
+ struct afb_binding_data_v2 *afbHidenData = dlsym(ctlPlugins[idx].dlHandle, "afbBindingV2data");
+ if (afbHidenData) *afbHidenData = afbBindingV2data;
+
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;
}
}
idx++;
}
+ return 0;
+ }
+ else if(pluginsJ)
+ {
+ err = PluginParse(apiHandle, section, pluginsJ, &pluginNb);
}
return err;
diff --git a/ctl-lib/ctl-plugin.h b/ctl-lib/ctl-plugin.h
index 56cd465..47076f7 100644
--- a/ctl-lib/ctl-plugin.h
+++ b/ctl-lib/ctl-plugin.h
@@ -31,7 +31,7 @@ extern "C" {
#include <stdio.h>
#include <json-c/json.h>
-#include "afb-definitions.h"
+#include <afb/afb-binding.h>
#ifndef CTL_PLUGIN_MAGIC
#define CTL_PLUGIN_MAGIC 852369147
@@ -60,7 +60,7 @@ typedef struct {
typedef struct {
const char *uid;
const char *info;
- AFB_ApiT api;
+ afb_api_t api;
void *dlHandle;
void *context;
json_object *paramsJ;
@@ -85,8 +85,8 @@ typedef enum {
typedef struct {
const char *uid;
- AFB_ApiT api;
- AFB_ReqT request;
+ afb_api_t api;
+ afb_req_t request;
void *context;
CtlPluginT *plugin;
CtlActionStatusT status;
@@ -96,7 +96,7 @@ typedef struct {
const char *uid;
const char *info;
const char *privileges;
- AFB_ApiT api;
+ afb_api_t api;
json_object *argsJ;
CtlActionTypeT type;
union {
@@ -135,7 +135,7 @@ typedef int (*Lua2cWrapperT) (void*luaHandle, const char *funcname, Lua2cFunctio
int lua2c_ ## funcname (void* luaState){return((*Lua2cWrap)(luaState, MACRO_STR_VALUE(funcname), funcname));};\
int funcname (CtlSourceT* source, json_object* argsJ, json_object** responseJ)
-extern char *GetDefaultPluginSearchPath(AFB_ApiT apiHandle, const char *prefix);
+extern char *GetDefaultPluginSearchPath(afb_api_t apiHandle, const char *prefix);
#ifdef __cplusplus
}
diff --git a/ctl-lib/ctl-timer.c b/ctl-lib/ctl-timer.c
deleted file mode 100644
index c36d2b1..0000000
--- a/ctl-lib/ctl-timer.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <systemd/sd-event.h>
-
-#include "ctl-config.h"
-#include "ctl-timer.h"
-
-#define DEFAULT_PAUSE_DELAY 3000
-#define DEFAULT_TEST_COUNT 1
-typedef struct {
- int value;
- const char *uid;
-} AutoTestCtxT;
-
-
-static int TimerNext (sd_event_source* source, uint64_t timer, void* handle) {
- TimerHandleT *timerHandle = (TimerHandleT*) handle;
- int done;
- uint64_t usec;
-
- done= timerHandle->callback(timerHandle);
- if (!done) {
- AFB_ApiWarning(timerHandle->api, "TimerNext Callback Fail Tag=%s", timerHandle->uid);
- return -1;
- }
-
- // Rearm timer if needed
- timerHandle->count --;
- if (timerHandle->count == 0) {
- sd_event_source_unref(source);
- if (timerHandle->freeCB) timerHandle->freeCB(timerHandle->context);
- free (handle);
- return 0;
- }
- else {
- // otherwise validate timer for a new run
- sd_event_now(AFB_GetEventLoop(timerHandle->api), CLOCK_MONOTONIC, &usec);
- sd_event_source_set_enabled(source, SD_EVENT_ONESHOT);
- sd_event_source_set_time(source, usec + timerHandle->delay*1000);
- }
-
- return 0;
-}
-
-void TimerEvtStop(TimerHandleT *timerHandle) {
-
- sd_event_source_unref(timerHandle->evtSource);
- free (timerHandle);
-}
-
-
-void TimerEvtStart(AFB_ApiT apiHandle, TimerHandleT *timerHandle, timerCallbackT callback, void *context) {
- uint64_t usec;
-
- // populate CB handle
- timerHandle->callback=callback;
- timerHandle->context=context;
- timerHandle->api=apiHandle;
-
- // set a timer with ~250us accuracy
- sd_event_now(AFB_GetEventLoop(apiHandle), CLOCK_MONOTONIC, &usec);
- sd_event_add_time(AFB_GetEventLoop(apiHandle), &timerHandle->evtSource, CLOCK_MONOTONIC, usec+timerHandle->delay*1000, 250, TimerNext, timerHandle);
-}
-
-
-// Create Binding Event at Init
-int TimerEvtInit (AFB_ApiT apiHandle) {
-
- AFB_ApiDebug (apiHandle, "Timer-Init Done");
- return 0;
-}
-
-uint64_t LockWait(AFB_ApiT apiHandle, uint64_t utimeout) {
- uint64_t current_usec, pre_usec;
-
- struct sd_event *event = AFB_GetEventLoop(apiHandle);
-
- sd_event_now(event, CLOCK_MONOTONIC, &pre_usec);
- sd_event_run(event, utimeout);
- sd_event_now(event, CLOCK_MONOTONIC, &current_usec);
-
- uint64_t diff = current_usec - pre_usec;
- utimeout = utimeout < diff ? 0 : utimeout - diff;
- return utimeout;
-}
diff --git a/ctl-lib/ctl-timer.h b/ctl-lib/ctl-timer.h
deleted file mode 100644
index a65a906..0000000
--- a/ctl-lib/ctl-timer.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef CTL_TIMER_INCLUDE
-#define CTL_TIMER_INCLUDE
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <systemd/sd-event.h>
-
-// ctl-timer.c
-// ----------------------
-
-typedef struct TimerHandleS {
- int magic;
- int count;
- int delay;
- const char*uid;
- void *context;
- sd_event_source *evtSource;
- AFB_ApiT api;
- int (*callback) (struct TimerHandleS *handle);
- int (*freeCB) (void *context) ;
-} TimerHandleT;
-
-typedef int (*timerCallbackT)(TimerHandleT *context);
-
-extern int TimerEvtInit (AFB_ApiT apiHandle);
-extern void TimerEvtStart(AFB_ApiT apiHandle, TimerHandleT *timerHandle, timerCallbackT callback, void *context);
-extern void TimerEvtStop(TimerHandleT *timerHandle);
-
-extern uint64_t LockWait(AFB_ApiT apiHandle, uint64_t utimeout);
-#ifdef __cplusplus
-}
-#endif
-
-#endif // CTL_TIMER_INCLUDE
diff --git a/ctl-lib/ctl-utilities.pc.in b/ctl-lib/ctl-utilities.pc.in
new file mode 100644
index 0000000..3ddbbb8
--- /dev/null
+++ b/ctl-lib/ctl-utilities.pc.in
@@ -0,0 +1,31 @@
+##
+## Copyright (C) 2016, 2017, 2018 "IoT.bzh"
+##
+## This file is part of afb-daemon project.
+##
+## 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, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+##
+
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include
+
+Name: @TARGET_NAME@
+Description: @PROJECT_DESCRIPTION@
+Version: @PROJECT_VERSION@
+URL: @PROJECT_URL@
+Libs.private:
+Libs: -L@CMAKE_INSTALL_LIBDIR@ -l@TARGET_NAME@
+Cflags: -I${includedir}
+