chiark / gitweb /
first attempt in implementinging execution logic
[elogind.git] / device.c
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 #include "name.h"
4 #include "device.h"
5 #include "strv.h"
6
7 static void device_dump(Name *n, FILE *f, const char *prefix) {
8
9         static const char* const state_table[_DEVICE_STATE_MAX] = {
10                 [DEVICE_DEAD] = "dead",
11                 [DEVICE_AVAILABLE] = "available"
12         };
13
14         Device *s = DEVICE(n);
15
16         assert(s);
17
18         fprintf(f,
19                 "%sDevice State: %s\n",
20                 prefix, state_table[s->state]);
21 }
22
23 static NameActiveState device_active_state(Name *n) {
24         return DEVICE(n)->state == DEVICE_DEAD ? NAME_INACTIVE : NAME_ACTIVE;
25 }
26
27 static void device_free_hook(Name *n) {
28         Device *d = DEVICE(n);
29
30         assert(d);
31         strv_free(d->sysfs);
32 }
33
34 const NameVTable device_vtable = {
35         .suffix = ".device",
36
37         .load = name_load_fragment_and_dropin,
38         .dump = device_dump,
39
40         .start = NULL,
41         .stop = NULL,
42         .reload = NULL,
43
44         .active_state = device_active_state,
45
46         .free_hook = device_free_hook
47 };