libalcommon  2.8.7.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
alproxy.h
Go to the documentation of this file.
1 
10 #pragma once
11 #ifndef _LIBALCOMMON_ALCOMMON_ALPROXY_H_
12 #define _LIBALCOMMON_ALCOMMON_ALPROXY_H_
13 
14 # include <alcommon/api.h>
15 # include <alcommon/almoduleinfo.h>
16 # include <alcommon/almodule.h>
17 # include <alvalue/alvalue.h>
18 # include <alerror/alerror.h>
19 
20 # include <boost/shared_ptr.hpp>
21 # include <boost/smart_ptr/enable_shared_from_this.hpp>
22 # include <qi/anyobject.hpp>
23 # include <qi/session.hpp>
24 
25 #ifdef _WIN32
26 # pragma warning(disable:4996)
27 # pragma warning(disable:4800)
28 #endif
29 
30 namespace AL
31 {
32 
33 
34 
35  class ALProxyPrivate;
36 
71  class ALCOMMON_API ALProxy : public ::boost::enable_shared_from_this<ALProxy>
72  {
73  public:
79  typedef boost::shared_ptr<ALProxy> Ptr;
85  typedef boost::weak_ptr<ALProxy> WeakPtr;
86 
87  typedef int (*onFinishedCallback)(const char*, int, const AL::ALValue &);
88 
93  boost::shared_ptr<ALProxy> getThis();
98  boost::shared_ptr<const ALProxy> getThis() const;
99 
105  {
106  NO_OPTION = 0,
107  FORCED_LOCAL = 1,
108  NO_LOAD_DEPENDS = 2,
109  MAIN_PROXY = 4
110  };
111 
119  ALProxy(boost::shared_ptr<ALBroker> pBroker,
120  const std::string &pModuleName,
121  int pProxyMask = 0,
122  int timeout = 0);
123 
129  ALProxy(const qi::SessionPtr& session, const std::string &serviceName);
130 
136  ALProxy(qi::AnyObject pObject, const std::string &pModuleName);
137 
146  ALProxy(const std::string &pModuleName,
147  const std::string &pIp,
148  int pPort,
149  int pProxyMask = 0,
150  int timeout = 0);
151 
161  ALProxy(const std::string &pModuleName,
162  const std::string &pIp,
163  int pPort,
164  boost::shared_ptr<ALBroker> pBroker,
165  int pProxyMask = 0,
166  int timeout = 0);
167 
169  virtual ~ALProxy(void);
170 
171  // This is not copyable
172  ALProxy(const ALProxy &rhs) = delete;
173  ALProxy& operator=(const ALProxy &rhs) = delete;
174 
175  // This is movable
176  // TODO VS2015: use default implementation
177  ALProxy(ALProxy&& other);
178  ALProxy& operator=(ALProxy&& other);
179 
183  std::string remoteBrokerName();
184 
196  AL::ALValue genericCall(const std::string &strMethodName,
197  const AL::ALValue &listParams);
198 
199 
217  int genericPCall(const std::string &strMethodName,
218  const AL::ALValue &listParams,
219  onFinishedCallback pCallbackToCallOnFinished = NULL,
220  const char *pszCallerName = NULL);
221 
226  std::string version();
227 
232  boost::shared_ptr<ALModule> getModule() const;
237  boost::shared_ptr<ALModuleCore> getModuleCore() const;
238 
244  int getInfo(ALModuleInfo &pModuleInfo);
245 
250  bool isLocal();
251 
258  bool isValid();
259 
266  boost::shared_ptr<ALFunctorBase> getFunctor(const std::string &pName,
267  const std::vector<std::string> &pParamTypes);
268 
273  boost::shared_ptr<ALBroker> getParentBroker(void) const;
274 
278  void destroyConnection(void);
279 
280  template <typename R>
281  R call(const std::string &pName);
282 
283  template <typename R, typename P1>
284  R call(const std::string &pName, const P1 &p1);
285 
286  template <typename R, typename P1, typename P2>
287  R call(const std::string &pName, const P1 &p1, const P2 &p2);
288 
289  template <typename R, typename P1, typename P2, typename P3>
290  R call(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3);
291 
292  template <typename R, typename P1, typename P2, typename P3, typename P4>
293  R call(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4);
294 
295  template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
296  R call(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5);
297 
298  template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
299  R call(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5, const P6 &p6);
300 
301  inline void callVoid(const std::string &pName);
302 
303  template <typename P1>
304  void callVoid(const std::string &pName, const P1 &p1);
305 
306  template <typename P1, typename P2>
307  void callVoid(const std::string &pName, const P1 &p1, const P2 &p2);
308 
309  template <typename P1, typename P2, typename P3>
310  void callVoid(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3);
311 
312  template <typename P1, typename P2, typename P3, typename P4>
313  void callVoid(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4);
314 
315  template <typename P1, typename P2, typename P3, typename P4, typename P5>
316  void callVoid(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5);
317 
318  template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
319  void callVoid(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5, const P6 &p6);
320 
321  inline int pCall(const std::string &pName);
322 
323  template <typename P1>
324  int pCall(const std::string &pName, const P1 &p1);
325 
326  template <typename P1, typename P2>
327  int pCall(const std::string &pName, const P1 &p1, const P2 &p2);
328 
329  template <typename P1, typename P2, typename P3>
330  int pCall(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3);
331 
332  template <typename P1, typename P2, typename P3, typename P4>
333  int pCall(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4);
334 
335  template <typename P1, typename P2, typename P3, typename P4, typename P5>
336  int pCall(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5);
337 
338  template <typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
339  int pCall(const std::string &pName, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5, const P6 &p6);
340 
351  bool wait(const int &id, const int &timeoutPeriod);
352 
359  qi::FutureSync<void> wait(const int &id);
360 
366  void stop(const int &id);
367 
374  bool isRunning(const int &id);
375 
382  int pCallNotify(const std::string &name,
383  const std::string &key,
384  const ALValue &value,
385  const ALValue &message = std::string(),
386  std::pair<int, int>* cache = 0);
387 
388  std::string moduleName() const;
389 
393  qi::AnyObject asObject();
394 
395  std::unique_ptr<ALProxyPrivate> _p;
396  qi::AnyWeakObject _object;
397  protected:
398  int xMetaPCall(const std::string &signature, const qi::GenericFunctionParameters &in);
399 
400  friend class AL::ALModuleCore;
402  }; // ALProxy
403 
404  typedef boost::shared_ptr<ALProxy> ALProxyPtr;
405 
411  template<typename ProxyType>
412  boost::shared_ptr<ProxyType> makeProxy(
413  const qi::SessionPtr& session,
414  const std::string& serviceName)
415  {
416  return boost::make_shared<ProxyType>(boost::make_shared<ALProxy>(session, serviceName));
417  }
418 } // namespace AL
419 
420 #include <alcommon/alproxy.hxx>
421 
422 #endif // _LIBALCOMMON_ALCOMMON_ALPROXY_H_
423 
boost::shared_ptr< ALProxy > Ptr
Shared pointer to ALProxy.
Definition: alproxy.h:79
ALProxy is a client to the served methods of a module.
Definition: alproxy.h:71
ALModuleInfo is the class of information about user modules.
Definition: almoduleinfo.h:27
ALModuleCore is the superclass of user modules.
Definition: almodulecore.h:57
#define ALCOMMON_API
Definition: api.h:14
boost::shared_ptr< ProxyType > makeProxy(const qi::SessionPtr &session, const std::string &serviceName)
Definition: alproxy.h:412
boost::weak_ptr< ALProxy > WeakPtr
Weak pointer to ALProxy.
Definition: alproxy.h:85
pProxyOption
Different options for the ALProxy.
Definition: alproxy.h:104
boost::shared_ptr< ALProxy > ALProxyPtr
Definition: alproxy.h:404