]> git.ipfire.org Git - people/ms/systemd.git/blame - name.h
start implementing a test suite for the engine
[people/ms/systemd.git] / name.h
CommitLineData
60918275
LP
1/*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3#ifndef foonamehfoo
4#define foonamehfoo
5
6#include <stdbool.h>
7#include <stdlib.h>
8
9typedef union Name Name;
10typedef struct Meta Meta;
11typedef struct Service Service;
12typedef struct Timer Timer;
13typedef struct Socket Socket;
14typedef struct Milestone Milestone;
15typedef struct Device Device;
16typedef struct Mount Mount;
17typedef struct Automount Automount;
18typedef struct Snapshot Snapshot;
19
20#include "job.h"
21#include "manager.h"
22#include "set.h"
23#include "util.h"
24#include "list.h"
42f4e3c4 25#include "socket-util.h"
60918275
LP
26
27typedef 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
40typedef enum NameState {
41 NAME_STUB,
42 NAME_LOADED,
a66d02c3
LP
43 NAME_FAILED,
44 _NAME_STATE_MAX
60918275
LP
45} NameState;
46
87d1515d 47typedef enum NameDependency {
60918275 48 /* Positive dependencies */
87d1515d
LP
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' */
60918275
LP
56
57 /* Negative dependencies */
87d1515d 58 NAME_CONFLICTS, /* inverse of 'conflicts' is 'conflicts' */
60918275
LP
59
60 /* Order */
87d1515d
LP
61 NAME_BEFORE, /* inverse of before is after and vice versa */
62 NAME_AFTER,
63 _NAME_DEPENDENCY_MAX
64} NameDependency;
65
66struct Meta {
67 Manager *manager;
68 NameType type;
69 NameState state;
70
71 Set *names;
72 Set *dependencies[_NAME_DEPENDENCY_MAX];
60918275 73
60918275
LP
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
86typedef 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
105typedef enum ServiceMode {
106 SERVICE_ONCE,
107 SERVICE_RESTART
108} ServiceMode;
109
110struct Service {
111 Meta meta;
112
113 ServiceState state;
114 ServiceMode mode;
115};
116
117typedef 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
131struct Timer {
132 Meta meta;
133
134 TimerState state;
135 Service *subject;
136
137 clockid_t clock_id;
138 usec_t next_elapse;
139};
140
141typedef 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,
42f4e3c4
LP
152 SOCKET_MAINTAINANCE,
153 _SOCKET_STATE_MAX
60918275
LP
154} SocketState;
155
156struct Socket {
157 Meta meta;
158
159 SocketState state;
42f4e3c4
LP
160
161 Address address;
60918275
LP
162 int *fds;
163 unsigned n_fds;
164
165 Service *subject;
166};
167
168typedef enum MilestoneState {
169 MILESTONE_DEAD,
170 MILESTONE_BEFORE,
171 MILESTONE_ACTIVE
172} MilestoneState;
173
174struct Milestone {
175 Meta meta;
176
177 MilestoneState state;
178};
179
180typedef enum DeviceState {
181 DEVICE_DEAD,
182 DEVICE_BEFORE,
183 DEVICE_AVAILABLE
184} DeviceState;
185
186struct Device {
187 Meta meta;
188
189 DeviceState state;
190 char *sysfs;
191};
192
193typedef enum MountState {
194 MOUNT_DEAD,
195 MOUNT_BEFORE,
196 MOUNT_MOUNTED
197} MountState;
198
199struct Mount {
200 Meta meta;
201
202 MountState state;
203 char *path;
204};
205
206typedef 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
220struct Automount {
221 Meta meta;
222
223 AutomountState state;
224 char *path;
225 Mount *subject;
226};
227
228typedef enum SnapshotState {
229 SNAPSHOT_DEAD,
230 SNAPSHOT_BEFORE,
231 SNAPSHOT_ACTIVE
232} SnapshotState;
233
234struct Snapshot {
235 Meta meta;
236
237 SnapshotState state;
238 bool cleanup:1;
239};
240
241union 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
263DEFINE_CAST(SERVICE, Service, service);
264DEFINE_CAST(TIMER, Timer, timer);
265DEFINE_CAST(SOCKET, Socket, socket);
266DEFINE_CAST(MILESTONE, Milestone, milestone);
267DEFINE_CAST(DEVICE, Device, device);
268DEFINE_CAST(MOUNT, Mount, mount);
269DEFINE_CAST(AUTOMOUNT, Automount, automount);
270DEFINE_CAST(SNAPSHOT, Snapshot, snapshot);
271
272/* For casting the various name types into a name */
273#define NAME(o) ((Name*) (o))
274
275bool name_is_ready(Name *name);
276NameType name_type_from_string(const char *n);
07232470 277bool name_is_valid(const char *n);
60918275
LP
278
279Name *name_new(Manager *m);
280void name_free(Name *name);
281int name_link(Name *name);
e5b5ae50 282int name_link_names(Name *name, bool replace);
87d1515d 283int name_merge(Name *name, Name *other);
7fad411c
LP
284int name_sanitize(Name *n);
285int name_load(Name *name);
a66d02c3
LP
286const char* name_id(Name *n);
287
ceed3570 288void name_dump(Name *n, FILE *f, const char *prefix);
60918275
LP
289
290#endif