forked from haiku/haiku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJob.h
157 lines (113 loc) · 3.48 KB
/
Job.h
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* Copyright 2015-2018, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef JOB_H
#define JOB_H
#include "BaseJob.h"
#include <map>
#include <set>
#include <vector>
#include <OS.h>
#include <StringList.h>
#include <locks.h>
using namespace BSupportKit;
class BMessage;
class BMessenger;
class Finder;
class Job;
class Target;
struct entry_ref;
typedef std::map<BString, BMessage> PortMap;
class TeamListener {
public:
virtual void TeamLaunched(Job* job, status_t status) = 0;
};
class Job : public BaseJob {
public:
Job(const char* name);
Job(const Job& other);
virtual ~Job();
::TeamListener* TeamListener() const;
void SetTeamListener(::TeamListener* listener);
bool IsEnabled() const;
void SetEnabled(bool enable);
bool IsService() const;
void SetService(bool service);
bool CreateDefaultPort() const;
void SetCreateDefaultPort(bool createPort);
void AddPort(BMessage& data);
const BStringList& Arguments() const;
BStringList& Arguments();
void AddArgument(const char* argument);
::Target* Target() const;
void SetTarget(::Target* target);
const BStringList& Requirements() const;
BStringList& Requirements();
void AddRequirement(const char* requirement);
const BStringList& Pending() const;
BStringList& Pending();
void AddPending(const char* pending);
virtual bool CheckCondition(ConditionContext& context) const;
status_t Init(const Finder& jobs,
std::set<BString>& dependencies);
status_t InitCheck() const;
team_id Team() const;
const PortMap& Ports() const;
port_id Port(const char* name = NULL) const;
port_id DefaultPort() const;
void SetDefaultPort(port_id port);
status_t Launch();
bool IsLaunched() const;
bool IsRunning() const;
void TeamDeleted();
bool CanBeLaunched() const;
bool IsLaunching() const;
void SetLaunching(bool launching);
status_t HandleGetLaunchData(BMessage* message);
status_t GetMessenger(BMessenger& messenger);
virtual status_t Run();
protected:
virtual status_t Execute();
private:
Job& operator=(const Job& other);
void _DeletePorts();
status_t _AddRequirement(BJob* dependency);
void _AddStringList(std::vector<const char*>& array,
const BStringList& list);
void _SetLaunchStatus(status_t launchStatus);
status_t _SendLaunchDataReply(BMessage* message);
void _SendPendingLaunchDataReplies();
status_t _CreateAndTransferPorts();
port_id _CreateAndTransferPort(const char* name,
int32 capacity);
status_t _Launch(const char* signature, entry_ref* ref,
int argCount, const char* const* args,
const char** environment);
private:
BStringList fArguments;
BStringList fRequirements;
bool fEnabled;
bool fService;
bool fCreateDefaultPort;
bool fLaunching;
PortMap fPortMap;
status_t fInitStatus;
team_id fTeam;
port_id fDefaultPort;
uint32 fToken;
status_t fLaunchStatus;
mutex fLaunchStatusLock;
::Target* fTarget;
::Condition* fCondition;
BStringList fPendingJobs;
BObjectList<BMessage>
fPendingLaunchDataReplies;
::TeamListener* fTeamListener;
};
class Finder {
public:
virtual Job* FindJob(const char* name) const = 0;
virtual Target* FindTarget(const char* name) const = 0;
};
#endif // JOB_H