diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2018-12-13 14:42:49 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2018-12-17 10:04:07 +0100 |
commit | eaf644db7106061481710adb75023122ce4bc150 (patch) | |
tree | 9b06621a42861997b96a6f0921a0b33dc685d654 /ctl-lib/ctl-timer.c | |
parent | eaf8c0808d54d987a532254887919822438b7848 (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>
Diffstat (limited to 'ctl-lib/ctl-timer.c')
-rw-r--r-- | ctl-lib/ctl-timer.c | 104 |
1 files changed, 0 insertions, 104 deletions
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, ¤t_usec); - - uint64_t diff = current_usec - pre_usec; - utimeout = utimeout < diff ? 0 : utimeout - diff; - return utimeout; -} |