]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/timer.h
Merge pull request #11083 from poettering/nspawn-settings-fixes
[thirdparty/systemd.git] / src / core / timer.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
c2f1db8f 2#pragma once
5cb5a6ff
LP
3
4typedef struct Timer Timer;
5
36697dc0 6#include "calendarspec.h"
57b7a260 7#include "unit.h"
5cb5a6ff 8
871d7de4
LP
9typedef enum TimerBase {
10 TIMER_ACTIVE,
11 TIMER_BOOT,
12 TIMER_STARTUP,
13 TIMER_UNIT_ACTIVE,
14 TIMER_UNIT_INACTIVE,
36697dc0 15 TIMER_CALENDAR,
871d7de4
LP
16 _TIMER_BASE_MAX,
17 _TIMER_BASE_INVALID = -1
18} TimerBase;
19
20typedef struct TimerValue {
36697dc0
LP
21 TimerBase base;
22 bool disabled;
36697dc0 23
b719810d
LP
24 usec_t value; /* only for monotonic events */
25 CalendarSpec *calendar_spec; /* only for calendar events */
871d7de4
LP
26 usec_t next_elapse;
27
871d7de4
LP
28 LIST_FIELDS(struct TimerValue, value);
29} TimerValue;
30
067d72c9
LP
31typedef enum TimerResult {
32 TIMER_SUCCESS,
33 TIMER_FAILURE_RESOURCES,
07299350 34 TIMER_FAILURE_START_LIMIT_HIT,
067d72c9
LP
35 _TIMER_RESULT_MAX,
36 _TIMER_RESULT_INVALID = -1
37} TimerResult;
38
5cb5a6ff 39struct Timer {
ac155bb8 40 Unit meta;
5cb5a6ff 41
9f5eb56a 42 usec_t accuracy_usec;
744c7693 43 usec_t random_usec;
9f5eb56a 44
871d7de4 45 LIST_HEAD(TimerValue, values);
36697dc0 46 usec_t next_elapse_realtime;
dedabea4
LP
47 usec_t next_elapse_monotonic_or_boottime;
48 dual_timestamp last_trigger;
5cb5a6ff 49
01f78473 50 TimerState state, deserialized_state;
871d7de4 51
718db961
LP
52 sd_event_source *monotonic_event_source;
53 sd_event_source *realtime_event_source;
871d7de4 54
067d72c9 55 TimerResult result;
e41e1943 56
06642d17 57 bool persistent;
dedabea4 58 bool wake_system;
3e0c30ac 59 bool remain_after_elapse;
06642d17
LP
60
61 char *stamp_path;
5cb5a6ff
LP
62};
63
79fc8b96
LP
64#define TIMER_MONOTONIC_CLOCK(t) ((t)->wake_system && clock_boottime_supported() ? CLOCK_BOOTTIME_ALARM : CLOCK_MONOTONIC)
65
74051b9b
LP
66void timer_free_values(Timer *t);
67
47be870b 68extern const UnitVTable timer_vtable;
5cb5a6ff 69
44a6b1b6
ZJS
70const char *timer_base_to_string(TimerBase i) _const_;
71TimerBase timer_base_from_string(const char *s) _pure_;
871d7de4 72
44a6b1b6
ZJS
73const char* timer_result_to_string(TimerResult i) _const_;
74TimerResult timer_result_from_string(const char *s) _pure_;
57b7a260
FS
75
76DEFINE_CAST(TIMER, Timer);