chiark / gitweb /
use #pragma once instead of foo*foo #define guards
[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
28 typedef enum TimerState {
29         TIMER_DEAD,
30         TIMER_WAITING,
31         TIMER_RUNNING,
32         TIMER_ELAPSED,
33         TIMER_FAILED,
34         _TIMER_STATE_MAX,
35         _TIMER_STATE_INVALID = -1
36 } TimerState;
37
38 typedef enum TimerBase {
39         TIMER_ACTIVE,
40         TIMER_BOOT,
41         TIMER_STARTUP,
42         TIMER_UNIT_ACTIVE,
43         TIMER_UNIT_INACTIVE,
44         _TIMER_BASE_MAX,
45         _TIMER_BASE_INVALID = -1
46 } TimerBase;
47
48 typedef struct TimerValue {
49         usec_t value;
50         usec_t next_elapse;
51
52         LIST_FIELDS(struct TimerValue, value);
53
54         TimerBase base;
55         bool disabled;
56 } TimerValue;
57
58 typedef enum TimerResult {
59         TIMER_SUCCESS,
60         TIMER_FAILURE_RESOURCES,
61         _TIMER_RESULT_MAX,
62         _TIMER_RESULT_INVALID = -1
63 } TimerResult;
64
65 struct Timer {
66         Unit meta;
67
68         LIST_HEAD(TimerValue, values);
69         usec_t next_elapse;
70
71         TimerState state, deserialized_state;
72         UnitRef unit;
73
74         Watch timer_watch;
75
76         TimerResult result;
77 };
78
79 void timer_unit_notify(Unit *u, UnitActiveState new_state);
80
81 extern const UnitVTable timer_vtable;
82
83 const char *timer_state_to_string(TimerState i);
84 TimerState timer_state_from_string(const char *s);
85
86 const char *timer_base_to_string(TimerBase i);
87 TimerBase timer_base_from_string(const char *s);
88
89 const char* timer_result_to_string(TimerResult i);
90 TimerResult timer_result_from_string(const char *s);