2 event.h -- I/O, timeout and signal event handling
3 Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef __MESHLINK_EVENT_H__
21 #define __MESHLINK_EVENT_H__
23 #include "splay_tree.h"
29 typedef struct event_loop_t event_loop_t;
31 typedef void (*io_cb_t)(event_loop_t *loop, void *data, int flags);
32 typedef void (*timeout_cb_t)(event_loop_t *loop, void *data);
33 typedef void (*signal_cb_t)(event_loop_t *loop, void *data);
40 struct splay_node_t node;
43 typedef struct timeout_t {
47 struct splay_node_t node;
50 typedef struct signal_t {
54 struct splay_node_t node;
61 volatile bool running;
65 splay_tree_t timeouts;
74 extern void io_add(event_loop_t *loop, io_t *io, io_cb_t cb, void *data, int fd, int flags);
75 extern void io_del(event_loop_t *loop, io_t *io);
76 extern void io_set(event_loop_t *loop, io_t *io, int flags);
78 extern void timeout_add(event_loop_t *loop, timeout_t *timeout, timeout_cb_t cb, void *data, struct timeval *tv);
79 extern void timeout_del(event_loop_t *loop, timeout_t *timeout);
80 extern void timeout_set(event_loop_t *loop, timeout_t *timeout, struct timeval *tv);
82 extern void signal_add(event_loop_t *loop, signal_t *sig, signal_cb_t cb, void *data, uint8_t signum);
83 extern void signal_trigger(event_loop_t *loop, signal_t *sig);
84 extern void signal_del(event_loop_t *loop, signal_t *sig);
86 extern void event_loop_init(event_loop_t *loop);
87 extern void event_loop_exit(event_loop_t *loop);
88 extern bool event_loop_run(event_loop_t *loop);
89 extern void event_loop_flush_output(event_loop_t *loop);
90 extern void event_loop_stop(event_loop_t *loop);