]>
Commit | Line | Data |
---|---|---|
52ad194e | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
60f067b4 JS |
2 | #ifndef foosdeventhfoo |
3 | #define foosdeventhfoo | |
4 | ||
5 | /*** | |
6 | This file is part of systemd. | |
7 | ||
8 | Copyright 2013 Lennart Poettering | |
9 | ||
10 | systemd is free software; you can redistribute it and/or modify it | |
11 | under the terms of the GNU Lesser General Public License as published by | |
12 | the Free Software Foundation; either version 2.1 of the License, or | |
13 | (at your option) any later version. | |
14 | ||
15 | systemd is distributed in the hope that it will be useful, but | |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 | Lesser General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU Lesser General Public License | |
21 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
22 | ***/ | |
23 | ||
60f067b4 JS |
24 | #include <inttypes.h> |
25 | #include <signal.h> | |
4c89c718 MP |
26 | #include <sys/epoll.h> |
27 | #include <sys/signalfd.h> | |
28 | #include <sys/types.h> | |
60f067b4 JS |
29 | |
30 | #include "_sd-common.h" | |
31 | ||
32 | /* | |
33 | Why is this better than pure epoll? | |
34 | ||
35 | - Supports event source prioritization | |
36 | - Scales better with a large number of time events because it does not require one timerfd each | |
37 | - Automatically tries to coalesce timer events system-wide | |
38 | - Handles signals and child PIDs | |
39 | */ | |
40 | ||
41 | _SD_BEGIN_DECLARATIONS; | |
42 | ||
43 | typedef struct sd_event sd_event; | |
44 | typedef struct sd_event_source sd_event_source; | |
45 | ||
46 | enum { | |
47 | SD_EVENT_OFF = 0, | |
48 | SD_EVENT_ON = 1, | |
49 | SD_EVENT_ONESHOT = -1 | |
50 | }; | |
51 | ||
52 | enum { | |
e3bff60a MP |
53 | SD_EVENT_INITIAL, |
54 | SD_EVENT_ARMED, | |
5eef597e | 55 | SD_EVENT_PENDING, |
60f067b4 JS |
56 | SD_EVENT_RUNNING, |
57 | SD_EVENT_EXITING, | |
4c89c718 | 58 | SD_EVENT_FINISHED, |
aa27b158 | 59 | SD_EVENT_PREPARING |
60f067b4 JS |
60 | }; |
61 | ||
62 | enum { | |
63 | /* And everything in-between and outside is good too */ | |
64 | SD_EVENT_PRIORITY_IMPORTANT = -100, | |
65 | SD_EVENT_PRIORITY_NORMAL = 0, | |
66 | SD_EVENT_PRIORITY_IDLE = 100 | |
67 | }; | |
68 | ||
69 | typedef int (*sd_event_handler_t)(sd_event_source *s, void *userdata); | |
70 | typedef int (*sd_event_io_handler_t)(sd_event_source *s, int fd, uint32_t revents, void *userdata); | |
71 | typedef int (*sd_event_time_handler_t)(sd_event_source *s, uint64_t usec, void *userdata); | |
72 | typedef int (*sd_event_signal_handler_t)(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata); | |
81c58355 | 73 | #if defined _GNU_SOURCE || _POSIX_C_SOURCE >= 199309L |
60f067b4 | 74 | typedef int (*sd_event_child_handler_t)(sd_event_source *s, const siginfo_t *si, void *userdata); |
aa27b158 MP |
75 | #else |
76 | typedef void* sd_event_child_handler_t; | |
77 | #endif | |
60f067b4 JS |
78 | |
79 | int sd_event_default(sd_event **e); | |
80 | ||
81 | int sd_event_new(sd_event **e); | |
82 | sd_event* sd_event_ref(sd_event *e); | |
83 | sd_event* sd_event_unref(sd_event *e); | |
84 | ||
85 | int sd_event_add_io(sd_event *e, sd_event_source **s, int fd, uint32_t events, sd_event_io_handler_t callback, void *userdata); | |
86 | int sd_event_add_time(sd_event *e, sd_event_source **s, clockid_t clock, uint64_t usec, uint64_t accuracy, sd_event_time_handler_t callback, void *userdata); | |
87 | int sd_event_add_signal(sd_event *e, sd_event_source **s, int sig, sd_event_signal_handler_t callback, void *userdata); | |
88 | int sd_event_add_child(sd_event *e, sd_event_source **s, pid_t pid, int options, sd_event_child_handler_t callback, void *userdata); | |
89 | int sd_event_add_defer(sd_event *e, sd_event_source **s, sd_event_handler_t callback, void *userdata); | |
90 | int sd_event_add_post(sd_event *e, sd_event_source **s, sd_event_handler_t callback, void *userdata); | |
91 | int sd_event_add_exit(sd_event *e, sd_event_source **s, sd_event_handler_t callback, void *userdata); | |
92 | ||
5eef597e | 93 | int sd_event_prepare(sd_event *e); |
4c89c718 | 94 | int sd_event_wait(sd_event *e, uint64_t usec); |
5eef597e | 95 | int sd_event_dispatch(sd_event *e); |
4c89c718 | 96 | int sd_event_run(sd_event *e, uint64_t usec); |
60f067b4 JS |
97 | int sd_event_loop(sd_event *e); |
98 | int sd_event_exit(sd_event *e, int code); | |
99 | ||
100 | int sd_event_now(sd_event *e, clockid_t clock, uint64_t *usec); | |
101 | ||
5eef597e | 102 | int sd_event_get_fd(sd_event *e); |
60f067b4 JS |
103 | int sd_event_get_state(sd_event *e); |
104 | int sd_event_get_tid(sd_event *e, pid_t *tid); | |
105 | int sd_event_get_exit_code(sd_event *e, int *code); | |
106 | int sd_event_set_watchdog(sd_event *e, int b); | |
107 | int sd_event_get_watchdog(sd_event *e); | |
5a920b42 | 108 | int sd_event_get_iteration(sd_event *e, uint64_t *ret); |
60f067b4 JS |
109 | |
110 | sd_event_source* sd_event_source_ref(sd_event_source *s); | |
111 | sd_event_source* sd_event_source_unref(sd_event_source *s); | |
112 | ||
113 | sd_event *sd_event_source_get_event(sd_event_source *s); | |
114 | void* sd_event_source_get_userdata(sd_event_source *s); | |
115 | void* sd_event_source_set_userdata(sd_event_source *s, void *userdata); | |
116 | ||
f47781d8 MP |
117 | int sd_event_source_set_description(sd_event_source *s, const char *description); |
118 | int sd_event_source_get_description(sd_event_source *s, const char **description); | |
60f067b4 JS |
119 | int sd_event_source_set_prepare(sd_event_source *s, sd_event_handler_t callback); |
120 | int sd_event_source_get_pending(sd_event_source *s); | |
121 | int sd_event_source_get_priority(sd_event_source *s, int64_t *priority); | |
122 | int sd_event_source_set_priority(sd_event_source *s, int64_t priority); | |
123 | int sd_event_source_get_enabled(sd_event_source *s, int *enabled); | |
124 | int sd_event_source_set_enabled(sd_event_source *s, int enabled); | |
125 | int sd_event_source_get_io_fd(sd_event_source *s); | |
126 | int sd_event_source_set_io_fd(sd_event_source *s, int fd); | |
127 | int sd_event_source_get_io_events(sd_event_source *s, uint32_t* events); | |
128 | int sd_event_source_set_io_events(sd_event_source *s, uint32_t events); | |
129 | int sd_event_source_get_io_revents(sd_event_source *s, uint32_t* revents); | |
130 | int sd_event_source_get_time(sd_event_source *s, uint64_t *usec); | |
131 | int sd_event_source_set_time(sd_event_source *s, uint64_t usec); | |
132 | int sd_event_source_get_time_accuracy(sd_event_source *s, uint64_t *usec); | |
133 | int sd_event_source_set_time_accuracy(sd_event_source *s, uint64_t usec); | |
134 | int sd_event_source_get_time_clock(sd_event_source *s, clockid_t *clock); | |
135 | int sd_event_source_get_signal(sd_event_source *s); | |
136 | int sd_event_source_get_child_pid(sd_event_source *s, pid_t *pid); | |
137 | ||
4c89c718 MP |
138 | /* Define helpers so that __attribute__((cleanup(sd_event_unrefp))) and similar may be used. */ |
139 | _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_event, sd_event_unref); | |
140 | _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_event_source, sd_event_source_unref); | |
141 | ||
60f067b4 JS |
142 | _SD_END_DECLARATIONS; |
143 | ||
144 | #endif |