03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

{<br />

return NULL; // Give up!<br />

}<br />

If the state entry completes successfully, however, the following code will be invoked by the<br />

RunL():<br />

CGdpStateMachine::TState* CGdpSmsSender::TSendMsgState::CompleteL()<br />

{<br />

RDebug::Print(_L("Message sent!!"));<br />

delete iSender.iSmsMsg;<br />

iSender.iSocket.Close();<br />

// Let handler know message sent successfully<br />

iSender.iHandler->SendComplete(KErrNone);<br />

return NULL; // Last state so return NULL<br />

}<br />

This simply releases the resources we have used to send the message and notifies the<br />

handler that we have successfully sent the message. Notice how we specify the next state to<br />

enter as NULL as we have completed the process.<br />

If the send fails, the ErrorL() function is invoked:<br />

CGdpStateMachine::TState* CGdpSmsSender::TSendMsgState::ErrorL(TInt<br />

aCode)<br />

{<br />

// Let handler know the reason for sent failure<br />

iSender.iHandler->SendComplete(aCode);<br />

User::Leave(aCode);<br />

return NULL; // Never actually hit<br />

}<br />

The sender state machine's error handler performs the following:<br />

CGdpStateMachine::TState* CGdpSmsSender::ErrorOnStateExit(TInt<br />

/*aError*/)<br />

{<br />

Reset();<br />

if (--iRetries < 0)<br />

return NULL;<br />

return CurrentState(); // Force re-entry to initial state<br />

}<br />

As asynchronous errors often indicate a communications error, we attempt to reset the state<br />

machine and do a limited number of retries.

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

Saved successfully!

Ooh no, something went wrong!