Orocos Real-Time Toolkit  2.8.3
Operation.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:55:18 CEST 2010 Operation.hpp
3 
4  Operation.hpp - description
5  -------------------
6  begin : Tue September 07 2010
7  copyright : (C) 2010 The SourceWorks
8  email : peter@thesourceworks.com
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_RTT_OPERATION_HPP_
40 #define ORO_RTT_OPERATION_HPP_
41 
42 #include <vector>
43 #include <string>
44 #include <boost/fusion/include/vector.hpp>
45 #include "base/OperationBase.hpp"
47 #ifdef ORO_SIGNALLING_OPERATIONS
48 #include "internal/Signal.hpp"
49 #endif
51 
52 namespace RTT
53 {
70  template<class Signature>
71  class Operation
72  : public base::OperationBase
73  {
74  public:
83  Operation(const std::string& name)
84  :OperationBase(name)
85  {
86  // set null implementation such that we can already add it to the interface and register signals.
87  ExecutionEngine* null_e = 0;
88  impl = boost::make_shared<internal::LocalOperationCaller<Signature> >( boost::function<Signature>(), null_e, null_e, ClientThread);
89  }
90 
98  Operation(const std::string& name, boost::function<Signature> func, ExecutionThread et = ClientThread, ExecutionEngine* ownerEngine = NULL )
99  :OperationBase(name)
100  {
101  this->calls(func, et, ownerEngine);
102  }
103 
112  template<class Function, class Object>
113  Operation(const std::string& name, Function func, Object o, ExecutionThread et = ClientThread, ExecutionEngine* ownerEngine = NULL )
114  :OperationBase(name)
115  {
116  this->calls(func, o, et, ownerEngine);
117  }
118 
120  {
121  }
122 
128  Operation<Signature>& doc(const std::string& description) { mdoc(description); return *this; }
129 
137  Operation<Signature>& arg(const std::string& name, const std::string& description) { marg(name, description); return *this; }
138 
147  Operation& calls(boost::function<Signature> func, ExecutionThread et = ClientThread, ExecutionEngine* ownerEngine = NULL ) {
148  // creates a Local OperationCaller
149  ExecutionEngine* null_caller = 0;
150  impl = boost::make_shared<internal::LocalOperationCaller<Signature> >(func, ownerEngine ? ownerEngine : this->mowner, null_caller, et);
151 #ifdef ORO_SIGNALLING_OPERATIONS
152  if (signal)
153  impl->setSignal(signal);
154 #endif
155  return *this;
156  }
157 
167  template<class Function, class Object>
168  Operation& calls(Function func, Object o, ExecutionThread et = ClientThread, ExecutionEngine* ownerEngine = NULL ) {
169  // creates a Local OperationCaller or sets function
170  ExecutionEngine* null_caller = 0;
171  impl = boost::make_shared<internal::LocalOperationCaller<Signature> >(func, o, ownerEngine ? ownerEngine : this->mowner, null_caller, et);
172 #ifdef ORO_SIGNALLING_OPERATIONS
173  if (signal)
174  impl->setSignal(signal);
175 #endif
176  return *this;
177  }
178 
179 #ifdef ORO_SIGNALLING_OPERATIONS
180 
187  void signals() {
188  // attaches a signal to a Local OperationCaller
189  ExecutionEngine* null_caller = 0;
190  if (!impl)
191  impl = boost::make_shared<internal::LocalOperationCaller<Signature> >( boost::function<Signature>(), this->mowner, null_caller, ClientThread);
192  if (!signal) {
193  signal = boost::make_shared<internal::Signal<Signature> >();
194  impl->setSignal( signal );
195  }
196  }
197 
203  Handle signals(boost::function<Signature> func) {
204  // attaches a signal to a Local OperationCaller
205  ExecutionEngine* null_caller = 0;
206  if (!impl)
207  impl = boost::make_shared<internal::LocalOperationCaller<Signature> >( boost::function<Signature>(), this->mowner, null_caller, ClientThread);
208  if (!signal) {
209  signal = boost::make_shared<internal::Signal<Signature> >();
210  impl->setSignal( signal );
211  }
212  return signal->connect( func );
213  }
214 
221  template<class Function, class Object>
222  Handle signals(Function func, Object o) {
223  return this->signals( internal::OperationCallerBinder<Signature>()(func, o) );
224  }
225 #endif
227  virtual const base::DisposableInterface::shared_ptr getImplementation() const { return impl; }
228 
230  virtual const typename base::OperationCallerBase<Signature>::shared_ptr getOperationCaller() const { return impl; }
231 
232 #ifdef ORO_SIGNALLING_OPERATIONS
233 
240 #endif
241  private:
243  virtual void ownerUpdated() {
244  if (impl)
245  impl->setOwner( this->mowner );
246  }
247  };
248 
249 }
250 
251 #endif /* OPERATION_HPP_ */
Operation< Signature > & doc(const std::string &description)
Document this operation.
Definition: Operation.hpp:128
This base class serves as a template-less handle for operation objects and also stores the name and d...
virtual base::OperationCallerBase< Signature >::shared_ptr getOperationCaller()
Definition: Operation.hpp:229
Operation(const std::string &name, Function func, Object o, ExecutionThread et=ClientThread, ExecutionEngine *ownerEngine=NULL)
Create an operation object with a name and class member function to execute.
Definition: Operation.hpp:113
virtual const base::DisposableInterface::shared_ptr getImplementation() const
Definition: Operation.hpp:227
The operation ties a C or C++ function into a component interface.
virtual const base::OperationCallerBase< Signature >::shared_ptr getOperationCaller() const
Definition: Operation.hpp:230
An execution engine serialises (executes one after the other) the execution of all commands...
Operation & calls(Function func, Object o, ExecutionThread et=ClientThread, ExecutionEngine *ownerEngine=NULL)
Indicate that this operation calls a given class member function.
Definition: Operation.hpp:168
boost::shared_ptr< Signal< Signature, TSlotFunction > > shared_ptr
Definition: Signal.hpp:215
boost::shared_ptr< OperationCallerBase< F > > shared_ptr
RTT_API void mdoc(const std::string &description)
Operation< Signature > & arg(const std::string &name, const std::string &description)
Document an argument of this operation.
Definition: Operation.hpp:137
boost::shared_ptr< DisposableInterface > shared_ptr
Use this type for shared pointer storage of an DisposableInterface object.
virtual base::DisposableInterface::shared_ptr getImplementation()
Returns the implementation object of this operation.
Definition: Operation.hpp:226
ExecutionEngine * mowner
Operation & calls(boost::function< Signature > func, ExecutionThread et=ClientThread, ExecutionEngine *ownerEngine=NULL)
Indicate that this operation calls a given function.
Definition: Operation.hpp:147
Operation(const std::string &name)
Create an operation object with a name.
Definition: Operation.hpp:83
Operation(const std::string &name, boost::function< Signature > func, ExecutionThread et=ClientThread, ExecutionEngine *ownerEngine=NULL)
Create an operation object with a name and function to execute.
Definition: Operation.hpp:98
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
Very simple factory class to bind a member function to an object pointer and leave the arguments open...
boost::shared_ptr< LocalOperationCaller > shared_ptr
The Handle holds the information, and allows manipulation, of a connection between a internal::Signal...
Definition: Handle.hpp:66
RTT_API void marg(const std::string &name, const std::string &description)
ExecutionThread
Users can choose if an operation&#39;s function is executed in the component&#39;s thread (OwnThread) or in t...