chiark / gitweb /
fixes to the dbus code to make GetAll() in the properties iface work
[elogind.git] / job.h
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 #ifndef foojobhfoo
4 #define foojobhfoo
5
6 #include <stdbool.h>
7 #include <inttypes.h>
8
9 typedef struct Job Job;
10 typedef struct JobDependency JobDependency;
11 typedef enum JobType JobType;
12 typedef enum JobState JobState;
13 typedef enum JobMode JobMode;
14
15 #include "manager.h"
16 #include "unit.h"
17 #include "hashmap.h"
18 #include "list.h"
19
20 enum JobType {
21         JOB_START,                  /* if a unit does not support being started, we'll just wait until it becomes active */
22         JOB_VERIFY_ACTIVE,
23
24         JOB_STOP,
25
26         JOB_RELOAD,                 /* if running reload */
27         JOB_RELOAD_OR_START,        /* if running reload, if not running start */
28
29         /* Note that restarts are first treated like JOB_STOP, but
30          * then instead of finishing are patched to become
31          * JOB_START. */
32         JOB_RESTART,                /* if running stop, then start unconditionally */
33         JOB_TRY_RESTART,            /* if running stop and then start */
34
35         _JOB_TYPE_MAX,
36         _JOB_TYPE_INVALID = -1
37 };
38
39 enum JobState {
40         JOB_WAITING,
41         JOB_RUNNING,
42         _JOB_STATE_MAX,
43         _JOB_STATE_INVALID = -1
44 };
45
46 enum JobMode {
47         JOB_FAIL,
48         JOB_REPLACE,
49         _JOB_MODE_MAX
50 };
51
52 struct JobDependency {
53         /* Encodes that the 'subject' job needs the 'object' job in
54          * some way. This structure is used only while building a transaction. */
55         Job *subject;
56         Job *object;
57
58         bool matters;
59
60         LIST_FIELDS(JobDependency, subject);
61         LIST_FIELDS(JobDependency, object);
62 };
63
64 struct Job {
65         Manager *manager;
66         uint32_t id;
67
68         Unit *unit;
69
70         JobType type;
71         JobState state;
72
73         bool installed:1;
74         bool in_run_queue:1;
75         bool matters_to_anchor:1;
76         bool forced:1;
77
78         LIST_FIELDS(Job, transaction);
79         LIST_FIELDS(Job, run_queue);
80
81         LIST_HEAD(JobDependency, subject_list);
82         LIST_HEAD(JobDependency, object_list);
83
84         /* Used for graph algs as a "I have been here" marker */
85         Job* marker;
86         unsigned generation;
87
88 };
89
90 Job* job_new(Manager *m, JobType type, Unit *unit);
91 void job_free(Job *job);
92 void job_dump(Job *j, FILE*f, const char *prefix);
93
94 JobDependency* job_dependency_new(Job *subject, Job *object, bool matters);
95 void job_dependency_free(JobDependency *l);
96 void job_dependency_delete(Job *subject, Job *object, bool *matters);
97
98 bool job_is_anchor(Job *j);
99
100 int job_merge(Job *j, Job *other);
101
102 int job_type_merge(JobType *a, JobType b);
103 bool job_type_is_mergeable(JobType a, JobType b);
104 bool job_type_is_superset(JobType a, JobType b);
105 bool job_type_is_conflicting(JobType a, JobType b);
106
107 void job_schedule_run(Job *j);
108 int job_run_and_invalidate(Job *j);
109 int job_finish_and_invalidate(Job *j, bool success);
110
111 const char* job_type_to_string(JobType t);
112 JobType job_type_from_string(const char *s);
113
114 const char* job_state_to_string(JobState t);
115 JobState job_state_from_string(const char *s);
116
117 char *job_dbus_path(Job *j);
118
119 #endif