Operation.hpp
Go to the documentation of this file.
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 
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             // creates a Local OperationCaller
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             // creates a Local OperationCaller or sets function
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             // attaches a signal to a Local OperationCaller
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 /* OPERATION_HPP_ */


rtt
Author(s): RTT Developers
autogenerated on Mon Oct 6 2014 03:13:37