chiark / gitweb /
conf-parse: add generic parser for strv
[elogind.git] / name.h
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 #ifndef foonamehfoo
4 #define foonamehfoo
5
6 #include <stdbool.h>
7 #include <stdlib.h>
8
9 typedef union Name Name;
10 typedef struct Meta Meta;
11 typedef struct Service Service;
12 typedef struct Timer Timer;
13 typedef struct Socket Socket;
14 typedef struct Milestone Milestone;
15 typedef struct Device Device;
16 typedef struct Mount Mount;
17 typedef struct Automount Automount;
18 typedef struct Snapshot Snapshot;
19
20 #include "job.h"
21 #include "manager.h"
22 #include "set.h"
23 #include "util.h"
24 #include "list.h"
25
26 typedef enum NameType {
27         NAME_SERVICE = 0,
28         NAME_TIMER,
29         NAME_SOCKET,
30         NAME_MILESTONE,
31         NAME_DEVICE,
32         NAME_MOUNT,
33         NAME_AUTOMOUNT,
34         NAME_SNAPSHOT,
35         _NAME_TYPE_MAX,
36         _NAME_TYPE_INVALID = -1,
37 } NameType;
38
39 typedef enum NameState {
40         NAME_STUB,
41         NAME_LOADED,
42         NAME_FAILED
43 } NameState;
44
45 struct Meta {
46         Manager *manager;
47         NameType type;
48         NameState state;
49
50         char **names;
51
52         /* Positive dependencies */
53         Set *requires, *soft_requires, *wants, *requisite, *soft_requisite;
54         Set *required_by;    /* inverse of 'requires', 'soft_requires', 'requisite' and 'soft_requisite' is 'required_by' */
55
56         /* Negative dependencies */
57         Set *conflicts;      /* inverse of 'conflicts' is 'conflicts' */
58
59         /* Order */
60         Set *before, *after; /* inverse of before is after and vice versa */
61
62         /* Information */
63         char *description;
64
65         /* If there is something to do with this name, then this is
66          * the job for it */
67         Job *job;
68
69         bool linked:1;
70
71         /* Load queue */
72         LIST_FIELDS(Meta);
73 };
74
75 typedef enum ServiceState {
76         SERVICE_DEAD,
77         SERVICE_BEFORE,
78         SERVICE_START_PRE,
79         SERVICE_START,
80         SERVICE_START_POST,
81         SERVICE_RUNNING,
82         SERVICE_RELOAD_PRE,
83         SERVICE_RELOAD,
84         SERVICE_RELOAD_POST,
85         SERVICE_STOP_PRE,
86         SERVICE_STOP,
87         SERVICE_SIGTERM,
88         SERVICE_SIGKILL,
89         SERVICE_STOP_POST,
90         SERVICE_HOLDOFF,
91         SERVICE_MAINTAINANCE
92 } ServiceState;
93
94 typedef enum ServiceMode {
95         SERVICE_ONCE,
96         SERVICE_RESTART
97 } ServiceMode;
98
99 struct Service {
100         Meta meta;
101
102         ServiceState state;
103         ServiceMode mode;
104 };
105
106 typedef enum TimerState {
107         TIMER_DEAD,
108         TIMER_BEFORE,
109         TIMER_START_PRE,
110         TIMER_START,
111         TIMER_START_POST,
112         TIMER_WAITING,
113         TIMER_RUNNING,
114         TIMER_STOP_PRE,
115         TIMER_STOP,
116         TIMER_STOP_POST,
117         TIMER_MAINTAINANCE
118 } TimerState;
119
120 struct Timer {
121         Meta meta;
122
123         TimerState state;
124         Service *subject;
125
126         clockid_t clock_id;
127         usec_t next_elapse;
128 };
129
130 typedef enum SocketState {
131         SOCKET_DEAD,
132         SOCKET_BEFORE,
133         SOCKET_START_PRE,
134         SOCKET_START,
135         SOCKET_START_POST,
136         SOCKET_LISTENING,
137         SOCKET_RUNNING,
138         SOCKET_STOP_PRE,
139         SOCKET_STOP,
140         SOCKET_STOP_POST,
141         SOCKET_MAINTAINANCE
142 } SocketState;
143
144 struct Socket {
145         Meta meta;
146
147         SocketState state;
148         int *fds;
149         unsigned n_fds;
150
151         Service *subject;
152 };
153
154 typedef enum MilestoneState {
155         MILESTONE_DEAD,
156         MILESTONE_BEFORE,
157         MILESTONE_ACTIVE
158 } MilestoneState;
159
160 struct Milestone {
161         Meta meta;
162
163         MilestoneState state;
164 };
165
166 typedef enum DeviceState {
167         DEVICE_DEAD,
168         DEVICE_BEFORE,
169         DEVICE_AVAILABLE
170 } DeviceState;
171
172 struct Device {
173         Meta meta;
174
175         DeviceState state;
176         char *sysfs;
177 };
178
179 typedef enum MountState {
180         MOUNT_DEAD,
181         MOUNT_BEFORE,
182         MOUNT_MOUNTED
183 } MountState;
184
185 struct Mount {
186         Meta meta;
187
188         MountState state;
189         char *path;
190 };
191
192 typedef enum AutomountState {
193         AUTOMOUNT_DEAD,
194         AUTOMOUNT_BEFORE,
195         AUTOMOUNT_START_PRE,
196         AUTOMOUNT_START,
197         AUTOMOUNT_START_POST,
198         AUTOMOUNT_WAITING,
199         AUTOMOUNT_RUNNING,
200         AUTOMOUNT_STOP_PRE,
201         AUTOMOUNT_STOP,
202         AUTOMOUNT_STOP_POST,
203         AUTOMOUNT_MAINTAINANCE
204 } AutomountState;
205
206 struct Automount {
207         Meta meta;
208
209         AutomountState state;
210         char *path;
211         Mount *subject;
212 };
213
214 typedef enum SnapshotState {
215         SNAPSHOT_DEAD,
216         SNAPSHOT_BEFORE,
217         SNAPSHOT_ACTIVE
218 } SnapshotState;
219
220 struct Snapshot {
221         Meta meta;
222
223         SnapshotState state;
224         bool cleanup:1;
225 };
226
227 union Name {
228         Meta meta;
229         Service service;
230         Timer timer;
231         Socket socket;
232         Milestone milestone;
233         Device device;
234         Mount mount;
235         Automount automount;
236         Snapshot snapshot;
237 };
238
239 /* For casting a name into the various name types */
240
241 #define DEFINE_CAST(UPPERCASE, MixedCase, lowercase)                    \
242         static inline MixedCase* UPPERCASE(Name *name) {                \
243                 if (name->meta.type != NAME_##UPPERCASE)                \
244                         return NULL;                                    \
245                                                                         \
246                 return &name->lowercase;                                \
247         }
248
249 DEFINE_CAST(SERVICE, Service, service);
250 DEFINE_CAST(TIMER, Timer, timer);
251 DEFINE_CAST(SOCKET, Socket, socket);
252 DEFINE_CAST(MILESTONE, Milestone, milestone);
253 DEFINE_CAST(DEVICE, Device, device);
254 DEFINE_CAST(MOUNT, Mount, mount);
255 DEFINE_CAST(AUTOMOUNT, Automount, automount);
256 DEFINE_CAST(SNAPSHOT, Snapshot, snapshot);
257
258 /* For casting the various name types into a name */
259 #define NAME(o) ((Name*) (o))
260
261 bool name_is_ready(Name *name);
262 NameType name_type_from_string(const char *n);
263 bool name_is_valid(const char *n);
264
265 Name *name_new(Manager *m);
266 void name_free(Name *name);
267 int name_link(Name *name);
268
269 int name_augment(Name *n);
270
271 #endif