Lines Matching defs:state

37  * <p>The state machine defined here is a hierarchical state machine which processes messages
40 * <p>A state is a <code>State</code> object and must implement
44 * cleanup of the state respectively. The <code>getName</code> method returns the
45 * name of the state the default implementation returns the class name it may be
46 * desirable to have this return the name of the state instance name instead.
47 * In particular if a particular state class has multiple instances.</p>
49 * <p>When a state machine is created <code>addState</code> is used to build the
51 * is the initial state. After construction the programmer calls <code>start</code>
52 * which initializes and starts the state machine. The first action the StateMachine
53 * is to the invoke <code>enter</code> for all of the initial state's hierarchy,
57 * state machine below mP1.enter will be invoked and then mS1.enter. Finally,
58 * messages sent to the state machine will be processed by the current state,
59 * in our simple state machine below that would initially be mS1.processMessage.</p>
63 mS2 mS1 ----> initial state
65 * <p>After the state machine is created and started, messages are sent to a state
67 * <code>obtainMessage</code>. When the state machine receives a message the
68 * current state's <code>processMessage</code> is invoked. In the above example
69 * mS1.processMessage will be invoked first. The state may use <code>transitionTo</code>
70 * to change the current state to a new state</p>
72 * <p>Each state in the state machine may have a zero or one parent states and if
73 * a child state is unable to handle a message it may have the message processed
75 * <code>unhandledMessage</code> will be invoked to give one last chance for the state machine
78 * <p>When all processing is completed a state machine may choose to call
80 * returns the state machine will transfer to an internal <code>HaltingState</code>
81 * and invoke <code>halting</code>. Any message subsequently received by the state
84 * <p>If it is desirable to completely stop the state machine call <code>quit</code> or
85 * <code>quitNow</code>. These will call <code>exit</code> of the current state and its parents,
91 * <p>Since the states are arranged in a hierarchy transitioning to a new state
94 * the current state is found. We then exit from the current state and its
95 * parent's up to but not including the common parent state and then enter all
96 * of the new states below the common parent down to the destination state.
104 * transition is made to a new state. At which time all of the deferred messages
105 * will be put on the front of the state machine queue with the oldest message
106 * at the front. These will then be processed by the new current state before
108 * these are protected and may only be invoked from within a state machine.</p>
110 * <p>To illustrate some of these properties we'll use state machine with an 8
111 * state hierarchy:</p>
119 mS3 mS4 mS5 ---> initial state
129 * processMessage the state machine runtime will find the common parent,
134 * <p>Now for some concrete examples, here is the canonical HelloWorld as a state machine.
164 * <p>A more interesting state machine is one with four states
171 * <p>Here is a description of this state machine using pseudo code.</p>
173 state mP1 {
188 state mS1 parent mP1 {
200 state mS2 parent mP1 {
217 state mP2 {
260 // Set the initial state
281 // Any message we don't understand in this state invokes unhandledMessage
420 // Name of the state machine and used as logging tag
460 * @param state the state which handled the message
461 * @param orgState is the first state the received the message but
463 * @param transToState is the state that was transitioned to after the message was
466 LogRec(StateMachine sm, Message msg, String info, IState state, IState orgState,
468 update(sm, msg, info, state, orgState, transToState);
473 * @param state that handled the message
474 * @param orgState is the first state the received the message
475 * @param dstState is the state that was the transition target when logging
477 public void update(StateMachine sm, Message msg, String info, IState state, IState orgState,
483 mState = state;
510 * @return the state that handled this message
517 * @return the state destination state if a transition is occurring or null if none.
524 * @return the original state that received the message.
562 * A list of log records including messages recently processed by the state machine.
650 * @param state that handled the message
651 * @param orgState is the first state the received the message but
653 * @param transToState is the state that was transitioned to after the message was
657 synchronized void add(StateMachine sm, Message msg, String messageInfo, IState state,
661 mLogRecVector.add(new LogRec(sm, msg, messageInfo, state, orgState, transToState));
668 pmi.update(sm, msg, messageInfo, state, orgState, transToState);
687 /** A list of log records including messages this state machine has processed */
690 /** true if construction of the state machine has not been completed */
699 /** A temporary stack used to manage the state stack */
705 /** State used when state machine is halted */
708 /** State used when state machine is quitting */
715 * Information about a state.
719 /** The state */
720 State state;
722 /** The parent of this state, null if there is no parent */
725 /** True when the state has been entered and on the stack */
733 return "state=" + state.getName() + ",active=" + active + ",parent="
734 + ((parentStateInfo == null) ? "null" : parentStateInfo.state.getName());
738 /** The map of all of the states in the state machine */
741 /** The initial state that will process the first message */
744 /** The destination state when transitionTo has been invoked */
772 * Handle messages sent to the state machine by calling
773 * the current state's processMessage. It also handles
775 * back onto the queue when transitioning to a new state.
808 * @param msgProcessedState is the state that processed the message
816 State orgState = mStateStack[mStateStackTopIndex].state;
847 * common ancestor state of the enter/exit states. Then
856 * Since we have transitioned to a new state we need to have
888 * state. All subsequent messages will be processed in
889 * in the halting state which invokes haltedProcessMessage(msg);
920 * Complete the construction of the state machine.
926 * Determine the maximum depth of the state hierarchy
927 * so we can allocate the state stacks.
952 * Process the message. If the current state doesn't handle
954 * call the state machines unhandledMessage method.
955 * @return the state that processed the message
960 mSm.log("processMsg: " + curStateInfo.state.getName());
966 while (!curStateInfo.state.processMessage(msg)) {
979 mSm.log("processMsg: " + curStateInfo.state.getName());
983 return (curStateInfo != null) ? curStateInfo.state : null;
987 * Call the exit method for each state from the top of stack
988 * up to the common ancestor state.
993 State curState = mStateStack[mStateStackTopIndex].state;
1002 * Invoke the enter method starting at the entering index to top of state stack
1006 if (mDbg) mSm.log("invokeEnterMethods: " + mStateStack[i].state.getName());
1007 mStateStack[i].state.enter();
1031 * Move the contents of the temporary stack to the state stack
1052 + mStateStack[mStateStackTopIndex].state.getName());
1061 * state that is already active i.e. StateInfo.active == true.
1066 * current state or null if there is no common parent.
1070 * Search up the parent list of the destination state for an active
1071 * state. Use a do while() loop as the destState must always be entered
1073 * the current state.
1117 * @return current state
1120 return mStateStack[mStateStackTopIndex].state;
1124 * Add a new state to the state machine. Bottom up addition
1125 * of states is allowed but the same state may only exist
1128 * @param state the state to add
1129 * @param parent the parent of state
1130 * @return stateInfo for this state
1132 private final StateInfo addState(State state, State parent) {
1134 mSm.log("addStateInternal: E state=" + state.getName() + ",parent="
1145 StateInfo stateInfo = mStateInfo.get(state);
1148 mStateInfo.put(state, stateInfo);
1151 // Validate that we aren't adding the same state in two different hierarchies.
1154 throw new RuntimeException("state already added");
1156 stateInfo.state = state;
1167 * @param sm the hierarchical state machine
1235 * @param looper for this state machine
1236 * @param name of the state machine
1246 * @param name of the state machine
1259 * @param name of the state machine
1268 * @param name of the state machine
1275 * Add a new state to the state machine
1276 * @param state the state to add
1277 * @param parent the parent of state
1279 protected final void addState(State state, State parent) {
1280 mSmHandler.addState(state, parent);
1284 * Add a new state to the state machine, parent will be null
1285 * @param state to add
1287 protected final void addState(State state) {
1288 mSmHandler.addState(state, null);
1292 * Set the initial state. This must be invoked before
1293 * and messages are sent to the state machine.
1295 * @param initialState is the state which will receive the first message.
1305 // mSmHandler can be null if the state machine has quit.
1312 * @return current state
1315 // mSmHandler can be null if the state machine has quit.
1322 * transition to destination state. Upon returning
1323 * from processMessage the current state's exit will
1333 * @param destState will be the state that receives the next message.
1340 * transition to halt state. Upon returning
1351 * Defer this message until next state transition.
1354 * order. (i.e. The next state the oldest messages will
1413 * Set to log only messages that cause a state transition
1425 // mSmHandler can be null if the state machine has quit.
1435 // mSmHandler can be null if the state machine has quit.
1445 // mSmHandler can be null if the state machine has quit.
1471 // mSmHandler can be null if the state machine has quit.
1475 smh.mStateStack[smh.mStateStackTopIndex].state, smh.mDestState);
1504 * @return Handler, maybe null if state machine has quit.
1511 * Get a message and set Message.target state machine handler.
1513 * Note: The handler can be null if the state machine has quit,
1525 * Get a message and set Message.target state machine handler, what.
1527 * Note: The handler can be null if the state machine has quit,
1540 * Get a message and set Message.target state machine handler,
1543 * Note: The handler can be null if the state machine has quit,
1557 * Get a message and set Message.target state machine handler,
1560 * Note: The handler can be null if the state machine has quit,
1575 * Get a message and set Message.target state machine handler,
1578 * Note: The handler can be null if the state machine has quit,
1593 * Get a message and set Message.target state machine handler,
1596 * Note: The handler can be null if the state machine has quit,
1612 * Enqueue a message to this state machine.
1614 * Message is ignored if state machine has quit.
1617 // mSmHandler can be null if the state machine has quit.
1625 * Enqueue a message to this state machine.
1627 * Message is ignored if state machine has quit.
1630 // mSmHandler can be null if the state machine has quit.
1638 * Enqueue a message to this state machine.
1640 * Message is ignored if state machine has quit.
1643 // mSmHandler can be null if the state machine has quit.
1651 * Enqueue a message to this state machine.
1653 * Message is ignored if state machine has quit.
1656 // mSmHandler can be null if the state machine has quit.
1664 * Enqueue a message to this state machine.
1666 * Message is ignored if state machine has quit.
1669 // mSmHandler can be null if the state machine has quit.
1677 * Enqueue a message to this state machine.
1679 * Message is ignored if state machine has quit.
1682 // mSmHandler can be null if the state machine has quit.
1690 * Enqueue a message to this state machine after a delay.
1692 * Message is ignored if state machine has quit.
1695 // mSmHandler can be null if the state machine has quit.
1703 * Enqueue a message to this state machine after a delay.
1705 * Message is ignored if state machine has quit.
1708 // mSmHandler can be null if the state machine has quit.
1716 * Enqueue a message to this state machine after a delay.
1718 * Message is ignored if state machine has quit.
1721 // mSmHandler can be null if the state machine has quit.
1729 * Enqueue a message to this state machine after a delay.
1731 * Message is ignored if state machine has quit.
1734 // mSmHandler can be null if the state machine has quit.
1742 * Enqueue a message to this state machine after a delay.
1744 * Message is ignored if state machine has quit.
1748 // mSmHandler can be null if the state machine has quit.
1756 * Enqueue a message to this state machine after a delay.
1758 * Message is ignored if state machine has quit.
1761 // mSmHandler can be null if the state machine has quit.
1769 * Enqueue a message to the front of the queue for this state machine.
1772 * Message is ignored if state machine has quit.
1775 // mSmHandler can be null if the state machine has quit.
1783 * Enqueue a message to the front of the queue for this state machine.
1786 * Message is ignored if state machine has quit.
1789 // mSmHandler can be null if the state machine has quit.
1797 * Enqueue a message to the front of the queue for this state machine.
1800 * Message is ignored if state machine has quit.
1803 // mSmHandler can be null if the state machine has quit.
1812 * Enqueue a message to the front of the queue for this state machine.
1815 * Message is ignored if state machine has quit.
1818 // mSmHandler can be null if the state machine has quit.
1826 * Enqueue a message to the front of the queue for this state machine.
1829 * Message is ignored if state machine has quit.
1832 // mSmHandler can be null if the state machine has quit.
1840 * Enqueue a message to the front of the queue for this state machine.
1843 * Message is ignored if state machine has quit.
1846 // mSmHandler can be null if the state machine has quit.
1858 // mSmHandler can be null if the state machine has quit.
1870 // mSmHandler can be null if the state machine has quit.
1878 * Quit the state machine after all currently queued up messages are processed.
1881 // mSmHandler can be null if the state machine is already stopped.
1889 * Quit the state machine immediately all currently queued messages will be discarded.
1892 // mSmHandler can be null if the state machine is already stopped.
1903 // mSmHandler can be null if the state machine has quit.
1916 // mSmHandler can be null if the state machine has quit.
1924 * Start the state machine.
1927 // mSmHandler can be null if the state machine has quit.
1936 * Dump the current state.