libalcommon
1.14.5
|
00001 00010 #pragma once 00011 #ifndef _LIBALCOMMON_ALCOMMON_ALPROXY_H_ 00012 #define _LIBALCOMMON_ALCOMMON_ALPROXY_H_ 00013 00014 # include <alcommon/almoduleinfo.h> 00015 # include <alcommon/almodule.h> 00016 # include <alcommon/detail/altaskinfo.h> 00017 # include <alcommon/alfunctor.h> 00018 00019 # include <alerror/alerror.h> 00020 00021 # include <boost/shared_ptr.hpp> 00022 # include <boost/smart_ptr/enable_shared_from_this.hpp> 00023 00024 #ifdef _WIN32 00025 # pragma warning(disable:4996) 00026 # pragma warning(disable:4800) 00027 #endif 00028 00029 namespace AL 00030 { 00031 class ALProxyImpl; 00032 00033 namespace detail { 00034 class PCallBase; 00035 } 00036 00065 class ALProxy : public ::boost::enable_shared_from_this<ALProxy> 00066 { 00067 public: 00073 typedef boost::shared_ptr<ALProxy> Ptr; 00079 typedef boost::weak_ptr<ALProxy> WeakPtr; 00080 00081 typedef int (*onFinishedCallback)(const char*, int, const AL::ALValue &); 00082 00087 boost::shared_ptr<ALProxy> getThis(); 00092 boost::shared_ptr<const ALProxy> getThis() const; 00093 00098 enum pProxyOption 00099 { 00100 NO_OPTION = 0, 00101 FORCED_LOCAL = 1, 00102 NO_LOAD_DEPENDS = 2, 00103 MAIN_PROXY = 4 00104 }; 00105 00106 ALProxy(const ALProxy &rhs); 00107 const ALProxy &operator=(const ALProxy &rhs); 00108 00109 public: 00117 ALProxy(boost::shared_ptr<ALBroker> pBroker, 00118 const std::string &pModuleName, 00119 int pProxyMask = 0, 00120 int timeout = 0); 00129 ALProxy(const std::string &pModuleName, 00130 const std::string &pIp, 00131 int pPort, 00132 int pProxyMask = 0, 00133 int timeout = 0); 00143 ALProxy(const std::string &pModuleName, 00144 const std::string &pIp, 00145 int pPort, 00146 boost::shared_ptr<ALBroker> pBroker, 00147 int pProxyMask = 0, 00148 int timeout = 0); 00155 ALProxy(const std::string &pModuleName, 00156 int pProxyOption, 00157 int pTimeout); 00158 00160 virtual ~ALProxy(void); 00161 00165 std::string remoteBrokerName(); 00166 00178 AL::ALValue genericCall(const std::string &strMethodName, 00179 const AL::ALValue &listParams); 00180 00181 00199 int genericPCall(const std::string &strMethodName, 00200 const AL::ALValue &listParams, 00201 onFinishedCallback pCallbackToCallOnFinished = NULL, 00202 const char *pszCallerName = NULL); 00203 00208 std::string version(); 00209 00214 boost::shared_ptr<ALModule> getModule() const; 00219 boost::shared_ptr<ALModuleCore> getModuleCore() const; 00220 00226 int getInfo(ALModuleInfo &pModuleInfo); 00227 00232 bool isLocal(); 00233 00240 bool isValid(); 00241 00248 boost::shared_ptr<ALFunctorBase> getFunctor(const std::string &pName, 00249 const std::vector<std::string> &pParamTypes); 00250 00255 boost::shared_ptr<ALBroker> getParentBroker(void) const; 00256 00260 void destroyConnection(void); 00261 00262 template <typename R> 00263 R call(const std::string &pName); 00264 00265 template <typename R, typename P1> 00266 R call(const std::string &pName, const P1 &p1); 00267 00268 template <typename R, typename P1, typename P2> 00269 R call(const std::string &pName, const P1 &p1, const P2 &p2); 00270 00271 template <typename R, typename P1, typename P2, typename P3> 00272 R call(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3); 00273 00274 template <typename R, typename P1, typename P2, typename P3, typename P4> 00275 R call(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4); 00276 00277 template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5> 00278 R call(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5); 00279 00280 template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> 00281 R call(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5, const P6 &p6); 00282 00283 inline void callVoid(const std::string &pName); 00284 00285 template <typename P1> 00286 void callVoid(const std::string &pName, const P1 &p1); 00287 00288 template <typename P1, typename P2> 00289 void callVoid(const std::string &pName, const P1 &p1, const P2 &p2); 00290 00291 template <typename P1, typename P2, typename P3> 00292 void callVoid(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3); 00293 00294 template <typename P1, typename P2, typename P3, typename P4> 00295 void callVoid(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4); 00296 00297 template <typename P1, typename P2, typename P3, typename P4, typename P5> 00298 void callVoid(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5); 00299 00300 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> 00301 void callVoid(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5, const P6 &p6); 00302 00303 inline int pCall(const std::string &pName); 00304 00305 template <typename P1> 00306 int pCall(const std::string &pName, const P1 &p1); 00307 00308 template <typename P1, typename P2> 00309 int pCall(const std::string &pName, const P1 &p1, const P2 &p2); 00310 00311 template <typename P1, typename P2, typename P3> 00312 int pCall(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3); 00313 00314 template <typename P1, typename P2, typename P3, typename P4> 00315 int pCall(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4); 00316 00317 template <typename P1, typename P2, typename P3, typename P4, typename P5> 00318 int pCall(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5); 00319 00320 template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> 00321 int pCall(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5, const P6 &p6); 00322 00323 00334 bool wait(const int &id, const int &timeoutPeriod); 00335 00341 void stop(const int &id); 00342 00349 bool isRunning(const int &id); 00350 00357 int pCallNotify(const std::string &name, 00358 const std::string &key, 00359 const ALValue &value, 00360 const ALValue &message = std::string()); 00361 00362 protected: 00363 void CALL_METHODS(const std::string &szMethodName, 00364 const AL::ALValue ¶m, 00365 AL::ALValue &result); 00366 void PCALL_METHODSNoID(const std::string &szMethodName, 00367 const AL::ALValue ¶m, 00368 AL::ALValue &result); 00369 void PCALL_METHODS(const std::string &szMethodName, 00370 const AL::ALValue ¶m, 00371 AL::ALValue &result); 00374 private: 00381 bool isScript(void); 00382 void init(boost::shared_ptr<ALBroker> pBroker, 00383 const std::string &pModuleName, 00384 int pProxyMask = 0, 00385 int timeout = 0); 00386 void init(const std::string& pModuleName, 00387 const std::string& pIpParam, 00388 int pPort, 00389 boost::shared_ptr<ALBroker> pBroker, 00390 int pProxyOption, 00391 int timeout); 00392 00393 int xGetFreeTaskUID(void); 00394 std::string xCleanEndpointAddress(const std::string &pEndpoint); 00395 AL::ALValue xWaitIfNecessary(AL::ALValue result); 00396 00397 boost::shared_ptr<detail::ALTaskInfo> xCreateTaskInfo(const std::string pMethodName); 00398 void xAddTask(const std::string &name, detail::PCallBase *pcall); 00399 ALMethodInfo* xLookupMethod(const std::string &pName); 00400 ALMethodInfo* xLookupMethod(const std::string &pMethodName, 00401 const AL::ALValue &pParams); 00402 ALMethodInfo* xLookupMethod(const std::string &pMethodName, 00403 const std::vector<std::string> &pParams, 00404 bool softCompare); 00405 const std::string& xGetModuleName(); 00406 void xExecute(const std::string &pMethod, 00407 const ALValue &pParams, 00408 ALValue &pResult); 00409 00410 int xPCallScript(const std::string &name, 00411 const ALValue ¶m); 00412 00413 private: 00415 ALProxyImpl *_private; 00416 00417 }; // ALProxy 00418 } // namespace AL 00419 00420 #include <alcommon/alproxy.hxx> 00421 00422 #endif // _LIBALCOMMON_ALCOMMON_ALPROXY_H_ 00423