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:
00083         Operation(const std::string& name)
00084         :OperationBase(name)
00085         {
00086             // set null implementation such that we can already add it to the interface and register signals.
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             // creates a Local OperationCaller
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             // creates a Local OperationCaller or sets function
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             // attaches a signal to a Local OperationCaller
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             // attaches a signal to a Local OperationCaller
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 /* OPERATION_HPP_ */


rtt
Author(s): RTT Developers
autogenerated on Wed Aug 26 2015 16:15:50