RemoteCommand.hpp

00001 /***************************************************************************
00002   tag: FMTC  do nov 2 13:06:09 CET 2006  RemoteCommand.hpp
00003 
00004                         RemoteCommand.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_COMMAND_HPP
00040 #define ORO_REMOTE_COMMAND_HPP
00041 
00042 #include <boost/function.hpp>
00043 #include <string>
00044 #include "DispatchInterface.hpp"
00045 #include "CommandProcessor.hpp"
00046 #include "CommandFunctors.hpp"
00047 #include "CommandBase.hpp"
00048 #include "DataSourceStorage.hpp"
00049 #include "Invoker.hpp"
00050 
00051 namespace RTT
00052 {
00053     namespace detail
00054     {
00061         template<class CommandT>
00062         class RemoteCommandImpl
00063             : public CommandBase<CommandT>,
00064               protected detail::DataSourceStorage<CommandT>
00065         {
00066         protected:
00067             CommandC mcom;
00068         public:
00072             RemoteCommandImpl()
00073                 : mcom()
00074             {}
00075 
00081             bool invoke() {
00082                 return mcom.execute();
00083             }
00084 
00085             template<class T1>
00086             bool invoke( T1 a1 ) {
00087                 this->store( a1 );
00088                 return mcom.execute();
00089             }
00090 
00091             template<class T1, class T2>
00092             bool invoke( T1 a1, T2 a2 ) {
00093                 this->store( a1, a2 );
00094                 return mcom.execute();
00095             }
00096 
00097             template<class T1, class T2, class T3>
00098             bool invoke( T1 a1, T2 a2, T3 a3 ) {
00099                 this->store( a1, a2, a3 );
00100                 return mcom.execute();
00101             }
00102 
00103             template<class T1, class T2, class T3, class T4>
00104             bool invoke( T1 a1, T2 a2, T3 a3, T4 a4 ) {
00105                 this->store( a1, a2, a3, a4 );
00106                 return mcom.execute();
00107             }
00108         };
00109 
00110 
00117         template<class CommandT>
00118         class RemoteCommand
00119             : public Invoker<CommandT,RemoteCommandImpl<CommandT> >
00120         {
00121         public:
00122             typedef CommandT Signature;
00123 
00130             RemoteCommand(CommandFactory* of, std::string name)
00131             {
00132                 // create the command.
00133                 this->mcom = CommandC(of, name);
00134                 // add the arguments to the command.
00135                 this->initArgs( this->mcom );
00136             }
00137 
00138             virtual void readArguments() {}
00139 
00140             virtual bool ready() const {
00141                 return this->mcom.ready();
00142             }
00143 
00144             virtual bool dispatch() {
00145                 return this->mcom.execute();
00146             }
00147 
00148             virtual bool execute() {
00149                 return this->mcom.execute();
00150             }
00151 
00152             virtual bool done() const {
00153                 return this->mcom.done();
00154             }
00155 
00156             virtual void reset() {
00157                 return this->mcom.reset();
00158             }
00159 
00160             virtual bool sent() const {
00161                 return this->mcom.sent();
00162             }
00163 
00164             virtual bool accepted() const {
00165                 return this->mcom.accepted();
00166             }
00167 
00168             virtual bool executed() const {
00169                 return this->mcom.executed();
00170             }
00171 
00172             virtual bool valid() const {
00173                 return this->mcom.valid();
00174             }
00175 
00176             virtual ConditionInterface* createCondition() const
00177             {
00178                 return new detail::ConditionFunctor<bool(void)>( boost::bind<bool>( boost::mem_fn(&RemoteCommand::done), this) );
00179             }
00180 
00188             virtual DispatchInterface* clone() const {
00189                 return new RemoteCommand(*this);
00190             }
00191 
00192             virtual CommandBase<CommandT>* cloneI() const {
00193                 return new RemoteCommand(*this);
00194             }
00195         };
00196     }
00197 }
00198 #endif
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3