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
00040 #include "StateMachineService.hpp"
00041
00042 #include "../Attribute.hpp"
00043 #include "../FactoryExceptions.hpp"
00044 #include "../TaskContext.hpp"
00045 #include "../OperationCaller.hpp"
00046
00047 namespace RTT
00048 {
00049
00050 using namespace detail;
00051
00052 void StateMachineService::createOperationFactory() {
00053
00054
00055
00056
00057 DataSource<StateMachinePtr>* ptr = _this.get();
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 addOperationDS("trace", &StateMachine::trace,ptr).doc("Trace the execution of this StateMachine. *Not* Real-Time.");
00069 addOperationDS("activate", &StateMachine::activate,ptr).doc("Activate this StateMachine to initial state and enter request Mode.");
00070 addOperationDS("deactivate", &StateMachine::deactivate,ptr).doc("Deactivate this StateMachine");
00071 addOperationDS("start", &StateMachine::automatic,ptr).doc("Start this StateMachine, enter automatic Mode.");
00072 addOperationDS("automatic", &StateMachine::automatic,ptr).doc("Start this StateMachine, enter automatic Mode.");
00073 addOperationDS("pause", &StateMachine::pause,ptr).doc("Pause this StateMachine, enter paused Mode.");
00074 addOperationDS("step", &StateMachine::step,ptr).doc(
00075 "Step this StateMachine. When paused, step a single instruction or transition evaluation. \n"
00076 "When in reactive mode, evaluate transitions and go to a next state, or if none, run handle.");
00077 addOperationDS("reset", &StateMachine::reset,ptr).doc("Reset this StateMachine to the initial state");
00078 addOperationDS("stop", &StateMachine::stop,ptr).doc("Stop this StateMachine to the final state and enter request Mode.");
00079 addOperationDS("reactive", &StateMachine::reactive,ptr).doc("Enter reactive mode (see requestState() and step() ).\n OperationCaller is done if ready for requestState() or step() method.");
00080 addOperationDS("requestState", &StateMachine::requestState,ptr).doc("Request to go to a particular state. Will succeed if there exists a valid transition from this state to the requested state.").arg("State", "The state to make the transition to.");
00081
00082 addOperationDS("inState", &StateMachine::inState,ptr).doc("Is the StateMachine in a given state ?").arg("State", "State Name");
00083 addOperationDS("inError", &StateMachine::inError,ptr).doc("Is this StateMachine in error ?");
00084 addOperationDS("getState", &StateMachine::getCurrentStateName,ptr).doc("The name of the current state. An empty string if not active.");
00085 addOperationDS("isActive", &StateMachine::isActive,ptr).doc("Is this StateMachine activated (possibly in transition) ?");
00086 addOperationDS("isRunning", &StateMachine::isAutomatic,ptr).doc("Is this StateMachine running in automatic mode ?");
00087 addOperationDS("isReactive", &StateMachine::isReactive,ptr).doc("Is this StateMachine ready and waiting for requests or events ?");
00088 addOperationDS("isPaused", &StateMachine::isPaused,ptr).doc("Is this StateMachine paused ?");
00089 addOperationDS("inInitialState", &StateMachine::inInitialState,ptr).doc("Is this StateMachine in the initial state ?");
00090 addOperationDS("inFinalState", &StateMachine::inFinalState,ptr).doc("Is this StateMachine in the final state ?");
00091 addOperationDS("inTransition", &StateMachine::inTransition,ptr).doc("Is this StateMachine executing a entry|handle|exit program ?");
00092 }
00093
00094 StateMachineServicePtr StateMachineService::copy(ParsedStateMachinePtr newsc, std::map<const DataSourceBase*, DataSourceBase*>& replacements, bool instantiate )
00095 {
00096
00097
00098
00099 StateMachineServicePtr tmp( new StateMachineService( newsc, this->mtc ) );
00100 replacements[ _this.get() ] = tmp->_this.get();
00101
00102 ConfigurationInterface* dummy = ConfigurationInterface::copy( replacements, instantiate );
00103 tmp->loadValues( dummy->getValues());
00104 delete dummy;
00105
00106 return tmp;
00107 }
00108
00109 StateMachineService::StateMachineService(ParsedStateMachinePtr statem, TaskContext* tc)
00110 : Service( statem->getName() ),
00111 _this( new ValueDataSource<StateMachinePtr>( statem ) ),
00112 statemachine(statem),
00113 mtc(tc)
00114 {
00115 this->createOperationFactory();
00116 this->setOwner( tc );
00117 }
00118
00119 StateMachineService::~StateMachineService()
00120 {
00121
00122 if ( statemachine ) {
00123 statemachine->setService( StateMachineServicePtr() );
00124 }
00125 }
00126
00127
00128 }
00129