8 #ifndef _LIBALCOMMON_ALCOMMON_ALPROXY_HXX_
9 #define _LIBALCOMMON_ALCOMMON_ALPROXY_HXX_
11 #include <alcommon/detail/alpcall.h>
16 #define CHECK_RESULT() \
17 if (getParamStrType<R>() != lDesc->returnInfo.strType) \
19 throw ALERROR("ALProxy", "call", \
20 std::string("wrong return type for function '") + \
22 " type is '" + getParamStrType<R>() + "'" + \
23 " instead of '" + lDesc->returnInfo.strType); \
26 #define CHECK_PARAM(x) \
27 if (getParamStrType<P ## x>() != lDesc->parameters[x-1].strType) \
29 throw ALERROR("ALProxy", "call/pCall", \
30 std::string("When trying to call module '") + \
31 xGetModuleName() + "'" \
32 " function '" + pName + "' parameter #" + \
34 " is of type " + getParamStrType<P ## x>() + \
35 " instead of type " + \
36 lDesc->parameters[x-1].strType); \
40 R ALProxy::call(
const std::string& pName)
48 xExecute(pName, param, result);
49 AL::detail::converter<R> conv;
50 return conv.convertFromALValue(result);
52 ALMethodInfo *lDesc = xLookupMethod(pName);
55 std::vector<std::string> param;
56 lDesc = xLookupMethod(pName, param,
true);
59 return (*(detail::ALFunctor_0<ALModule, R> *)(lDesc->getFunction()))();
62 CALL_METHODS(pName, p, r);
64 throw ALERROR(
"ALProxy",
"call",
"Waiting for the result of a void function");
65 AL::detail::converter<R> conv;
66 return conv.convertFromALValue(r);
69 template <
typename R,
typename P1>
70 R ALProxy::call(
const std::string& pName,
const P1 &p1)
80 xExecute(pName, param, result);
81 AL::detail::converter<R> conv;
82 R resultConv = conv.convertFromALValue(result);
85 ALMethodInfo *lDesc = xLookupMethod(pName);
88 std::vector<std::string> param;
89 param.push_back(getParamStrType<P1>());
90 lDesc = xLookupMethod(pName, param,
false);
94 return (*(detail::ALFunctor_1<ALModule, P1, R> *)(lDesc->getFunction()))(p1);
99 CALL_METHODS(pName, p, r);
102 std::string error = std::string(
"Waiting for the result of a void function ") + pName + std::string(
" ") + p.
toString(VerbosityMini) + std::string(
" ") + r.
toString(VerbosityMini);
103 throw ALERROR(
"ALProxy",
"call", error);
105 AL::detail::converter<R> conv;
106 R resultConv = conv.convertFromALValue(r);
111 template <
typename R,
typename P1,
typename P2>
112 R ALProxy::call(
const std::string& pName,
const P1 &p1,
const P2 &p2)
123 xExecute(pName, param, result);
126 ALMethodInfo *lDesc = xLookupMethod(pName);
129 std::vector<std::string> param;
130 param.push_back(getParamStrType<P1>());
131 param.push_back(getParamStrType<P2>());
132 lDesc = xLookupMethod(pName, param,
false);
137 return (*(detail::ALFunctor_2<ALModule, P1, P2, R> *)(lDesc->getFunction()))(p1, p2);
143 CALL_METHODS(pName, p, r);
145 throw ALERROR(
"ALProxy",
"call",
"Waiting for the result of a void function");
146 AL::detail::converter<R> conv;
147 R resultConv = conv.convertFromALValue(r);
152 template <
typename R,
typename P1,
typename P2,
typename P3>
153 R ALProxy::call(
const std::string& pName,
const P1 &p1,
const P2 &p2,
const P3 &p3)
165 xExecute(pName, param, result);
168 ALMethodInfo *lDesc = xLookupMethod(pName);
171 std::vector<std::string> param;
172 param.push_back(getParamStrType<P1>());
173 param.push_back(getParamStrType<P2>());
174 param.push_back(getParamStrType<P3>());
175 lDesc = xLookupMethod(pName, param,
false);
181 return (*(detail::ALFunctor_3<ALModule, P1, P2, P3, R> *)(lDesc->getFunction()))(p1, p2, p3);
189 CALL_METHODS(pName, p, r);
191 throw ALERROR(
"ALProxy",
"call",
"Waiting for the result of a void function");
192 AL::detail::converter<R> conv;
193 R resultConv = conv.convertFromALValue(r);
198 template <
typename R,
typename P1,
typename P2,
typename P3,
typename P4>
199 R ALProxy::call(
const std::string& pName,
const P1 &p1,
const P2 &p2,
const P3 &p3,
const P4 &p4)
212 xExecute(pName, param, result);
215 ALMethodInfo *lDesc = xLookupMethod(pName);
218 std::vector<std::string> param;
219 param.push_back(getParamStrType<P1>());
220 param.push_back(getParamStrType<P2>());
221 param.push_back(getParamStrType<P3>());
222 param.push_back(getParamStrType<P4>());
223 lDesc = xLookupMethod(pName, param,
false);
230 return (*(detail::ALFunctor_4<ALModule, P1, P2, P3, P4, R> *)(lDesc->getFunction()))(p1, p2, p3, p4);
238 CALL_METHODS(pName, p, r);
240 throw ALERROR(
"ALProxy",
"call",
"Waiting for the result of a void function");
241 AL::detail::converter<R> conv;
242 R resultConv = conv.convertFromALValue(r);
247 template <
typename R,
typename P1,
typename P2,
typename P3,
typename P4,
typename P5>
248 R ALProxy::call(
const std::string& pName,
const P1 &p1,
const P2 &p2,
const P3 &p3,
const P4 &p4,
const P5 &p5)
262 xExecute(pName, param, result);
265 ALMethodInfo *lDesc = xLookupMethod(pName);
268 std::vector<std::string> param;
269 param.push_back(getParamStrType<P1>());
270 param.push_back(getParamStrType<P2>());
271 param.push_back(getParamStrType<P3>());
272 param.push_back(getParamStrType<P4>());
273 param.push_back(getParamStrType<P5>());
274 lDesc = xLookupMethod(pName, param,
false);
282 return (*(detail::ALFunctor_5<ALModule, P1, P2, P3, P4, P5, R> *)(lDesc->getFunction()))(p1, p2, p3, p4, p5);
291 CALL_METHODS(pName, p, r);
293 throw ALERROR(
"ALProxy",
"call",
"Waiting for the result of a void function");
294 AL::detail::converter<R> conv;
295 R resultConv = conv.convertFromALValue(r);
300 template <
typename R,
typename P1,
typename P2,
typename P3,
typename P4,
typename P5,
typename P6>
301 R ALProxy::call(
const std::string& pName,
const P1 &p1,
const P2 &p2,
const P3 &p3,
const P4 &p4,
const P5 &p5,
const P6 &p6)
316 xExecute(pName, param, result);
320 ALMethodInfo *lDesc = xLookupMethod(pName);
322 throw ALERROR(
"ALProxy",
"call",
"Function does not exist");
330 return (*(detail::ALFunctor_6<ALModule, P1, P2, P3, P4, P5, P6, R> *)(lDesc->getFunction()))(p1, p2, p3, p4, p5, p6);
340 CALL_METHODS(pName, p, r);
342 throw ALERROR(
"ALProxy",
"call",
"Waiting for the result of a void function");
343 AL::detail::converter<R> conv;
344 R resultConv = conv.convertFromALValue(r);
349 void ALProxy::callVoid(
const std::string& pName)
357 xExecute(pName, param, result);
360 ALMethodInfo *lDesc = xLookupMethod(pName);
362 throw ALERROR(
"ALProxy",
"getMethodInfo", std::string(
"Function ") + pName +
" does not exist in module " + xGetModuleName() );
363 (*(detail::ALFunctor_0<ALModule, ALVoid> *)(xLookupMethod(pName)->
ptrOnMethod.get()))();
367 CALL_METHODS(pName, p, r);
371 template <
typename P1>
372 void ALProxy::callVoid(
const std::string& pName,
const P1 &p1)
381 AL::detail::converter<P1> conv;
382 param[0] = conv.convertToALValue(p1);
383 xExecute(pName, param, result);
386 ALMethodInfo *lDesc = xLookupMethod(pName);
389 std::vector<std::string> param;
390 param.push_back(getParamStrType<P1>());
391 lDesc = xLookupMethod(pName, param,
false);
394 (*(detail::ALFunctor_1<ALModule, P1, void> *)(lDesc->getFunction()))(p1);
399 AL::detail::converter<P1> conv;
400 p[0] = conv.convertToALValue(p1);
401 CALL_METHODS(pName, p, r);
405 template <
typename P1,
typename P2>
406 void ALProxy::callVoid(
const std::string& pName,
const P1 &p1,
const P2 &p2)
417 xExecute(pName, param, result);
420 ALMethodInfo *lDesc = xLookupMethod(pName);
423 std::vector<std::string> param;
424 param.push_back(getParamStrType<P1>());
425 param.push_back(getParamStrType<P2>());
426 lDesc = xLookupMethod(pName, param,
false);
430 (*(detail::ALFunctor_2<ALModule, P1, P2, void> *)(lDesc->getFunction()))(p1, p2);
437 CALL_METHODS(pName, p, r);
440 template <
typename P1,
typename P2,
typename P3>
441 void ALProxy::callVoid(
const std::string& pName,
const P1 &p1,
const P2 &p2,
const P3 &p3)
453 xExecute(pName, param, result);
456 ALMethodInfo *lDesc = xLookupMethod(pName);
459 std::vector<std::string> param;
460 param.push_back(getParamStrType<P1>());
461 param.push_back(getParamStrType<P2>());
462 param.push_back(getParamStrType<P3>());
463 lDesc = xLookupMethod(pName, param,
false);
468 (*(detail::ALFunctor_3<ALModule, P1, P2, P3, void> *)(lDesc->getFunction()))(p1, p2, p3);
476 CALL_METHODS(pName, p, r);
479 template <
typename P1,
typename P2,
typename P3,
typename P4>
480 void ALProxy::callVoid(
const std::string& pName,
const P1 &p1,
const P2 &p2,
const P3 &p3,
const P4 &p4)
493 xExecute(pName, param, result);
496 ALMethodInfo *lDesc = xLookupMethod(pName);
499 std::vector<std::string> param;
500 param.push_back(getParamStrType<P1>());
501 param.push_back(getParamStrType<P2>());
502 param.push_back(getParamStrType<P3>());
503 param.push_back(getParamStrType<P4>());
504 lDesc = xLookupMethod(pName, param,
false);
510 (*(detail::ALFunctor_4<ALModule, P1, P2, P3, P4, ALVoid> *)(lDesc->getFunction()))(p1, p2, p3, p4);
519 CALL_METHODS(pName, p, r);
522 template <
typename P1,
typename P2,
typename P3,
typename P4,
typename P5>
523 void ALProxy::callVoid(
const std::string& pName,
const P1 &p1,
const P2 &p2,
const P3 &p3,
const P4 &p4,
const P5 &p5)
537 xExecute(pName, param, result);
540 ALMethodInfo *lDesc = xLookupMethod(pName);
543 std::vector<std::string> param;
544 param.push_back(getParamStrType<P1>());
545 param.push_back(getParamStrType<P2>());
546 param.push_back(getParamStrType<P3>());
547 param.push_back(getParamStrType<P4>());
548 param.push_back(getParamStrType<P5>());
549 lDesc = xLookupMethod(pName, param,
false);
556 (*(detail::ALFunctor_5<ALModule, P1, P2, P3, P4, P5, ALVoid> *)(lDesc->getFunction()))(p1, p2, p3, p4, p5);
566 CALL_METHODS(pName, p, r);
570 template <
typename P1,
typename P2,
typename P3,
typename P4,
typename P5,
typename P6>
571 void ALProxy::callVoid(
const std::string& pName,
const P1 &p1,
const P2 &p2,
const P3 &p3,
const P4 &p4,
const P5 &p5,
const P6 &p6)
587 xExecute(pName, param, result);
590 ALMethodInfo *lDesc = xLookupMethod(pName);
592 throw ALERROR(
"ALProxy",
"call",
"Function does not exist");
599 (*(detail::ALFunctor_6<ALModule, P1, P2, P3, P4, P5, P6, ALVoid> *)(lDesc->getFunction()))(p1, p2, p3, p4, p5, p6);
610 CALL_METHODS(pName, p, r);
614 int ALProxy::pCall(
const std::string& pName)
621 return xPCallScript(pName, param);
623 ALMethodInfo *lDesc = xLookupMethod(pName);
625 throw ALERROR(
"ALProxy",
"getMethodInfo", std::string(
"Function ") + pName +
" does not exist in module " + xGetModuleName() );
626 boost::shared_ptr<detail::ALTaskInfo> r = xCreateTaskInfo(pName);
627 detail::PCallBase *pcall(
new detail::_pcall0((detail::ALFunctor_0<ALModule, ALVoid> *)(lDesc->getFunction()),r,
getModuleCore()));
628 xAddTask(r->toString(), pcall);
632 PCALL_METHODS(pName, p, r);
637 template <
typename P1>
638 int ALProxy::pCall(
const std::string& pName,
const P1 &p1)
646 AL::detail::converter<P1> conv;
647 param[0] = conv.convertToALValue(p1);
648 return xPCallScript(pName, param);
650 ALMethodInfo *lDesc = xLookupMethod(pName);
653 std::vector<std::string> param;
654 param.push_back(getParamStrType<P1>());
655 lDesc = xLookupMethod(pName, param,
true);
658 boost::shared_ptr<detail::ALTaskInfo> r = xCreateTaskInfo(pName);
659 detail::PCallBase *task(
new detail::_pcall1<P1>((detail::ALFunctor_1<ALModule, P1, ALVoid> *)(lDesc->getFunction()), p1,
getModuleCore(),r ));
660 xAddTask(r->toString(), task);
665 AL::detail::converter<P1> conv;
666 p[0] = conv.convertToALValue(p1);
667 PCALL_METHODS(pName, p, r);
672 template <
typename P1,
typename P2>
673 int ALProxy::pCall(
const std::string& pName,
const P1 &p1,
const P2 &p2)
683 return xPCallScript(pName, param);
685 ALMethodInfo *lDesc = xLookupMethod(pName);
688 std::vector<std::string> param;
689 param.push_back(getParamStrType<P1>());
690 param.push_back(getParamStrType<P2>());
691 lDesc = xLookupMethod(pName, param,
true);
695 boost::shared_ptr<detail::ALTaskInfo> r = xCreateTaskInfo(pName);
696 detail::PCallBase *task(
new detail::_pcall2<P1, P2>((detail::ALFunctor_2<ALModule, P1, P2, ALVoid> *)(lDesc->getFunction()), p1, p2,
getModuleCore(), r));
697 xAddTask(r->toString(), task);
704 PCALL_METHODS(pName, p, r);
708 template <
typename P1,
typename P2,
typename P3>
709 int ALProxy::pCall(
const std::string& pName,
const P1 &p1,
const P2 &p2,
const P3 &p3)
720 return xPCallScript(pName, param);
722 ALMethodInfo *lDesc = xLookupMethod(pName);
725 std::vector<std::string> param;
726 param.push_back(getParamStrType<P1>());
727 param.push_back(getParamStrType<P2>());
728 param.push_back(getParamStrType<P3>());
729 lDesc = xLookupMethod(pName, param,
true);
734 boost::shared_ptr<detail::ALTaskInfo> r = xCreateTaskInfo(pName);
735 detail::PCallBase *task(
new detail::_pcall3<P1, P2, P3>((detail::ALFunctor_3<ALModule, P1, P2, P3, ALVoid> *)(lDesc->getFunction()), p1, p2, p3,
getModuleCore(),r));
736 xAddTask(r->toString(), task);
744 PCALL_METHODS(pName, p, r);
748 template <
typename P1,
typename P2,
typename P3,
typename P4>
749 int ALProxy::pCall(
const std::string& pName,
const P1 &p1,
const P2 &p2,
const P3 &p3,
const P4 &p4)
761 return xPCallScript(pName, param);
763 ALMethodInfo *lDesc = xLookupMethod(pName);
766 std::vector<std::string> param;
767 param.push_back(getParamStrType<P1>());
768 param.push_back(getParamStrType<P2>());
769 param.push_back(getParamStrType<P3>());
770 param.push_back(getParamStrType<P4>());
771 lDesc = xLookupMethod(pName, param,
true);
777 boost::shared_ptr<detail::ALTaskInfo> r = xCreateTaskInfo(pName);
778 detail::PCallBase *task(
new detail::_pcall4<P1, P2, P3, P4>((detail::ALFunctor_4<ALModule, P1, P2, P3, P4, ALVoid> *)(lDesc->getFunction()), p1, p2, p3, p4,
getModuleCore(), r ));
779 xAddTask(r->toString(), task);
788 PCALL_METHODS(pName, p, r);
792 template <
typename P1,
typename P2,
typename P3,
typename P4,
typename P5>
793 int ALProxy::pCall(
const std::string& pName,
const P1 &p1,
const P2 &p2,
const P3 &p3,
const P4 &p4,
const P5 &p5)
806 return xPCallScript(pName, param);
808 ALMethodInfo *lDesc = xLookupMethod(pName);
811 std::vector<std::string> param;
812 param.push_back(getParamStrType<P1>());
813 param.push_back(getParamStrType<P2>());
814 param.push_back(getParamStrType<P3>());
815 param.push_back(getParamStrType<P4>());
816 param.push_back(getParamStrType<P5>());
817 lDesc = xLookupMethod(pName, param,
false);
824 boost::shared_ptr<detail::ALTaskInfo> r = xCreateTaskInfo(pName);
825 detail::PCallBase *task(
new detail::_pcall5<P1, P2, P3, P4, P5>((detail::ALFunctor_5<ALModule, P1, P2, P3, P4, P5, ALVoid> *)(lDesc->getFunction()), p1, p2, p3, p4, p5,
getModuleCore(), r));
826 xAddTask(r->toString(), task);
836 PCALL_METHODS(pName, p, r);
841 template <
typename P1,
typename P2,
typename P3,
typename P4,
typename P5,
typename P6>
842 int ALProxy::pCall(
const std::string& pName,
const P1 &p1,
const P2 &p2,
const P3 &p3,
const P4 &p4,
const P5 &p5,
const P6 &p6)
856 return xPCallScript(pName, param);
858 ALMethodInfo *lDesc = xLookupMethod(pName);
860 throw ALERROR(
"ALProxy",
"call",
"Function does not exist");
867 boost::shared_ptr<detail::ALTaskInfo> r = xCreateTaskInfo(pName);
868 detail::PCallBase *task(
new detail::_pcall6<P1, P2, P3, P4, P5, P6>((detail::ALFunctor_6<ALModule, P1, P2, P3, P4, P5, P6, ALVoid> *)(lDesc->getFunction()), p1, p2, p3, p4, p5, p6,
getModuleCore(), r));
869 xAddTask(r->toString(), task);
880 PCALL_METHODS(pName, p, r);
885 #endif // _LIBALCOMMON_ALCOMMON_ALPROXY_HXX_