]> git.ipfire.org Git - thirdparty/systemd.git/blame - job.h
add simple event loop
[thirdparty/systemd.git] / job.h
CommitLineData
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
9typedef struct Job Job;
e5b5ae50 10typedef struct JobDependency JobDependency;
60918275 11typedef enum JobType JobType;
e5b5ae50 12typedef enum JobState JobState;
5cb5a6ff 13typedef enum JobMode JobMode;
60918275
LP
14
15#include "manager.h"
16#include "name.h"
17#include "hashmap.h"
18#include "list.h"
19
20enum JobType {
5cb5a6ff
LP
21 JOB_START, /* if a name does not support being started, we'll just wait until it becomes active */
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 39enum JobState {
60918275
LP
40 JOB_WAITING,
41 JOB_RUNNING,
60918275 42 _JOB_STATE_MAX
e5b5ae50 43};
60918275
LP
44
45enum JobMode {
46 JOB_FAIL,
47 JOB_REPLACE,
48 _JOB_MODE_MAX
49};
50
e5b5ae50
LP
51struct JobDependency {
52 /* Encodes that the 'subject' job needs the 'object' job in
53 * some way. This structure is used only while building a transaction. */
54 Job *subject;
55 Job *object;
56
57 bool matters;
58
59 /* Linked list for the subjects, resp objects */
60 JobDependency *subject_prev, *subject_next;
61 JobDependency *object_prev, *object_next;
62};
63
60918275
LP
64struct Job {
65 Manager *manager;
66 uint32_t id;
67
e5b5ae50
LP
68 Name *name;
69
60918275
LP
70 JobType type;
71 JobState state;
60918275
LP
72
73 bool linked:1;
e5b5ae50 74 bool matters_to_anchor:1;
5cb5a6ff 75 bool forced:1;
e5b5ae50
LP
76
77 /* These fields are used only while building a transaction */
78 Job *transaction_next, *transaction_prev;
79
80 JobDependency *subject_list;
81 JobDependency *object_list;
82
5cb5a6ff 83 /* Used for graph algs as a "I have been here" marker */
e5b5ae50
LP
84 Job* marker;
85 unsigned generation;
60918275
LP
86};
87
88Job* job_new(Manager *m, JobType type, Name *name);
60918275 89void job_free(Job *job);
ceed3570 90void job_dump(Job *j, FILE*f, const char *prefix);
60918275 91
e5b5ae50
LP
92JobDependency* job_dependency_new(Job *subject, Job *object, bool matters);
93void job_dependency_free(JobDependency *l);
94void job_dependency_delete(Job *subject, Job *object, bool *matters);
95
96bool job_is_anchor(Job *j);
97
98int job_merge(Job *j, Job *other);
99
1ffba6fe
LP
100const char* job_type_to_string(JobType t);
101int job_type_merge(JobType *a, JobType b);
5cb5a6ff 102bool job_type_is_mergeable(JobType a, JobType b);
1ffba6fe 103bool job_type_is_superset(JobType a, JobType b);
e094e853 104bool job_type_is_conflicting(JobType a, JobType b);
5cb5a6ff
LP
105bool job_type_is_applicable(JobType j, NameType n);
106
107int job_run_and_invalidate(Job *j);
108int job_finish_and_invalidate(Job *j, bool success);
1ffba6fe 109
60918275 110#endif