1 #ifndef MESHLINK_EVENT_H
2 #define MESHLINK_EVENT_H
5 event.h -- I/O, timeout and signal event handling
6 Copyright (C) 2014, 2017 Guus Sliepen <guus@meshlink.io>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "splay_tree.h"
30 typedef struct event_loop_t event_loop_t;
31 struct meshlink_handle;
33 typedef void (*io_cb_t)(event_loop_t *loop, void *data, int flags);
34 typedef void (*timeout_cb_t)(event_loop_t *loop, void *data);
35 typedef void (*signal_cb_t)(event_loop_t *loop, void *data);
36 typedef struct timespec(*idle_cb_t)(event_loop_t *loop, void *data);
39 struct splay_node_t node;
46 typedef struct timeout_t {
47 struct splay_node_t node;
53 typedef struct signal_t {
54 struct splay_node_t node;
56 #ifdef HAVE_STDATOMIC_H
57 volatile atomic_flag set;
66 volatile bool running;
71 splay_tree_t timeouts;
84 void io_add(event_loop_t *loop, io_t *io, io_cb_t cb, void *data, int fd, int flags);
85 void io_del(event_loop_t *loop, io_t *io);
86 void io_set(event_loop_t *loop, io_t *io, int flags);
88 void timeout_add(event_loop_t *loop, timeout_t *timeout, timeout_cb_t cb, void *data, struct timespec *tv);
89 void timeout_del(event_loop_t *loop, timeout_t *timeout);
90 void timeout_set(event_loop_t *loop, timeout_t *timeout, struct timespec *tv);
92 void signal_add(event_loop_t *loop, signal_t *sig, signal_cb_t cb, void *data, uint8_t signum);
93 void signal_trigger(event_loop_t *loop, signal_t *sig);
94 void signal_del(event_loop_t *loop, signal_t *sig);
96 void idle_set(event_loop_t *loop, idle_cb_t cb, void *data);
98 void event_loop_init(event_loop_t *loop);
99 void event_loop_exit(event_loop_t *loop);
100 bool event_loop_run(event_loop_t *loop, struct meshlink_handle *mesh) __attribute__((__warn_unused_result__));
101 void event_loop_flush_output(event_loop_t *loop);
102 void event_loop_start(event_loop_t *loop);
103 void event_loop_stop(event_loop_t *loop);