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:
00083 Operation(const std::string& name)
00084 :OperationBase(name)
00085 {
00086
00087 ExecutionEngine* null_e = 0;
00088 impl = boost::make_shared<internal::LocalOperationCaller<Signature> >( boost::function<Signature>(), null_e, null_e, ClientThread);
00089 }
00090
00098 Operation(const std::string& name, boost::function<Signature> func, ExecutionThread et = ClientThread, ExecutionEngine* ownerEngine = NULL )
00099 :OperationBase(name)
00100 {
00101 this->calls(func, et, ownerEngine);
00102 }
00103
00112 template<class Function, class Object>
00113 Operation(const std::string& name, Function func, Object o, ExecutionThread et = ClientThread, ExecutionEngine* ownerEngine = NULL )
00114 :OperationBase(name)
00115 {
00116 this->calls(func, o, et, ownerEngine);
00117 }
00118
00119 ~Operation()
00120 {
00121 }
00122
00128 Operation<Signature>& doc(const std::string& description) { mdoc(description); return *this; }
00129
00137 Operation<Signature>& arg(const std::string& name, const std::string& description) { marg(name, description); return *this; }
00138
00147 Operation& calls(boost::function<Signature> func, ExecutionThread et = ClientThread, ExecutionEngine* ownerEngine = NULL ) {
00148
00149 ExecutionEngine* null_caller = 0;
00150 impl = boost::make_shared<internal::LocalOperationCaller<Signature> >(func, ownerEngine ? ownerEngine : this->mowner, null_caller, et);
00151 #ifdef ORO_SIGNALLING_OPERATIONS
00152 if (signal)
00153 impl->setSignal(signal);
00154 #endif
00155 return *this;
00156 }
00157
00167 template<class Function, class Object>
00168 Operation& calls(Function func, Object o, ExecutionThread et = ClientThread, ExecutionEngine* ownerEngine = NULL ) {
00169
00170 ExecutionEngine* null_caller = 0;
00171 impl = boost::make_shared<internal::LocalOperationCaller<Signature> >(func, o, ownerEngine ? ownerEngine : this->mowner, null_caller, et);
00172 #ifdef ORO_SIGNALLING_OPERATIONS
00173 if (signal)
00174 impl->setSignal(signal);
00175 #endif
00176 return *this;
00177 }
00178
00179 #ifdef ORO_SIGNALLING_OPERATIONS
00180
00187 void signals() {
00188
00189 ExecutionEngine* null_caller = 0;
00190 if (!impl)
00191 impl = boost::make_shared<internal::LocalOperationCaller<Signature> >( boost::function<Signature>(), this->mowner, null_caller, ClientThread);
00192 if (!signal) {
00193 signal = boost::make_shared<internal::Signal<Signature> >();
00194 impl->setSignal( signal );
00195 }
00196 }
00197
00203 Handle signals(boost::function<Signature> func) {
00204
00205 ExecutionEngine* null_caller = 0;
00206 if (!impl)
00207 impl = boost::make_shared<internal::LocalOperationCaller<Signature> >( boost::function<Signature>(), this->mowner, null_caller, ClientThread);
00208 if (!signal) {
00209 signal = boost::make_shared<internal::Signal<Signature> >();
00210 impl->setSignal( signal );
00211 }
00212 return signal->connect( func );
00213 }
00214
00221 template<class Function, class Object>
00222 Handle signals(Function func, Object o) {
00223 return this->signals( internal::OperationCallerBinder<Signature>()(func, o) );
00224 }
00225 #endif
00226 virtual base::DisposableInterface::shared_ptr getImplementation() { return impl; }
00227 virtual const base::DisposableInterface::shared_ptr getImplementation() const { return impl; }
00228
00229 virtual typename base::OperationCallerBase<Signature>::shared_ptr getOperationCaller() { return impl; }
00230 virtual const typename base::OperationCallerBase<Signature>::shared_ptr getOperationCaller() const { return impl; }
00231
00232 #ifdef ORO_SIGNALLING_OPERATIONS
00233
00239 typename internal::Signal<Signature>::shared_ptr signal;
00240 #endif
00241 private:
00242 typename internal::LocalOperationCaller<Signature>::shared_ptr impl;
00243 virtual void ownerUpdated() {
00244 if (impl)
00245 impl->setOwner( this->mowner );
00246 }
00247 };
00248
00249 }
00250
00251 #endif