00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef ORO_REMOTE_METHOD_HPP
00040 #define ORO_REMOTE_METHOD_HPP
00041
00042 #include <boost/function.hpp>
00043 #include <string>
00044 #include "../base/OperationCallerBase.hpp"
00045 #include "OperationCallerC.hpp"
00046 #include "DataSourceStorage.hpp"
00047 #include "Invoker.hpp"
00048
00049 #include <boost/fusion/include/vector_tie.hpp>
00050 #include <boost/fusion/include/filter_if.hpp>
00051 #include <boost/fusion/include/as_vector.hpp>
00052
00053
00054
00055 namespace RTT
00056 {
00057 namespace internal
00058 {
00059 namespace bf = ::boost::fusion;
00060
00070 template<class OperationCallerT>
00071 class RemoteOperationCallerImpl
00072 : public base::OperationCallerBase<OperationCallerT>,
00073 public internal::CollectBase<OperationCallerT>
00074 {
00075 protected:
00076 OperationCallerC mmeth;
00077 SendHandleC mhandle;
00078 DataSourceStorage<OperationCallerT> sendargs;
00079 DataSourceStorage<typename CollectType<OperationCallerT>::type > collectargs;
00080 public:
00081 typedef OperationCallerT Signature;
00082 typedef typename boost::function_traits<OperationCallerT>::result_type result_type;
00083
00087 RemoteOperationCallerImpl()
00088 : mmeth(), mhandle()
00089 {}
00090
00094 RemoteOperationCallerImpl(SendHandleC handle)
00095 : mmeth(), mhandle(handle)
00096 {}
00097
00098 virtual void executeAndDispose() { assert(false); }
00099 virtual bool isError() const { return false; }
00100 virtual void dispose() { assert(false); }
00101
00107 template<class Xignored>
00108 result_type call_impl() {
00109 mmeth.call();
00110 return sendargs.getResult();
00111 }
00112
00113 template<class T1>
00114 result_type call_impl( T1 a1 ) {
00115 sendargs.store( a1 );
00116 mmeth.call();
00117 return sendargs.getResult();
00118 }
00119
00120 template<class T1, class T2>
00121 result_type call_impl( T1 a1, T2 a2 ) {
00122 sendargs.store( a1, a2 );
00123 mmeth.call();
00124 return sendargs.getResult();
00125 }
00126
00127 template<class T1, class T2, class T3>
00128 result_type call_impl( T1 a1, T2 a2, T3 a3 ) {
00129 sendargs.store( a1, a2, a3 );
00130 mmeth.call();
00131 return sendargs.getResult();
00132 }
00133
00134 template<class T1, class T2, class T3, class T4>
00135 result_type call_impl( T1 a1, T2 a2, T3 a3, T4 a4 ) {
00136 sendargs.store( a1, a2, a3, a4 );
00137 mmeth.call();
00138 return sendargs.getResult();
00139 }
00140
00141 template<class T1, class T2, class T3, class T4, class T5, class T6>
00142 result_type call_impl( T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6 ) {
00143 sendargs.store( a1, a2, a3, a4, a5, a6 );
00144 mmeth.call();
00145 return sendargs.getResult();
00146 }
00147
00148 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7>
00149 result_type call_impl( T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7 ) {
00150 sendargs.store( a1, a2, a3, a4, a5, a6, a7 );
00151 mmeth.call();
00152 return sendargs.getResult();
00153 }
00154
00155 template<class T1, class T2, class T3, class T4, class T5>
00156 result_type call_impl( T1 a1, T2 a2, T3 a3, T4 a4, T5 a5 ) {
00157 sendargs.store( a1, a2, a3, a4, a5 );
00158 mmeth.call();
00159 return sendargs.getResult();
00160 }
00161
00162 SendHandle<Signature> send_impl() {
00163 mhandle = mmeth.send();
00164
00165 return SendHandle<Signature>( boost::make_shared< RemoteOperationCaller<OperationCallerT> >( mhandle ) );
00166 }
00167
00168 template<class T1>
00169 SendHandle<Signature> send_impl( T1 a1 ) {
00170 sendargs.store( a1 );
00171 mhandle = mmeth.send();
00172 return SendHandle<Signature>( boost::make_shared< RemoteOperationCaller<OperationCallerT> >( mhandle ) );
00173 }
00174
00175 template<class T1, class T2>
00176 SendHandle<Signature> send_impl( T1 a1, T2 a2 ) {
00177 sendargs.store( a1, a2 );
00178 mhandle = mmeth.send();
00179 return SendHandle<Signature>( boost::make_shared< RemoteOperationCaller<OperationCallerT> >( mhandle ) );
00180 }
00181
00182 template<class T1, class T2, class T3>
00183 SendHandle<Signature> send_impl( T1 a1, T2 a2, T3 a3 ) {
00184 sendargs.store( a1, a2, a3 );
00185 mhandle = mmeth.send();
00186 return SendHandle<Signature>( boost::make_shared< RemoteOperationCaller<OperationCallerT> >( mhandle ) );
00187 }
00188
00189 template<class T1, class T2, class T3, class T4>
00190 SendHandle<Signature> send_impl( T1 a1, T2 a2, T3 a3, T4 a4 ) {
00191 sendargs.store( a1, a2, a3, a4 );
00192 mhandle = mmeth.send();
00193 return SendHandle<Signature>( boost::make_shared< RemoteOperationCaller<OperationCallerT> >( mhandle ) );
00194 }
00195
00196 template<class T1, class T2, class T3, class T4, class T5>
00197 SendHandle<Signature> send_impl( T1 a1, T2 a2, T3 a3, T4 a4, T5 a5 ) {
00198 sendargs.store( a1, a2, a3, a4, a5 );
00199 mhandle = mmeth.send();
00200 return SendHandle<Signature>( boost::make_shared< RemoteOperationCaller<OperationCallerT> >( mhandle ) );
00201 }
00202
00203 template<class T1, class T2, class T3, class T4, class T5, class T6>
00204 SendHandle<Signature> send_impl( T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6 ) {
00205 sendargs.store( a1, a2, a3, a4, a5, a6 );
00206 mhandle = mmeth.send();
00207 return SendHandle<Signature>( boost::make_shared< RemoteOperationCaller<OperationCallerT> >( mhandle ) );
00208 }
00209
00210 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7>
00211 SendHandle<Signature> send_impl( T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7 ) {
00212 sendargs.store( a1, a2, a3, a4, a5, a6, a7 );
00213 mhandle = mmeth.send();
00214 return SendHandle<Signature>( boost::make_shared< RemoteOperationCaller<OperationCallerT> >( mhandle ) );
00215 }
00216
00217 SendStatus collectIfDone_impl() {
00218 if ( mhandle.collectIfDone() == SendSuccess ) {
00219 return SendSuccess;
00220 } else
00221 return SendNotReady;
00222 }
00223
00224 template<class T1>
00225 SendStatus collectIfDone_impl( T1& a1 ) {
00226 collectargs.store( a1 );
00227 if ( mhandle.collectIfDone() == SendSuccess ) {
00228 return SendSuccess;
00229 } else
00230 return SendNotReady;
00231 }
00232
00233 template<class T1, class T2>
00234 SendStatus collectIfDone_impl( T1& a1, T2& a2 ) {
00235 collectargs.store( a1, a2);
00236 if ( mhandle.collectIfDone() == SendSuccess ) {
00237 return SendSuccess;
00238 }
00239 return SendNotReady;
00240 }
00241
00242 template<class T1, class T2, class T3>
00243 SendStatus collectIfDone_impl( T1& a1, T2& a2, T3& a3 ) {
00244 collectargs.store( a1, a2, a3);
00245 if ( mhandle.collectIfDone() == SendSuccess ) {
00246 return SendSuccess;
00247 } else
00248 return SendNotReady;
00249 }
00250
00251 template<class T1, class T2, class T3, class T4>
00252 SendStatus collectIfDone_impl( T1& a1, T2& a2, T3& a3, T4& a4 ) {
00253 collectargs.store( a1, a2, a3, a4);
00254 if ( mhandle.collectIfDone() == SendSuccess ) {
00255 return SendSuccess;
00256 } else
00257 return SendNotReady;
00258 }
00259
00260 template<class T1, class T2, class T3, class T4, class T5, class T6>
00261 SendStatus collectIfDone_impl( T1& a1, T2& a2, T3& a3, T4& a4, T5& a5, T6& a6 ) {
00262 collectargs.store( a1, a2, a3, a4, a5, a6);
00263 if ( mhandle.collectIfDone() == SendSuccess ) {
00264 return SendSuccess;
00265 } else
00266 return SendNotReady;
00267 }
00268
00269 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7>
00270 SendStatus collectIfDone_impl( T1& a1, T2& a2, T3& a3, T4& a4, T5& a5, T6& a6, T7& a7 ) {
00271 collectargs.store( a1, a2, a3, a4, a5, a6, a7 );
00272 if ( mhandle.collectIfDone() == SendSuccess ) {
00273 return SendSuccess;
00274 } else
00275 return SendNotReady;
00276 }
00277
00278 template<class T1, class T2, class T3, class T4, class T5>
00279 SendStatus collectIfDone_impl( T1& a1, T2& a2, T3& a3, T4& a4, T5& a5 ) {
00280 collectargs.store( a1, a2, a3, a4, a5);
00281 if ( mhandle.collectIfDone() == SendSuccess ) {
00282 return SendSuccess;
00283 } else
00284 return SendNotReady;
00285 }
00286
00287 SendStatus collect_impl() {
00288 return mhandle.collect();
00289 }
00290 template<class T1>
00291 SendStatus collect_impl( T1& a1 ) {
00292 collectargs.store( a1 );
00293 return mhandle.collect();
00294 }
00295
00296 template<class T1, class T2>
00297 SendStatus collect_impl( T1& a1, T2& a2 ) {
00298 collectargs.store( a1, a2);
00299 return mhandle.collect();
00300 }
00301
00302 template<class T1, class T2, class T3>
00303 SendStatus collect_impl( T1& a1, T2& a2, T3& a3 ) {
00304 collectargs.store( a1, a2, a3);
00305 return mhandle.collect();
00306 }
00307
00308 template<class T1, class T2, class T3, class T4>
00309 SendStatus collect_impl( T1& a1, T2& a2, T3& a3, T4& a4 ) {
00310 collectargs.store( a1, a2, a3, a4);
00311 return mhandle.collect();
00312 }
00313
00314 template<class T1, class T2, class T3, class T4, class T5>
00315 SendStatus collect_impl( T1& a1, T2& a2, T3& a3, T4& a4, T5& a5 ) {
00316 collectargs.store( a1, a2, a3, a4, a5);
00317 return mhandle.collect();
00318 }
00319
00320 result_type ret_impl()
00321 {
00322 return sendargs.getResult();
00323 }
00324
00330 template<class T1>
00331 result_type ret_impl(T1 a1)
00332 {
00333 sendargs.store( a1 );
00334 mhandle.collectIfDone();
00335 return sendargs.getResult();
00336 }
00337
00338 template<class T1,class T2>
00339 result_type ret_impl(T1 a1, T2 a2)
00340 {
00341 sendargs.store( a1, a2 );
00342 mhandle.collectIfDone();
00343 return sendargs.getResult();
00344 }
00345
00346 template<class T1,class T2, class T3>
00347 result_type ret_impl(T1 a1, T2 a2, T3 a3)
00348 {
00349 sendargs.store( a1, a2, a3 );
00350 mhandle.collectIfDone();
00351 return sendargs.getResult();
00352 }
00353
00354 template<class T1,class T2, class T3, class T4>
00355 result_type ret_impl(T1 a1, T2 a2, T3 a3, T4 a4)
00356 {
00357 sendargs.store( a1, a2, a3, a4 );
00358 mhandle.collectIfDone();
00359 return sendargs.getResult();
00360 }
00361
00362 template<class T1,class T2, class T3, class T4, class T5, class T6>
00363 result_type ret_impl(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
00364 {
00365 sendargs.store( a1, a2, a3, a4, a5, a6 );
00366 mhandle.collectIfDone();
00367 return sendargs.getResult();
00368 }
00369
00370 template<class T1,class T2, class T3, class T4, class T5, class T6, class T7>
00371 result_type ret_impl(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7)
00372 {
00373 sendargs.store( a1, a2, a3, a4, a5, a6, a7 );
00374 mhandle.collectIfDone();
00375 return sendargs.getResult();
00376 }
00377
00378 template<class T1,class T2, class T3, class T4, class T5>
00379 result_type ret_impl(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
00380 {
00381 sendargs.store( a1, a2, a3, a4, a5);
00382 mhandle.collectIfDone();
00383 return sendargs.getResult();
00384 }
00385 };
00386
00387
00403 template<class OperationCallerT>
00404 class RemoteOperationCaller
00405 : public Invoker<OperationCallerT,RemoteOperationCallerImpl<OperationCallerT> >
00406 {
00407 public:
00408 typedef OperationCallerT Signature;
00409
00416 RemoteOperationCaller(OperationInterfacePart* of, std::string name, ExecutionEngine* caller)
00417 {
00418
00419 this->mmeth = OperationCallerC(of, name, caller);
00420
00421 this->sendargs.initArgs( this->mmeth );
00422 this->sendargs.initRet( this->mmeth );
00423 }
00424
00425 RemoteOperationCaller(const SendHandleC& sh )
00426 {
00427 this->mhandle = sh;
00428 this->collectargs.initArgs( this->mhandle );
00429
00430 this->mhandle.setAutoCollect(false);
00431 }
00432
00433 virtual bool ready() const {
00434 return this->mmeth.ready();
00435 }
00436
00437 virtual base::OperationCallerBase<OperationCallerT>* cloneI(ExecutionEngine* caller) const {
00438 RemoteOperationCaller<OperationCallerT>* rm = new RemoteOperationCaller<OperationCallerT>( this->mmeth.getOrp(), this->mmeth.getName(), caller);
00439 return rm;
00440 }
00441 };
00442 }
00443 }
00444 #endif