]> git.ipfire.org Git - thirdparty/systemd.git/blob - name.h
first attempt in implementinging execution logic
[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
25 #define NAME_MAX 32
26
27 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 };
39
40 enum NameLoadState {
41 NAME_STUB,
42 NAME_LOADED,
43 NAME_FAILED,
44 _NAME_LOAD_STATE_MAX
45 };
46
47 enum NameActiveState {
48 NAME_ACTIVE,
49 NAME_ACTIVE_RELOADING,
50 NAME_INACTIVE,
51 NAME_ACTIVATING,
52 NAME_DEACTIVATING,
53 _NAME_ACTIVE_STATE_MAX
54 };
55
56 static inline bool NAME_IS_ACTIVE_OR_RELOADING(NameActiveState t) {
57 return t == NAME_ACTIVE || t == NAME_ACTIVE_RELOADING;
58 }
59
60 static inline bool NAME_IS_ACTIVE_OR_ACTIVATING(NameActiveState t) {
61 return t == NAME_ACTIVE || t == NAME_ACTIVATING || t == NAME_ACTIVE_RELOADING;
62 }
63
64 static inline bool NAME_IS_INACTIVE_OR_DEACTIVATING(NameActiveState t) {
65 return t == NAME_INACTIVE || t == NAME_DEACTIVATING;
66 }
67
68 enum NameDependency {
69 /* Positive dependencies */
70 NAME_REQUIRES,
71 NAME_SOFT_REQUIRES,
72 NAME_WANTS,
73 NAME_REQUISITE,
74 NAME_SOFT_REQUISITE,
75 NAME_REQUIRED_BY, /* inverse of 'requires' and 'requisite' is 'required_by' */
76 NAME_SOFT_REQUIRED_BY, /* inverse of 'soft_requires' and 'soft_requisite' is 'soft_required_by' */
77 NAME_WANTED_BY, /* inverse of 'wants' */
78
79 /* Negative dependencies */
80 NAME_CONFLICTS, /* inverse of 'conflicts' is 'conflicts' */
81
82 /* Order */
83 NAME_BEFORE, /* inverse of before is after and vice versa */
84 NAME_AFTER,
85 _NAME_DEPENDENCY_MAX
86 };
87
88 struct Meta {
89 Manager *manager;
90 NameType type;
91 NameLoadState load_state;
92
93 Set *names;
94 Set *dependencies[_NAME_DEPENDENCY_MAX];
95
96 char *description;
97
98 /* If there is something to do with this name, then this is
99 * the job for it */
100 Job *job;
101
102 bool linked:1;
103
104 /* Load queue */
105 LIST_FIELDS(Meta);
106 };
107
108 #include "service.h"
109 #include "timer.h"
110 #include "socket.h"
111 #include "milestone.h"
112 #include "device.h"
113 #include "mount.h"
114 #include "automount.h"
115 #include "snapshot.h"
116
117 union Name {
118 Meta meta;
119 Service service;
120 Timer timer;
121 Socket socket;
122 Milestone milestone;
123 Device device;
124 Mount mount;
125 Automount automount;
126 Snapshot snapshot;
127 };
128
129 struct NameVTable {
130 const char *suffix;
131
132 int (*load)(Name *n);
133 void (*dump)(Name *n, FILE *f, const char *prefix);
134
135 int (*start)(Name *n);
136 int (*stop)(Name *n);
137 int (*reload)(Name *n);
138
139 /* Boils down the more complex internal state of this name to
140 * a simpler one that the engine can understand */
141 NameActiveState (*active_state)(Name *n);
142
143 void (*free_hook)(Name *n);
144 };
145
146 /* For casting a name into the various name types */
147 #define DEFINE_CAST(UPPERCASE, MixedCase) \
148 static inline MixedCase* UPPERCASE(Name *name) { \
149 if (!name || name->meta.type != NAME_##UPPERCASE) \
150 return NULL; \
151 \
152 return (MixedCase*) name; \
153 }
154
155 /* For casting the various name types into a name */
156 #define NAME(o) ((Name*) (o))
157
158 DEFINE_CAST(SOCKET, Socket);
159 DEFINE_CAST(TIMER, Timer);
160 DEFINE_CAST(SERVICE, Service);
161 DEFINE_CAST(MILESTONE, Milestone);
162 DEFINE_CAST(DEVICE, Device);
163 DEFINE_CAST(MOUNT, Mount);
164 DEFINE_CAST(AUTOMOUNT, Automount);
165 DEFINE_CAST(SNAPSHOT, Snapshot);
166
167 NameActiveState name_active_state(Name *name);
168
169 bool name_type_can_start(NameType t);
170 bool name_type_can_reload(NameType t);
171
172 NameType name_type_from_string(const char *n);
173 bool name_is_valid(const char *n);
174
175 Name *name_new(Manager *m);
176 void name_free(Name *name);
177 int name_link(Name *name);
178 int name_link_names(Name *name, bool replace);
179 int name_merge(Name *name, Name *other);
180 int name_sanitize(Name *n);
181 int name_load_fragment_and_dropin(Name *n);
182 int name_load(Name *name);
183 const char* name_id(Name *n);
184 const char *name_description(Name *n);
185
186 void name_dump(Name *n, FILE *f, const char *prefix);
187
188 int name_start(Name *n);
189 int name_stop(Name *n);
190 int name_reload(Name *n);
191
192 int name_notify(Name *n, NameActiveState old, NameActiveState new);
193
194 #endif