CommandExecFunction.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 COMMAND_EXEC_FUNCTION_HPP
00040 #define COMMAND_EXEC_FUNCTION_HPP
00041
00042 #include "ConditionInterface.hpp"
00043 #include "CommandInterface.hpp"
00044 #include "DataSources.hpp"
00045 #include "ProgramInterface.hpp"
00046 #include "ProgramProcessor.hpp"
00047 #include "DispatchInterface.hpp"
00048 #include "DataSource.hpp"
00049 #include <boost/shared_ptr.hpp>
00050
00051 namespace RTT
00052 {
00053 using namespace detail;
00057 class RTT_API ConditionExecFunction
00058 : public ConditionInterface
00059 {
00060 DataSource<ProgramInterface*>::shared_ptr _v;
00061 public:
00062 ConditionExecFunction( DataSource<ProgramInterface*>* v)
00063 : _v( v )
00064 {}
00065
00066 bool evaluate()
00067 {
00068 return _v->get()->isStopped();
00069 }
00070
00071 ConditionInterface* clone() const
00072 {
00073 return new ConditionExecFunction( _v.get() );
00074 }
00075
00076 ConditionInterface* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const
00077 {
00078
00079
00080 return new ConditionExecFunction( _v->copy( alreadyCloned ) );
00081 }
00082
00083 };
00084
00090 class RTT_API CommandExecFunction
00091 : public DispatchInterface
00092 {
00093 CommandInterface* minit;
00094 ProgramProcessor* _proc;
00095 AssignableDataSource<ProgramInterface*>::shared_ptr _v;
00096 boost::shared_ptr<ProgramInterface> _foo;
00097 bool isqueued;
00098 AssignableDataSource<bool>::shared_ptr maccept;
00099 public:
00108 CommandExecFunction( CommandInterface* init_com, boost::shared_ptr<ProgramInterface> foo, ProgramProcessor* p, AssignableDataSource<ProgramInterface*>* v = 0 , AssignableDataSource<bool>* a = 0 );
00109
00110 ~CommandExecFunction();
00111
00112 void readArguments()
00113 {
00114 minit->readArguments();
00115 }
00116
00117 bool ready() const {
00118 return !isqueued;
00119 }
00120
00121 bool dispatch()
00122 {
00123 return execute();
00124 }
00125
00126 bool execute()
00127 {
00128
00129 if (isqueued == false ) {
00130 isqueued = true;
00131 maccept->set( minit->execute() && _proc->runFunction( _foo.get() ) );
00132 return maccept->get();
00133 }
00134
00135
00136 return maccept->get() && ! _foo->inError();
00137 }
00138
00139 void reset()
00140 {
00141
00142 _foo->reset();
00143 minit->reset();
00144 isqueued = false;
00145
00146 _foo->stop();
00147 }
00148
00149 virtual bool sent() const {
00150 return isqueued;
00151 }
00152
00153 virtual bool accepted() const {
00154 return maccept->get();
00155 }
00156
00157 virtual bool executed() const {
00158 return isqueued;
00159 }
00160
00161 virtual bool valid() const {
00162 return maccept->get() && ! _foo->inError();
00163 }
00164
00165 virtual bool done() const {
00166 return maccept->get() && _v->get()->isStopped();
00167 }
00168
00172 ConditionInterface* createCondition() const
00173 {
00174 return new ConditionExecFunction( _v.get() );
00175 }
00176
00177 DispatchInterface* clone() const
00178 {
00179
00180 return new CommandExecFunction( minit->clone(), _foo, _proc, _v.get(), maccept.get() );
00181 }
00182
00183 DispatchInterface* copy( std::map<const DataSourceBase*, DataSourceBase*>& alreadyCloned ) const
00184 {
00185
00186
00187 boost::shared_ptr<ProgramInterface> fcpy( _foo->copy(alreadyCloned) );
00188 AssignableDataSource<ProgramInterface*>* vcpy = _v->copy(alreadyCloned);
00189 vcpy->set( fcpy.get() );
00190 AssignableDataSource<bool>* acpy = maccept->copy(alreadyCloned);
00191 return new CommandExecFunction( minit->copy(alreadyCloned), fcpy , _proc, vcpy, acpy );
00192 }
00193
00194 };
00195
00196 }
00197
00198 #endif