03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

else<br />

// Everything was OK, leave this state<br />

nextState = iState->CompleteL();<br />

}<br />

{<br />

// Something went wrong, ERROR<br />

nextState = iState->ErrorL(err);<br />

}<br />

// Just move on to the next state (could be NULL, in which case<br />

we're done)<br />

ChangeState(nextState);<br />

}<br />

Here, I selectively call either the CompleteL() or ErrorL() members of the current state,<br />

depending on the outcome of the asynchronous request as returned by iStatus.Int(),<br />

inherited from CActive.<br />

Both these member functions indicate state entry asynchronous request completion. I've just<br />

separated them for implementation convenience within the concrete state classes.<br />

Either one of the state completion functions may return a new state to try to enter next. If<br />

NULL is returned, we drop out of RunL() and revert to inactive mode.<br />

Note that unlike ChangeState() this is not run within a trap harness. CActive provides<br />

RunError() to handle and leaves occurring within RunL().<br />

TInt CGdpStateMachine::RunError(TInt aError)<br />

/**<br />

**/<br />

This is called if RunL leaves.<br />

This will be through CompleteL or ErrorL leaving.<br />

Handle the error in the state machine.<br />

{<br />

TState* nextState = ErrorOnStateExit(aError);<br />

ChangeState(nextState);<br />

return KErrNone;<br />

}<br />

Any errors are passed to the concrete state machine's ErrorOnStateExit() error<br />

handler.<br />

Note that SetActive() is never called by the state machine. This is entirely the<br />

responsibility of the concrete state classes, whenever they make an asynchronous request.<br />

The remaining state machine functions are fairly straightforward. The most interesting are<br />

DoCancel(), which simply calls the Cancel() member of the current state, and

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!