1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
7 This file is part of systemd.
9 Copyright 2013 Lennart Poettering
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.
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.
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/>.
25 #include <sys/types.h>
26 #include <sys/signalfd.h>
27 #include <sys/epoll.h>
31 #include "_sd-common.h"
34 Why is this better than pure epoll?
36 - Supports event source priorisation
37 - Scales better with a large number of time events, since it doesn't require one timerfd each
38 - Automatically tries to coalesce timer events system-wide
39 - Handles signals and child PIDs
42 _SD_BEGIN_DECLARATIONS;
44 typedef struct sd_event sd_event;
45 typedef struct sd_event_source sd_event_source;
61 /* And everything inbetween and outside is good too */
62 SD_EVENT_PRIORITY_IMPORTANT = -100,
63 SD_EVENT_PRIORITY_NORMAL = 0,
64 SD_EVENT_PRIORITY_IDLE = 100
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);
73 int sd_event_default(sd_event **e);
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);
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_exit(sd_event *e, sd_event_handler_t callback, void *userdata, sd_event_source **s);
87 int sd_event_run(sd_event *e, uint64_t timeout);
88 int sd_event_loop(sd_event *e);
89 int sd_event_exit(sd_event *e, int code);
91 int sd_event_get_state(sd_event *e);
92 int sd_event_get_tid(sd_event *e, pid_t *tid);
93 int sd_event_get_exit_code(sd_event *e, int *code);
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);
96 int sd_event_set_watchdog(sd_event *e, int b);
97 int sd_event_get_watchdog(sd_event *e);
99 sd_event_source* sd_event_source_ref(sd_event_source *s);
100 sd_event_source* sd_event_source_unref(sd_event_source *s);
102 int sd_event_source_set_prepare(sd_event_source *s, sd_event_handler_t callback);
103 int sd_event_source_get_pending(sd_event_source *s);
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);
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);
108 void* sd_event_source_get_userdata(sd_event_source *s);
109 void* sd_event_source_set_userdata(sd_event_source *s, void *userdata);
110 int sd_event_source_get_io_fd(sd_event_source *s);
111 int sd_event_source_set_io_fd(sd_event_source *s, int fd);
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);
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);
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);
119 int sd_event_source_get_signal(sd_event_source *s);
120 int sd_event_source_get_child_pid(sd_event_source *s, pid_t *pid);
121 sd_event *sd_event_source_get_event(sd_event_source *s);
123 _SD_END_DECLARATIONS;