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