Orocos Real-Time Toolkit  2.9.0
RemoteOperationCaller.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: FMTC do nov 2 13:06:09 CET 2006 RemoteOperationCaller.hpp
3 
4  RemoteOperationCaller.hpp - description
5  -------------------
6  begin : do november 02 2006
7  copyright : (C) 2006 FMTC
8  email : peter.soetens@fmtc.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 #ifndef ORO_REMOTE_METHOD_HPP
40 #define ORO_REMOTE_METHOD_HPP
41 
42 #include <boost/function.hpp>
43 #include <string>
44 #include "../base/OperationCallerBase.hpp"
45 #include "OperationCallerC.hpp"
46 #include "DataSourceStorage.hpp"
47 #include "Invoker.hpp"
48 
49 #include <boost/fusion/include/vector_tie.hpp>
50 #include <boost/fusion/include/filter_if.hpp>
51 #include <boost/fusion/include/as_vector.hpp>
52 
53 
54 
55 namespace RTT
56 {
57  namespace internal
58  {
59  namespace bf = ::boost::fusion;
60 
70  template<class OperationCallerT>
72  : public base::OperationCallerBase<OperationCallerT>,
73  public internal::CollectBase<OperationCallerT>
74  {
75  protected:
80  public:
81  typedef OperationCallerT Signature;
82  typedef typename boost::function_traits<OperationCallerT>::result_type result_type;
83 
88  : mmeth(), mhandle()
89  {}
90 
95  : mmeth(), mhandle(handle)
96  {}
97 
98  virtual void executeAndDispose() { assert(false); }
99  virtual bool isError() const { return false; }
100  virtual void dispose() { assert(false); }
101 
107  template<class Xignored>
108  result_type call_impl() {
109  mmeth.call();
110  return sendargs.getResult();
111  }
112 
113  template<class T1>
114  result_type call_impl( T1 a1 ) {
115  sendargs.store( a1 );
116  mmeth.call();
117  return sendargs.getResult();
118  }
119 
120  template<class T1, class T2>
121  result_type call_impl( T1 a1, T2 a2 ) {
122  sendargs.store( a1, a2 );
123  mmeth.call();
124  return sendargs.getResult();
125  }
126 
127  template<class T1, class T2, class T3>
128  result_type call_impl( T1 a1, T2 a2, T3 a3 ) {
129  sendargs.store( a1, a2, a3 );
130  mmeth.call();
131  return sendargs.getResult();
132  }
133 
134  template<class T1, class T2, class T3, class T4>
135  result_type call_impl( T1 a1, T2 a2, T3 a3, T4 a4 ) {
136  sendargs.store( a1, a2, a3, a4 );
137  mmeth.call();
138  return sendargs.getResult();
139  }
140 
141  template<class T1, class T2, class T3, class T4, class T5, class T6>
142  result_type call_impl( T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6 ) {
143  sendargs.store( a1, a2, a3, a4, a5, a6 );
144  mmeth.call();
145  return sendargs.getResult();
146  }
147 
148  template<class T1, class T2, class T3, class T4, class T5, class T6, class T7>
149  result_type call_impl( T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7 ) {
150  sendargs.store( a1, a2, a3, a4, a5, a6, a7 );
151  mmeth.call();
152  return sendargs.getResult();
153  }
154 
155  template<class T1, class T2, class T3, class T4, class T5>
156  result_type call_impl( T1 a1, T2 a2, T3 a3, T4 a4, T5 a5 ) {
157  sendargs.store( a1, a2, a3, a4, a5 );
158  mmeth.call();
159  return sendargs.getResult();
160  }
161 
163  mhandle = mmeth.send();
164  // @todo: get remote collect from rt allocation.
165  return SendHandle<Signature>( boost::make_shared< RemoteOperationCaller<OperationCallerT> >( mhandle ) );
166  }
167 
168  template<class T1>
170  sendargs.store( a1 );
171  mhandle = mmeth.send();
172  return SendHandle<Signature>( boost::make_shared< RemoteOperationCaller<OperationCallerT> >( mhandle ) );
173  }
174 
175  template<class T1, class T2>
177  sendargs.store( a1, a2 );
178  mhandle = mmeth.send();
179  return SendHandle<Signature>( boost::make_shared< RemoteOperationCaller<OperationCallerT> >( mhandle ) );
180  }
181 
182  template<class T1, class T2, class T3>
183  SendHandle<Signature> send_impl( T1 a1, T2 a2, T3 a3 ) {
184  sendargs.store( a1, a2, a3 );
185  mhandle = mmeth.send();
186  return SendHandle<Signature>( boost::make_shared< RemoteOperationCaller<OperationCallerT> >( mhandle ) );
187  }
188 
189  template<class T1, class T2, class T3, class T4>
190  SendHandle<Signature> send_impl( T1 a1, T2 a2, T3 a3, T4 a4 ) {
191  sendargs.store( a1, a2, a3, a4 );
192  mhandle = mmeth.send();
193  return SendHandle<Signature>( boost::make_shared< RemoteOperationCaller<OperationCallerT> >( mhandle ) );
194  }
195 
196  template<class T1, class T2, class T3, class T4, class T5>
197  SendHandle<Signature> send_impl( T1 a1, T2 a2, T3 a3, T4 a4, T5 a5 ) {
198  sendargs.store( a1, a2, a3, a4, a5 );
199  mhandle = mmeth.send();
200  return SendHandle<Signature>( boost::make_shared< RemoteOperationCaller<OperationCallerT> >( mhandle ) );
201  }
202 
203  template<class T1, class T2, class T3, class T4, class T5, class T6>
204  SendHandle<Signature> send_impl( T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6 ) {
205  sendargs.store( a1, a2, a3, a4, a5, a6 );
206  mhandle = mmeth.send();
207  return SendHandle<Signature>( boost::make_shared< RemoteOperationCaller<OperationCallerT> >( mhandle ) );
208  }
209 
210  template<class T1, class T2, class T3, class T4, class T5, class T6, class T7>
211  SendHandle<Signature> send_impl( T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7 ) {
212  sendargs.store( a1, a2, a3, a4, a5, a6, a7 );
213  mhandle = mmeth.send();
214  return SendHandle<Signature>( boost::make_shared< RemoteOperationCaller<OperationCallerT> >( mhandle ) );
215  }
216 
218  if ( mhandle.collectIfDone() == SendSuccess ) {
219  return SendSuccess;
220  } else
221  return SendNotReady;
222  }
223 
224  template<class T1>
226  collectargs.store( a1 );
227  if ( mhandle.collectIfDone() == SendSuccess ) {
228  return SendSuccess;
229  } else
230  return SendNotReady;
231  }
232 
233  template<class T1, class T2>
234  SendStatus collectIfDone_impl( T1& a1, T2& a2 ) {
235  collectargs.store( a1, a2);
236  if ( mhandle.collectIfDone() == SendSuccess ) {
237  return SendSuccess;
238  }
239  return SendNotReady;
240  }
241 
242  template<class T1, class T2, class T3>
243  SendStatus collectIfDone_impl( T1& a1, T2& a2, T3& a3 ) {
244  collectargs.store( a1, a2, a3);
245  if ( mhandle.collectIfDone() == SendSuccess ) {
246  return SendSuccess;
247  } else
248  return SendNotReady;
249  }
250 
251  template<class T1, class T2, class T3, class T4>
252  SendStatus collectIfDone_impl( T1& a1, T2& a2, T3& a3, T4& a4 ) {
253  collectargs.store( a1, a2, a3, a4);
254  if ( mhandle.collectIfDone() == SendSuccess ) {
255  return SendSuccess;
256  } else
257  return SendNotReady;
258  }
259 
260  template<class T1, class T2, class T3, class T4, class T5, class T6>
261  SendStatus collectIfDone_impl( T1& a1, T2& a2, T3& a3, T4& a4, T5& a5, T6& a6 ) {
262  collectargs.store( a1, a2, a3, a4, a5, a6);
263  if ( mhandle.collectIfDone() == SendSuccess ) {
264  return SendSuccess;
265  } else
266  return SendNotReady;
267  }
268 
269  template<class T1, class T2, class T3, class T4, class T5, class T6, class T7>
270  SendStatus collectIfDone_impl( T1& a1, T2& a2, T3& a3, T4& a4, T5& a5, T6& a6, T7& a7 ) {
271  collectargs.store( a1, a2, a3, a4, a5, a6, a7 );
272  if ( mhandle.collectIfDone() == SendSuccess ) {
273  return SendSuccess;
274  } else
275  return SendNotReady;
276  }
277 
278  template<class T1, class T2, class T3, class T4, class T5>
279  SendStatus collectIfDone_impl( T1& a1, T2& a2, T3& a3, T4& a4, T5& a5 ) {
280  collectargs.store( a1, a2, a3, a4, a5);
281  if ( mhandle.collectIfDone() == SendSuccess ) {
282  return SendSuccess;
283  } else
284  return SendNotReady;
285  }
286 
288  return mhandle.collect();
289  }
290  template<class T1>
292  collectargs.store( a1 );
293  return mhandle.collect();
294  }
295 
296  template<class T1, class T2>
297  SendStatus collect_impl( T1& a1, T2& a2 ) {
298  collectargs.store( a1, a2);
299  return mhandle.collect();
300  }
301 
302  template<class T1, class T2, class T3>
303  SendStatus collect_impl( T1& a1, T2& a2, T3& a3 ) {
304  collectargs.store( a1, a2, a3);
305  return mhandle.collect();
306  }
307 
308  template<class T1, class T2, class T3, class T4>
309  SendStatus collect_impl( T1& a1, T2& a2, T3& a3, T4& a4 ) {
310  collectargs.store( a1, a2, a3, a4);
311  return mhandle.collect();
312  }
313 
314  template<class T1, class T2, class T3, class T4, class T5>
315  SendStatus collect_impl( T1& a1, T2& a2, T3& a3, T4& a4, T5& a5 ) {
316  collectargs.store( a1, a2, a3, a4, a5);
317  return mhandle.collect();
318  }
319 
320  result_type ret_impl()
321  {
322  return sendargs.getResult(); // may return void.
323  }
324 
330  template<class T1>
331  result_type ret_impl(T1 a1)
332  {
333  sendargs.store( a1 );
334  mhandle.collectIfDone();
335  return sendargs.getResult(); // may return void.
336  }
337 
338  template<class T1,class T2>
339  result_type ret_impl(T1 a1, T2 a2)
340  {
341  sendargs.store( a1, a2 );
342  mhandle.collectIfDone();
343  return sendargs.getResult(); // may return void.
344  }
345 
346  template<class T1,class T2, class T3>
347  result_type ret_impl(T1 a1, T2 a2, T3 a3)
348  {
349  sendargs.store( a1, a2, a3 );
350  mhandle.collectIfDone();
351  return sendargs.getResult(); // may return void.
352  }
353 
354  template<class T1,class T2, class T3, class T4>
355  result_type ret_impl(T1 a1, T2 a2, T3 a3, T4 a4)
356  {
357  sendargs.store( a1, a2, a3, a4 );
358  mhandle.collectIfDone();
359  return sendargs.getResult(); // may return void.
360  }
361 
362  template<class T1,class T2, class T3, class T4, class T5, class T6>
363  result_type ret_impl(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
364  {
365  sendargs.store( a1, a2, a3, a4, a5, a6 );
366  mhandle.collectIfDone();
367  return sendargs.getResult(); // may return void.
368  }
369 
370  template<class T1,class T2, class T3, class T4, class T5, class T6, class T7>
371  result_type ret_impl(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7)
372  {
373  sendargs.store( a1, a2, a3, a4, a5, a6, a7 );
374  mhandle.collectIfDone();
375  return sendargs.getResult(); // may return void.
376  }
377 
378  template<class T1,class T2, class T3, class T4, class T5>
379  result_type ret_impl(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
380  {
381  sendargs.store( a1, a2, a3, a4, a5);
382  mhandle.collectIfDone();
383  return sendargs.getResult(); // may return void.
384  }
385  };
386 
387 
403  template<class OperationCallerT>
405  : public Invoker<OperationCallerT,RemoteOperationCallerImpl<OperationCallerT> >
406  {
407  public:
408  typedef OperationCallerT Signature;
409 
419  {
420  // create the method.
421  this->mmeth = OperationCallerC(of, name, caller);
422  // add the arguments to the method.
423  this->sendargs.initArgs( this->mmeth );
424  this->sendargs.initRet( this->mmeth );
426  }
427 
429  {
430  this->mhandle = sh;
431  this->collectargs.initArgs( this->mhandle );
432  // no need to collect on remote operations.
433  this->mhandle.setAutoCollect(false);
434  }
435 
436  virtual bool ready() const {
437  return this->mmeth.ready();
438  }
439 
441  // re-create the method.
442  this->mmeth = OperationCallerC(this->mmeth, caller);
443  // add the arguments to the method.
444  this->sendargs.initArgs( this->mmeth );
445  this->sendargs.initRet( this->mmeth );
447  }
448 
451  return rm;
452  }
453  };
454  }
455 }
456 #endif
result_type call_impl(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
SendStatus collect_impl(T1 &a1, T2 &a2, T3 &a3, T4 &a4, T5 &a5)
bool ready() const
Returns true if this method is ready for execution.
SendStatus collectIfDone_impl(T1 &a1, T2 &a2, T3 &a3, T4 &a4, T5 &a5, T6 &a6)
SendHandleC send()
Send the contained method.
SendStatus collectIfDone_impl(T1 &a1, T2 &a2, T3 &a3, T4 &a4)
result_type ret_impl(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7)
std::string const & getName() const
Returns the name of the operation that will be called.
virtual void setCaller(ExecutionEngine *caller)
virtual base::OperationCallerBase< OperationCallerT > * cloneI(ExecutionEngine *caller) const
SendHandle< Signature > send_impl(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
virtual void setCaller(ExecutionEngine *ee)
Sets the caller&#39;s engine of this operation.
Creates an invocation object with a function signature to invoke and an implementation in which an op...
Definition: Invoker.hpp:61
result_type ret_impl(T1 a1)
This function has the same signature of call() and returns the stored return value, and tries to return all arguments.
SendHandle< Signature > send_impl(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7)
DataSourceStorage< OperationCallerT > sendargs
SendStatus collectIfDone_impl(T1 &a1, T2 &a2, T3 &a3, T4 &a4, T5 &a5)
SendHandle< Signature > send_impl(T1 a1, T2 a2, T3 a3, T4 a4)
void setAutoCollect(bool on_off)
When set to &#39;on&#39;, the destruction of this SendHandleC will cause a call to collect() before all data ...
virtual void executeAndDispose()
Execute functionality and free this object.
SendStatus collect()
Collect the contained method.
result_type call_impl(T1 a1, T2 a2, T3 a3, T4 a4)
RemoteOperationCaller(OperationInterfacePart *of, std::string name, ExecutionEngine *caller=0)
Create a RemoteOperationCaller object which executes a remote method.
result_type ret_impl(T1 a1, T2 a2, T3 a3, T4 a4)
result_type call_impl(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
The base class for all method implementations.
An execution engine serialises (executes one after the other) the execution of all commands...
SendStatus
Returns the status of a send() or collect() invocation.
Definition: SendStatus.hpp:53
SendStatus collect_impl(T1 &a1, T2 &a2, T3 &a3, T4 &a4)
SendHandle< Signature > send_impl(T1 a1, T2 a2, T3 a3)
OperationInterfacePart * getOrp() const
Returns the factory which we use to produce the operation call.
A template-less SendHandle manager.
Definition: SendHandleC.hpp:61
A OperationCaller implementation which delegates C++ to datasource conversions when C++ code tries to...
RemoteOperationCallerImpl(SendHandleC handle)
Create from a sendhandle.
result_type call_impl(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7)
result_type ret_impl(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
The SendHandle is used to collect the result values of an asynchronous invocation.
Definition: rtt-fwd.hpp:79
A template-less manager for OperationCaller calls.
SendStatus collectIfDone()
Collect the contained method.
DataSourceStorage< typename CollectType< OperationCallerT >::type > collectargs
This class defines the interface for creating operation objects without using C++ templates...
bool call()
Call the contained method.
virtual void dispose()
Just free this object without executing it.
RemoteOperationCallerImpl()
The defaults are reset by the constructor.
Returned when the send() succeeded, but the operation has not yet been executed by the receiving comp...
Definition: SendStatus.hpp:57
SendHandle< Signature > send_impl(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
result_type call_impl()
Call this operator if the RemoteOperationCaller takes no arguments.
SendHandle< Signature > send_impl(T1 a1, T2 a2)
SendStatus collect_impl(T1 &a1, T2 &a2, T3 &a3)
Returned when the send() failed to deliver the operation call to the receiving component.
Definition: SendStatus.hpp:56
This struct takes the user&#39;s Function signature F and transforms it to the form required in the Colle...
Definition: CollectBase.hpp:69
result_type ret_impl(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
SendStatus collectIfDone_impl(T1 &a1, T2 &a2, T3 &a3, T4 &a4, T5 &a5, T6 &a6, T7 &a7)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52
A OperationCaller implementation which executes a remote function which is encapsulated in a Operatio...
result_type ret_impl(T1 a1, T2 a2, T3 a3)
result_type call_impl(T1 a1, T2 a2, T3 a3)
SendStatus collectIfDone_impl(T1 &a1, T2 &a2, T3 &a3)
boost::function_traits< OperationCallerT >::result_type result_type