]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
c2f1db8f | 2 | #pragma once |
5cb5a6ff LP |
3 | |
4 | typedef struct Timer Timer; | |
c8bc7519 | 5 | typedef struct ActivationDetailsTimer ActivationDetailsTimer; |
5cb5a6ff | 6 | |
36697dc0 | 7 | #include "calendarspec.h" |
57b7a260 | 8 | #include "unit.h" |
5cb5a6ff | 9 | |
871d7de4 LP |
10 | typedef enum TimerBase { |
11 | TIMER_ACTIVE, | |
12 | TIMER_BOOT, | |
13 | TIMER_STARTUP, | |
14 | TIMER_UNIT_ACTIVE, | |
15 | TIMER_UNIT_INACTIVE, | |
36697dc0 | 16 | TIMER_CALENDAR, |
871d7de4 | 17 | _TIMER_BASE_MAX, |
2d93c20e | 18 | _TIMER_BASE_INVALID = -EINVAL, |
871d7de4 LP |
19 | } TimerBase; |
20 | ||
21 | typedef struct TimerValue { | |
36697dc0 LP |
22 | TimerBase base; |
23 | bool disabled; | |
36697dc0 | 24 | |
b719810d LP |
25 | usec_t value; /* only for monotonic events */ |
26 | CalendarSpec *calendar_spec; /* only for calendar events */ | |
871d7de4 LP |
27 | usec_t next_elapse; |
28 | ||
871d7de4 LP |
29 | LIST_FIELDS(struct TimerValue, value); |
30 | } TimerValue; | |
31 | ||
067d72c9 LP |
32 | typedef enum TimerResult { |
33 | TIMER_SUCCESS, | |
34 | TIMER_FAILURE_RESOURCES, | |
07299350 | 35 | TIMER_FAILURE_START_LIMIT_HIT, |
067d72c9 | 36 | _TIMER_RESULT_MAX, |
2d93c20e | 37 | _TIMER_RESULT_INVALID = -EINVAL, |
067d72c9 LP |
38 | } TimerResult; |
39 | ||
5cb5a6ff | 40 | struct Timer { |
ac155bb8 | 41 | Unit meta; |
5cb5a6ff | 42 | |
9f5eb56a | 43 | usec_t accuracy_usec; |
744c7693 | 44 | usec_t random_usec; |
9f5eb56a | 45 | |
871d7de4 | 46 | LIST_HEAD(TimerValue, values); |
36697dc0 | 47 | usec_t next_elapse_realtime; |
dedabea4 LP |
48 | usec_t next_elapse_monotonic_or_boottime; |
49 | dual_timestamp last_trigger; | |
5cb5a6ff | 50 | |
01f78473 | 51 | TimerState state, deserialized_state; |
871d7de4 | 52 | |
718db961 LP |
53 | sd_event_source *monotonic_event_source; |
54 | sd_event_source *realtime_event_source; | |
871d7de4 | 55 | |
067d72c9 | 56 | TimerResult result; |
e41e1943 | 57 | |
06642d17 | 58 | bool persistent; |
dedabea4 | 59 | bool wake_system; |
3e0c30ac | 60 | bool remain_after_elapse; |
efebb613 LP |
61 | bool on_clock_change; |
62 | bool on_timezone_change; | |
acf24a1a | 63 | bool fixed_random_delay; |
06642d17 LP |
64 | |
65 | char *stamp_path; | |
5cb5a6ff LP |
66 | }; |
67 | ||
c8bc7519 LB |
68 | struct ActivationDetailsTimer { |
69 | ActivationDetails meta; | |
70 | dual_timestamp last_trigger; | |
71 | }; | |
72 | ||
ba4e0427 | 73 | #define TIMER_MONOTONIC_CLOCK(t) ((t)->wake_system ? CLOCK_BOOTTIME_ALARM : CLOCK_MONOTONIC) |
79fc8b96 | 74 | |
74051b9b LP |
75 | void timer_free_values(Timer *t); |
76 | ||
47be870b | 77 | extern const UnitVTable timer_vtable; |
c8bc7519 | 78 | extern const ActivationDetailsVTable activation_details_timer_vtable; |
5cb5a6ff | 79 | |
44a6b1b6 ZJS |
80 | const char *timer_base_to_string(TimerBase i) _const_; |
81 | TimerBase timer_base_from_string(const char *s) _pure_; | |
871d7de4 | 82 | |
44a6b1b6 ZJS |
83 | const char* timer_result_to_string(TimerResult i) _const_; |
84 | TimerResult timer_result_from_string(const char *s) _pure_; | |
57b7a260 FS |
85 | |
86 | DEFINE_CAST(TIMER, Timer); | |
c8bc7519 | 87 | DEFINE_ACTIVATION_DETAILS_CAST(ACTIVATION_DETAILS_TIMER, ActivationDetailsTimer, TIMER); |