udev: String substitutions can be done in ENV, too
[systemd_ALT.git] / src / core / timer.h
blob914e42580e350840d0ed712dbaf72c2ccd524f4a
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
4 typedef struct Timer Timer;
5 typedef struct ActivationDetailsTimer ActivationDetailsTimer;
7 #include "calendarspec.h"
8 #include "unit.h"
10 typedef enum TimerBase {
11 TIMER_ACTIVE,
12 TIMER_BOOT,
13 TIMER_STARTUP,
14 TIMER_UNIT_ACTIVE,
15 TIMER_UNIT_INACTIVE,
16 TIMER_CALENDAR,
17 _TIMER_BASE_MAX,
18 _TIMER_BASE_INVALID = -EINVAL,
19 } TimerBase;
21 typedef struct TimerValue {
22 TimerBase base;
23 bool disabled;
25 usec_t value; /* only for monotonic events */
26 CalendarSpec *calendar_spec; /* only for calendar events */
27 usec_t next_elapse;
29 LIST_FIELDS(struct TimerValue, value);
30 } TimerValue;
32 typedef enum TimerResult {
33 TIMER_SUCCESS,
34 TIMER_FAILURE_RESOURCES,
35 TIMER_FAILURE_START_LIMIT_HIT,
36 _TIMER_RESULT_MAX,
37 _TIMER_RESULT_INVALID = -EINVAL,
38 } TimerResult;
40 struct Timer {
41 Unit meta;
43 usec_t accuracy_usec;
44 usec_t random_usec;
46 LIST_HEAD(TimerValue, values);
47 usec_t next_elapse_realtime;
48 usec_t next_elapse_monotonic_or_boottime;
49 dual_timestamp last_trigger;
51 TimerState state, deserialized_state;
53 sd_event_source *monotonic_event_source;
54 sd_event_source *realtime_event_source;
56 TimerResult result;
58 bool persistent;
59 bool wake_system;
60 bool remain_after_elapse;
61 bool on_clock_change;
62 bool on_timezone_change;
63 bool fixed_random_delay;
65 char *stamp_path;
68 struct ActivationDetailsTimer {
69 ActivationDetails meta;
70 dual_timestamp last_trigger;
73 #define TIMER_MONOTONIC_CLOCK(t) ((t)->wake_system ? CLOCK_BOOTTIME_ALARM : CLOCK_MONOTONIC)
75 void timer_free_values(Timer *t);
77 extern const UnitVTable timer_vtable;
78 extern const ActivationDetailsVTable activation_details_timer_vtable;
80 const char *timer_base_to_string(TimerBase i) _const_;
81 TimerBase timer_base_from_string(const char *s) _pure_;
83 const char* timer_result_to_string(TimerResult i) _const_;
84 TimerResult timer_result_from_string(const char *s) _pure_;
86 DEFINE_CAST(TIMER, Timer);
87 DEFINE_ACTIVATION_DETAILS_CAST(ACTIVATION_DETAILS_TIMER, ActivationDetailsTimer, TIMER);