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