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_DATASOURCE_ARGS_COMMAND_HPP
00040 #define ORO_DATASOURCE_ARGS_COMMAND_HPP
00041
00042 #include "CommandFunctors.hpp"
00043 #include "CommandProcessor.hpp"
00044 #include "CommandDSFunctors.hpp"
00045 #include "DispatchInterface.hpp"
00046
00047 namespace RTT
00048 {
00049 namespace detail
00050 {
00055 template<class CommandT,
00056 class CommandF = detail::Functor<CommandT> >
00057 class DataSourceArgsCommand
00058 : public DispatchInterface
00059 {
00060 CommandF mcom;
00061 mutable CommandF mcon;
00062 CommandProcessor* mcp;
00063 bool minvoked, maccept, mvalid, mexec, minvert;
00064 public:
00065 typedef boost::function_traits<CommandT> traits;
00066 typedef CommandT Signature;
00067 typedef bool result_type;
00068
00069 DataSourceArgsCommand(boost::function<CommandT> com, boost::function<CommandT> con, CommandProcessor* cp, bool inverted)
00070 : mcom( com ), mcon( con ),
00071 mcp( cp ),
00072 minvoked(false), maccept(false),
00073 mvalid(false), mexec(false), minvert(inverted)
00074 {
00075 }
00076
00077 DataSourceArgsCommand(CommandF com, CommandF con, CommandProcessor* cp, bool inverted)
00078 : mcom( com ), mcon( con ),
00079 mcp( cp ),
00080 minvoked(false), maccept(false),
00081 mvalid(false), mexec(false), minvert(inverted)
00082 {
00083 }
00084
00085 DataSourceArgsCommand<CommandT,CommandF>* create() const
00086 {
00087 return clone();
00088 }
00089
00090 template<class Arg1T>
00091 DataSourceArgsCommand<CommandT,CommandF>* create(DataSource<Arg1T>* a1) const
00092 {
00093 DataSourceArgsCommand<CommandT,CommandF>* r = this->clone();
00094 r->mcom.setArguments(a1);
00095 r->mcon.setArguments(a1);
00096 return r;
00097 }
00098
00099 template<class Arg1T, class Arg2T>
00100 DataSourceArgsCommand<CommandT,CommandF>* create(DataSource<Arg1T>* a1, DataSource<Arg2T>* a2) const
00101 {
00102 DataSourceArgsCommand<CommandT,CommandF>* r = this->clone();
00103 r->mcom.setArguments(a1, a2);
00104 r->mcon.setArguments(a1, a2);
00105 return r;
00106 }
00107
00108 template<class Arg1T, class Arg2T, class Arg3T>
00109 DataSourceArgsCommand<CommandT,CommandF>* create(DataSource<Arg1T>* a1, DataSource<Arg2T>* a2, DataSource<Arg3T>* a3) const
00110 {
00111 DataSourceArgsCommand<CommandT,CommandF>* r = this->clone();
00112 r->mcom.setArguments(a1, a2, a3);
00113 r->mcon.setArguments(a1, a2, a3);
00114 return r;
00115 }
00116
00117 template<class Arg1T, class Arg2T, class Arg3T, class Arg4T>
00118 DataSourceArgsCommand<CommandT,CommandF>* create(DataSource<Arg1T>* a1, DataSource<Arg2T>* a2, DataSource<Arg3T>* a3, DataSource<Arg4T>* a4) const
00119 {
00120 DataSourceArgsCommand<CommandT,CommandF>* r = this->clone();
00121 r->mcom.setArguments(a1, a2, a3, a4);
00122 r->mcon.setArguments(a1, a2, a3, a4);
00123 return r;
00124 }
00125
00126 bool ready() const {
00127 return !minvoked;
00128 }
00129
00130 virtual bool dispatch() {
00131 if (minvoked)
00132 return false;
00133 minvoked = true;
00134 this->readArguments();
00135 return maccept = (mcp->process( this ) != 0);
00136 }
00137
00138 virtual void readArguments() { mcom.readArguments(); }
00139
00140 virtual bool execute() {
00141 mvalid = mcom.execute();
00142 mexec = true;
00143 return mvalid;
00144 }
00145
00146 virtual bool done() const {
00147 if (mexec && mvalid )
00148 return mcon.evaluate() != minvert;
00149 return false;
00150 }
00151
00152 virtual void reset() {
00153 minvoked = (false);
00154 maccept = (false);
00155 mvalid = (false);
00156 mexec = (false);
00157 }
00158
00159 virtual bool sent() const {
00160 return minvoked;
00161 }
00162
00163 virtual bool accepted() const {
00164 return maccept;
00165 }
00166
00167 virtual bool executed() const {
00168 return mexec;
00169 }
00170
00171 virtual bool valid() const {
00172 return mvalid;
00173 }
00174
00175 virtual ConditionInterface* createCondition() const
00176 {
00177 return new detail::ConditionFunctor<CommandT,CommandF>(mcon, minvert);
00178 }
00179
00180 virtual DataSourceArgsCommand<CommandT,CommandF>* clone() const {
00181 return new DataSourceArgsCommand<CommandT,CommandF>(*this);
00182 }
00183
00184 virtual DataSourceArgsCommand<CommandT,CommandF>* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const {
00185 return new DataSourceArgsCommand<CommandT,CommandF>(CommandF(mcom.copy(alreadyCloned)),
00186 CommandF(mcon.copy(alreadyCloned)),mcp, minvert);
00187 }
00188
00189 };
00190 }
00191 }
00192
00193 #endif