summaryrefslogtreecommitdiff
path: root/timer.c
blob: c3ebba0d1ba80220cfd97112bd91cdee6c21a7b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*-*- Mode: C; c-basic-offset: 8 -*-*/

#include <errno.h>

#include "unit.h"
#include "timer.h"

static void timer_done(Unit *u) {
        Timer *t = TIMER(u);

        assert(t);
}

static int timer_init(Unit *u) {
        int r;

        assert(u);

        /* Make sure this config file actually exists */

        if ((r = unit_load_fragment_and_dropin(u)) <= 0)
                return r < 0 ? r : -ENOENT;

        return 0;
}

static UnitActiveState timer_active_state(Unit *u) {

        static const UnitActiveState table[_TIMER_STATE_MAX] = {
                [TIMER_DEAD] = UNIT_INACTIVE,
                [TIMER_WAITING] = UNIT_ACTIVE,
                [TIMER_RUNNING] = UNIT_ACTIVE
        };

        return table[TIMER(u)->state];
}

const UnitVTable timer_vtable = {
        .suffix = ".timer",

        .init = timer_init,
        .done = timer_done,

        .active_state = timer_active_state
};