]>
Commit | Line | Data |
---|---|---|
fd38203a LP |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | #ifndef foosdeventhfoo | |
4 | #define foosdeventhfoo | |
5 | ||
6 | /*** | |
7 | This file is part of systemd. | |
8 | ||
9 | Copyright 2013 Lennart Poettering | |
10 | ||
11 | systemd is free software; you can redistribute it and/or modify it | |
12 | under the terms of the GNU Lesser General Public License as published by | |
13 | the Free Software Foundation; either version 2.1 of the License, or | |
14 | (at your option) any later version. | |
15 | ||
16 | systemd is distributed in the hope that it will be useful, but | |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 | Lesser General Public License for more details. | |
20 | ||
21 | You should have received a copy of the GNU Lesser General Public License | |
22 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
23 | ***/ | |
24 | ||
25 | #include <sys/types.h> | |
26 | #include <sys/signalfd.h> | |
27 | #include <sys/epoll.h> | |
28 | #include <inttypes.h> | |
29 | #include <signal.h> | |
30 | ||
0095c454 LP |
31 | #include "_sd-common.h" |
32 | ||
fd38203a LP |
33 | /* |
34 | Why is this better than pure epoll? | |
35 | ||
36 | - Supports event source priorisation | |
37 | - Scales better with a large number of time events, since it doesn't require one timerfd each | |
eaa3cbef | 38 | - Automatically tries to coalesce timer events system-wide |
fd38203a | 39 | - Handles signals and child PIDs |
fd38203a LP |
40 | */ |
41 | ||
0095c454 | 42 | _SD_BEGIN_DECLARATIONS; |
6695ed7a | 43 | |
fd38203a LP |
44 | typedef struct sd_event sd_event; |
45 | typedef struct sd_event_source sd_event_source; | |
46 | ||
da7e457c | 47 | enum { |
baf76283 LP |
48 | SD_EVENT_OFF = 0, |
49 | SD_EVENT_ON = 1, | |
fd38203a | 50 | SD_EVENT_ONESHOT = -1 |
da7e457c LP |
51 | }; |
52 | ||
53 | enum { | |
54 | SD_EVENT_PASSIVE, | |
55 | SD_EVENT_RUNNING, | |
56 | SD_EVENT_QUITTING, | |
57 | SD_EVENT_FINISHED | |
58 | }; | |
fd38203a | 59 | |
6ee69bab LP |
60 | enum { |
61 | /* And everything inbetween and outside is good too */ | |
62 | SD_PRIORITY_IMPORTANT = -100, | |
63 | SD_PRIORITY_NORMAL = 0, | |
64 | SD_PRIORITY_IDLE = 100 | |
65 | }; | |
66 | ||
fd38203a LP |
67 | typedef int (*sd_io_handler_t)(sd_event_source *s, int fd, uint32_t revents, void *userdata); |
68 | typedef int (*sd_time_handler_t)(sd_event_source *s, uint64_t usec, void *userdata); | |
69 | typedef int (*sd_signal_handler_t)(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata); | |
70 | typedef int (*sd_child_handler_t)(sd_event_source *s, const siginfo_t *si, void *userdata); | |
71 | typedef int (*sd_defer_handler_t)(sd_event_source *s, void *userdata); | |
72 | typedef int (*sd_prepare_handler_t)(sd_event_source *s, void *userdata); | |
da7e457c | 73 | typedef int (*sd_quit_handler_t)(sd_event_source *s, void *userdata); |
fd38203a | 74 | |
afc6adb5 LP |
75 | int sd_event_default(sd_event **e); |
76 | ||
fd38203a LP |
77 | int sd_event_new(sd_event **e); |
78 | sd_event* sd_event_ref(sd_event *e); | |
79 | sd_event* sd_event_unref(sd_event *e); | |
80 | ||
81 | int sd_event_add_io(sd_event *e, int fd, uint32_t events, sd_io_handler_t callback, void *userdata, sd_event_source **s); | |
c2ba3ad6 LP |
82 | int sd_event_add_monotonic(sd_event *e, uint64_t usec, uint64_t accuracy, sd_time_handler_t callback, void *userdata, sd_event_source **s); |
83 | int sd_event_add_realtime(sd_event *e, uint64_t usec, uint64_t accuracy, sd_time_handler_t callback, void *userdata, sd_event_source **s); | |
fd38203a LP |
84 | int sd_event_add_signal(sd_event *e, int sig, sd_signal_handler_t callback, void *userdata, sd_event_source **s); |
85 | int sd_event_add_child(sd_event *e, pid_t pid, int options, sd_child_handler_t callback, void *userdata, sd_event_source **s); | |
86 | int sd_event_add_defer(sd_event *e, sd_defer_handler_t callback, void *userdata, sd_event_source **s); | |
da7e457c | 87 | int sd_event_add_quit(sd_event *e, sd_quit_handler_t callback, void *userdata, sd_event_source **s); |
fd38203a LP |
88 | |
89 | int sd_event_run(sd_event *e, uint64_t timeout); | |
90 | int sd_event_loop(sd_event *e); | |
91 | ||
da7e457c | 92 | int sd_event_get_state(sd_event *e); |
afc6adb5 | 93 | int sd_event_get_tid(sd_event *e, pid_t *tid); |
da7e457c | 94 | int sd_event_get_quit(sd_event *e); |
fd38203a | 95 | int sd_event_request_quit(sd_event *e); |
46e8c825 LP |
96 | int sd_event_get_now_realtime(sd_event *e, uint64_t *usec); |
97 | int sd_event_get_now_monotonic(sd_event *e, uint64_t *usec); | |
fd38203a LP |
98 | |
99 | sd_event_source* sd_event_source_ref(sd_event_source *s); | |
100 | sd_event_source* sd_event_source_unref(sd_event_source *s); | |
101 | ||
afc6adb5 LP |
102 | sd_event *sd_event_get(sd_event_source *s); |
103 | ||
305f78bf | 104 | int sd_event_source_set_prepare(sd_event_source *s, sd_prepare_handler_t callback); |
fd38203a | 105 | int sd_event_source_get_pending(sd_event_source *s); |
fd38203a LP |
106 | int sd_event_source_get_priority(sd_event_source *s, int *priority); |
107 | int sd_event_source_set_priority(sd_event_source *s, int priority); | |
baf76283 LP |
108 | int sd_event_source_get_enabled(sd_event_source *s, int *enabled); |
109 | int sd_event_source_set_enabled(sd_event_source *s, int enabled); | |
305f78bf LP |
110 | void* sd_event_source_get_userdata(sd_event_source *s); |
111 | int sd_event_source_get_io_fd(sd_event_source *s); | |
112 | int sd_event_source_get_io_events(sd_event_source *s, uint32_t* events); | |
113 | int sd_event_source_set_io_events(sd_event_source *s, uint32_t events); | |
114 | int sd_event_source_get_io_revents(sd_event_source *s, uint32_t* revents); | |
fd38203a LP |
115 | int sd_event_source_get_time(sd_event_source *s, uint64_t *usec); |
116 | int sd_event_source_set_time(sd_event_source *s, uint64_t usec); | |
c2ba3ad6 LP |
117 | int sd_event_source_set_time_accuracy(sd_event_source *s, uint64_t usec); |
118 | int sd_event_source_get_time_accuracy(sd_event_source *s, uint64_t *usec); | |
305f78bf | 119 | int sd_event_source_get_signal(sd_event_source *s); |
4bee8012 | 120 | int sd_event_source_get_child_pid(sd_event_source *s, pid_t *pid); |
fd38203a | 121 | |
0095c454 | 122 | _SD_END_DECLARATIONS; |
6695ed7a | 123 | |
fd38203a | 124 | #endif |