docs/ikteam: Delete most files.
[haiku.git] / src / servers / launch / Job.h
blob84048f53122ef9baf2e386747be08248bae65a15
1 /*
2 * Copyright 2015, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef JOB_H
6 #define JOB_H
9 #include "BaseJob.h"
11 #include <map>
12 #include <set>
13 #include <vector>
15 #include <OS.h>
16 #include <StringList.h>
18 #include <locks.h>
21 using namespace BSupportKit;
22 class BMessage;
23 class BMessenger;
25 class Finder;
26 class Job;
27 class Target;
29 struct entry_ref;
32 typedef std::map<BString, BMessage> PortMap;
35 class TeamRegistrator {
36 public:
37 virtual void RegisterTeam(Job* job) = 0;
41 class Job : public BaseJob {
42 public:
43 Job(const char* name);
44 Job(const Job& other);
45 virtual ~Job();
47 ::TeamRegistrator* TeamRegistrator() const;
48 void SetTeamRegistrator(
49 ::TeamRegistrator* registrator);
51 bool IsEnabled() const;
52 void SetEnabled(bool enable);
54 bool IsService() const;
55 void SetService(bool service);
57 bool CreateDefaultPort() const;
58 void SetCreateDefaultPort(bool createPort);
60 void AddPort(BMessage& data);
62 const BStringList& Arguments() const;
63 BStringList& Arguments();
64 void AddArgument(const char* argument);
66 ::Target* Target() const;
67 void SetTarget(::Target* target);
69 const BStringList& Requirements() const;
70 BStringList& Requirements();
71 void AddRequirement(const char* requirement);
73 const BStringList& Pending() const;
74 BStringList& Pending();
75 void AddPending(const char* pending);
77 virtual bool CheckCondition(ConditionContext& context) const;
79 status_t Init(const Finder& jobs,
80 std::set<BString>& dependencies);
81 status_t InitCheck() const;
83 team_id Team() const;
85 const PortMap& Ports() const;
86 port_id Port(const char* name = NULL) const;
88 port_id DefaultPort() const;
89 void SetDefaultPort(port_id port);
91 status_t Launch();
92 bool IsLaunched() const;
93 bool IsRunning() const;
94 void TeamDeleted();
95 bool CanBeLaunched() const;
97 bool IsLaunching() const;
98 void SetLaunching(bool launching);
100 status_t HandleGetLaunchData(BMessage* message);
101 status_t GetMessenger(BMessenger& messenger);
103 virtual status_t Run();
105 protected:
106 virtual status_t Execute();
108 private:
109 Job& operator=(const Job& other);
110 void _DeletePorts();
111 status_t _AddRequirement(BJob* dependency);
112 void _AddStringList(std::vector<const char*>& array,
113 const BStringList& list);
115 void _SetLaunchStatus(status_t launchStatus);
117 status_t _SendLaunchDataReply(BMessage* message);
118 void _SendPendingLaunchDataReplies();
120 status_t _CreateAndTransferPorts();
121 port_id _CreateAndTransferPort(const char* name,
122 int32 capacity);
124 status_t _Launch(const char* signature, entry_ref* ref,
125 int argCount, const char* const* args,
126 const char** environment);
128 private:
129 BStringList fArguments;
130 BStringList fRequirements;
131 bool fEnabled;
132 bool fService;
133 bool fCreateDefaultPort;
134 bool fLaunching;
135 PortMap fPortMap;
136 status_t fInitStatus;
137 team_id fTeam;
138 port_id fDefaultPort;
139 uint32 fToken;
140 status_t fLaunchStatus;
141 mutex fLaunchStatusLock;
142 ::Target* fTarget;
143 ::Condition* fCondition;
144 BStringList fPendingJobs;
145 BObjectList<BMessage>
146 fPendingLaunchDataReplies;
147 ::TeamRegistrator* fTeamRegistrator;
151 class Finder {
152 public:
153 virtual Job* FindJob(const char* name) const = 0;
154 virtual Target* FindTarget(const char* name) const = 0;
158 #endif // JOB_H