summaryrefslogtreecommitdiff
path: root/job.h
blob: d839db5a40c98a951526b9bef693177f16c7f10d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*-*- Mode: C; c-basic-offset: 8 -*-*/

#ifndef foojobhfoo
#define foojobhfoo

#include <stdbool.h>
#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"
#include "hashmap.h"
#include "list.h"

enum JobType {
        JOB_START,
        JOB_STOP,
        JOB_VERIFY_STARTED,
        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
};

enum JobState {
        JOB_WAITING,
        JOB_RUNNING,
        JOB_DONE,
        _JOB_STATE_MAX
};

enum JobMode {
        JOB_FAIL,
        JOB_REPLACE,
        _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;

        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);
void job_free(Job *job);
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