chiark / gitweb /
make sure impact of transactions is minimized
[elogind.git] / job.h
diff --git a/job.h b/job.h
index 0fc6fec4625316865faf1d43fd71359563b8a9e7..d839db5a40c98a951526b9bef693177f16c7f10d 100644 (file)
--- a/job.h
+++ b/job.h
@@ -7,8 +7,10 @@
 #include <inttypes.h>
 
 typedef struct Job Job;
+typedef struct JobDependency JobDependency;
 typedef enum JobType JobType;
 typedef enum JobMode JobMode;
+typedef enum JobState JobState;
 
 #include "manager.h"
 #include "name.h"
@@ -19,19 +21,20 @@ enum JobType {
         JOB_START,
         JOB_STOP,
         JOB_VERIFY_STARTED,
-        JOB_RELOAD,
-        JOB_RESTART,
-        JOB_TRY_RESTART, /* restart if running */
-        JOB_RESTART_FINISH, /* 2nd part of a restart, i.e. the actual starting */
-        _JOB_TYPE_MAX
+        JOB_RELOAD,          /* reload if running */
+        JOB_RELOAD_OR_START, /* reload if running, start if not running */
+        JOB_RESTART,         /* stop if running, then start unconditionally */
+        JOB_TRY_RESTART,     /* stop and start if running */
+        _JOB_TYPE_MAX,
+        _JOB_TYPE_INVALID = -1
 };
 
-typedef enum JobState {
+enum JobState {
         JOB_WAITING,
         JOB_RUNNING,
         JOB_DONE,
         _JOB_STATE_MAX
-} JobState;
+};
 
 enum JobMode {
         JOB_FAIL,
@@ -39,20 +42,58 @@ enum JobMode {
         _JOB_MODE_MAX
 };
 
+struct JobDependency {
+        /* Encodes that the 'subject' job needs the 'object' job in
+         * some way. This structure is used only while building a transaction. */
+        Job *subject;
+        Job *object;
+
+        bool matters;
+
+        /* Linked list for the subjects, resp objects */
+        JobDependency *subject_prev, *subject_next;
+        JobDependency *object_prev, *object_next;
+};
+
 struct Job {
         Manager *manager;
         uint32_t id;
 
+        Name *name;
+
         JobType type;
         JobState state;
-        Name *name;
 
         bool linked:1;
+        bool matters_to_anchor:1;
+
+        /* These fields are used only while building a transaction */
+        Job *transaction_next, *transaction_prev;
+
+        JobDependency *subject_list;
+        JobDependency *object_list;
+
+        /* used for graph algs as a "I have been here" marker */
+        Job* marker;
+        unsigned generation;
 };
 
 Job* job_new(Manager *m, JobType type, Name *name);
-int job_link(Job *job);
 void job_free(Job *job);
-void job_dump(Job *j, FILE*f);
+void job_dump(Job *j, FILE*f, const char *prefix);
+
+JobDependency* job_dependency_new(Job *subject, Job *object, bool matters);
+void job_dependency_free(JobDependency *l);
+void job_dependency_delete(Job *subject, Job *object, bool *matters);
+
+bool job_is_anchor(Job *j);
+
+int job_merge(Job *j, Job *other);
+
+const char* job_type_to_string(JobType t);
+int job_type_merge(JobType *a, JobType b);
+bool job_type_mergeable(JobType a, JobType b);
+bool job_type_is_superset(JobType a, JobType b);
+bool job_type_is_conflicting(JobType a, JobType b);
 
 #endif