platformmanagerApi.h
Go to the documentation of this file.
1 
3 #pragma once
4 
5 #include <boost/function.hpp>
6 #include <boost/system/error_code.hpp>
7 #include <boost/shared_ptr.hpp>
8 #include <boost/thread.hpp>
9 #include <boost/asio.hpp>
10 #include <vector>
11 
12 #include "platformManagerTypes.h"
13 
14 
19 
25 namespace dpyPlatformmanager {
26 
31  OK = 0,
32  ERROR = 1
33 };
34 
35 
39 struct Options
40 {
41  std::string processExec;
42  std::string processPath;
43  std::vector<std::string> args;
44  bool relaunch;
46  bool critical;
47 };
48 
53  ADDED = 0,
54  REMOVED = 1,
55 };
56 
57 
61 struct Info
62 {
63  std::string name;
66 };
67 
68 
73 typedef boost::function<void(const bool &available)> service_availability_handler;
74 
82 typedef boost::function<void(boost::system::error_code error_code, std::vector<dpyPlatformmanager::Info> info)> process_status_handler_function;
83 
84 
92 typedef boost::function<void(boost::system::error_code error_code, std::vector<dpyPlatformmanager::ExtendedProcessInfo> info)> extended_process_status_handler_function;
93 
101 typedef boost::function<void(boost::system::error_code error_code, const dpyPlatformmanager::EvaluationStatus& status)> evaluation_status_handler_function;
102 
109 typedef boost::function<void(boost::system::error_code error_code)> result_handler_function;
110 
111 
118 typedef boost::function<void(boost::system::error_code error_code, std::string name, ProcessListEvent event, Options options )> process_list_event_handler_function;
119 
126 typedef boost::function<void(boost::system::error_code error_code, std::string name, ProcessListEvent event, dpyPlatformmanager::ExtendedProcessOptions options )> process_list_event_extended_handler_function;
127 
134 typedef boost::function<void(boost::system::error_code error_code, std::string name, ProcessEvent event)> process_event_handler_function;
135 
136 }
137 
142 {
143  public:
148  virtual void availabilityStatusChange(__attribute__((unused)) bool available) {};
153  virtual void evaluationStatusChange(__attribute__((unused)) const dpyPlatformmanager::EvaluationStatus& status) {};
158  virtual void processStatusChange(__attribute__((unused)) std::vector<dpyPlatformmanager::Info> info) {};
159 
164  virtual void processStatusChange(__attribute__((unused)) std::vector<dpyPlatformmanager::ExtendedProcessInfo> info) {};
165 
172  virtual void processListEvent(__attribute__((unused)) std::string name, __attribute__((unused)) dpyPlatformmanager::ProcessListEvent event, __attribute__((unused)) dpyPlatformmanager::Options options) {};
173 
180  virtual void processListEvent(__attribute__((unused)) std::string name, __attribute__((unused)) dpyPlatformmanager::ProcessListEvent event, __attribute__((unused)) dpyPlatformmanager::ExtendedProcessOptions options) {};
181 
187  virtual void processEvent(__attribute__((unused)) std::string name, __attribute__((unused)) dpyPlatformmanager::ProcessEvent event) {};
192  {
193  }
194 };
195 
202 {
203 
204 private:
208  boost::shared_ptr<PlatformManagerClient> mClient;
212  std::vector<PlatformManagerObserver*> observersList;
213 public:
214 
215 
216  explicit PlatformManager(std::string ip = "127.0.0.1");
217  virtual ~PlatformManager();
218 
219  bool isAlive();
220  void monitorServiceAvailability_S(dpyPlatformmanager::service_availability_handler handler);
221  void monitorServiceAvailability_U();
222  [[deprecated("asyncGetProcessStatus is deprecated, use the version of asyncGetProcessStatus using extended_process_status_handler_function handler")]]
223  void asyncGetProcessStatus(dpyPlatformmanager::process_status_handler_function handler, std::string name = "");
224  void asyncGetExtendedProcessStatus(dpyPlatformmanager::extended_process_status_handler_function handler, std::string name = "");
225  void asyncStartProcess(dpyPlatformmanager::result_handler_function handler, std::string name);
226  void asyncStopProcess(dpyPlatformmanager::result_handler_function handler, std::string name);
227  [[deprecated("asyncAddProcess is deprecated, use the version of asyncAddProcess using dpyPlatformmanager::ExtendedProcessOptions struct")]]
228  void asyncAddProcess(dpyPlatformmanager::result_handler_function handler, std::string name, dpyPlatformmanager::Options options);
229  void asyncAddProcess(dpyPlatformmanager::result_handler_function handler, std::string name, dpyPlatformmanager::ExtendedProcessOptions options);
230 
231  void asyncDelProcess(dpyPlatformmanager::result_handler_function handler, std::string name);
232  void asyncKickWatchdog(dpyPlatformmanager::result_handler_function handler, std::string name);
233  void asyncKickWatchdog(dpyPlatformmanager::result_handler_function handler, std::string name, int deadline);
234 
235 #ifdef TESTING
236  virtual void asyncWait(dpyPlatformmanager::result_handler_function handler, std::string processName);
237  virtual void asyncFinished(dpyPlatformmanager::result_handler_function handler, std::string processName, dpyPlatformmanager::EvaluationResult);
238  //Observer
239  virtual boost::system::error_code subscribe(PlatformManagerObserver *observer);
240  virtual boost::system::error_code unsubscribe(PlatformManagerObserver *observer);
241 #else
242  void asyncWait(dpyPlatformmanager::result_handler_function handler, std::string processName);
243  void asyncFinished(dpyPlatformmanager::result_handler_function handler, std::string processName, dpyPlatformmanager::EvaluationResult);
244  //Observer
245  boost::system::error_code subscribe(PlatformManagerObserver *observer);
246  boost::system::error_code unsubscribe(PlatformManagerObserver *observer);
247 #endif
248 
249 };
virtual void processListEvent() std
Definition: platformmanagerApi.h:172
boost::function< void(const bool &available)> service_availability_handler
Prototype of the handler function used to monitor service availability.
Definition: platformmanagerApi.h:73
Options option
Definition: platformmanagerApi.h:64
std::string name
Definition: platformmanagerApi.h:63
virtual void processEvent() std
Definition: platformmanagerApi.h:187
std::string processExec
Definition: platformmanagerApi.h:41
EvaluationResult
Definition: platformmanagerApi.h:30
Definition: platformManagerTypes.h:48
boost::function< void(boost::system::error_code error_code, std::string name, ProcessListEvent event, Options options)> process_list_event_handler_function
Handler for process list events.
Definition: platformmanagerApi.h:118
std::vector< std::string > args
Definition: platformmanagerApi.h:43
virtual void availabilityStatusChange() bool available)
Definition: platformmanagerApi.h:148
Definition: platformmanagerApi.h:61
virtual ~PlatformManagerObserver()
Destructor.
Definition: platformmanagerApi.h:191
ProcessEvent
Definition: platformManagerTypes.h:25
bool critical
Definition: platformmanagerApi.h:46
boost::function< void(boost::system::error_code error_code, std::string name, ProcessListEvent event, dpyPlatformmanager::ExtendedProcessOptions options)> process_list_event_extended_handler_function
Handler for process list events.
Definition: platformmanagerApi.h:126
EvaluationStatus
Definition: platformManagerTypes.h:15
int delayOnLaunch
Definition: platformmanagerApi.h:45
virtual void processStatusChange() std
Definition: platformmanagerApi.h:158
Deepsy Platformmanager namespace that includes the different enums, structs or method signatures that...
Definition: platformmanagerApi.h:18
Definition: platformmanagerApi.h:31
boost::function< void(boost::system::error_code error_code, std::string name, ProcessEvent event)> process_event_handler_function
Handler for process events.
Definition: platformmanagerApi.h:134
Definition: platformmanagerApi.h:32
Definition: platformmanagerApi.h:54
Status status
Definition: platformmanagerApi.h:65
virtual void evaluationStatusChange() const dpyPlatformmanager
Definition: platformmanagerApi.h:153
Allows to interact with a platform manager.
Definition: platformmanagerApi.h:201
boost::function< void(boost::system::error_code error_code)> result_handler_function
Handler for command function callback.
Definition: platformmanagerApi.h:109
Definition: platformmanagerApi.h:141
Interacts with platform manager service.
Definition: platformmanagerClient.h:14
Definition: platformmanagerApi.h:39
Definition: platformManagerTypes.h:35
std::string processPath
Definition: platformmanagerApi.h:42
Definition: platformmanagerApi.h:53
boost::function< void(boost::system::error_code error_code, std::vector< dpyPlatformmanager::ExtendedProcessInfo > info)> extended_process_status_handler_function
Handler for status function callback.
Definition: platformmanagerApi.h:92
bool relaunch
Definition: platformmanagerApi.h:44
boost::function< void(boost::system::error_code error_code, std::vector< dpyPlatformmanager::Info > info)> process_status_handler_function
Handler for status function callback.
Definition: platformmanagerApi.h:82
boost::function< void(boost::system::error_code error_code, const dpyPlatformmanager::EvaluationStatus &status)> evaluation_status_handler_function
Handler for status function callback.
Definition: platformmanagerApi.h:101
ProcessListEvent
Definition: platformmanagerApi.h:52