]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/systemd/sd-event.h
core: convert PID 1 to libsystemd-bus
[thirdparty/systemd.git] / src / systemd / sd-event.h
CommitLineData
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
44typedef struct sd_event sd_event;
45typedef struct sd_event_source sd_event_source;
46
da7e457c 47enum {
baf76283
LP
48 SD_EVENT_OFF = 0,
49 SD_EVENT_ON = 1,
fd38203a 50 SD_EVENT_ONESHOT = -1
da7e457c
LP
51};
52
53enum {
54 SD_EVENT_PASSIVE,
55 SD_EVENT_RUNNING,
56 SD_EVENT_QUITTING,
57 SD_EVENT_FINISHED
58};
fd38203a 59
6ee69bab
LP
60enum {
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
67typedef int (*sd_event_handler_t)(sd_event_source *s, void *userdata);
68typedef int (*sd_event_io_handler_t)(sd_event_source *s, int fd, uint32_t revents, void *userdata);
69typedef int (*sd_event_time_handler_t)(sd_event_source *s, uint64_t usec, void *userdata);
70typedef int (*sd_event_signal_handler_t)(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata);
71typedef int (*sd_event_child_handler_t)(sd_event_source *s, const siginfo_t *si, void *userdata);
fd38203a 72
afc6adb5
LP
73int sd_event_default(sd_event **e);
74
fd38203a
LP
75int sd_event_new(sd_event **e);
76sd_event* sd_event_ref(sd_event *e);
77sd_event* sd_event_unref(sd_event *e);
78
718db961
LP
79int sd_event_add_io(sd_event *e, int fd, uint32_t events, sd_event_io_handler_t callback, void *userdata, sd_event_source **s);
80int 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);
81int 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);
82int sd_event_add_signal(sd_event *e, int sig, sd_event_signal_handler_t callback, void *userdata, sd_event_source **s);
83int sd_event_add_child(sd_event *e, pid_t pid, int options, sd_event_child_handler_t callback, void *userdata, sd_event_source **s);
84int sd_event_add_defer(sd_event *e, sd_event_handler_t callback, void *userdata, sd_event_source **s);
85int sd_event_add_quit(sd_event *e, sd_event_handler_t callback, void *userdata, sd_event_source **s);
fd38203a
LP
86
87int sd_event_run(sd_event *e, uint64_t timeout);
88int sd_event_loop(sd_event *e);
89
da7e457c 90int sd_event_get_state(sd_event *e);
afc6adb5 91int sd_event_get_tid(sd_event *e, pid_t *tid);
da7e457c 92int sd_event_get_quit(sd_event *e);
fd38203a 93int sd_event_request_quit(sd_event *e);
46e8c825
LP
94int sd_event_get_now_realtime(sd_event *e, uint64_t *usec);
95int sd_event_get_now_monotonic(sd_event *e, uint64_t *usec);
fd38203a
LP
96
97sd_event_source* sd_event_source_ref(sd_event_source *s);
98sd_event_source* sd_event_source_unref(sd_event_source *s);
99
afc6adb5
LP
100sd_event *sd_event_get(sd_event_source *s);
101
718db961 102int sd_event_source_set_prepare(sd_event_source *s, sd_event_handler_t callback);
fd38203a 103int sd_event_source_get_pending(sd_event_source *s);
fd38203a
LP
104int sd_event_source_get_priority(sd_event_source *s, int *priority);
105int sd_event_source_set_priority(sd_event_source *s, int priority);
baf76283
LP
106int sd_event_source_get_enabled(sd_event_source *s, int *enabled);
107int sd_event_source_set_enabled(sd_event_source *s, int enabled);
305f78bf
LP
108void* sd_event_source_get_userdata(sd_event_source *s);
109int sd_event_source_get_io_fd(sd_event_source *s);
110int sd_event_source_get_io_events(sd_event_source *s, uint32_t* events);
111int sd_event_source_set_io_events(sd_event_source *s, uint32_t events);
112int sd_event_source_get_io_revents(sd_event_source *s, uint32_t* revents);
fd38203a
LP
113int sd_event_source_get_time(sd_event_source *s, uint64_t *usec);
114int sd_event_source_set_time(sd_event_source *s, uint64_t usec);
c2ba3ad6
LP
115int sd_event_source_set_time_accuracy(sd_event_source *s, uint64_t usec);
116int sd_event_source_get_time_accuracy(sd_event_source *s, uint64_t *usec);
305f78bf 117int sd_event_source_get_signal(sd_event_source *s);
4bee8012 118int 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