libalcommon  2.1.4.13
 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/api.h>
18 # include <alcommon/almoduleinfo.h>
19 # include <alvalue/alvalue.h>
20 
21 # include <boost/shared_ptr.hpp>
22 # include <boost/smart_ptr/enable_shared_from_this.hpp>
23 # include <boost/noncopyable.hpp>
24 
25 //needed because templated code initialize an ALProxy in this file
26 # include <alcommon/alproxy.h>
27 
28 # include <qi/macro.hpp>
29 # include <qimessaging/session.hpp>
30 
31 # define BROKERMASK_KEEPALIVE 1
32 # define BROKERMASK_LIGHT 2
33 # define BROKERMASK_NOSERVER 4
34 # define BROKERMASK_NOHEARTBEAT 8
35 # define BROKERMASK_WITHALNETWORK 16
37 namespace AL
38 {
39  class ALTask;
40  class ALModuleCore;
41  class ALBrokerManager;
42  class ALBrokerInfo;
43 
73  class ALBrokerPrivate;
74  class ALBroker : public ::boost::enable_shared_from_this<ALBroker>, public ::boost::noncopyable
75  {
76  public:
82  typedef boost::shared_ptr<ALBroker> Ptr;
88  typedef boost::weak_ptr<ALBroker> WeakPtr;
89 
94  boost::shared_ptr<ALBroker> getThis();
99  boost::shared_ptr<const ALBroker> getThis() const;
100 
104  ALBroker();
105 
109  virtual ~ALBroker(void);
110 
115  void setBrokerManagerInstance(boost::shared_ptr<ALBrokerManager> pBrokerManager);
116 
122  boost::shared_ptr<ALModuleCore> getModuleByName(const std::string &pModuleName);
123 
132  int unregisterModule(const std::string &pModuleName);
133 
140  bool isModulePresent(const std::string &pModuleName);
141 
147  int getModuleList(boost::shared_ptr<std::vector<ALModuleInfo> > pModuleList);
148 
154  int getBrokerList(std::vector<ALModuleInfo> &pBrokerList);
155 
161  int getGlobalModuleList(boost::shared_ptr<std::vector<ALModuleInfo> > pModuleList);
162 
163 
168  bool isExiting() const;
169 
174  bool isConnected();
175 
180  int shutdown();
181 
186  std::string getName() const;
187 
192  std::string getIP() const;
193 
198  int getPort() const;
199 
203  std::string getParentIP() const;
204 
208  int getParentPort() const;
209 
216  boost::shared_ptr<ALProxy> getProxy(const std::string &pProxyName, int deprecated = 0);
217 
223  std::string httpGet(const std::string &pPath);
224 
225 
226  template <typename T>
227  boost::shared_ptr<T> getSpecialisedProxy(const std::string &name = std::string()) {
228  //if (name.empty())
229  //return boost::shared_ptr<T>(new T(getThis()));
230  //else
231  return boost::shared_ptr<T>(new T(getProxy(name)));
232  }
233 
241  #define getMemoryProxy() getSpecialisedProxy<AL::ALMemoryProxy>("ALMemory")
242 
250  #define getLedsProxy() getSpecialisedProxy<AL::ALLedsProxy>("ALLeds")
251 
259  #define getLoggerProxy() getSpecialisedProxy<AL::ALLoggerProxy>("ALLogger")
260 
268  #define getMotionProxy() getSpecialisedProxy<AL::ALMotionProxy>("ALMotion")
269 
277  #define getPreferencesProxy() getSpecialisedProxy<AL::ALPreferencesProxy>("ALPreferences")
278 
286  #define getDcmProxy() getSpecialisedProxy<AL::DCMProxy>("DCM")
287 
288 
301  static boost::shared_ptr<ALBroker> createBroker(const std::string &pName,
302  const std::string &pIP,
303  int pPort,
304  const std::string &pParentIP,
305  int pParentPort,
306  int pKeepAlive = 0,
307  std::string pPath = "",
308  bool pLoadLib = true);
309 
310  qi::SessionPtr session();
311  public:
313  boost::weak_ptr<ALBrokerManager> fBrokerManager;
314 
316  ALBrokerPrivate *_p;
317 
318  };
319 
320  typedef boost::shared_ptr<ALBroker> ALBrokerPtr;
321 
322 } // !namespace AL
323 
324 
325 #endif // _LIBALCOMMON_ALCOMMON_ALBROKER_H_
boost::shared_ptr< ALBroker > ALBrokerPtr
Definition: albroker.h:320
ALBroker serves methods advertised by connected modules to clients participating in the network...
Definition: albroker.h:74
boost::shared_ptr< T > getSpecialisedProxy(const std::string &name=std::string())
Definition: albroker.h:227
ALModuleCore is the superclass of user modules.
Definition: almodulecore.h:58
boost::shared_ptr< ALBroker > Ptr
Shared pointer to ALBroker.
Definition: albroker.h:82
boost::weak_ptr< ALBroker > WeakPtr
Weak pointer to ALBroker.
Definition: albroker.h:88
boost::weak_ptr< ALBrokerManager > fBrokerManager
Definition: albroker.h:313
ALBrokerManager is a class to manage brokers.
ALBrokerPrivate * _p
Definition: albroker.h:316