diff options
Diffstat (limited to 'ctl-lib')
-rw-r--r-- | ctl-lib/CMakeLists.txt | 95 | ||||
-rw-r--r-- | ctl-lib/afb-definitions.h | 45 | ||||
-rw-r--r-- | ctl-lib/ctl-action.c | 2 | ||||
-rw-r--r-- | ctl-lib/ctl-config.c | 10 | ||||
-rw-r--r-- | ctl-lib/ctl-lua.c | 8 | ||||
-rw-r--r-- | ctl-lib/ctl-lua.h | 2 | ||||
-rw-r--r-- | ctl-lib/ctl-onload.c | 2 | ||||
-rw-r--r-- | ctl-lib/ctl-plugin.c | 12 | ||||
-rw-r--r-- | ctl-lib/ctl-plugin.h | 2 | ||||
-rw-r--r-- | ctl-lib/ctl-timer.c | 104 | ||||
-rw-r--r-- | ctl-lib/ctl-timer.h | 54 | ||||
-rw-r--r-- | ctl-lib/ctl-utilities.pc.in | 31 |
12 files changed, 119 insertions, 248 deletions
diff --git a/ctl-lib/CMakeLists.txt b/ctl-lib/CMakeLists.txt index 3ab0774..f3a0d18 100644 --- a/ctl-lib/CMakeLists.txt +++ b/ctl-lib/CMakeLists.txt @@ -15,29 +15,80 @@ # 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() +set(CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_PREFIX}/lib) +set(CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/include) +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 aaf4d17..0000000 --- a/ctl-lib/afb-definitions.h +++ /dev/null @@ -1,45 +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_ - -#if(AFB_BINDING_VERSION == 3) - #include <afb/afb-binding.h> - - #define AFB_ReqNone NULL -/* - * 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 - - typedef struct { - const char *verb; /* name of the verb, NULL only at end of the array */ - void (*callback)(afb_req_t 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; -#endif - -#endif /* _AFB_DEFINITIONS_INCLUDE_ */ diff --git a/ctl-lib/ctl-action.c b/ctl-lib/ctl-action.c index d1ab471..438f4af 100644 --- a/ctl-lib/ctl-action.c +++ b/ctl-lib/ctl-action.c @@ -400,7 +400,7 @@ int AddActionsToSection(afb_api_t apiHandle, CtlSectionT *section, json_object * return 0; } -int AddActionsToSectionFromPlugin(AFB_ApiT apiHandle, CtlPluginT *externalCtlPlugins, CtlSectionT *section, json_object *actionsJ, int exportApi) { +int AddActionsToSectionFromPlugin(afb_api_t apiHandle, CtlPluginT *externalCtlPlugins, CtlSectionT *section, json_object *actionsJ, int exportApi) { ctlPlugins = externalCtlPlugins; return AddActionsToSection(apiHandle, section, actionsJ, exportApi); } diff --git a/ctl-lib/ctl-config.c b/ctl-lib/ctl-config.c index 6d46130..42391db 100644 --- a/ctl-lib/ctl-config.c +++ b/ctl-lib/ctl-config.c @@ -233,11 +233,10 @@ json_object* CtlUpdateSectionConfig(afb_api_t apiHandle, CtlConfigT *ctlHandle, 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_API_ERROR(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); @@ -252,11 +251,10 @@ json_object* CtlUpdateSectionConfig(afb_api_t apiHandle, CtlConfigT *ctlHandle, } } } 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_API_ERROR(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); diff --git a/ctl-lib/ctl-lua.c b/ctl-lib/ctl-lua.c index 2f96448..3e0f2c7 100644 --- a/ctl-lib/ctl-lua.c +++ b/ctl-lib/ctl-lua.c @@ -283,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); diff --git a/ctl-lib/ctl-lua.h b/ctl-lib/ctl-lua.h index b686c37..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 (); diff --git a/ctl-lib/ctl-onload.c b/ctl-lib/ctl-onload.c index 46196c2..c631e4c 100644 --- a/ctl-lib/ctl-onload.c +++ b/ctl-lib/ctl-onload.c @@ -43,7 +43,7 @@ int OnloadConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *actions 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, §ion->actions[idx], NULL); diff --git a/ctl-lib/ctl-plugin.c b/ctl-lib/ctl-plugin.c index 0a41c7f..c65cee8 100644 --- a/ctl-lib/ctl-plugin.c +++ b/ctl-lib/ctl-plugin.c @@ -84,8 +84,8 @@ static int PluginLoadCOne(afb_api_t apiHandle, const char *pluginpath, json_obje } CtlPluginMagicT *ctlPluginMagic = (CtlPluginMagicT*) dlsym(dlHandle, "CtlPluginMagic"); - if (!ctlPluginMagic || ctlPluginMagic->magic != CTL_PLUGIN_MAGIC) { - AFB_API_ERROR(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_API_NOTICE(apiHandle, "CTL-PLUGIN-LOADONE %s successfully registered", ctlPluginMagic->uid); @@ -266,14 +266,14 @@ char *GetDefaultPluginSearchPath(afb_api_t 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); diff --git a/ctl-lib/ctl-plugin.h b/ctl-lib/ctl-plugin.h index 752d471..7d1146b 100644 --- a/ctl-lib/ctl-plugin.h +++ b/ctl-lib/ctl-plugin.h @@ -30,7 +30,7 @@ extern "C" { #include <json-c/json.h> -#include "afb-definitions.h" +#include <afb/afb-binding.h> #ifndef CTL_PLUGIN_MAGIC #define CTL_PLUGIN_MAGIC 852369147 diff --git a/ctl-lib/ctl-timer.c b/ctl-lib/ctl-timer.c deleted file mode 100644 index c4cba28..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_API_WARNING(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_api_get_event_loop(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_api_t 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_api_get_event_loop(apiHandle), CLOCK_MONOTONIC, &usec); - sd_event_add_time(afb_api_get_event_loop(apiHandle), &timerHandle->evtSource, CLOCK_MONOTONIC, usec+timerHandle->delay*1000, 250, TimerNext, timerHandle); -} - - -// Create Binding Event at Init -int TimerEvtInit (afb_api_t apiHandle) { - - AFB_API_DEBUG (apiHandle, "Timer-Init Done"); - return 0; -} - -uint64_t LockWait(afb_api_t apiHandle, uint64_t utimeout) { - uint64_t current_usec, pre_usec; - - struct sd_event *event = afb_api_get_event_loop(apiHandle); - - sd_event_now(event, CLOCK_MONOTONIC, &pre_usec); - sd_event_run(event, utimeout); - sd_event_now(event, CLOCK_MONOTONIC, ¤t_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 ffc8f82..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_api_t api; - int (*callback) (struct TimerHandleS *handle); - int (*freeCB) (void *context) ; -} TimerHandleT; - -typedef int (*timerCallbackT)(TimerHandleT *context); - -extern int TimerEvtInit (afb_api_t apiHandle); -extern void TimerEvtStart(afb_api_t apiHandle, TimerHandleT *timerHandle, timerCallbackT callback, void *context); -extern void TimerEvtStop(TimerHandleT *timerHandle); - -extern uint64_t LockWait(afb_api_t 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} + |