libalcommon
1.14.5
|
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/almoduleinfo.h> 00018 # include <alvalue/alvalue.h> 00019 00020 # include <boost/shared_ptr.hpp> 00021 # include <boost/smart_ptr/enable_shared_from_this.hpp> 00022 # include <boost/noncopyable.hpp> 00023 00024 # include <qi/macro.hpp> 00025 00026 # define BROKERMASK_KEEPALIVE 1 00027 # define BROKERMASK_LIGHT 2 00028 # define BROKERMASK_NOSERVER 4 00029 # define BROKERMASK_NOHEARTBEAT 8 00030 # define BROKERMASK_WITHALNETWORK 16 00032 namespace AL 00033 { 00034 class ALTask; 00035 class ALModuleCore; 00036 class ALProxy; 00037 class ALBrokerManager; 00038 class ALBrokerInfo; 00039 class ALBrokerImpl; 00040 00070 class ALBroker : public ::boost::enable_shared_from_this<ALBroker>, public ::boost::noncopyable 00071 { 00072 public: 00078 typedef boost::shared_ptr<ALBroker> Ptr; 00084 typedef boost::weak_ptr<ALBroker> WeakPtr; 00085 00090 boost::shared_ptr<ALBroker> getThis(); 00095 boost::shared_ptr<const ALBroker> getThis() const; 00096 00100 ALBroker(); 00101 00105 virtual ~ALBroker(void); 00106 00111 void setBrokerManagerInstance(boost::shared_ptr<ALBrokerManager> pBrokerManager); 00112 00118 boost::shared_ptr<ALModuleCore> getModuleByName(const std::string &pModuleName); 00119 00135 int registerModule(boost::shared_ptr<ALModuleCore> pModule); 00136 00145 int unregisterModule(const std::string &pModuleName); 00146 00153 bool isModulePresent(const std::string &pModuleName); 00154 00160 int getModuleList(boost::shared_ptr<std::vector<ALModuleInfo> > pModuleList); 00161 00167 int getBrokerList(std::vector<ALModuleInfo> &pBrokerList); 00168 00174 int getGlobalModuleList(boost::shared_ptr<std::vector<ALModuleInfo> > pModuleList); 00175 00176 00181 bool isExiting() const; 00182 00187 int shutdown(); 00188 00193 std::string getName() const; 00194 00199 std::string getIP() const; 00200 00205 int getPort() const; 00206 00210 std::string getParentIP(); 00211 00215 int getParentPort(); 00216 00223 boost::shared_ptr<ALProxy> getProxy(const std::string &pProxyName, int pProxyOption = 0); 00224 00230 const std::string httpGet(const std::string &pPath); 00231 00232 00233 template <typename T> 00234 boost::shared_ptr<T> getSpecialisedProxy(const std::string &name = std::string()) { 00235 if (name.empty()) 00236 return boost::shared_ptr<T>(new T(getThis())); 00237 else 00238 return boost::shared_ptr<T>(new T(getProxy(name))); 00239 } 00240 00248 #define getMemoryProxy() getSpecialisedProxy<AL::ALMemoryProxy>("ALMemory") 00249 00257 #define getLedsProxy() getSpecialisedProxy<AL::ALLedsProxy>("ALLeds") 00258 00266 #define getLoggerProxy() getSpecialisedProxy<AL::ALLoggerProxy>("ALLogger") 00267 00275 #define getMotionProxy() getSpecialisedProxy<AL::ALMotionProxy>("ALMotion") 00276 00284 #define getPreferencesProxy() getSpecialisedProxy<AL::ALPreferencesProxy>("ALPreferences") 00285 00293 #define getDcmProxy() getSpecialisedProxy<AL::DCMProxy>("DCM") 00294 00295 00308 static boost::shared_ptr<ALBroker> createBroker(const std::string &pName, 00309 const std::string &pIP, 00310 int pPort, 00311 const std::string &pParentIP, 00312 int pParentPort, 00313 int pKeepAlive = 0, 00314 std::string pPath = "", 00315 bool pLoadLib = true); 00316 00317 public: 00319 boost::weak_ptr<ALBrokerManager> fBrokerManager; 00320 00322 ALBrokerImpl *_private; 00323 00324 }; 00325 00326 } // !namespace AL 00327 00328 00329 #endif // _LIBALCOMMON_ALCOMMON_ALBROKER_H_