libalcommon  2.8.7.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
alproxy.hxx
Go to the documentation of this file.
1 
7 #pragma once
8 #ifndef _LIBALCOMMON_ALCOMMON_ALPROXY_HXX_
9 #define _LIBALCOMMON_ALCOMMON_ALPROXY_HXX_
10 
11 #include <qi/type/objecttypebuilder.hpp>
12 
13 namespace AL
14 {
15 
16  #define pushi(z, n,_) args.push_back(::qi::AnyReference::from(p ## n));
17  #define consti(z, n,_) , const P ## n & p ## n
18  #define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma) \
19  template<typename R comma ATYPEDECL> \
20  R ALProxy::call(const std::string& pName BOOST_PP_REPEAT(n, consti, _) ) \
21 { \
22  qi::AnyObject object = _object.lock(); \
23  if (!object) \
24  throw ALERROR(moduleName(), pName, "module destroyed"); \
25  ::qi::GenericFunctionParameters args; \
26  args.reserve(n); \
27  BOOST_PP_REPEAT(n, pushi, _) \
28  try \
29  { \
30  qi::AnyValue res(object.metaCall(pName, args).value(), false, true); \
31  qi::Promise<R> prom(qi::FutureCallbackType_Sync); \
32  if (qi::detail::handleFuture(res.asReference(), prom)) \
33  { \
34  res.release(); /* handleFuture will free it */ \
35  prom.future().wait(); \
36  qiLogDebug("alproxy.call") << prom.future().hasError(); \
37  return (R)prom.future().value(); \
38  } \
39  else \
40  return res.to<R>(); \
41  /*return qi::AnyValue(object.metaCall(pName, args).value(), false, true).to<R>();*/ \
42  } \
43  catch(const std::exception& e) \
44  { \
45  throw ALERROR(moduleName(), pName, e.what()); \
46  } \
47  }
48  QI_GEN_RANGE(genCall, 7)
49 #undef pushi
50 #undef genCall
51 
52  #define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma) \
53  QI_GEN_MAYBE_TEMPLATE_OPEN(comma) ATYPEDECL QI_GEN_MAYBE_TEMPLATE_CLOSE(comma) \
54  inline void ALProxy::callVoid(const std::string& pName BOOST_PP_REPEAT(n, consti, _)) \
55  { \
56  call<void>(pName comma AUSE); \
57  }
58 
59 QI_GEN_RANGE(genCall, 7)
60 #undef genCall
61 #undef consti
62 
63  inline
64  int ALProxy::pCall(const std::string& pName)
65  {
66  qi::AnyObject object = _object.lock();
67  if (!object)
68  throw ALERROR(moduleName(), pName, "module destroyed");
69  qi::GenericFunctionParameters params;
70  return xMetaPCall(pName, params);
71  }
72 
73  template<typename P0>
74  int ALProxy::pCall(const std::string& pName, const P0 &p0)
75  {
76  qi::AnyObject object = _object.lock();
77  if (!object)
78  throw ALERROR(moduleName(), pName, "module destroyed");
79  qi::GenericFunctionParameters params;
80  params.push_back(qi::AnyReference::from(p0));
81  return xMetaPCall(pName, params);
82  }
83 
84  template<typename P0, typename P1>
85  int ALProxy::pCall(const std::string& pName, const P0 &p0, const P1 &p1)
86  {
87  qi::AnyObject object = _object.lock();
88  if (!object)
89  throw ALERROR(moduleName(), pName, "module destroyed");
90  qi::GenericFunctionParameters params;
91  params.push_back(qi::AnyReference::from(p0));
92  params.push_back(qi::AnyReference::from(p1));
93  return xMetaPCall(pName, params);
94  }
95 
96  template<typename P0, typename P1, typename P2>
97  int ALProxy::pCall(const std::string& pName, const P0 &p0, const P1 &p1, const P2 &p2)
98  {
99  qi::AnyObject object = _object.lock();
100  if (!object)
101  throw ALERROR(moduleName(), pName, "module destroyed");
102  qi::GenericFunctionParameters params;
103  params.push_back(qi::AnyReference::from(p0));
104  params.push_back(qi::AnyReference::from(p1));
105  params.push_back(qi::AnyReference::from(p2));
106  return xMetaPCall(pName, params);
107  }
108 
109  template<typename P0, typename P1, typename P2, typename P3>
110  int ALProxy::pCall(const std::string& pName, const P0 &p0, const P1 &p1, const P2 &p2, const P3 &p3)
111  {
112  qi::AnyObject object = _object.lock();
113  if (!object)
114  throw ALERROR(moduleName(), pName, "module destroyed");
115  qi::GenericFunctionParameters params;
116  params.push_back(qi::AnyReference::from(p0));
117  params.push_back(qi::AnyReference::from(p1));
118  params.push_back(qi::AnyReference::from(p2));
119  params.push_back(qi::AnyReference::from(p3));
120  return xMetaPCall(pName, params);
121  }
122 
123  template<typename P0, typename P1, typename P2, typename P3, typename P4>
124  int ALProxy::pCall(const std::string& pName, const P0 &p0, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4)
125  {
126  qi::AnyObject object = _object.lock();
127  if (!object)
128  throw ALERROR(moduleName(), pName, "module destroyed");
129  qi::GenericFunctionParameters params;
130  params.push_back(qi::AnyReference::from(p0));
131  params.push_back(qi::AnyReference::from(p1));
132  params.push_back(qi::AnyReference::from(p2));
133  params.push_back(qi::AnyReference::from(p3));
134  params.push_back(qi::AnyReference::from(p4));
135  return xMetaPCall(pName, params);
136  }
137 
138  template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>
139  int ALProxy::pCall(const std::string& pName, const P0 &p0, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5)
140  {
141  qi::AnyObject object = _object.lock();
142  if (!object)
143  throw ALERROR(moduleName(), pName, "module destroyed");
144  qi::GenericFunctionParameters params;
145  params.push_back(qi::AnyReference::from(p0));
146  params.push_back(qi::AnyReference::from(p1));
147  params.push_back(qi::AnyReference::from(p2));
148  params.push_back(qi::AnyReference::from(p3));
149  params.push_back(qi::AnyReference::from(p4));
150  params.push_back(qi::AnyReference::from(p5));
151  return xMetaPCall(pName, params);
152  }
153 
154 }
155 #endif // _LIBALCOMMON_ALCOMMON_ALPROXY_HXX_
#define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma)
Definition: alproxy.hxx:52
int pCall(const std::string &pName)
Definition: alproxy.hxx:64