From a185e5cf960ec2083fc45048e93a3a22a02c094f Mon Sep 17 00:00:00 2001 From: Clément Bénier Date: Thu, 30 Aug 2018 11:03:22 +0200 Subject: shared library: update to a v3 shared library MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AFB_BINDING_VERSION = 3 - remove preprocessor variables - mandatory lua - name of library is ctl-utilities - does not work with v2 versions Signed-off-by: Clément Bénier --- CMakeLists.txt | 1 + ctl-lib/CMakeLists.txt | 93 ++++++++++++++++++++++++++++++++++----------- ctl-lib/ctl-config.c | 10 ++--- ctl-lib/ctl-event.c | 25 ------------ ctl-lib/ctl-lua.c | 2 +- ctl-lib/ctl-plugin.c | 12 +++--- ctl-lib/ctl-plugin.h | 2 +- ctl-lib/ctl-utilities.pc.in | 31 +++++++++++++++ 8 files changed, 115 insertions(+), 61 deletions(-) create mode 100644 ctl-lib/ctl-utilities.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index a6c55d7..ca66211 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,4 +17,5 @@ ########################################################################### # This component should be included as a submodule and wont compile as standalone +CMAKE_MINIMUM_REQUIRED(VERSION 3.3) add_subdirectory("ctl-lib") diff --git a/ctl-lib/CMakeLists.txt b/ctl-lib/CMakeLists.txt index 3ab0774..147cfb0 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() +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-timer.c ctl-lua-utils.c) +ADD_COMPILE_OPTIONS(-DCONTROL_SUPPORT_LUA) + +set(CONTROLLER_HEADERS afb-definitions.h ctl-config.h ctl-lua.h + ctl-plugin.h ctl-timer.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/ctl-config.c b/ctl-lib/ctl-config.c index 339b14c..d1fb4bb 100644 --- a/ctl-lib/ctl-config.c +++ b/ctl-lib/ctl-config.c @@ -232,11 +232,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_ApiError(apiHandle, "No config files found in search path. No changes has been made\n -- %s", bindingPath); return sectionArrayJ; } oneFile = ConfigSearch(apiHandle, responseJ); @@ -251,11 +250,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_ApiError(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-event.c b/ctl-lib/ctl-event.c index 4174000..bb847b5 100644 --- a/ctl-lib/ctl-event.c +++ b/ctl-lib/ctl-event.c @@ -23,7 +23,6 @@ #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) { int idx = 0; CtlActionT* actions = NULL; @@ -60,30 +59,6 @@ void CtrlDispatchApiEvent (AFB_ApiT apiHandle, const char *evtLabel, struct json (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], json_object_get(eventJ)); -} -#endif - // onload section receive one action or an array of actions int EventConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ) { diff --git a/ctl-lib/ctl-lua.c b/ctl-lib/ctl-lua.c index 1a2554c..8d67ae4 100644 --- a/ctl-lib/ctl-lua.c +++ b/ctl-lib/ctl-lua.c @@ -40,7 +40,7 @@ #endif static lua_State* luaState; -CtlPluginT *ctlPlugins = NULL; +static CtlPluginT *ctlPlugins = NULL; #if CTX_MAGIC_VALUE static int CTX_MAGIC = CTX_MAGIC_VALUE; diff --git a/ctl-lib/ctl-plugin.c b/ctl-lib/ctl-plugin.c index d27b71d..e57fb8a 100644 --- a/ctl-lib/ctl-plugin.c +++ b/ctl-lib/ctl-plugin.c @@ -84,8 +84,8 @@ static int PluginLoadCOne(AFB_ApiT apiHandle, const char *pluginpath, json_objec } 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_ApiError(apiHandle, "CTL-PLUGIN-LOADONE symbol'CtlPluginMagic' missing %s", pluginpath); return -1; } else { AFB_ApiNotice(apiHandle, "CTL-PLUGIN-LOADONE %s successfully registered", ctlPluginMagic->uid); @@ -268,14 +268,14 @@ 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); diff --git a/ctl-lib/ctl-plugin.h b/ctl-lib/ctl-plugin.h index e4b8ccb..6fff0c5 100644 --- a/ctl-lib/ctl-plugin.h +++ b/ctl-lib/ctl-plugin.h @@ -115,7 +115,7 @@ typedef struct { } exec; } CtlActionT; -extern CtlPluginT *ctlPlugins; +static CtlPluginT *ctlPlugins; typedef int(*DispatchPluginInstallCbT)(CtlPluginT *plugin, void* handle); 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} + -- cgit 1.2.3-korg