]>
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 */ | |
718db961 LP |
62 | SD_EVENT_PRIORITY_IMPORTANT = -100, |
63 | SD_EVENT_PRIORITY_NORMAL = 0, | |
64 | SD_EVENT_PRIORITY_IDLE = 100 | |
6ee69bab LP |
65 | }; |
66 | ||
718db961 LP |
67 | typedef int (*sd_event_handler_t)(sd_event_source *s, void *userdata); |
68 | typedef int (*sd_event_io_handler_t)(sd_event_source *s, int fd, uint32_t revents, void *userdata); | |
69 | typedef int (*sd_event_time_handler_t)(sd_event_source *s, uint64_t usec, void *userdata); | |
70 | typedef int (*sd_event_signal_handler_t)(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata); | |
71 | typedef int (*sd_event_child_handler_t)(sd_event_source *s, const siginfo_t *si, void *userdata); | |
fd38203a | 72 | |
afc6adb5 LP |
73 | int sd_event_default(sd_event **e); |
74 | ||
fd38203a LP |
75 | int sd_event_new(sd_event **e); |
76 | sd_event* sd_event_ref(sd_event *e); | |
77 | sd_event* sd_event_unref(sd_event *e); | |
78 | ||
718db961 LP |
79 | int sd_event_add_io(sd_event *e, int fd, uint32_t events, sd_event_io_handler_t callback, void *userdata, sd_event_source **s); |
80 | int sd_event_add_monotonic(sd_event *e, uint64_t usec, uint64_t accuracy, sd_event_time_handler_t callback, void *userdata, sd_event_source **s); | |
81 | int sd_event_add_realtime(sd_event *e, uint64_t usec, uint64_t accuracy, sd_event_time_handler_t callback, void *userdata, sd_event_source **s); | |
82 | int sd_event_add_signal(sd_event *e, int sig, sd_event_signal_handler_t callback, void *userdata, sd_event_source **s); | |
83 | int sd_event_add_child(sd_event *e, pid_t pid, int options, sd_event_child_handler_t callback, void *userdata, sd_event_source **s); | |
84 | int sd_event_add_defer(sd_event *e, sd_event_handler_t callback, void *userdata, sd_event_source **s); | |
85 | int sd_event_add_quit(sd_event *e, sd_event_handler_t callback, void *userdata, sd_event_source **s); | |
fd38203a LP |
86 | |
87 | int sd_event_run(sd_event *e, uint64_t timeout); | |
88 | int sd_event_loop(sd_event *e); | |
89 | ||
da7e457c | 90 | int sd_event_get_state(sd_event *e); |
afc6adb5 | 91 | int sd_event_get_tid(sd_event *e, pid_t *tid); |
da7e457c | 92 | int sd_event_get_quit(sd_event *e); |
fd38203a | 93 | int sd_event_request_quit(sd_event *e); |
46e8c825 LP |
94 | int sd_event_get_now_realtime(sd_event *e, uint64_t *usec); |
95 | int sd_event_get_now_monotonic(sd_event *e, uint64_t *usec); | |
fd38203a LP |
96 | |
97 | sd_event_source* sd_event_source_ref(sd_event_source *s); | |
98 | sd_event_source* sd_event_source_unref(sd_event_source *s); | |
99 | ||
afc6adb5 LP |
100 | sd_event *sd_event_get(sd_event_source *s); |
101 | ||
718db961 | 102 | int sd_event_source_set_prepare(sd_event_source *s, sd_event_handler_t callback); |
fd38203a | 103 | int sd_event_source_get_pending(sd_event_source *s); |
fd38203a LP |
104 | int sd_event_source_get_priority(sd_event_source *s, int *priority); |
105 | int sd_event_source_set_priority(sd_event_source *s, int priority); | |
baf76283 LP |
106 | int sd_event_source_get_enabled(sd_event_source *s, int *enabled); |
107 | int sd_event_source_set_enabled(sd_event_source *s, int enabled); | |
305f78bf LP |
108 | void* sd_event_source_get_userdata(sd_event_source *s); |
109 | int sd_event_source_get_io_fd(sd_event_source *s); | |
110 | int sd_event_source_get_io_events(sd_event_source *s, uint32_t* events); | |
111 | int sd_event_source_set_io_events(sd_event_source *s, uint32_t events); | |
112 | int sd_event_source_get_io_revents(sd_event_source *s, uint32_t* revents); | |
fd38203a LP |
113 | int sd_event_source_get_time(sd_event_source *s, uint64_t *usec); |
114 | int sd_event_source_set_time(sd_event_source *s, uint64_t usec); | |
c2ba3ad6 LP |
115 | int sd_event_source_set_time_accuracy(sd_event_source *s, uint64_t usec); |
116 | int sd_event_source_get_time_accuracy(sd_event_source *s, uint64_t *usec); | |
305f78bf | 117 | int sd_event_source_get_signal(sd_event_source *s); |
4bee8012 | 118 | int sd_event_source_get_child_pid(sd_event_source *s, pid_t *pid); |
fd38203a | 119 | |
0095c454 | 120 | _SD_END_DECLARATIONS; |
6695ed7a | 121 | |
fd38203a | 122 | #endif |