Debian Codegraph @

src/core/timer.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "core-forward.h"
5 #include "unit.h"
6
7 typedef enum TimerBase {
8 TIMER_ACTIVE,
9 TIMER_BOOT,
10 TIMER_STARTUP,
11 TIMER_UNIT_ACTIVE,
12 TIMER_UNIT_INACTIVE,
13 TIMER_CALENDAR,
14 _TIMER_BASE_MAX,
15 _TIMER_BASE_INVALID = -EINVAL,
16 } TimerBase;
17
18 typedef struct TimerValue {
19 TimerBase base;
20 bool disabled;
21
22 usec_t value; /* only for monotonic events */
23 CalendarSpec *calendar_spec; /* only for calendar events */
24 usec_t next_elapse;
25
26 LIST_FIELDS(struct TimerValue, value);
27 } TimerValue;
28
29 typedef enum TimerResult {
30 TIMER_SUCCESS,
31 TIMER_FAILURE_RESOURCES,
32 TIMER_FAILURE_START_LIMIT_HIT,
33 _TIMER_RESULT_MAX,
34 _TIMER_RESULT_INVALID = -EINVAL,
35 } TimerResult;
36
37 typedef struct Timer {
38 Unit meta;
39
40 usec_t accuracy_usec;
41 usec_t random_delay_usec;
42 usec_t random_offset_usec;
43
44 LIST_HEAD(TimerValue, values);
45 usec_t next_elapse_realtime;
46 usec_t next_elapse_monotonic_or_boottime;
47 dual_timestamp last_trigger;
48
49 TimerState state, deserialized_state;
50
51 sd_event_source *monotonic_event_source;
52 sd_event_source *realtime_event_source;
53
54 TimerResult result;
55
56 bool persistent;
57 bool wake_system;
58 bool remain_after_elapse;
59 bool on_clock_change;
60 bool on_timezone_change;
61 bool fixed_random_delay;
62 bool defer_reactivation;
63
64 char *stamp_path;
65 } Timer;
66
67 typedef struct ActivationDetailsTimer {
68 ActivationDetails meta;
69 dual_timestamp last_trigger;
70 } ActivationDetailsTimer;
71
72 #define TIMER_MONOTONIC_CLOCK(t) ((t)->wake_system ? CLOCK_BOOTTIME_ALARM : CLOCK_MONOTONIC)
73
74 uint64_t timer_next_elapse_monotonic(const Timer *t);
75
76 void timer_free_values(Timer *t);
77
78 extern const UnitVTable timer_vtable;
79 extern const ActivationDetailsVTable activation_details_timer_vtable;
80
81 DECLARE_STRING_TABLE_LOOKUP(timer_base, TimerBase);
82
83 char* timer_base_to_usec_string(TimerBase i);
84
85 DECLARE_STRING_TABLE_LOOKUP(timer_result, TimerResult);
86
87 DEFINE_CAST(TIMER, Timer);
88 DEFINE_ACTIVATION_DETAILS_CAST(ACTIVATION_DETAILS_TIMER, ActivationDetailsTimer, TIMER);