1 /*-*- Mode: C; c-basic-offset: 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;
22 #include "socket-util.h"
37 _NAME_TYPE_INVALID = -1,
47 enum NameActiveState {
49 NAME_ACTIVE_RELOADING,
53 _NAME_ACTIVE_STATE_MAX
56 static inline bool NAME_IS_ACTIVE_OR_RELOADING(NameActiveState t) {
57 return t == NAME_ACTIVE || t == NAME_ACTIVE_RELOADING;
60 static inline bool NAME_IS_ACTIVE_OR_ACTIVATING(NameActiveState t) {
61 return t == NAME_ACTIVE || t == NAME_ACTIVATING || t == NAME_ACTIVE_RELOADING;
64 static inline bool NAME_IS_INACTIVE_OR_DEACTIVATING(NameActiveState t) {
65 return t == NAME_INACTIVE || t == NAME_DEACTIVATING;
69 /* Positive dependencies */
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' */
79 /* Negative dependencies */
80 NAME_CONFLICTS, /* inverse of 'conflicts' is 'conflicts' */
83 NAME_BEFORE, /* inverse of before is after and vice versa */
91 NameLoadState load_state;
94 Set *dependencies[_NAME_DEPENDENCY_MAX];
98 /* If there is something to do with this name, then this is
111 #include "milestone.h"
114 #include "automount.h"
115 #include "snapshot.h"
132 int (*load)(Name *n);
133 void (*dump)(Name *n, FILE *f, const char *prefix);
135 int (*start)(Name *n);
136 int (*stop)(Name *n);
137 int (*reload)(Name *n);
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);
143 void (*fd_event)(Name *n, int fd, uint32_t events);
144 void (*sigchld_event)(Name *n, pid_t pid, int code, int status);
146 void (*free_hook)(Name *n);
149 extern const NameVTable * const name_vtable[_NAME_TYPE_MAX];
151 #define NAME_VTABLE(n) name_vtable[(n)->meta.type]
153 /* For casting a name into the various name types */
154 #define DEFINE_CAST(UPPERCASE, MixedCase) \
155 static inline MixedCase* UPPERCASE(Name *name) { \
156 if (!name || name->meta.type != NAME_##UPPERCASE) \
159 return (MixedCase*) name; \
162 /* For casting the various name types into a name */
163 #define NAME(o) ((Name*) (o))
165 DEFINE_CAST(SOCKET, Socket);
166 DEFINE_CAST(TIMER, Timer);
167 DEFINE_CAST(SERVICE, Service);
168 DEFINE_CAST(MILESTONE, Milestone);
169 DEFINE_CAST(DEVICE, Device);
170 DEFINE_CAST(MOUNT, Mount);
171 DEFINE_CAST(AUTOMOUNT, Automount);
172 DEFINE_CAST(SNAPSHOT, Snapshot);
174 NameActiveState name_active_state(Name *name);
176 bool name_type_can_start(NameType t);
177 bool name_type_can_reload(NameType t);
179 NameType name_type_from_string(const char *n);
180 bool name_is_valid(const char *n);
182 Name *name_new(Manager *m);
183 void name_free(Name *name);
184 int name_link(Name *name);
185 int name_link_names(Name *name, bool replace);
186 int name_merge(Name *name, Name *other);
187 int name_sanitize(Name *n);
188 int name_load_fragment_and_dropin(Name *n);
189 int name_load(Name *name);
190 const char* name_id(Name *n);
191 const char *name_description(Name *n);
193 void name_dump(Name *n, FILE *f, const char *prefix);
195 int name_start(Name *n);
196 int name_stop(Name *n);
197 int name_reload(Name *n);
199 void name_notify(Name *n, NameActiveState os, NameActiveState ns);
201 int name_watch_fd(Name *n, int fd, uint32_t events);
202 void name_unwatch_fd(Name *n, int fd);
204 int name_watch_pid(Name *n, pid_t pid);
205 void name_unwatch_pid(Name *n, pid_t pid);