]>
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 | |
8 | ||
9 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
10 | under the terms of the GNU Lesser General Public License as published by |
11 | the Free Software Foundation; either version 2.1 of the License, or | |
a7334b09 LP |
12 | (at your option) any later version. |
13 | ||
14 | systemd is distributed in the hope that it will be useful, but | |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 17 | Lesser General Public License for more details. |
a7334b09 | 18 | |
5430f7f2 | 19 | You should have received a copy of the GNU Lesser General Public License |
a7334b09 LP |
20 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
21 | ***/ | |
22 | ||
5cb5a6ff LP |
23 | typedef struct Timer Timer; |
24 | ||
36697dc0 | 25 | #include "calendarspec.h" |
5cb5a6ff | 26 | |
871d7de4 LP |
27 | typedef enum TimerBase { |
28 | TIMER_ACTIVE, | |
29 | TIMER_BOOT, | |
30 | TIMER_STARTUP, | |
31 | TIMER_UNIT_ACTIVE, | |
32 | TIMER_UNIT_INACTIVE, | |
36697dc0 | 33 | TIMER_CALENDAR, |
871d7de4 LP |
34 | _TIMER_BASE_MAX, |
35 | _TIMER_BASE_INVALID = -1 | |
36 | } TimerBase; | |
37 | ||
38 | typedef struct TimerValue { | |
36697dc0 LP |
39 | TimerBase base; |
40 | bool disabled; | |
36697dc0 | 41 | |
b719810d LP |
42 | usec_t value; /* only for monotonic events */ |
43 | CalendarSpec *calendar_spec; /* only for calendar events */ | |
871d7de4 LP |
44 | usec_t next_elapse; |
45 | ||
871d7de4 LP |
46 | LIST_FIELDS(struct TimerValue, value); |
47 | } TimerValue; | |
48 | ||
067d72c9 LP |
49 | typedef enum TimerResult { |
50 | TIMER_SUCCESS, | |
51 | TIMER_FAILURE_RESOURCES, | |
07299350 | 52 | TIMER_FAILURE_START_LIMIT_HIT, |
067d72c9 LP |
53 | _TIMER_RESULT_MAX, |
54 | _TIMER_RESULT_INVALID = -1 | |
55 | } TimerResult; | |
56 | ||
5cb5a6ff | 57 | struct Timer { |
ac155bb8 | 58 | Unit meta; |
5cb5a6ff | 59 | |
9f5eb56a | 60 | usec_t accuracy_usec; |
744c7693 | 61 | usec_t random_usec; |
9f5eb56a | 62 | |
871d7de4 | 63 | LIST_HEAD(TimerValue, values); |
36697dc0 | 64 | usec_t next_elapse_realtime; |
dedabea4 LP |
65 | usec_t next_elapse_monotonic_or_boottime; |
66 | dual_timestamp last_trigger; | |
5cb5a6ff | 67 | |
01f78473 | 68 | TimerState state, deserialized_state; |
871d7de4 | 69 | |
718db961 LP |
70 | sd_event_source *monotonic_event_source; |
71 | sd_event_source *realtime_event_source; | |
871d7de4 | 72 | |
067d72c9 | 73 | TimerResult result; |
e41e1943 | 74 | |
06642d17 | 75 | bool persistent; |
dedabea4 | 76 | bool wake_system; |
3e0c30ac | 77 | bool remain_after_elapse; |
06642d17 LP |
78 | |
79 | char *stamp_path; | |
5cb5a6ff LP |
80 | }; |
81 | ||
79fc8b96 LP |
82 | #define TIMER_MONOTONIC_CLOCK(t) ((t)->wake_system && clock_boottime_supported() ? CLOCK_BOOTTIME_ALARM : CLOCK_MONOTONIC) |
83 | ||
74051b9b LP |
84 | void timer_free_values(Timer *t); |
85 | ||
47be870b | 86 | extern const UnitVTable timer_vtable; |
5cb5a6ff | 87 | |
44a6b1b6 ZJS |
88 | const char *timer_base_to_string(TimerBase i) _const_; |
89 | TimerBase timer_base_from_string(const char *s) _pure_; | |
871d7de4 | 90 | |
44a6b1b6 ZJS |
91 | const char* timer_result_to_string(TimerResult i) _const_; |
92 | TimerResult timer_result_from_string(const char *s) _pure_; |