chiark / gitweb /
core: add a setting to globally control the default for timer unit accuracy
[elogind.git] / src / core / timer.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6   This file is part of systemd.
7
8   Copyright 2010 Lennart Poettering
9
10   systemd is free software; you can redistribute it and/or modify it
11   under the terms of the GNU Lesser General Public License as published by
12   the Free Software Foundation; either version 2.1 of the License, or
13   (at your option) any later version.
14
15   systemd is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 typedef struct Timer Timer;
25
26 #include "unit.h"
27 #include "calendarspec.h"
28
29 typedef enum TimerState {
30         TIMER_DEAD,
31         TIMER_WAITING,
32         TIMER_RUNNING,
33         TIMER_ELAPSED,
34         TIMER_FAILED,
35         _TIMER_STATE_MAX,
36         _TIMER_STATE_INVALID = -1
37 } TimerState;
38
39 typedef enum TimerBase {
40         TIMER_ACTIVE,
41         TIMER_BOOT,
42         TIMER_STARTUP,
43         TIMER_UNIT_ACTIVE,
44         TIMER_UNIT_INACTIVE,
45         TIMER_CALENDAR,
46         _TIMER_BASE_MAX,
47         _TIMER_BASE_INVALID = -1
48 } TimerBase;
49
50 typedef struct TimerValue {
51         TimerBase base;
52         bool disabled;
53
54         usec_t value; /* only for monotonic events */
55         CalendarSpec *calendar_spec; /* only for calendar events */
56         usec_t next_elapse;
57
58         LIST_FIELDS(struct TimerValue, value);
59 } TimerValue;
60
61 typedef enum TimerResult {
62         TIMER_SUCCESS,
63         TIMER_FAILURE_RESOURCES,
64         _TIMER_RESULT_MAX,
65         _TIMER_RESULT_INVALID = -1
66 } TimerResult;
67
68 struct Timer {
69         Unit meta;
70
71         usec_t accuracy_usec;
72
73         LIST_HEAD(TimerValue, values);
74         usec_t next_elapse_realtime;
75         usec_t next_elapse_monotonic_or_boottime;
76         dual_timestamp last_trigger;
77
78         TimerState state, deserialized_state;
79
80         sd_event_source *monotonic_event_source;
81         sd_event_source *realtime_event_source;
82
83         TimerResult result;
84
85         bool persistent;
86         bool wake_system;
87
88         char *stamp_path;
89 };
90
91 void timer_free_values(Timer *t);
92
93 extern const UnitVTable timer_vtable;
94
95 const char *timer_state_to_string(TimerState i) _const_;
96 TimerState timer_state_from_string(const char *s) _pure_;
97
98 const char *timer_base_to_string(TimerBase i) _const_;
99 TimerBase timer_base_from_string(const char *s) _pure_;
100
101 const char* timer_result_to_string(TimerResult i) _const_;
102 TimerResult timer_result_from_string(const char *s) _pure_;