]>
Commit | Line | Data |
---|---|---|
60918275 LP |
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; | |
e5b5ae50 | 10 | typedef struct JobDependency JobDependency; |
60918275 | 11 | typedef enum JobType JobType; |
e5b5ae50 | 12 | typedef enum JobState JobState; |
5cb5a6ff | 13 | typedef enum JobMode JobMode; |
60918275 LP |
14 | |
15 | #include "manager.h" | |
87f0e418 | 16 | #include "unit.h" |
60918275 LP |
17 | #include "hashmap.h" |
18 | #include "list.h" | |
19 | ||
20 | enum JobType { | |
87f0e418 | 21 | JOB_START, /* if a unit does not support being started, we'll just wait until it becomes active */ |
5cb5a6ff LP |
22 | JOB_VERIFY_ACTIVE, |
23 | ||
60918275 | 24 | JOB_STOP, |
5cb5a6ff LP |
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 | ||
e5b5ae50 LP |
35 | _JOB_TYPE_MAX, |
36 | _JOB_TYPE_INVALID = -1 | |
60918275 LP |
37 | }; |
38 | ||
e5b5ae50 | 39 | enum JobState { |
60918275 LP |
40 | JOB_WAITING, |
41 | JOB_RUNNING, | |
94f04347 LP |
42 | _JOB_STATE_MAX, |
43 | _JOB_STATE_INVALID = -1 | |
e5b5ae50 | 44 | }; |
60918275 LP |
45 | |
46 | enum JobMode { | |
47 | JOB_FAIL, | |
48 | JOB_REPLACE, | |
b548631a LP |
49 | _JOB_MODE_MAX, |
50 | _JOB_MODE_INVALID = -1 | |
60918275 LP |
51 | }; |
52 | ||
e5b5ae50 LP |
53 | struct JobDependency { |
54 | /* Encodes that the 'subject' job needs the 'object' job in | |
55 | * some way. This structure is used only while building a transaction. */ | |
56 | Job *subject; | |
57 | Job *object; | |
58 | ||
59 | bool matters; | |
60 | ||
034c6ed7 LP |
61 | LIST_FIELDS(JobDependency, subject); |
62 | LIST_FIELDS(JobDependency, object); | |
e5b5ae50 LP |
63 | }; |
64 | ||
60918275 LP |
65 | struct Job { |
66 | Manager *manager; | |
67 | uint32_t id; | |
68 | ||
87f0e418 | 69 | Unit *unit; |
e5b5ae50 | 70 | |
60918275 LP |
71 | JobType type; |
72 | JobState state; | |
60918275 | 73 | |
ac1135be | 74 | bool installed:1; |
034c6ed7 | 75 | bool in_run_queue:1; |
e5b5ae50 | 76 | bool matters_to_anchor:1; |
5cb5a6ff | 77 | bool forced:1; |
e5b5ae50 | 78 | |
034c6ed7 LP |
79 | LIST_FIELDS(Job, transaction); |
80 | LIST_FIELDS(Job, run_queue); | |
e5b5ae50 | 81 | |
44d8db9e LP |
82 | LIST_HEAD(JobDependency, subject_list); |
83 | LIST_HEAD(JobDependency, object_list); | |
e5b5ae50 | 84 | |
5cb5a6ff | 85 | /* Used for graph algs as a "I have been here" marker */ |
e5b5ae50 LP |
86 | Job* marker; |
87 | unsigned generation; | |
034c6ed7 | 88 | |
60918275 LP |
89 | }; |
90 | ||
87f0e418 | 91 | Job* job_new(Manager *m, JobType type, Unit *unit); |
60918275 | 92 | void job_free(Job *job); |
ceed3570 | 93 | void job_dump(Job *j, FILE*f, const char *prefix); |
60918275 | 94 | |
e5b5ae50 LP |
95 | JobDependency* job_dependency_new(Job *subject, Job *object, bool matters); |
96 | void job_dependency_free(JobDependency *l); | |
97 | void job_dependency_delete(Job *subject, Job *object, bool *matters); | |
98 | ||
99 | bool job_is_anchor(Job *j); | |
100 | ||
101 | int job_merge(Job *j, Job *other); | |
102 | ||
1ffba6fe | 103 | int job_type_merge(JobType *a, JobType b); |
5cb5a6ff | 104 | bool job_type_is_mergeable(JobType a, JobType b); |
1ffba6fe | 105 | bool job_type_is_superset(JobType a, JobType b); |
e094e853 | 106 | bool job_type_is_conflicting(JobType a, JobType b); |
5cb5a6ff | 107 | |
034c6ed7 | 108 | void job_schedule_run(Job *j); |
5cb5a6ff LP |
109 | int job_run_and_invalidate(Job *j); |
110 | int job_finish_and_invalidate(Job *j, bool success); | |
1ffba6fe | 111 | |
94f04347 LP |
112 | const char* job_type_to_string(JobType t); |
113 | JobType job_type_from_string(const char *s); | |
114 | ||
115 | const char* job_state_to_string(JobState t); | |
116 | JobState job_state_from_string(const char *s); | |
117 | ||
b548631a LP |
118 | const char* job_mode_to_string(JobMode t); |
119 | JobMode job_mode_from_string(const char *s); | |
120 | ||
ea430986 LP |
121 | char *job_dbus_path(Job *j); |
122 | ||
60918275 | 123 | #endif |