RemoteMethod.hpp

00001 /***************************************************************************
00002   tag: FMTC  do nov 2 13:06:09 CET 2006  RemoteMethod.hpp
00003 
00004                         RemoteMethod.hpp -  description
00005                            -------------------
00006     begin                : do november 02 2006
00007     copyright            : (C) 2006 FMTC
00008     email                : peter.soetens@fmtc.be
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_REMOTE_METHOD_HPP
00040 #define ORO_REMOTE_METHOD_HPP
00041 
00042 #include <boost/function.hpp>
00043 #include <string>
00044 #include "MethodBase.hpp"
00045 #include "MethodC.hpp"
00046 #include "DataSourceStorage.hpp"
00047 #include "Invoker.hpp"
00048 
00049 namespace RTT
00050 {
00051     namespace detail
00052     {
00059         template<class MethodT>
00060         class RemoteMethodImpl
00061             : public MethodBase<MethodT>,
00062               protected detail::DataSourceStorage<MethodT>
00063         {
00064         protected:
00065             MethodC mmeth;
00066         public:
00067             typedef typename boost::function_traits<MethodT>::result_type result_type;
00068 
00072             RemoteMethodImpl()
00073                 : mmeth()
00074             {}
00075 
00081             result_type invoke() {
00082                 mmeth.execute();
00083                 return this->detail::DataSourceStorage<MethodT>::getResult();
00084             }
00085 
00086             template<class T1>
00087             result_type invoke( T1 a1 ) {
00088                 this->store( a1 );
00089                 mmeth.execute();
00090                 return this->detail::DataSourceStorage<MethodT>::getResult();
00091             }
00092 
00093             template<class T1, class T2>
00094             result_type invoke( T1 a1, T2 a2 ) {
00095                 this->store( a1, a2 );
00096                 mmeth.execute();
00097                 return this->detail::DataSourceStorage<MethodT>::getResult();
00098             }
00099 
00100             template<class T1, class T2, class T3>
00101             result_type invoke( T1 a1, T2 a2, T3 a3 ) {
00102                 this->store( a1, a2, a3 );
00103                 mmeth.execute();
00104                 return this->detail::DataSourceStorage<MethodT>::getResult();
00105             }
00106 
00107             template<class T1, class T2, class T3, class T4>
00108             result_type invoke( T1 a1, T2 a2, T3 a3, T4 a4 ) {
00109                 this->store( a1, a2, a3, a4 );
00110                 mmeth.execute();
00111                 return this->detail::DataSourceStorage<MethodT>::getResult();
00112             }
00113         };
00114 
00115 
00122         template<class MethodT>
00123         class RemoteMethod
00124             : public Invoker<MethodT,RemoteMethodImpl<MethodT> >
00125         {
00126         public:
00127             typedef MethodT Signature;
00128 
00135             RemoteMethod(MethodFactory* of, std::string name)
00136             {
00137                 // create the method.
00138                 this->mmeth = MethodC(of, name);
00139                 // add the arguments to the method.
00140                 this->initArgs( this->mmeth );
00141                 this->initRet(  this->mmeth );
00142             }
00143 
00144             virtual void readArguments() {}
00145 
00146             virtual bool ready() const {
00147                 return this->mmeth.ready();
00148             }
00149 
00150             virtual bool execute() {
00151                 return this->mmeth.execute();
00152             }
00153 
00161             virtual ActionInterface* clone() const {
00162                 return new RemoteMethod(*this);
00163             }
00164 
00165             virtual MethodBase<MethodT>* cloneI() const {
00166                 return new RemoteMethod(*this);
00167             }
00168         };
00169     }
00170 }
00171 #endif
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3