libalcommon  2.8.7.4
 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 <qi/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 ALModuleCore;
40  class ALBrokerManager;
41  class ALBrokerInfo;
42 
72  class ALBrokerPrivate;
73  class ALCOMMON_API ALBroker : public ::boost::enable_shared_from_this<ALBroker>, public ::boost::noncopyable
74  {
75  public:
81  typedef boost::shared_ptr<ALBroker> Ptr;
87  typedef boost::weak_ptr<ALBroker> WeakPtr;
88 
93  boost::shared_ptr<ALBroker> getThis();
98  boost::shared_ptr<const ALBroker> getThis() const;
99 
103  ALBroker();
104 
108  virtual ~ALBroker(void);
109 
114  void setBrokerManagerInstance(boost::shared_ptr<ALBrokerManager> pBrokerManager);
115 
121  boost::shared_ptr<ALModuleCore> getModuleByName(const std::string &pModuleName);
122 
131  int unregisterModule(const std::string &pModuleName);
132 
139  bool isModulePresent(const std::string &pModuleName);
140 
146  int getModuleList(boost::shared_ptr<std::vector<ALModuleInfo> > pModuleList);
147 
153  int getBrokerList(std::vector<ALModuleInfo> &pBrokerList);
154 
160  int getGlobalModuleList(boost::shared_ptr<std::vector<ALModuleInfo> > pModuleList);
161 
162 
167  bool isExiting() const;
168 
173  bool isConnected();
174 
179  int shutdown();
180 
185  std::string getName() const;
186 
191  std::string getIP() const;
192 
197  int getPort() const;
198 
202  std::string getParentIP() const;
203 
207  int getParentPort() const;
208 
215  boost::shared_ptr<ALProxy> getProxy(const std::string &pProxyName, int deprecated = 0);
216 
217  template <typename T>
218  boost::shared_ptr<T> getSpecialisedProxy(const std::string &name = std::string()) {
219  //if (name.empty())
220  //return boost::shared_ptr<T>(new T(getThis()));
221  //else
222  return boost::shared_ptr<T>(new T(getProxy(name)));
223  }
224 
232  #define getMemoryProxy() getSpecialisedProxy<AL::ALMemoryProxy>("ALMemory")
233 
241  #define getLedsProxy() getSpecialisedProxy<AL::ALLedsProxy>("ALLeds")
242 
250  #define getLoggerProxy() getSpecialisedProxy<AL::ALLoggerProxy>("ALLogger")
251 
259  #define getMotionProxy() getSpecialisedProxy<AL::ALMotionProxy>("ALMotion")
260 
268  #define getPreferencesProxy() getSpecialisedProxy<AL::ALPreferencesProxy>("ALPreferences")
269 
277  #define getDcmProxy() getSpecialisedProxy<AL::DCMProxy>("DCM")
278 
279 
292  static boost::shared_ptr<ALBroker> createBroker(const std::string &pName,
293  const std::string &pIP,
294  int pPort,
295  const std::string &pParentIP,
296  int pParentPort,
297  int pKeepAlive = 0,
298  std::string pPath = "",
299  bool pLoadLib = true);
300 
301  static boost::shared_ptr<ALBroker> createBroker(const std::string &name, qi::SessionPtr session);
302 
303  qi::SessionPtr session();
304  public:
306  boost::weak_ptr<ALBrokerManager> fBrokerManager;
307 
309  ALBrokerPrivate *_p;
310 
311  };
312 
313  typedef boost::shared_ptr<ALBroker> ALBrokerPtr;
314 
315 } // !namespace AL
316 
317 
318 #endif // _LIBALCOMMON_ALCOMMON_ALBROKER_H_
ALBrokerManager is a class to manage brokers.
ALModuleCore is the superclass of user modules.
Definition: almodulecore.h:57
boost::weak_ptr< ALBroker > WeakPtr
Weak pointer to ALBroker.
Definition: albroker.h:87
ALBrokerPrivate * _p
Definition: albroker.h:309
boost::weak_ptr< ALBrokerManager > fBrokerManager
Definition: albroker.h:306
boost::shared_ptr< ALBroker > ALBrokerPtr
Definition: albroker.h:313
boost::shared_ptr< T > getSpecialisedProxy(const std::string &name=std::string())
Definition: albroker.h:218
ALBroker serves methods advertised by connected modules to clients participating in the network...
Definition: albroker.h:73
boost::shared_ptr< ALBroker > Ptr
Shared pointer to ALBroker.
Definition: albroker.h:81
#define ALCOMMON_API
Definition: api.h:14