Go to the documentation of this file.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_RTT_OPERATION_HPP_
00040 #define ORO_RTT_OPERATION_HPP_
00041
00042 #include <vector>
00043 #include <string>
00044 #include <boost/fusion/include/vector.hpp>
00045 #include "base/OperationBase.hpp"
00046 #include "internal/LocalOperationCaller.hpp"
00047 #ifdef ORO_SIGNALLING_OPERATIONS
00048 #include "internal/Signal.hpp"
00049 #endif
00050 #include "internal/OperationCallerBinder.hpp"
00051
00052 namespace RTT
00053 {
00070 template<class Signature>
00071 class Operation
00072 : public base::OperationBase
00073 {
00074 public:
00082 Operation(const std::string& name)
00083 :OperationBase(name)
00084 {
00085
00086 ExecutionEngine* null_e = 0;
00087 impl = boost::make_shared<internal::LocalOperationCaller<Signature> >( boost::function<Signature>(), this->mowner, null_e, OwnThread);
00088 }
00089
00097 Operation(const std::string& name, boost::function<Signature> func, ExecutionThread et = ClientThread, ExecutionEngine* ee = NULL )
00098 :OperationBase(name)
00099 {
00100 this->calls(func, et, ee);
00101 }
00102
00111 template<class Function, class Object>
00112 Operation(const std::string& name, Function func, Object o, ExecutionThread et = ClientThread, ExecutionEngine* ee = NULL )
00113 :OperationBase(name)
00114 {
00115 this->calls(func, o, et, ee);
00116 }
00117
00118 ~Operation()
00119 {
00120 }
00121
00127 Operation<Signature>& doc(const std::string& description) { mdoc(description); return *this; }
00128
00136 Operation<Signature>& arg(const std::string& name, const std::string& description) { marg(name, description); return *this; }
00137
00146 Operation& calls(boost::function<Signature> func, ExecutionThread et = ClientThread, ExecutionEngine* ownerEngine = NULL ) {
00147
00148 ExecutionEngine* null_e = 0;
00149 impl = boost::make_shared<internal::LocalOperationCaller<Signature> >(func, this->mowner, null_e, et, ownerEngine);
00150 #ifdef ORO_SIGNALLING_OPERATIONS
00151 if (signal)
00152 impl->setSignal(signal);
00153 #endif
00154 return *this;
00155 }
00156
00166 template<class Function, class Object>
00167 Operation& calls(Function func, Object o, ExecutionThread et = ClientThread, ExecutionEngine* ownerEngine = NULL ) {
00168
00169 ExecutionEngine* null_e = 0;
00170 impl = boost::make_shared<internal::LocalOperationCaller<Signature> >(func, o, this->mowner, null_e, et, ownerEngine);
00171 #ifdef ORO_SIGNALLING_OPERATIONS
00172 if (signal)
00173 impl->setSignal(signal);
00174 #endif
00175 return *this;
00176 }
00177
00178 #ifdef ORO_SIGNALLING_OPERATIONS
00179
00184 Handle signals(boost::function<Signature> func) {
00185
00186 ExecutionEngine* null_e = 0;
00187 if (!impl)
00188 impl = boost::make_shared<internal::LocalOperationCaller<Signature> >( boost::function<Signature>(), this->mowner, null_e, OwnThread);
00189 if (!signal) {
00190 signal = boost::make_shared<internal::Signal<Signature> >();
00191 impl->setSignal( signal );
00192 }
00193 return signal->connect( func );
00194 }
00195
00202 template<class Function, class Object>
00203 Handle signals(Function func, Object o) {
00204 return this->signals( internal::OperationCallerBinder<Signature>()(func, o) );
00205 }
00206 #endif
00207 virtual base::DisposableInterface::shared_ptr getImplementation() { return impl; }
00208 virtual const base::DisposableInterface::shared_ptr getImplementation() const { return impl; }
00209
00210 virtual typename base::OperationCallerBase<Signature>::shared_ptr getOperationCaller() { return impl; }
00211 virtual const typename base::OperationCallerBase<Signature>::shared_ptr getOperationCaller() const { return impl; }
00212
00213 #ifdef ORO_SIGNALLING_OPERATIONS
00214
00220 typename internal::Signal<Signature>::shared_ptr signal;
00221 #endif
00222 private:
00223 typename internal::LocalOperationCaller<Signature>::shared_ptr impl;
00224 virtual void ownerUpdated() {
00225 if (impl)
00226 impl->setExecutor( this->mowner );
00227 }
00228 };
00229
00230 }
00231
00232 #endif