]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/timer.h
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / core / timer.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
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
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
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
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 ***/
22
23 typedef struct Timer Timer;
24
25 #include "calendarspec.h"
26
27 typedef enum TimerBase {
28 TIMER_ACTIVE,
29 TIMER_BOOT,
30 TIMER_STARTUP,
31 TIMER_UNIT_ACTIVE,
32 TIMER_UNIT_INACTIVE,
33 TIMER_CALENDAR,
34 _TIMER_BASE_MAX,
35 _TIMER_BASE_INVALID = -1
36 } TimerBase;
37
38 typedef struct TimerValue {
39 TimerBase base;
40 bool disabled;
41
42 usec_t value; /* only for monotonic events */
43 CalendarSpec *calendar_spec; /* only for calendar events */
44 usec_t next_elapse;
45
46 LIST_FIELDS(struct TimerValue, value);
47 } TimerValue;
48
49 typedef enum TimerResult {
50 TIMER_SUCCESS,
51 TIMER_FAILURE_RESOURCES,
52 TIMER_FAILURE_START_LIMIT_HIT,
53 _TIMER_RESULT_MAX,
54 _TIMER_RESULT_INVALID = -1
55 } TimerResult;
56
57 struct Timer {
58 Unit meta;
59
60 usec_t accuracy_usec;
61 usec_t random_usec;
62
63 LIST_HEAD(TimerValue, values);
64 usec_t next_elapse_realtime;
65 usec_t next_elapse_monotonic_or_boottime;
66 dual_timestamp last_trigger;
67
68 TimerState state, deserialized_state;
69
70 sd_event_source *monotonic_event_source;
71 sd_event_source *realtime_event_source;
72
73 TimerResult result;
74
75 bool persistent;
76 bool wake_system;
77 bool remain_after_elapse;
78
79 char *stamp_path;
80 };
81
82 #define TIMER_MONOTONIC_CLOCK(t) ((t)->wake_system && clock_boottime_supported() ? CLOCK_BOOTTIME_ALARM : CLOCK_MONOTONIC)
83
84 void timer_free_values(Timer *t);
85
86 extern const UnitVTable timer_vtable;
87
88 const char *timer_base_to_string(TimerBase i) _const_;
89 TimerBase timer_base_from_string(const char *s) _pure_;
90
91 const char* timer_result_to_string(TimerResult i) _const_;
92 TimerResult timer_result_from_string(const char *s) _pure_;