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