4 * Copyright (c) 2011 David Herrmann <dh.herrmann@googlemail.com>
5 * Copyright (c) 2011 University of Tuebingen
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files
9 * (the "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * This provides a basic event loop similar to those provided by glib etc.
30 * It uses linux specific features like signalfd so it may not be easy to port
31 * it to other platforms.
34 #ifndef KMSCON_ELOOP_H
35 #define KMSCON_ELOOP_H
43 typedef void (*kmscon_fd_cb) (struct kmscon_fd *fd, void *data);
44 typedef void (*kmscon_signal_cb)
45 (struct kmscon_signal *sig, int signum, void *data);
47 enum kmscon_eloop_flags {
48 KMSCON_READABLE = 0x01,
49 KMSCON_WRITEABLE = 0x02,
53 int kmscon_eloop_new(struct kmscon_eloop **out);
54 void kmscon_eloop_ref(struct kmscon_eloop *loop);
55 void kmscon_eloop_unref(struct kmscon_eloop *loop);
57 int kmscon_eloop_get_fd(struct kmscon_eloop *loop);
58 int kmscon_eloop_dispatch(struct kmscon_eloop *loop, int timeout);
62 int kmscon_fd_new(struct kmscon_fd **out);
63 void kmscon_fd_ref(struct kmscon_fd *fd);
64 void kmscon_fd_unref(struct kmscon_fd *fd);
66 int kmscon_eloop_new_fd(struct kmscon_eloop *loop, struct kmscon_fd **out,
67 int rfd, int mask, kmscon_fd_cb cb, void *data);
68 int kmscon_eloop_add_fd(struct kmscon_eloop *loop, struct kmscon_fd *fd,
69 int rfd, int mask, kmscon_fd_cb cb, void *data);
70 void kmscon_eloop_rm_fd(struct kmscon_fd *fd);
71 int kmscon_eloop_update_fd(struct kmscon_fd *fd, int mask);
75 int kmscon_signal_new(struct kmscon_signal **out);
76 void kmscon_signal_ref(struct kmscon_signal *sig);
77 void kmscon_signal_unref(struct kmscon_signal *sig);
79 int kmscon_eloop_new_signal(struct kmscon_eloop *loop,
80 struct kmscon_signal **out, int signum, kmscon_signal_cb cb,
82 int kmscon_eloop_add_signal(struct kmscon_eloop *loop,
83 struct kmscon_signal *sig, int signum, kmscon_signal_cb cb, void *data);
84 void kmscon_eloop_rm_signal(struct kmscon_signal *sig);
86 #endif /* KMSCON_ELOOP_H */