]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/timer.h
24719671ba713667af9b1a4d1665571f389e580d
[thirdparty/systemd.git] / src / core / timer.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 Copyright 2010 Lennart Poettering
6 ***/
7
8 typedef struct Timer Timer;
9
10 #include "calendarspec.h"
11 #include "unit.h"
12
13 typedef enum TimerBase {
14 TIMER_ACTIVE,
15 TIMER_BOOT,
16 TIMER_STARTUP,
17 TIMER_UNIT_ACTIVE,
18 TIMER_UNIT_INACTIVE,
19 TIMER_CALENDAR,
20 _TIMER_BASE_MAX,
21 _TIMER_BASE_INVALID = -1
22 } TimerBase;
23
24 typedef struct TimerValue {
25 TimerBase base;
26 bool disabled;
27
28 usec_t value; /* only for monotonic events */
29 CalendarSpec *calendar_spec; /* only for calendar events */
30 usec_t next_elapse;
31
32 LIST_FIELDS(struct TimerValue, value);
33 } TimerValue;
34
35 typedef enum TimerResult {
36 TIMER_SUCCESS,
37 TIMER_FAILURE_RESOURCES,
38 TIMER_FAILURE_START_LIMIT_HIT,
39 _TIMER_RESULT_MAX,
40 _TIMER_RESULT_INVALID = -1
41 } TimerResult;
42
43 struct Timer {
44 Unit meta;
45
46 usec_t accuracy_usec;
47 usec_t random_usec;
48
49 LIST_HEAD(TimerValue, values);
50 usec_t next_elapse_realtime;
51 usec_t next_elapse_monotonic_or_boottime;
52 dual_timestamp last_trigger;
53
54 TimerState state, deserialized_state;
55
56 sd_event_source *monotonic_event_source;
57 sd_event_source *realtime_event_source;
58
59 TimerResult result;
60
61 bool persistent;
62 bool wake_system;
63 bool remain_after_elapse;
64
65 char *stamp_path;
66 };
67
68 #define TIMER_MONOTONIC_CLOCK(t) ((t)->wake_system && clock_boottime_supported() ? CLOCK_BOOTTIME_ALARM : CLOCK_MONOTONIC)
69
70 void timer_free_values(Timer *t);
71
72 extern const UnitVTable timer_vtable;
73
74 const char *timer_base_to_string(TimerBase i) _const_;
75 TimerBase timer_base_from_string(const char *s) _pure_;
76
77 const char* timer_result_to_string(TimerResult i) _const_;
78 TimerResult timer_result_from_string(const char *s) _pure_;
79
80 DEFINE_CAST(TIMER, Timer);