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