libalcommon  2.0.6.8
/home/opennao/work/master/sdk/libnaoqi/libalcommon/alcommon/albroker.h
Go to the documentation of this file.
00001 
00010 #pragma once
00011 #ifndef _LIBALCOMMON_ALCOMMON_ALBROKER_H_
00012 #define _LIBALCOMMON_ALCOMMON_ALBROKER_H_
00013 
00014 # include <list>
00015 # include <map>
00016 
00017 # include <alcommon/api.h>
00018 # include <alcommon/almoduleinfo.h>
00019 # include <alvalue/alvalue.h>
00020 
00021 # include <boost/shared_ptr.hpp>
00022 # include <boost/smart_ptr/enable_shared_from_this.hpp>
00023 # include <boost/noncopyable.hpp>
00024 
00025 //needed because templated code initialize an ALProxy in this file
00026 # include <alcommon/alproxy.h>
00027 
00028 # include <qi/macro.hpp>
00029 # include <qimessaging/session.hpp>
00030 
00031 # define BROKERMASK_KEEPALIVE     1  
00032 # define BROKERMASK_LIGHT         2  
00033 # define BROKERMASK_NOSERVER      4  
00034 # define BROKERMASK_NOHEARTBEAT   8  
00035 # define BROKERMASK_WITHALNETWORK 16 
00037 namespace AL
00038 {
00039   class ALTask;
00040   class ALModuleCore;
00041   class ALBrokerManager;
00042   class ALBrokerInfo;
00043 
00073   class ALBrokerPrivate;
00074   class ALBroker : public ::boost::enable_shared_from_this<ALBroker>, public ::boost::noncopyable
00075   {
00076   public:
00082     typedef boost::shared_ptr<ALBroker> Ptr;
00088     typedef boost::weak_ptr<ALBroker>   WeakPtr;
00089 
00094     boost::shared_ptr<ALBroker>       getThis();
00099     boost::shared_ptr<const ALBroker> getThis() const;
00100 
00104     ALBroker();
00105 
00109     virtual ~ALBroker(void);
00110 
00115     void setBrokerManagerInstance(boost::shared_ptr<ALBrokerManager> pBrokerManager);
00116 
00122     boost::shared_ptr<ALModuleCore> getModuleByName(const std::string &pModuleName);
00123 
00132     int unregisterModule(const std::string &pModuleName);
00133 
00140     bool isModulePresent(const std::string &pModuleName);
00141 
00147     int getModuleList(boost::shared_ptr<std::vector<ALModuleInfo> > pModuleList);
00148 
00154     int getBrokerList(std::vector<ALModuleInfo> &pBrokerList);
00155 
00161     int getGlobalModuleList(boost::shared_ptr<std::vector<ALModuleInfo> > pModuleList);
00162 
00163 
00168     bool isExiting() const;
00169 
00174     bool isConnected();
00175 
00180     int shutdown();
00181 
00186     std::string getName() const;
00187 
00192     std::string getIP() const;
00193 
00198     int getPort() const;
00199 
00203     std::string getParentIP() const;
00204 
00208     int getParentPort() const;
00209 
00216     boost::shared_ptr<ALProxy> getProxy(const std::string &pProxyName, int deprecated = 0);
00217 
00223     std::string httpGet(const std::string &pPath);
00224 
00225 
00226     template <typename T>
00227     boost::shared_ptr<T> getSpecialisedProxy(const std::string &name = std::string()) {
00228       //if (name.empty())
00229         //return boost::shared_ptr<T>(new T(getThis()));
00230       //else
00231       return boost::shared_ptr<T>(new T(getProxy(name)));
00232     }
00233 
00241     #define getMemoryProxy()      getSpecialisedProxy<AL::ALMemoryProxy>("ALMemory")
00242 
00250     #define getLedsProxy()        getSpecialisedProxy<AL::ALLedsProxy>("ALLeds")
00251 
00259     #define getLoggerProxy()      getSpecialisedProxy<AL::ALLoggerProxy>("ALLogger")
00260 
00268     #define getMotionProxy()      getSpecialisedProxy<AL::ALMotionProxy>("ALMotion")
00269 
00277     #define getPreferencesProxy() getSpecialisedProxy<AL::ALPreferencesProxy>("ALPreferences")
00278 
00286     #define getDcmProxy()         getSpecialisedProxy<AL::DCMProxy>("DCM")
00287 
00288 
00301     static boost::shared_ptr<ALBroker> createBroker(const std::string &pName,
00302                                                     const std::string &pIP,
00303                                                     int pPort,
00304                                                     const std::string &pParentIP,
00305                                                     int pParentPort,
00306                                                     int pKeepAlive = 0,
00307                                                     std::string pPath = "",
00308                                                     bool pLoadLib = true);
00309 
00310     qi::SessionPtr session();
00311   public:
00313     boost::weak_ptr<ALBrokerManager> fBrokerManager;
00314 
00316     ALBrokerPrivate *_p;
00317 
00318   };
00319 
00320   typedef boost::shared_ptr<ALBroker> ALBrokerPtr;
00321 
00322 } // !namespace AL
00323 
00324 
00325 #endif  // _LIBALCOMMON_ALCOMMON_ALBROKER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines