]>
Commit | Line | Data |
---|---|---|
60918275 LP |
1 | /*-*- Mode: C; c-basic-offset: 8 -*-*/ |
2 | ||
3 | #ifndef foomanagerhfoo | |
4 | #define foomanagerhfoo | |
5 | ||
6 | #include <stdbool.h> | |
7 | #include <inttypes.h> | |
a66d02c3 | 8 | #include <stdio.h> |
60918275 LP |
9 | |
10 | typedef struct Manager Manager; | |
acbb0225 LP |
11 | typedef enum WatchType WatchType; |
12 | typedef struct Watch Watch; | |
13 | ||
14 | enum WatchType { | |
15 | WATCH_INVALID, | |
16 | WATCH_SIGNAL_FD, | |
17 | WATCH_FD, | |
18 | WATCH_TIMER | |
19 | }; | |
20 | ||
21 | struct Watch { | |
22 | int fd; | |
23 | WatchType type; | |
24 | union Unit *unit; | |
25 | }; | |
60918275 | 26 | |
87f0e418 | 27 | #include "unit.h" |
60918275 LP |
28 | #include "job.h" |
29 | #include "hashmap.h" | |
30 | #include "list.h" | |
31 | #include "set.h" | |
32 | ||
ce578209 LP |
33 | typedef enum SpecialUnit { |
34 | SPECIAL_SYSLOG_SERVICE, | |
35 | SPECIAL_DBUS_SERVICE, | |
36 | SPECIAL_LOGGER_SOCKET, | |
98b5b298 LP |
37 | SPECIAL_CTRL_ALT_DEL_TARGET, |
38 | SPECIAL_KBREQUEST_TARGET, | |
ce578209 LP |
39 | _SPECIAL_UNIT_MAX |
40 | } SpecialUnit; | |
41 | ||
60918275 LP |
42 | struct Manager { |
43 | uint32_t current_job_id; | |
44 | ||
87f0e418 | 45 | /* Note that the set of units we know of is allowed to be |
87d1515d LP |
46 | * incosistent. However the subset of it that is loaded may |
47 | * not, and the list of jobs may neither. */ | |
48 | ||
87f0e418 LP |
49 | /* Active jobs and units */ |
50 | Hashmap *units; /* name string => Unit object n:1 */ | |
60918275 LP |
51 | Hashmap *jobs; /* job id => Job object 1:1 */ |
52 | ||
87f0e418 | 53 | /* Units that need to be loaded */ |
60918275 LP |
54 | LIST_HEAD(Meta, load_queue); /* this is actually more a stack than a queue, but uh. */ |
55 | ||
034c6ed7 LP |
56 | /* Jobs that need to be run */ |
57 | LIST_HEAD(Job, run_queue); /* more a stack than a queue, too */ | |
58 | ||
e5b5ae50 | 59 | /* Jobs to be added */ |
87f0e418 | 60 | Hashmap *transaction_jobs; /* Unit object => Job object list 1:1 */ |
e5b5ae50 | 61 | JobDependency *transaction_anchor; |
223dabab LP |
62 | |
63 | bool dispatching_load_queue:1; | |
034c6ed7 | 64 | bool dispatching_run_queue:1; |
5cb5a6ff | 65 | |
87f0e418 | 66 | Hashmap *watch_pids; /* pid => Unit object n:1 */ |
9152c765 LP |
67 | |
68 | int epoll_fd; | |
acbb0225 LP |
69 | |
70 | Watch signal_watch; | |
ce578209 LP |
71 | |
72 | Unit *special_units[_SPECIAL_UNIT_MAX]; /* some special units */ | |
60918275 LP |
73 | }; |
74 | ||
75 | Manager* manager_new(void); | |
76 | void manager_free(Manager *m); | |
77 | ||
78 | Job *manager_get_job(Manager *m, uint32_t id); | |
87f0e418 | 79 | Unit *manager_get_unit(Manager *m, const char *name); |
60918275 | 80 | |
0301abf4 | 81 | int manager_load_unit(Manager *m, const char *path_or_name, Unit **_ret); |
87f0e418 | 82 | int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool force, Job **_ret); |
60918275 | 83 | |
87f0e418 | 84 | void manager_dump_units(Manager *s, FILE *f, const char *prefix); |
cea8e32e | 85 | void manager_dump_jobs(Manager *s, FILE *f, const char *prefix); |
a66d02c3 | 86 | |
302d0040 | 87 | void manager_transaction_unlink_job(Manager *m, Job *j); |
e5b5ae50 | 88 | |
7fad411c LP |
89 | void manager_clear_jobs(Manager *m); |
90 | ||
034c6ed7 | 91 | void manager_dispatch_run_queue(Manager *m); |
9152c765 | 92 | int manager_loop(Manager *m); |
83c60c9f | 93 | |
60918275 | 94 | #endif |