xref: /haiku/src/servers/launch/Job.h (revision ea19a80ed6ba3f34abb2e4d138ddc666580b8d82)
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
7 
8 
9 #include "BaseJob.h"
10 
11 #include <map>
12 #include <set>
13 #include <vector>
14 
15 #include <OS.h>
16 #include <StringList.h>
17 
18 
19 using namespace BSupportKit;
20 class BMessage;
21 
22 class Finder;
23 class Target;
24 
25 
26 typedef std::map<BString, BMessage> PortMap;
27 
28 
29 class Job : public BaseJob {
30 public:
31 								Job(const char* name);
32 								Job(const Job& other);
33 	virtual						~Job();
34 
35 			bool				IsEnabled() const;
36 			void				SetEnabled(bool enable);
37 
38 			bool				IsService() const;
39 			void				SetService(bool service);
40 
41 			bool				CreateDefaultPort() const;
42 			void				SetCreateDefaultPort(bool createPort);
43 
44 			void				AddPort(BMessage& data);
45 
46 			const BStringList&	Arguments() const;
47 			BStringList&		Arguments();
48 			void				AddArgument(const char* argument);
49 
50 			::Target*			Target() const;
51 			void				SetTarget(::Target* target);
52 
53 			const BStringList&	Requirements() const;
54 			BStringList&		Requirements();
55 			void				AddRequirement(const char* requirement);
56 
57 			status_t			Init(const Finder& jobs,
58 									std::set<BString>& dependencies);
59 			status_t			InitCheck() const;
60 
61 			team_id				Team() const;
62 
63 			const PortMap&		Ports() const;
64 			port_id				Port(const char* name = NULL) const;
65 
66 			status_t			Launch();
67 			bool				IsLaunched() const;
68 
69 protected:
70 	virtual	status_t			Execute();
71 
72 private:
73 			Job&				operator=(const Job& other);
74 			void				_DeletePorts();
75 			status_t			_AddRequirement(BJob* dependency);
76 			void				_AddStringList(std::vector<const char*>& array,
77 									const BStringList& list);
78 
79 private:
80 			BStringList			fArguments;
81 			BStringList			fRequirements;
82 			bool				fEnabled;
83 			bool				fService;
84 			bool				fCreateDefaultPort;
85 			PortMap				fPortMap;
86 			status_t			fInitStatus;
87 			team_id				fTeam;
88 			::Target*			fTarget;
89 			::Condition*		fCondition;
90 };
91 
92 
93 class Finder {
94 public:
95 	virtual	Job*				FindJob(const char* name) const = 0;
96 	virtual	Target*				FindTarget(const char* name) const = 0;
97 };
98 
99 
100 #endif // JOB_H
101