chiark / gitweb /
793a55fb454190d1cb2879a35b9bb60eaa0481bb
[elogind.git] / manager.h
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 #ifndef foomanagerhfoo
4 #define foomanagerhfoo
5
6 #include <stdbool.h>
7 #include <inttypes.h>
8 #include <stdio.h>
9
10 typedef struct Manager Manager;
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 };
26
27 #include "unit.h"
28 #include "job.h"
29 #include "hashmap.h"
30 #include "list.h"
31 #include "set.h"
32
33 #define SPECIAL_DEFAULT_TARGET "default.target"
34 #define SPECIAL_SYSLOG_SERVICE "syslog.service"
35 #define SPECIAL_DBUS_SERVICE "messagebus.service"
36 #define SPECIAL_LOGGER_SOCKET "systemd-logger.socket"
37 #define SPECIAL_KBREQUEST_TARGET "kbrequest.target"
38 #define SPECIAL_CTRL_ALT_DEL_TARGET "ctrl-alt-del.target"
39
40 struct Manager {
41         uint32_t current_job_id;
42
43         /* Note that the set of units we know of is allowed to be
44          * incosistent. However the subset of it that is loaded may
45          * not, and the list of jobs may neither. */
46
47         /* Active jobs and units */
48         Hashmap *units;  /* name string => Unit object n:1 */
49         Hashmap *jobs;   /* job id => Job object 1:1 */
50
51         /* Units that need to be loaded */
52         LIST_HEAD(Meta, load_queue); /* this is actually more a stack than a queue, but uh. */
53
54         /* Jobs that need to be run */
55         LIST_HEAD(Job, run_queue);   /* more a stack than a queue, too */
56
57         /* Jobs to be added */
58         Hashmap *transaction_jobs;      /* Unit object => Job object list 1:1 */
59         JobDependency *transaction_anchor;
60
61         bool dispatching_load_queue:1;
62         bool dispatching_run_queue:1;
63
64         Hashmap *watch_pids;  /* pid => Unit object n:1 */
65
66         int epoll_fd;
67
68         Watch signal_watch;
69
70         struct udev* udev;
71 };
72
73 Manager* manager_new(void);
74 void manager_free(Manager *m);
75
76 int manager_coldplug(Manager *m);
77
78 Job *manager_get_job(Manager *m, uint32_t id);
79 Unit *manager_get_unit(Manager *m, const char *name);
80
81 int manager_load_unit(Manager *m, const char *path_or_name, Unit **_ret);
82 int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool force, Job **_ret);
83
84 void manager_dump_units(Manager *s, FILE *f, const char *prefix);
85 void manager_dump_jobs(Manager *s, FILE *f, const char *prefix);
86
87 void manager_transaction_unlink_job(Manager *m, Job *j);
88
89 void manager_clear_jobs(Manager *m);
90
91 void manager_dispatch_load_queue(Manager *m);
92 void manager_dispatch_run_queue(Manager *m);
93
94 int manager_loop(Manager *m);
95
96 #endif