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;
32 typedef void (*io_cb_t)(event_loop_t *loop, void *data, int flags);
33 typedef void (*timeout_cb_t)(event_loop_t *loop, void *data);
34 typedef void (*signal_cb_t)(event_loop_t *loop, void *data);
35 typedef struct timeval(*idle_cb_t)(event_loop_t *loop, void *data);
42 struct splay_node_t node;
45 typedef struct timeout_t {
49 struct splay_node_t node;
52 typedef struct signal_t {
56 struct splay_node_t node;
63 volatile bool running;
68 splay_tree_t timeouts;
80 extern void io_add(event_loop_t *loop, io_t *io, io_cb_t cb, void *data, int fd, int flags);
81 extern void io_del(event_loop_t *loop, io_t *io);
82 extern void io_set(event_loop_t *loop, io_t *io, int flags);
84 extern void timeout_add(event_loop_t *loop, timeout_t *timeout, timeout_cb_t cb, void *data, struct timeval *tv);
85 extern void timeout_del(event_loop_t *loop, timeout_t *timeout);
86 extern void timeout_set(event_loop_t *loop, timeout_t *timeout, struct timeval *tv);
88 extern void signal_add(event_loop_t *loop, signal_t *sig, signal_cb_t cb, void *data, uint8_t signum);
89 extern void signal_trigger(event_loop_t *loop, signal_t *sig);
90 extern void signal_del(event_loop_t *loop, signal_t *sig);
92 extern void idle_set(event_loop_t *loop, idle_cb_t cb, void *data);
94 extern void event_loop_init(event_loop_t *loop);
95 extern void event_loop_exit(event_loop_t *loop);
96 extern bool event_loop_run(event_loop_t *loop, pthread_mutex_t *mutex);
97 extern void event_loop_flush_output(event_loop_t *loop);
98 extern void event_loop_start(event_loop_t *loop);
99 extern void event_loop_stop(event_loop_t *loop);