]> git.ipfire.org Git - thirdparty/systemd.git/blob - name.h
drop useless newline
[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 NameVTable NameVTable;
12 typedef enum NameType NameType;
13 typedef enum NameLoadState NameLoadState;
14 typedef enum NameActiveState NameActiveState;
15 typedef enum NameDependency NameDependency;
16
17 #include "job.h"
18 #include "manager.h"
19 #include "set.h"
20 #include "util.h"
21 #include "list.h"
22 #include "socket-util.h"
23 #include "execute.h"
24 #include "util.h"
25
26 #define NAME_MAX 32
27 #define DEFAULT_TIMEOUT_USEC (20*USEC_PER_SEC)
28 #define DEFAULT_RESTART_USEC (100*USEC_PER_MSEC)
29
30 enum NameType {
31 NAME_SERVICE = 0,
32 NAME_TIMER,
33 NAME_SOCKET,
34 NAME_TARGET,
35 NAME_DEVICE,
36 NAME_MOUNT,
37 NAME_AUTOMOUNT,
38 NAME_SNAPSHOT,
39 _NAME_TYPE_MAX,
40 _NAME_TYPE_INVALID = -1,
41 };
42
43 enum NameLoadState {
44 NAME_STUB,
45 NAME_LOADED,
46 NAME_FAILED,
47 _NAME_LOAD_STATE_MAX
48 };
49
50 enum NameActiveState {
51 NAME_ACTIVE,
52 NAME_ACTIVE_RELOADING,
53 NAME_INACTIVE,
54 NAME_ACTIVATING,
55 NAME_DEACTIVATING,
56 _NAME_ACTIVE_STATE_MAX
57 };
58
59 static inline bool NAME_IS_ACTIVE_OR_RELOADING(NameActiveState t) {
60 return t == NAME_ACTIVE || t == NAME_ACTIVE_RELOADING;
61 }
62
63 static inline bool NAME_IS_ACTIVE_OR_ACTIVATING(NameActiveState t) {
64 return t == NAME_ACTIVE || t == NAME_ACTIVATING || t == NAME_ACTIVE_RELOADING;
65 }
66
67 static inline bool NAME_IS_INACTIVE_OR_DEACTIVATING(NameActiveState t) {
68 return t == NAME_INACTIVE || t == NAME_DEACTIVATING;
69 }
70
71 enum NameDependency {
72 /* Positive dependencies */
73 NAME_REQUIRES,
74 NAME_SOFT_REQUIRES,
75 NAME_WANTS,
76 NAME_REQUISITE,
77 NAME_SOFT_REQUISITE,
78
79 /* Inverse of the above */
80 NAME_REQUIRED_BY, /* inverse of 'requires' and 'requisite' is 'required_by' */
81 NAME_SOFT_REQUIRED_BY, /* inverse of 'soft_requires' and 'soft_requisite' is 'soft_required_by' */
82 NAME_WANTED_BY, /* inverse of 'wants' */
83
84 /* Negative dependencies */
85 NAME_CONFLICTS, /* inverse of 'conflicts' is 'conflicts' */
86
87 /* Order */
88 NAME_BEFORE, /* inverse of before is after and vice versa */
89 NAME_AFTER,
90
91 _NAME_DEPENDENCY_MAX,
92 _NAME_DEPENDENCY_INVALID = -1
93 };
94
95 struct Meta {
96 Manager *manager;
97 NameType type;
98 NameLoadState load_state;
99
100 char *id; /* One name is special because we use it for identification. Points to an entry in the names set */
101
102 Set *names;
103 Set *dependencies[_NAME_DEPENDENCY_MAX];
104
105 char *description;
106
107 /* If there is something to do with this name, then this is
108 * the job for it */
109 Job *job;
110
111 bool in_load_queue:1;
112
113 usec_t active_enter_timestamp;
114 usec_t active_exit_timestamp;
115
116 /* Load queue */
117 LIST_FIELDS(Meta, load_queue);
118 };
119
120 #include "service.h"
121 #include "timer.h"
122 #include "socket.h"
123 #include "target.h"
124 #include "device.h"
125 #include "mount.h"
126 #include "automount.h"
127 #include "snapshot.h"
128
129 union Name {
130 Meta meta;
131 Service service;
132 Timer timer;
133 Socket socket;
134 Target target;
135 Device device;
136 Mount mount;
137 Automount automount;
138 Snapshot snapshot;
139 };
140
141 struct NameVTable {
142 const char *suffix;
143
144 int (*init)(Name *n);
145 void (*done)(Name *n);
146
147 void (*dump)(Name *n, FILE *f, const char *prefix);
148
149 int (*start)(Name *n);
150 int (*stop)(Name *n);
151 int (*reload)(Name *n);
152
153 bool (*can_reload)(Name *n);
154
155 /* Boils down the more complex internal state of this name to
156 * a simpler one that the engine can understand */
157 NameActiveState (*active_state)(Name *n);
158
159 void (*fd_event)(Name *n, int fd, uint32_t events);
160 void (*sigchld_event)(Name *n, pid_t pid, int code, int status);
161 void (*timer_event)(Name *n, int id, uint64_t n_elapsed);
162
163 void (*retry)(Name *n);
164 };
165
166 extern const NameVTable * const name_vtable[_NAME_TYPE_MAX];
167
168 #define NAME_VTABLE(n) name_vtable[(n)->meta.type]
169
170 /* For casting a name into the various name types */
171 #define DEFINE_CAST(UPPERCASE, MixedCase) \
172 static inline MixedCase* UPPERCASE(Name *name) { \
173 if (!name || name->meta.type != NAME_##UPPERCASE) \
174 return NULL; \
175 \
176 return (MixedCase*) name; \
177 }
178
179 /* For casting the various name types into a name */
180 #define NAME(o) ((Name*) (o))
181
182 DEFINE_CAST(SOCKET, Socket);
183 DEFINE_CAST(TIMER, Timer);
184 DEFINE_CAST(SERVICE, Service);
185 DEFINE_CAST(TARGET, Target);
186 DEFINE_CAST(DEVICE, Device);
187 DEFINE_CAST(MOUNT, Mount);
188 DEFINE_CAST(AUTOMOUNT, Automount);
189 DEFINE_CAST(SNAPSHOT, Snapshot);
190
191 NameType name_type_from_string(const char *n);
192 bool name_is_valid(const char *n);
193
194 Name *name_new(Manager *m);
195 void name_free(Name *name);
196
197 int name_add_name(Name *n, const char *text);
198 int name_add_dependency(Name *n, NameDependency d, Name *other);
199
200 void name_add_to_load_queue(Name *n);
201
202 int name_merge(Name *name, Name *other);
203
204 int name_load_fragment_and_dropin(Name *n);
205 int name_load(Name *name);
206
207 const char* name_id(Name *n);
208 const char *name_description(Name *n);
209
210 NameActiveState name_active_state(Name *name);
211
212 void name_dump(Name *n, FILE *f, const char *prefix);
213
214 bool name_can_reload(Name *n);
215 bool name_can_start(Name *n);
216
217 int name_start(Name *n);
218 int name_stop(Name *n);
219 int name_reload(Name *n);
220
221 void name_notify(Name *n, NameActiveState os, NameActiveState ns);
222
223 int name_watch_fd(Name *n, int fd, uint32_t events);
224 void name_unwatch_fd(Name *n, int fd);
225
226 int name_watch_pid(Name *n, pid_t pid);
227 void name_unwatch_pid(Name *n, pid_t pid);
228
229 int name_watch_timer(Name *n, usec_t delay, int *id);
230 void name_unwatch_timer(Name *n, int *id);
231
232 char *name_change_suffix(const char *t, const char *suffix);
233
234 bool name_job_is_applicable(Name *n, JobType j);
235
236 #endif