libalcommon  1.14
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
albroker.h
Go to the documentation of this file.
1 
10 #pragma once
11 #ifndef _LIBALCOMMON_ALCOMMON_ALBROKER_H_
12 #define _LIBALCOMMON_ALCOMMON_ALBROKER_H_
13 
14 # include <list>
15 # include <map>
16 
17 # include <alcommon/almoduleinfo.h>
18 # include <alvalue/alvalue.h>
19 
20 # include <boost/shared_ptr.hpp>
21 # include <boost/smart_ptr/enable_shared_from_this.hpp>
22 # include <boost/noncopyable.hpp>
23 
24 # include <qi/macro.hpp>
25 
26 # define BROKERMASK_KEEPALIVE 1
27 # define BROKERMASK_LIGHT 2
28 # define BROKERMASK_NOSERVER 4
29 # define BROKERMASK_NOHEARTBEAT 8
30 # define BROKERMASK_WITHALNETWORK 16
32 namespace AL
33 {
34  class ALTask;
35  class ALModuleCore;
36  class ALProxy;
37  class ALBrokerManager;
38  class ALBrokerInfo;
39  class ALBrokerImpl;
40 
70  class ALBroker : public ::boost::enable_shared_from_this<ALBroker>, public ::boost::noncopyable
71  {
72  public:
78  typedef boost::shared_ptr<ALBroker> Ptr;
84  typedef boost::weak_ptr<ALBroker> WeakPtr;
85 
90  boost::shared_ptr<ALBroker> getThis();
95  boost::shared_ptr<const ALBroker> getThis() const;
96 
100  ALBroker();
101 
105  virtual ~ALBroker(void);
106 
111  void setBrokerManagerInstance(boost::shared_ptr<ALBrokerManager> pBrokerManager);
112 
118  boost::shared_ptr<ALModuleCore> getModuleByName(const std::string &pModuleName);
119 
135  int registerModule(boost::shared_ptr<ALModuleCore> pModule);
136 
145  int unregisterModule(const std::string &pModuleName);
146 
153  bool isModulePresent(const std::string &pModuleName);
154 
160  int getModuleList(boost::shared_ptr<std::vector<ALModuleInfo> > pModuleList);
161 
167  int getBrokerList(std::vector<ALModuleInfo> &pBrokerList);
168 
174  int getGlobalModuleList(boost::shared_ptr<std::vector<ALModuleInfo> > pModuleList);
175 
176 
181  bool isExiting() const;
182 
187  int shutdown();
188 
193  std::string getName() const;
194 
199  std::string getIP() const;
200 
205  int getPort() const;
206 
210  std::string getParentIP();
211 
215  int getParentPort();
216 
223  boost::shared_ptr<ALProxy> getProxy(const std::string &pProxyName, int pProxyOption = 0);
224 
230  const std::string httpGet(const std::string &pPath);
231 
232 
233  template <typename T>
234  boost::shared_ptr<T> getSpecialisedProxy(const std::string &name = std::string()) {
235  if (name.empty())
236  return boost::shared_ptr<T>(new T(getThis()));
237  else
238  return boost::shared_ptr<T>(new T(getProxy(name)));
239  }
240 
248  #define getMemoryProxy() getSpecialisedProxy<AL::ALMemoryProxy>("ALMemory")
249 
257  #define getLedsProxy() getSpecialisedProxy<AL::ALLedsProxy>("ALLeds")
258 
266  #define getLoggerProxy() getSpecialisedProxy<AL::ALLoggerProxy>("ALLogger")
267 
275  #define getMotionProxy() getSpecialisedProxy<AL::ALMotionProxy>("ALMotion")
276 
284  #define getPreferencesProxy() getSpecialisedProxy<AL::ALPreferencesProxy>("ALPreferences")
285 
293  #define getDcmProxy() getSpecialisedProxy<AL::DCMProxy>("DCM")
294 
295 
308  static boost::shared_ptr<ALBroker> createBroker(const std::string &pName,
309  const std::string &pIP,
310  int pPort,
311  const std::string &pParentIP,
312  int pParentPort,
313  int pKeepAlive = 0,
314  std::string pPath = "",
315  bool pLoadLib = true);
316 
317  public:
319  boost::weak_ptr<ALBrokerManager> fBrokerManager;
320 
322  ALBrokerImpl *_private;
323 
324  };
325 
326 } // !namespace AL
327 
328 
329 #endif // _LIBALCOMMON_ALCOMMON_ALBROKER_H_