RemoteCommand.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
00133 this->mcom = CommandC(of, name);
00134
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