From 913edaca1c69a742d0c811f45c3545ac464e1786 Mon Sep 17 00:00:00 2001 From: Clément Bénier Date: Tue, 4 Sep 2018 10:42:22 +0200 Subject: remove ctl-timer: add it in helpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit remove ctl-timer, it is moved by afb-timer in helpers thus, moved afb-definitions in helpers too Signed-off-by: Clément Bénier --- ctl-lib/CMakeLists.txt | 6 +-- ctl-lib/afb-definitions.h | 116 ------------------------------------------- ctl-lib/afb-definitions_v2.h | 85 ------------------------------- ctl-lib/ctl-lua.h | 2 +- ctl-lib/ctl-plugin.h | 2 +- ctl-lib/ctl-timer.c | 104 -------------------------------------- ctl-lib/ctl-timer.h | 54 -------------------- 7 files changed, 5 insertions(+), 364 deletions(-) delete mode 100644 ctl-lib/afb-definitions.h delete mode 100644 ctl-lib/afb-definitions_v2.h delete mode 100644 ctl-lib/ctl-timer.c delete mode 100644 ctl-lib/ctl-timer.h diff --git a/ctl-lib/CMakeLists.txt b/ctl-lib/CMakeLists.txt index e066bbc..63f4f06 100644 --- a/ctl-lib/CMakeLists.txt +++ b/ctl-lib/CMakeLists.txt @@ -52,13 +52,13 @@ foreach (PKG_CONFIG ${PKG_REQUIRED_LIST}) endforeach(PKG_CONFIG) -set(CTL_LUA_SOURCE ctl-lua.c ctl-timer.c ctl-lua-utils.c) +set(CTL_LUA_SOURCE ctl-lua.c ctl-lua-utils.c) ADD_COMPILE_OPTIONS(-DCONTROL_SUPPORT_LUA) -set(CONTROLLER_HEADERS afb-definitions.h afb-definitions_v2.h +set(CONTROLLER_HEADERS ctl-config.h ctl-config_v2.h ctl-config_v3.h ctl-lua.h - ctl-plugin.h ctl-timer.h + ctl-plugin.h ) # Define project Targets diff --git a/ctl-lib/afb-definitions.h b/ctl-lib/afb-definitions.h deleted file mode 100644 index 116be69..0000000 --- a/ctl-lib/afb-definitions.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C) 2016-2018 "IoT.bzh" - * Author Fulup Ar Foll - * Contrib Jonathan Aillet - * - * 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 != 2) -#include -#define AFB_ReqNone NULL -typedef struct afb_req_x2* AFB_ReqT; -typedef struct afb_api_x3* AFB_ApiT; - -typedef struct afb_event_x2* AFB_EventT; -#define AFB_EventIsValid(eventid) eventid -#define AFB_EventPush afb_event_x2_push -#define AFB_ReqSubscribe afb_req_x2_subscribe - -#define AFB_ReqJson(request) afb_req_x2_json(request) - -#define AFB_ReqSuccess(r,o,i) afb_req_x2_reply(r,o,NULL,i) -#define AFB_ReqSuccessF(r,o,...) afb_req_x2_reply_f(r,o,NULL,__VA_ARGS__) -#define AFB_ReqFail(r,e,i) afb_req_x2_reply(r,NULL,e,i) -#define AFB_ReqFailF(r,e,...) afb_req_x2_reply_f(r,NULL,e,__VA_ARGS__) - -#define AFB_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_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_ClientCtxClear(request) afb_req_x2_context_clear(request) - -#define AFB_ReqSetLOA(request, level) afb_req_session_set_LOA(request, level) - - -typedef struct { - const char *verb; /* name of the verb, NULL only at end of the array */ - void (*callback)(AFB_ReqT req); /* callback function implementing the verb */ - const struct afb_auth *auth; /* required authorisation, can be NULL */ - const char *info; /* some info about the verb, can be NULL */ - uint32_t session; -} AFB_ApiVerbs; - - -#define AFB_EventMake(api, name) afb_api_x3_make_event_x2(api, name) -#define AFB_ApiVerbose(api, level, ...) afb_api_x3_verbose(api, level, __VA_ARGS__) -#define AFB_ApiNotice(api, ...) AFB_API_NOTICE_V3 (api, __VA_ARGS__) -#define AFB_ApiWarning(api, ...) AFB_API_WARNING_V3 (api, __VA_ARGS__) -#define AFB_ApiDebug(api, ...) AFB_API_DEBUG_V3 (api, __VA_ARGS__) -#define AFB_ApiError(api, ...) AFB_API_ERROR_V3 (api, __VA_ARGS__) -#define AFB_ApiInfo(api, ...) AFB_API_INFO_V3 (api, __VA_ARGS__) - -#define AFB_GetApiSettings afb_api_x3_settings - -#define AFB_ServiceCall(api, ...) afb_api_x3_call_legacy(api, __VA_ARGS__) -#define AFB_ServiceSync(api, ...) afb_api_x3_call_sync_legacy(api, __VA_ARGS__) - -#define AFB_ApiCall(api, ...) afb_api_x3_call(api, __VA_ARGS__) -#define AFB_ApiSync(api, ...) afb_api_x3_call_sync(api, __VA_ARGS__) - -#define AFB_RequireApi(api, ...) afb_api_x3_require_api(api, __VA_ARGS__) - -#define AFB_GetEventLoop(api) afb_api_x3_get_event_loop(api) -#define AFB_RootDirGetFD(api) afb_api_x3_rootdir_get_fd(api) -#define AFB_ReqVCBData afb_req_x2_get_vcbdata -#define AFB_ReqGetApi afb_req_get_api - -#define AFB_NewApi afb_api_x3_new_api - -#define AFB_ApiAddVerb afb_api_x3_add_verb - -#define AFB_ApiSetUserData afb_api_x3_set_userdata -#define AFB_ApiGetUserData afb_api_x3_get_userdata - -#define AFB_ApiOnEvent afb_api_x3_on_event -#define AFB_ApiOnInit afb_api_x3_on_init -#define AFB_ApiSeal afb_api_x3_seal - -#define AFB_ClientCtxSet(request, replace, createCB, freeCB, handle) afb_req_x2_context(request, replace, createCB, freeCB, handle) - -#endif - -#include "afb-definitions_v2.h" - -#endif /* _AFB_DEFINITIONS_INCLUDE_ */ diff --git a/ctl-lib/afb-definitions_v2.h b/ctl-lib/afb-definitions_v2.h deleted file mode 100644 index 66c5ed2..0000000 --- a/ctl-lib/afb-definitions_v2.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2016-2018 "IoT.bzh" - * Author Fulup Ar Foll - * Contrib Jonathan Aillet - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, something express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef _AFB_DEFINITIONS_V2_INCLUDE_ -#define _AFB_DEFINITIONS_V2_INCLUDE_ - -// Legacy DYNAPI support. Deprecated and will be removed. -#if(AFB_BINDING_VERSION == 2) -#include - -typedef struct afb_req AFB_ReqT; -typedef void* AFB_ApiT; -#define AFB_ReqNone (struct afb_req){0,0} - -typedef struct afb_event AFB_EventT; -#define AFB_EventPush afb_event_push -#define AFB_ReqSubscribe afb_req_subscribe -#define AFB_EventIsValid(event) afb_event_is_valid(event) -#define AFB_EventMake(api, name) afb_daemon_make_event(name) - -#define AFB_ReqJson(request) afb_req_x1_json(request) -#define AFB_ReqSuccess afb_req_success -#define AFB_ReqSuccessF afb_req_success_f -#define AFB_ReqFail afb_req_fail -#define AFB_ReqFailF afb_req_fail_f - -#define AFB_ReqNotice(request, ...) AFB_NOTICE (__VA_ARGS__) -#define AFB_ReqWarning(request, ...) AFB_WARNING (__VA_ARGS__) -#define AFB_ReqDebug(request, ...) AFB_DEBUG (__VA_ARGS__) -#define AFB_ReqError(request, ...) AFB_ERROR (__VA_ARGS__) -#define AFB_ReqInfo(request, ...) AFB_INFO (__VA_ARGS__) - -#define AFB_ApiVerbose(api, level, ...) afb_daemon_verbose_v2(level,__VA_ARGS__) -#define AFB_ApiNotice(api, ...) AFB_NOTICE (__VA_ARGS__) -#define AFB_ApiWarning(api, ...) AFB_WARNING (__VA_ARGS__) -#define AFB_ApiDebug(api, ...) AFB_DEBUG (__VA_ARGS__) -#define AFB_ApiError(api, ...) AFB_ERROR (__VA_ARGS__) -#define AFB_ApiInfo(api, ...) AFB_INFO (__VA_ARGS__) - -#define AFB_GetApiSettings(api) json_object_new_object() - -#define AFB_ReqIsValid(request) afb_req_is_valid(request) -#define AFB_EvtIsValid(evtHandle) afb_event_is_valid(evtHandle) - -#define AFB_ServiceCall(api, ...) afb_service_call(__VA_ARGS__) -#define AFB_ServiceSync(api, ...) afb_service_call_sync(__VA_ARGS__) - -#define AFB_RequireApi(api, ...) afb_daemon_require_api(__VA_ARGS__) - -#define AFB_GetEventLoop(api) afb_daemon_get_event_loop() -#define AFB_RootDirGetFD(api) afb_daemon_rootdir_get_fd() -#define AFB_ReqVCBData afb_req_get_vcbdata - -#define AFB_ReqSetLOA(request, level) afb_req_session_set_LOA(request, level) - -static inline void* AFB_ClientCtxSet(afb_req request, int replace, void *(*create_context)(void *closure), void (*free_context)(void*), void *closure) -{ - void *ctx = create_context(closure); - if(ctx) - {afb_req_context_set(request, ctx, free_context);} - return ctx; -} - -#define AFB_ClientCtxClear(request) afb_req_context_clear(request) - -#define AFB_ApiVerbs afb_verb_v2 - -#endif -#endif /* _AFB_DEFINITIONS_INCLUDE_ */ diff --git a/ctl-lib/ctl-lua.h b/ctl-lib/ctl-lua.h index a02c6e1..3093cbb 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 int LuaLibInit (); diff --git a/ctl-lib/ctl-plugin.h b/ctl-lib/ctl-plugin.h index e4b8ccb..766244d 100644 --- a/ctl-lib/ctl-plugin.h +++ b/ctl-lib/ctl-plugin.h @@ -30,7 +30,7 @@ extern "C" { #include -#include "afb-definitions.h" +#include #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 c36d2b1..0000000 --- a/ctl-lib/ctl-timer.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2016 "IoT.bzh" - * Author Fulup Ar Foll - * - * 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 -#include -#include -#include - -#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, ¤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 a65a906..0000000 --- a/ctl-lib/ctl-timer.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2016 "IoT.bzh" - * Author Fulup Ar Foll - * - * 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 - -// 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 -- cgit 1.2.3-korg