From 2477edba0ae270a337f284ac7862d172f66a0303 Mon Sep 17 00:00:00 2001 From: cbdev Date: Wed, 28 Feb 2018 17:05:56 +0100 Subject: Update ArtNet configuration syntax, add mm_timestamp API --- midimonster.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'midimonster.c') diff --git a/midimonster.c b/midimonster.c index eb5510c..87abfb1 100644 --- a/midimonster.c +++ b/midimonster.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "midimonster.h" #include "config.h" #include "backend.h" @@ -19,6 +20,7 @@ static size_t mappings = 0; static channel_mapping* map = NULL; static size_t fds = 0; static managed_fd* fd = NULL; +static uint64_t global_timestamp = 0; static event_collection event_pool[2] = { {0}, @@ -28,10 +30,24 @@ static event_collection* primary = event_pool; volatile static sig_atomic_t shutdown_requested = 0; -void signal_handler(int signum){ +static void signal_handler(int signum){ shutdown_requested = 1; } +uint64_t mm_timestamp(){ + return global_timestamp; +} + +static void update_timestamp(){ + struct timespec current; + if(clock_gettime(CLOCK_MONOTONIC_COARSE, ¤t)){ + fprintf(stderr, "Failed to update global timestamp, time-based processing for some backends may be impaired: %s\n", strerror(errno)); + return; + } + + global_timestamp = current.tv_sec * 1000 + current.tv_nsec / 1000000; +} + int mm_map_channel(channel* from, channel* to){ size_t u, m; //find existing source mapping @@ -277,6 +293,9 @@ int main(int argc, char** argv){ } } + //update this iteration's timestamp + update_timestamp(); + //run backend processing, collect events DBGPF("%zu backend FDs signaled\n", n); if(backends_handle(n, signaled_fds)){ -- cgit v1.2.3