summaryrefslogtreecommitdiff
path: root/device.c
blob: ec0a40a4df6561c333226057b5702662e5640a3d (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
/*-*- Mode: C; c-basic-offset: 8 -*-*/

#include "name.h"
#include "device.h"
#include "strv.h"

static void device_done(Name *n) {
        Device *d = DEVICE(n);

        assert(d);
        strv_free(d->sysfs);
}

static void device_dump(Name *n, FILE *f, const char *prefix) {

        static const char* const state_table[_DEVICE_STATE_MAX] = {
                [DEVICE_DEAD] = "dead",
                [DEVICE_AVAILABLE] = "available"
        };

        Device *s = DEVICE(n);

        assert(s);

        fprintf(f,
                "%sDevice State: %s\n",
                prefix, state_table[s->state]);
}

static NameActiveState device_active_state(Name *n) {
        return DEVICE(n)->state == DEVICE_DEAD ? NAME_INACTIVE : NAME_ACTIVE;
}

const NameVTable device_vtable = {
        .suffix = ".device",

        .init = name_load_fragment_and_dropin,
        .done = device_done,
        .dump = device_dump,

        .active_state = device_active_state
};