chiark / gitweb /
refuse to add jobs for names that are not loaded
[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 JobMode JobMode;
13 typedef enum JobState JobState;
14
15 #include "manager.h"
16 #include "name.h"
17 #include "hashmap.h"
18 #include "list.h"
19
20 enum JobType {
21         JOB_START,
22         JOB_STOP,
23         JOB_VERIFY_STARTED,
24         JOB_RELOAD,          /* reload if running */
25         JOB_RELOAD_OR_START, /* reload if running, start if not running */
26         JOB_RESTART,         /* stop if running, then start unconditionally */
27         JOB_TRY_RESTART,     /* stop and start if running */
28         _JOB_TYPE_MAX,
29         _JOB_TYPE_INVALID = -1
30 };
31
32 enum JobState {
33         JOB_WAITING,
34         JOB_RUNNING,
35         JOB_DONE,
36         _JOB_STATE_MAX
37 };
38
39 enum JobMode {
40         JOB_FAIL,
41         JOB_REPLACE,
42         _JOB_MODE_MAX
43 };
44
45 struct JobDependency {
46         /* Encodes that the 'subject' job needs the 'object' job in
47          * some way. This structure is used only while building a transaction. */
48         Job *subject;
49         Job *object;
50
51         bool matters;
52
53         /* Linked list for the subjects, resp objects */
54         JobDependency *subject_prev, *subject_next;
55         JobDependency *object_prev, *object_next;
56 };
57
58 struct Job {
59         Manager *manager;
60         uint32_t id;
61
62         Name *name;
63
64         JobType type;
65         JobState state;
66
67         bool linked:1;
68         bool matters_to_anchor:1;
69
70         /* These fields are used only while building a transaction */
71         Job *transaction_next, *transaction_prev;
72
73         JobDependency *subject_list;
74         JobDependency *object_list;
75
76         /* used for graph algs as a "I have been here" marker */
77         Job* marker;
78         unsigned generation;
79 };
80
81 Job* job_new(Manager *m, JobType type, Name *name);
82 void job_free(Job *job);
83 void job_dump(Job *j, FILE*f, const char *prefix);
84
85 JobDependency* job_dependency_new(Job *subject, Job *object, bool matters);
86 void job_dependency_free(JobDependency *l);
87 void job_dependency_delete(Job *subject, Job *object, bool *matters);
88
89 bool job_is_anchor(Job *j);
90
91 int job_merge(Job *j, Job *other);
92
93 #endif