libalcommon  2.1.0.18
/home/opennao/work/master/sdk/libnaoqi/libalcommon/alcommon/alproxy.hxx
Go to the documentation of this file.
00001 
00007 #pragma once
00008 #ifndef _LIBALCOMMON_ALCOMMON_ALPROXY_HXX_
00009 #define _LIBALCOMMON_ALCOMMON_ALPROXY_HXX_
00010 
00011 #include <qitype/objecttypebuilder.hpp>
00012 
00013 namespace AL
00014 {
00015 
00016   #define pushi(z, n,_) args.push_back(::qi::AnyReference::from(p ## n));
00017   #define consti(z, n,_) , const P ## n & p ## n
00018   #define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma) \
00019   template<typename R comma ATYPEDECL>                      \
00020   R ALProxy::call(const std::string& pName  BOOST_PP_REPEAT(n, consti, _) )      \
00021 {                                                                     \
00022     qi::AnyObject object = _object.lock();                            \
00023     if (!object)                                                      \
00024       throw ALERROR(moduleName(), pName, "module destroyed");         \
00025     ::qi::GenericFunctionParameters args;                             \
00026     args.reserve(n);                                                  \
00027     BOOST_PP_REPEAT(n, pushi, _)                                      \
00028     try                                                               \
00029     {                                                                 \
00030       qi::AnyValue res(object.metaCall(pName, args).value(), false, true); \
00031       qi::Promise<R> prom(qi::FutureCallbackType_Sync);              \
00032       if (qi::detail::handleFuture(res.asReference(), prom))         \
00033       {                                                              \
00034         res.release(); /* handleFuture will free it */               \
00035         prom.future().wait();                                        \
00036         qiLogDebug("alproxy.call") << prom.future().hasError();      \
00037         return (R)prom.future().value();                             \
00038       }                                                              \
00039       else                                                           \
00040         return res.to<R>();                                          \
00041       /*return qi::AnyValue(object.metaCall(pName, args).value(), false, true).to<R>();*/   \
00042     }                                                                 \
00043     catch(const std::exception& e)                                    \
00044     {                                                                 \
00045       throw ALERROR(moduleName(), pName, e.what());                   \
00046     }                                                                 \
00047   }
00048   QI_GEN_RANGE(genCall, 7)
00049 #undef pushi
00050 #undef genCall
00051 
00052   #define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma) \
00053   QI_GEN_MAYBE_TEMPLATE_OPEN(comma) ATYPEDECL QI_GEN_MAYBE_TEMPLATE_CLOSE(comma) \
00054   inline void ALProxy::callVoid(const std::string& pName  BOOST_PP_REPEAT(n, consti, _))   \
00055   {                                                                     \
00056     call<void>(pName comma AUSE);                                       \
00057   }
00058 
00059 QI_GEN_RANGE(genCall, 7)
00060 #undef genCall
00061 #undef consti
00062 
00063   inline
00064   int ALProxy::pCall(const std::string& pName)
00065   {
00066     qi::AnyObject object = _object.lock();
00067     if (!object)
00068       throw ALERROR(moduleName(), pName, "module destroyed");
00069     qi::GenericFunctionParameters params;
00070     return xMetaPCall(pName, params);
00071   }
00072 
00073   template<typename P0>
00074   int ALProxy::pCall(const std::string& pName, const P0 &p0)
00075   {
00076     qi::AnyObject object = _object.lock();
00077     if (!object)
00078       throw ALERROR(moduleName(), pName, "module destroyed");
00079     qi::GenericFunctionParameters params;
00080     params.push_back(qi::AnyReference::from(p0));
00081     return xMetaPCall(pName, params);
00082   }
00083 
00084   template<typename P0, typename P1>
00085   int ALProxy::pCall(const std::string& pName, const P0 &p0, const P1 &p1)
00086   {
00087     qi::AnyObject object = _object.lock();
00088     if (!object)
00089       throw ALERROR(moduleName(), pName, "module destroyed");
00090     qi::GenericFunctionParameters params;
00091     params.push_back(qi::AnyReference::from(p0));
00092     params.push_back(qi::AnyReference::from(p1));
00093     return xMetaPCall(pName, params);
00094   }
00095 
00096   template<typename P0, typename P1, typename P2>
00097   int ALProxy::pCall(const std::string& pName, const P0 &p0, const P1 &p1, const P2 &p2)
00098   {
00099     qi::AnyObject object = _object.lock();
00100     if (!object)
00101       throw ALERROR(moduleName(), pName, "module destroyed");
00102     qi::GenericFunctionParameters params;
00103     params.push_back(qi::AnyReference::from(p0));
00104     params.push_back(qi::AnyReference::from(p1));
00105     params.push_back(qi::AnyReference::from(p2));
00106     return xMetaPCall(pName, params);
00107   }
00108 
00109   template<typename P0, typename P1, typename P2, typename P3>
00110   int ALProxy::pCall(const std::string& pName, const P0 &p0, const P1 &p1, const P2 &p2, const P3 &p3)
00111   {
00112     qi::AnyObject object = _object.lock();
00113     if (!object)
00114       throw ALERROR(moduleName(), pName, "module destroyed");
00115     qi::GenericFunctionParameters params;
00116     params.push_back(qi::AnyReference::from(p0));
00117     params.push_back(qi::AnyReference::from(p1));
00118     params.push_back(qi::AnyReference::from(p2));
00119     params.push_back(qi::AnyReference::from(p3));
00120     return xMetaPCall(pName, params);
00121   }
00122 
00123   template<typename P0, typename P1, typename P2, typename P3, typename P4>
00124   int ALProxy::pCall(const std::string& pName, const P0 &p0, const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4)
00125   {
00126     qi::AnyObject object = _object.lock();
00127     if (!object)
00128       throw ALERROR(moduleName(), pName, "module destroyed");
00129     qi::GenericFunctionParameters params;
00130     params.push_back(qi::AnyReference::from(p0));
00131     params.push_back(qi::AnyReference::from(p1));
00132     params.push_back(qi::AnyReference::from(p2));
00133     params.push_back(qi::AnyReference::from(p3));
00134     params.push_back(qi::AnyReference::from(p4));
00135     return xMetaPCall(pName, params);
00136   }
00137 
00138   template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>
00139   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)
00140   {
00141     qi::AnyObject object = _object.lock();
00142     if (!object)
00143       throw ALERROR(moduleName(), pName, "module destroyed");
00144     qi::GenericFunctionParameters params;
00145     params.push_back(qi::AnyReference::from(p0));
00146     params.push_back(qi::AnyReference::from(p1));
00147     params.push_back(qi::AnyReference::from(p2));
00148     params.push_back(qi::AnyReference::from(p3));
00149     params.push_back(qi::AnyReference::from(p4));
00150     params.push_back(qi::AnyReference::from(p5));
00151     return xMetaPCall(pName, params);
00152   }
00153 
00154 }
00155 #endif  // _LIBALCOMMON_ALCOMMON_ALPROXY_HXX_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines