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 #include "internal/Signal.hpp"
00048 #include "internal/OperationCallerBinder.hpp"
00049
00050 namespace RTT
00051 {
00068 template<class Signature>
00069 class Operation
00070 : public base::OperationBase
00071 {
00072 public:
00080 Operation(const std::string& name)
00081 :OperationBase(name)
00082 {
00083
00084 ExecutionEngine* null_e = 0;
00085 impl = boost::make_shared<internal::LocalOperationCaller<Signature> >( boost::function<Signature>(), this->mowner, null_e, OwnThread);
00086 }
00087
00094 Operation(const std::string& name, boost::function<Signature> func, ExecutionThread et = ClientThread )
00095 :OperationBase(name)
00096 {
00097 this->calls(func,et);
00098 }
00099
00107 template<class Function, class Object>
00108 Operation(const std::string& name, Function func, Object o, ExecutionThread et = ClientThread )
00109 :OperationBase(name)
00110 {
00111 this->calls(func, o, et);
00112 }
00113
00114 ~Operation()
00115 {
00116 }
00117
00123 Operation<Signature>& doc(const std::string& description) { mdoc(description); return *this; }
00124
00132 Operation<Signature>& arg(const std::string& name, const std::string& description) { marg(name, description); return *this; }
00133
00141 Operation& calls(boost::function<Signature> func, ExecutionThread et = ClientThread ) {
00142
00143 ExecutionEngine* null_e = 0;
00144 impl = boost::make_shared<internal::LocalOperationCaller<Signature> >(func, this->mowner, null_e, et);
00145 if (signal)
00146 impl->setSignal(signal);
00147 return *this;
00148 }
00149
00158 template<class Function, class Object>
00159 Operation& calls(Function func, Object o, ExecutionThread et = ClientThread ) {
00160
00161 ExecutionEngine* null_e = 0;
00162 impl = boost::make_shared<internal::LocalOperationCaller<Signature> >(func, o, this->mowner, null_e, et);
00163 if (signal)
00164 impl->setSignal(signal);
00165 return *this;
00166 }
00167
00173 Handle signals(boost::function<Signature> func) {
00174
00175 ExecutionEngine* null_e = 0;
00176 if (!impl)
00177 impl = boost::make_shared<internal::LocalOperationCaller<Signature> >( boost::function<Signature>(), this->mowner, null_e, OwnThread);
00178 if (!signal) {
00179 signal = boost::make_shared<internal::Signal<Signature> >();
00180 impl->setSignal( signal );
00181 }
00182 return signal->connect( func );
00183 }
00184
00191 template<class Function, class Object>
00192 Handle signals(Function func, Object o) {
00193 return this->signals( internal::OperationCallerBinder<Signature>()(func, o) );
00194 }
00195
00196 virtual base::DisposableInterface::shared_ptr getImplementation() { return impl; }
00197 virtual const base::DisposableInterface::shared_ptr getImplementation() const { return impl; }
00198
00199 virtual typename base::OperationCallerBase<Signature>::shared_ptr getOperationCaller() { return impl; }
00200 virtual const typename base::OperationCallerBase<Signature>::shared_ptr getOperationCaller() const { return impl; }
00201
00208 typename internal::Signal<Signature>::shared_ptr signal;
00209 private:
00210 typename internal::LocalOperationCaller<Signature>::shared_ptr impl;
00211 virtual void ownerUpdated() {
00212 impl->setExecutor( this->mowner );
00213 }
00214 };
00215
00216 }
00217
00218 #endif