Orocos Real-Time Toolkit
2.5.0
|
00001 /*************************************************************************** 00002 tag: The SourceWorks Tue Sep 7 00:55:18 CEST 2010 Operation.hpp 00003 00004 Operation.hpp - description 00005 ------------------- 00006 begin : Tue September 07 2010 00007 copyright : (C) 2010 The SourceWorks 00008 email : peter@thesourceworks.com 00009 00010 *************************************************************************** 00011 * This library is free software; you can redistribute it and/or * 00012 * modify it under the terms of the GNU General Public * 00013 * License as published by the Free Software Foundation; * 00014 * version 2 of the License. * 00015 * * 00016 * As a special exception, you may use this file as part of a free * 00017 * software library without restriction. Specifically, if other files * 00018 * instantiate templates or use macros or inline functions from this * 00019 * file, or you compile this file and link it with other files to * 00020 * produce an executable, this file does not by itself cause the * 00021 * resulting executable to be covered by the GNU General Public * 00022 * License. This exception does not however invalidate any other * 00023 * reasons why the executable file might be covered by the GNU General * 00024 * Public License. * 00025 * * 00026 * This library is distributed in the hope that it will be useful, * 00027 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00028 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00029 * Lesser General Public License for more details. * 00030 * * 00031 * You should have received a copy of the GNU General Public * 00032 * License along with this library; if not, write to the Free Software * 00033 * Foundation, Inc., 59 Temple Place, * 00034 * Suite 330, Boston, MA 02111-1307 USA * 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 // set null implementation such that we can 00086 ExecutionEngine* null_e = 0; 00087 impl = boost::make_shared<internal::LocalOperationCaller<Signature> >( boost::function<Signature>(), this->mowner, null_e, OwnThread); 00088 } 00089 00096 Operation(const std::string& name, boost::function<Signature> func, ExecutionThread et = ClientThread ) 00097 :OperationBase(name) 00098 { 00099 this->calls(func,et); 00100 } 00101 00109 template<class Function, class Object> 00110 Operation(const std::string& name, Function func, Object o, ExecutionThread et = ClientThread ) 00111 :OperationBase(name) 00112 { 00113 this->calls(func, o, et); 00114 } 00115 00116 ~Operation() 00117 { 00118 } 00119 00125 Operation<Signature>& doc(const std::string& description) { mdoc(description); return *this; } 00126 00134 Operation<Signature>& arg(const std::string& name, const std::string& description) { marg(name, description); return *this; } 00135 00143 Operation& calls(boost::function<Signature> func, ExecutionThread et = ClientThread ) { 00144 // creates a Local OperationCaller 00145 ExecutionEngine* null_e = 0; 00146 impl = boost::make_shared<internal::LocalOperationCaller<Signature> >(func, this->mowner, null_e, et); 00147 #ifdef ORO_SIGNALLING_OPERATIONS 00148 if (signal) 00149 impl->setSignal(signal); 00150 #endif 00151 return *this; 00152 } 00153 00162 template<class Function, class Object> 00163 Operation& calls(Function func, Object o, ExecutionThread et = ClientThread ) { 00164 // creates a Local OperationCaller or sets function 00165 ExecutionEngine* null_e = 0; 00166 impl = boost::make_shared<internal::LocalOperationCaller<Signature> >(func, o, this->mowner, null_e, et); 00167 #ifdef ORO_SIGNALLING_OPERATIONS 00168 if (signal) 00169 impl->setSignal(signal); 00170 #endif 00171 return *this; 00172 } 00173 00174 #ifdef ORO_SIGNALLING_OPERATIONS 00175 00180 Handle signals(boost::function<Signature> func) { 00181 // attaches a signal to a Local OperationCaller 00182 ExecutionEngine* null_e = 0; 00183 if (!impl) 00184 impl = boost::make_shared<internal::LocalOperationCaller<Signature> >( boost::function<Signature>(), this->mowner, null_e, OwnThread); 00185 if (!signal) { 00186 signal = boost::make_shared<internal::Signal<Signature> >(); 00187 impl->setSignal( signal ); 00188 } 00189 return signal->connect( func ); 00190 } 00191 00198 template<class Function, class Object> 00199 Handle signals(Function func, Object o) { 00200 return this->signals( internal::OperationCallerBinder<Signature>()(func, o) ); 00201 } 00202 #endif 00203 virtual base::DisposableInterface::shared_ptr getImplementation() { return impl; } 00204 virtual const base::DisposableInterface::shared_ptr getImplementation() const { return impl; } 00205 00206 virtual typename base::OperationCallerBase<Signature>::shared_ptr getOperationCaller() { return impl; } 00207 virtual const typename base::OperationCallerBase<Signature>::shared_ptr getOperationCaller() const { return impl; } 00208 00209 #ifdef ORO_SIGNALLING_OPERATIONS 00210 00216 typename internal::Signal<Signature>::shared_ptr signal; 00217 #endif 00218 private: 00219 typename internal::LocalOperationCaller<Signature>::shared_ptr impl; 00220 virtual void ownerUpdated() { 00221 if (impl) 00222 impl->setExecutor( this->mowner ); 00223 } 00224 }; 00225 00226 } 00227 00228 #endif /* OPERATION_HPP_ */