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