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"
27 #define DEFAULT_TIMEOUT_USEC (20*USEC_PER_SEC)
28 #define DEFAULT_RESTART_USEC (100*USEC_PER_MSEC)
40 _NAME_TYPE_INVALID
= -1,
50 enum NameActiveState
{
52 NAME_ACTIVE_RELOADING
,
56 _NAME_ACTIVE_STATE_MAX
59 static inline bool NAME_IS_ACTIVE_OR_RELOADING(NameActiveState t
) {
60 return t
== NAME_ACTIVE
|| t
== NAME_ACTIVE_RELOADING
;
63 static inline bool NAME_IS_ACTIVE_OR_ACTIVATING(NameActiveState t
) {
64 return t
== NAME_ACTIVE
|| t
== NAME_ACTIVATING
|| t
== NAME_ACTIVE_RELOADING
;
67 static inline bool NAME_IS_INACTIVE_OR_DEACTIVATING(NameActiveState t
) {
68 return t
== NAME_INACTIVE
|| t
== NAME_DEACTIVATING
;
72 /* Positive dependencies */
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' */
84 /* Negative dependencies */
85 NAME_CONFLICTS
, /* inverse of 'conflicts' is 'conflicts' */
88 NAME_BEFORE
, /* inverse of before is after and vice versa */
92 _NAME_DEPENDENCY_INVALID
= -1
98 NameLoadState load_state
;
100 char *id
; /* One name is special because we use it for identification. Points to an entry in the names set */
103 Set
*dependencies
[_NAME_DEPENDENCY_MAX
];
107 /* If there is something to do with this name, then this is
111 bool in_load_queue
:1;
113 usec_t active_enter_timestamp
;
114 usec_t active_exit_timestamp
;
117 LIST_FIELDS(Meta
, load_queue
);
126 #include "automount.h"
127 #include "snapshot.h"
144 int (*init
)(Name
*n
);
145 void (*done
)(Name
*n
);
147 void (*dump
)(Name
*n
, FILE *f
, const char *prefix
);
149 int (*start
)(Name
*n
);
150 int (*stop
)(Name
*n
);
151 int (*reload
)(Name
*n
);
154 bool (*can_reload
)(Name
*n
);
156 /* Boils down the more complex internal state of this name to
157 * a simpler one that the engine can understand */
158 NameActiveState (*active_state
)(Name
*n
);
160 void (*fd_event
)(Name
*n
, int fd
, uint32_t events
);
161 void (*sigchld_event
)(Name
*n
, pid_t pid
, int code
, int status
);
162 void (*timer_event
)(Name
*n
, int id
, uint64_t n_elapsed
);
164 void (*retry
)(Name
*n
);
167 extern const NameVTable
* const name_vtable
[_NAME_TYPE_MAX
];
169 #define NAME_VTABLE(n) name_vtable[(n)->meta.type]
171 /* For casting a name into the various name types */
172 #define DEFINE_CAST(UPPERCASE, MixedCase) \
173 static inline MixedCase* UPPERCASE(Name *name) { \
174 if (!name || name->meta.type != NAME_##UPPERCASE) \
177 return (MixedCase*) name; \
180 /* For casting the various name types into a name */
181 #define NAME(o) ((Name*) (o))
183 DEFINE_CAST(SOCKET
, Socket
);
184 DEFINE_CAST(TIMER
, Timer
);
185 DEFINE_CAST(SERVICE
, Service
);
186 DEFINE_CAST(TARGET
, Target
);
187 DEFINE_CAST(DEVICE
, Device
);
188 DEFINE_CAST(MOUNT
, Mount
);
189 DEFINE_CAST(AUTOMOUNT
, Automount
);
190 DEFINE_CAST(SNAPSHOT
, Snapshot
);
192 NameType
name_type_from_string(const char *n
);
193 bool name_is_valid(const char *n
);
195 Name
*name_new(Manager
*m
);
196 void name_free(Name
*name
);
198 int name_add_name(Name
*n
, const char *text
);
199 int name_add_dependency(Name
*n
, NameDependency d
, Name
*other
);
201 void name_add_to_load_queue(Name
*n
);
203 int name_merge(Name
*name
, Name
*other
);
205 int name_load_fragment_and_dropin(Name
*n
);
206 int name_load(Name
*name
);
208 const char* name_id(Name
*n
);
209 const char *name_description(Name
*n
);
211 NameActiveState
name_active_state(Name
*name
);
213 void name_dump(Name
*n
, FILE *f
, const char *prefix
);
215 bool name_can_reload(Name
*n
);
216 bool name_can_start(Name
*n
);
218 int name_start(Name
*n
);
219 int name_stop(Name
*n
);
220 int name_reload(Name
*n
);
222 void name_notify(Name
*n
, NameActiveState os
, NameActiveState ns
);
224 int name_watch_fd(Name
*n
, int fd
, uint32_t events
);
225 void name_unwatch_fd(Name
*n
, int fd
);
227 int name_watch_pid(Name
*n
, pid_t pid
);
228 void name_unwatch_pid(Name
*n
, pid_t pid
);
230 int name_watch_timer(Name
*n
, usec_t delay
, int *id
);
231 void name_unwatch_timer(Name
*n
, int *id
);
233 char *name_change_suffix(const char *t
, const char *suffix
);
235 bool name_job_is_applicable(Name
*n
, JobType j
);