chiark / gitweb /
implement drop-in directories
[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 ManagerEventType ManagerEventType;
12
13 #include "unit.h"
14 #include "job.h"
15 #include "hashmap.h"
16 #include "list.h"
17 #include "set.h"
18
19 enum ManagerEventType {
20         MANAGER_SIGNAL,
21         MANAGER_FD,
22         MANAGER_TIMER
23 };
24
25 struct Manager {
26         uint32_t current_job_id;
27
28         /* Note that the set of units we know of is allowed to be
29          * incosistent. However the subset of it that is loaded may
30          * not, and the list of jobs may neither. */
31
32         /* Active jobs and units */
33         Hashmap *units;  /* name string => Unit object n:1 */
34         Hashmap *jobs;   /* job id => Job object 1:1 */
35
36         /* Units that need to be loaded */
37         LIST_HEAD(Meta, load_queue); /* this is actually more a stack than a queue, but uh. */
38
39         /* Jobs that need to be run */
40         LIST_HEAD(Job, run_queue);   /* more a stack than a queue, too */
41
42         /* Jobs to be added */
43         Hashmap *transaction_jobs;      /* Unit object => Job object list 1:1 */
44         JobDependency *transaction_anchor;
45
46         bool dispatching_load_queue:1;
47         bool dispatching_run_queue:1;
48
49         Hashmap *watch_pids;  /* pid => Unit object n:1 */
50
51         int epoll_fd;
52         int signal_fd;
53 };
54
55 Manager* manager_new(void);
56 void manager_free(Manager *m);
57
58 Job *manager_get_job(Manager *m, uint32_t id);
59 Unit *manager_get_unit(Manager *m, const char *name);
60
61 int manager_load_unit(Manager *m, const char *path_or_name, Unit **_ret);
62 int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool force, Job **_ret);
63
64 void manager_dump_units(Manager *s, FILE *f, const char *prefix);
65 void manager_dump_jobs(Manager *s, FILE *f, const char *prefix);
66
67 void manager_transaction_unlink_job(Manager *m, Job *j);
68
69 void manager_clear_jobs(Manager *m);
70
71 void manager_dispatch_run_queue(Manager *m);
72 int manager_loop(Manager *m);
73
74 #endif