Methods Summary |
---|
protected void | addLogRec(java.lang.String string)Add the string to LogRecords.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.mLogRecords.add(this, smh.getCurrentMessage(), string, smh.getCurrentState(),
smh.mStateStack[smh.mStateStackTopIndex].state, smh.mDestState);
|
protected final void | addState(State state, State parent)Add a new state to the state machine
mSmHandler.addState(state, parent);
|
protected final void | addState(State state)Add a new state to the state machine, parent will be null
mSmHandler.addState(state, null);
|
public final java.util.Collection | copyLogRecs()
Vector<LogRec> vlr = new Vector<LogRec>();
SmHandler smh = mSmHandler;
if (smh != null) {
for (LogRec lr : smh.mLogRecords.mLogRecVector) {
vlr.add(lr);
}
}
return vlr;
|
protected final void | deferMessage(android.os.Message msg)Defer this message until next state transition.
Upon transitioning all deferred messages will be
placed on the queue and reprocessed in the original
order. (i.e. The next state the oldest messages will
be processed first)
mSmHandler.deferMessage(msg);
|
public void | dump(java.io.FileDescriptor fd, java.io.PrintWriter pw, java.lang.String[] args)Dump the current state.
// Cannot just invoke pw.println(this.toString()) because if the
// resulting string is to long it won't be displayed.
pw.println(getName() + ":");
pw.println(" total records=" + getLogRecCount());
for (int i = 0; i < getLogRecSize(); i++) {
pw.println(" rec[" + i + "]: " + getLogRec(i).toString());
pw.flush();
}
pw.println("curState=" + getCurrentState().getName());
|
protected final android.os.Message | getCurrentMessage()
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return null;
return smh.getCurrentMessage();
|
protected final IState | getCurrentState()
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return null;
return smh.getCurrentState();
|
public final android.os.Handler | getHandler()
return mSmHandler;
|
public final com.android.internal.util.StateMachine$LogRec | getLogRec(int index)
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return null;
return smh.mLogRecords.get(index);
|
public final int | getLogRecCount()
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return 0;
return smh.mLogRecords.count();
|
public final int | getLogRecSize()
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return 0;
return smh.mLogRecords.size();
|
protected java.lang.String | getLogRecString(android.os.Message msg)Return a string to be logged by LogRec, default
is an empty string. Override if additional information is desired.
return "";
|
public final java.lang.String | getName()
return mName;
|
protected java.lang.String | getWhatToString(int what)
return null;
|
protected void | haltedProcessMessage(android.os.Message msg)Called for any message that is received after
transitionToHalting is called.
|
private void | initStateMachine(java.lang.String name, android.os.Looper looper)Initialize.
mName = name;
mSmHandler = new SmHandler(looper, this);
|
public boolean | isDbg()
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return false;
return smh.isDbg();
|
protected final boolean | isQuit(android.os.Message msg)Validate that the message was sent by
{@link StateMachine#quit} or {@link StateMachine#quitNow}.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return msg.what == SM_QUIT_CMD;
return smh.isQuit(msg);
|
protected void | log(java.lang.String s)Log with debug
Log.d(mName, s);
|
protected void | logAndAddLogRec(java.lang.String s)Log with debug and add to the LogRecords.
addLogRec(s);
log(s);
|
protected void | logd(java.lang.String s)Log with debug attribute
Log.d(mName, s);
|
protected void | loge(java.lang.String s)Log with error attribute
Log.e(mName, s);
|
protected void | loge(java.lang.String s, java.lang.Throwable e)Log with error attribute
Log.e(mName, s, e);
|
protected void | logi(java.lang.String s)Log with info attribute
Log.i(mName, s);
|
protected void | logv(java.lang.String s)Log with verbose attribute
Log.v(mName, s);
|
protected void | logw(java.lang.String s)Log with warning attribute
Log.w(mName, s);
|
public final android.os.Message | obtainMessage()Get a message and set Message.target state machine handler.
Note: The handler can be null if the state machine has quit,
which means target will be null and may cause a AndroidRuntimeException
in MessageQueue#enqueMessage if sent directly or if sent using
StateMachine#sendMessage the message will just be ignored.
return Message.obtain(mSmHandler);
|
public final android.os.Message | obtainMessage(int what)Get a message and set Message.target state machine handler, what.
Note: The handler can be null if the state machine has quit,
which means target will be null and may cause a AndroidRuntimeException
in MessageQueue#enqueMessage if sent directly or if sent using
StateMachine#sendMessage the message will just be ignored.
return Message.obtain(mSmHandler, what);
|
public final android.os.Message | obtainMessage(int what, java.lang.Object obj)Get a message and set Message.target state machine handler,
what and obj.
Note: The handler can be null if the state machine has quit,
which means target will be null and may cause a AndroidRuntimeException
in MessageQueue#enqueMessage if sent directly or if sent using
StateMachine#sendMessage the message will just be ignored.
return Message.obtain(mSmHandler, what, obj);
|
public final android.os.Message | obtainMessage(int what, int arg1)Get a message and set Message.target state machine handler,
what, arg1 and arg2
Note: The handler can be null if the state machine has quit,
which means target will be null and may cause a AndroidRuntimeException
in MessageQueue#enqueMessage if sent directly or if sent using
StateMachine#sendMessage the message will just be ignored.
// use this obtain so we don't match the obtain(h, what, Object) method
return Message.obtain(mSmHandler, what, arg1, 0);
|
public final android.os.Message | obtainMessage(int what, int arg1, int arg2)Get a message and set Message.target state machine handler,
what, arg1 and arg2
Note: The handler can be null if the state machine has quit,
which means target will be null and may cause a AndroidRuntimeException
in MessageQueue#enqueMessage if sent directly or if sent using
StateMachine#sendMessage the message will just be ignored.
return Message.obtain(mSmHandler, what, arg1, arg2);
|
public final android.os.Message | obtainMessage(int what, int arg1, int arg2, java.lang.Object obj)Get a message and set Message.target state machine handler,
what, arg1, arg2 and obj
Note: The handler can be null if the state machine has quit,
which means target will be null and may cause a AndroidRuntimeException
in MessageQueue#enqueMessage if sent directly or if sent using
StateMachine#sendMessage the message will just be ignored.
return Message.obtain(mSmHandler, what, arg1, arg2, obj);
|
protected void | onHalting()This will be called once after handling a message that called
transitionToHalting. All subsequent messages will invoke
{@link StateMachine#haltedProcessMessage(Message)}
|
protected void | onQuitting()This will be called once after a quit message that was NOT handled by
the derived StateMachine. The StateMachine will stop and any subsequent messages will be
ignored. In addition, if this StateMachine created the thread, the thread will
be stopped after this method returns.
|
protected final void | quit()Quit the state machine after all currently queued up messages are processed.
// mSmHandler can be null if the state machine is already stopped.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.quit();
|
protected final void | quitNow()Quit the state machine immediately all currently queued messages will be discarded.
// mSmHandler can be null if the state machine is already stopped.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.quitNow();
|
protected boolean | recordLogRec(android.os.Message msg)
return true;
|
protected final void | removeMessages(int what)Removes a message from the message queue.
Protected, may only be called by instances of StateMachine.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.removeMessages(what);
|
public final void | sendMessage(int what)Enqueue a message to this state machine.
Message is ignored if state machine has quit.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.sendMessage(obtainMessage(what));
|
public final void | sendMessage(int what, java.lang.Object obj)Enqueue a message to this state machine.
Message is ignored if state machine has quit.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.sendMessage(obtainMessage(what, obj));
|
public final void | sendMessage(int what, int arg1)Enqueue a message to this state machine.
Message is ignored if state machine has quit.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.sendMessage(obtainMessage(what, arg1));
|
public final void | sendMessage(int what, int arg1, int arg2)Enqueue a message to this state machine.
Message is ignored if state machine has quit.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.sendMessage(obtainMessage(what, arg1, arg2));
|
public final void | sendMessage(int what, int arg1, int arg2, java.lang.Object obj)Enqueue a message to this state machine.
Message is ignored if state machine has quit.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.sendMessage(obtainMessage(what, arg1, arg2, obj));
|
public final void | sendMessage(android.os.Message msg)Enqueue a message to this state machine.
Message is ignored if state machine has quit.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.sendMessage(msg);
|
protected final void | sendMessageAtFrontOfQueue(int what)Enqueue a message to the front of the queue for this state machine.
Protected, may only be called by instances of StateMachine.
Message is ignored if state machine has quit.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.sendMessageAtFrontOfQueue(obtainMessage(what));
|
protected final void | sendMessageAtFrontOfQueue(int what, java.lang.Object obj)Enqueue a message to the front of the queue for this state machine.
Protected, may only be called by instances of StateMachine.
Message is ignored if state machine has quit.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.sendMessageAtFrontOfQueue(obtainMessage(what, obj));
|
protected final void | sendMessageAtFrontOfQueue(int what, int arg1)Enqueue a message to the front of the queue for this state machine.
Protected, may only be called by instances of StateMachine.
Message is ignored if state machine has quit.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.sendMessageAtFrontOfQueue(obtainMessage(what, arg1));
|
protected final void | sendMessageAtFrontOfQueue(int what, int arg1, int arg2)Enqueue a message to the front of the queue for this state machine.
Protected, may only be called by instances of StateMachine.
Message is ignored if state machine has quit.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.sendMessageAtFrontOfQueue(obtainMessage(what, arg1, arg2));
|
protected final void | sendMessageAtFrontOfQueue(int what, int arg1, int arg2, java.lang.Object obj)Enqueue a message to the front of the queue for this state machine.
Protected, may only be called by instances of StateMachine.
Message is ignored if state machine has quit.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.sendMessageAtFrontOfQueue(obtainMessage(what, arg1, arg2, obj));
|
protected final void | sendMessageAtFrontOfQueue(android.os.Message msg)Enqueue a message to the front of the queue for this state machine.
Protected, may only be called by instances of StateMachine.
Message is ignored if state machine has quit.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.sendMessageAtFrontOfQueue(msg);
|
public final void | sendMessageDelayed(int what, long delayMillis)Enqueue a message to this state machine after a delay.
Message is ignored if state machine has quit.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.sendMessageDelayed(obtainMessage(what), delayMillis);
|
public final void | sendMessageDelayed(int what, java.lang.Object obj, long delayMillis)Enqueue a message to this state machine after a delay.
Message is ignored if state machine has quit.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.sendMessageDelayed(obtainMessage(what, obj), delayMillis);
|
public final void | sendMessageDelayed(int what, int arg1, long delayMillis)Enqueue a message to this state machine after a delay.
Message is ignored if state machine has quit.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.sendMessageDelayed(obtainMessage(what, arg1), delayMillis);
|
public final void | sendMessageDelayed(int what, int arg1, int arg2, long delayMillis)Enqueue a message to this state machine after a delay.
Message is ignored if state machine has quit.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.sendMessageDelayed(obtainMessage(what, arg1, arg2), delayMillis);
|
public final void | sendMessageDelayed(int what, int arg1, int arg2, java.lang.Object obj, long delayMillis)Enqueue a message to this state machine after a delay.
Message is ignored if state machine has quit.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.sendMessageDelayed(obtainMessage(what, arg1, arg2, obj), delayMillis);
|
public final void | sendMessageDelayed(android.os.Message msg, long delayMillis)Enqueue a message to this state machine after a delay.
Message is ignored if state machine has quit.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.sendMessageDelayed(msg, delayMillis);
|
public void | setDbg(boolean dbg)Set debug enable/disabled.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
smh.setDbg(dbg);
|
protected final void | setInitialState(State initialState)Set the initial state. This must be invoked before
and messages are sent to the state machine.
mSmHandler.setInitialState(initialState);
|
public final void | setLogOnlyTransitions(boolean enable)Set to log only messages that cause a state transition
mSmHandler.mLogRecords.setLogOnlyTransitions(enable);
|
public final void | setLogRecSize(int maxSize)Set number of log records to maintain and clears all current records.
mSmHandler.mLogRecords.setSize(maxSize);
|
public void | start()Start the state machine.
// mSmHandler can be null if the state machine has quit.
SmHandler smh = mSmHandler;
if (smh == null) return;
/** Send the complete construction message */
smh.completeConstruction();
|
public java.lang.String | toString()
StringWriter sr = new StringWriter();
PrintWriter pr = new PrintWriter(sr);
dump(null, pr, null);
pr.flush();
pr.close();
return sr.toString();
|
protected final void | transitionTo(IState destState)transition to destination state. Upon returning
from processMessage the current state's exit will
be executed and upon the next message arriving
destState.enter will be invoked.
this function can also be called inside the enter function of the
previous transition target, but the behavior is undefined when it is
called mid-way through a previous transition (for example, calling this
in the enter() routine of a intermediate node when the current transition
target is one of the nodes descendants).
mSmHandler.transitionTo(destState);
|
protected final void | transitionToHaltingState()transition to halt state. Upon returning
from processMessage we will exit all current
states, execute the onHalting() method and then
for all subsequent messages haltedProcessMessage
will be called.
mSmHandler.transitionTo(mSmHandler.mHaltingState);
|
protected void | unhandledMessage(android.os.Message msg)Called when message wasn't handled
if (mSmHandler.mDbg) loge(" - unhandledMessage: msg.what=" + msg.what);
|