|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjp.go.aist.rtm.RTC.StateMachine<STATE,LISTENER>
public class StateMachine<STATE,LISTENER>
State machine class
StateMachine class is a class to realize a state machine. Example: ActiveObject assumes to be an active object that has the state machine. There are three states such as INACTIVE, ACTIVE and ERROR state, and if you want to define Entry or Exit action, this class will realize as follows:
class ActiveObject { public: enum MyState { INACTIVE, ACTIVE, ERROR }; typedef StatesIf you want to give a class to some states, you must implement the class to satisfy the following conditions:MyStates; ActiveObject() : m_sm(3) { m_sm.setNOP(&ActiveObject::nullAction); m_sm.setListener(this); m_sm.setExitAction(INACTIVE, &ActiveObject::inactiveExit); : m_sm.setPostDoAction(ERROR, &ActiveObject::errorPostDo); m_sm.setTransitionAction(&ActiveObject:transition); }; bool nullAction(MyStates st) {}; bool inactiveExit(MyStates st) {}; : bool errorPostDo(MyStates st) {}; bool transition(MyStates st) {}; private: StateMachine m_sm; };
Field Summary | |
---|---|
protected java.util.HashMap<STATE,StateAction> |
m_do
Callback function for Do action |
protected java.util.HashMap<STATE,StateAction> |
m_entry
Callback function for Entry action |
protected java.util.HashMap<STATE,StateAction> |
m_exit
Callback function for Exit action |
protected LISTENER |
m_listener
Callback function for listener |
protected int |
m_num
Number of state |
protected java.util.HashMap<STATE,StateAction> |
m_postdo
Callback function for PostDo action |
protected java.util.HashMap<STATE,StateAction> |
m_predo
Callback function for PreDo action |
protected StateHolder<STATE> |
m_states
Current state information |
protected StateAction |
m_transit
Callback function for State transition action |
Constructor Summary | |
---|---|
StateMachine(int num_of_state)
Constructor |
Method Summary | |
---|---|
STATE |
getState()
Get current state |
void |
goTo(STATE state)
Transit State |
boolean |
isIn(STATE state)
Check current state |
boolean |
setDoAction(STATE state,
StateAction call_back)
Set Do action function |
boolean |
setEntryAction(STATE state,
StateAction call_back)
Set Entry action function |
boolean |
setExitAction(STATE state,
StateAction call_back)
Set Exit action function |
void |
setListener(LISTENER listener)
Set Listener Object |
void |
setNOP()
Set NOP function |
boolean |
setPostDoAction(STATE state,
StateAction call_back)
Set PostDo action function |
boolean |
setPreDoAction(STATE state,
StateAction call_back)
Set PreDo action function |
void |
setStartState(StateHolder states)
Set the initial state |
boolean |
setTransitionAction(StateAction call_back)
Set state transition action function |
void |
worker()
Worker function |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int m_num
protected LISTENER m_listener
protected java.util.HashMap<STATE,StateAction> m_entry
protected java.util.HashMap<STATE,StateAction> m_predo
protected java.util.HashMap<STATE,StateAction> m_do
protected java.util.HashMap<STATE,StateAction> m_postdo
protected java.util.HashMap<STATE,StateAction> m_exit
protected StateAction m_transit
protected StateHolder<STATE> m_states
Constructor Detail |
---|
public StateMachine(int num_of_state)
num_of_state
-
Number of states in the state machineMethod Detail |
---|
public void setNOP()
Set NOP function that does not do anything
public void setListener(LISTENER listener)
Set Listener Object invoked when various actions are executed.
listener
-
Listener objectpublic boolean setEntryAction(STATE state, StateAction call_back)
Set callback function for Entry action that is executed when entering in each state.
state
-
Target state for the setcall_back
-
Callback function for Entry action
public boolean setPreDoAction(STATE state, StateAction call_back)
Set callback function for PreDo action that is executed in each state.
state
-
Target state for the setcall_back
-
Callback function for PreDo action
public boolean setDoAction(STATE state, StateAction call_back)
Set callback function for Do action that is executed in each state.
state
-
Target state for the setcall_back
-
Callback function for Do action
public boolean setPostDoAction(STATE state, StateAction call_back)
Set callback function for PostDo action that is executed in each state.
state
-
Target state for the setcall_back
-
Callback function for PostDo action
public boolean setExitAction(STATE state, StateAction call_back)
Set callback function for Exit action that is executed in each state.
state
-
Target state for the setcall_back
-
Callback function for Exit action
public boolean setTransitionAction(StateAction call_back)
Set callback function for State transition action that is executed when transiting to the state.
call_back
-
Callback function for State transition
public void setStartState(StateHolder states)
Set the initial state of the state machine.
states
-
Initial statepublic STATE getState()
public boolean isIn(STATE state)
Check whether current state matches the state specified by argument.
state
-
Target state for the check
public void goTo(STATE state)
Transit to the specified state. This function sets the next state forcibly. Therefore, to determine the next state, users must get current state and implement that logic. If transit destination is the same as the current state, flag of self-transition will be set.
state
-
State of the transition destinationpublic void worker()
This is a worker function of the state machine. Execute the invocation of each action at actual state transition and the state transition occurrence.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |