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.

class TState<br />

{<br />

public:<br />

virtual void EnterL() = 0;<br />

virtual TState* CompleteL() = 0;<br />

virtual TState* ErrorL(TInt aCode) = 0;<br />

virtual void Cancel() = 0;<br />

};<br />

protected:<br />

CGdpStateMachine(TPriority aPriority);<br />

void ChangeState(TState* aNextState);<br />

inline TState* CurrentState();<br />

void SetNextState(TState* aNextState);<br />

void ReEnterCurrentState();<br />

// Methods to be implemented by concrete state machines<br />

virtual TState* ErrorOnStateEntry(TInt aError) = 0;<br />

virtual TState* ErrorOnStateExit(TInt aError) = 0;<br />

private:<br />

// Overrides of CActive functions<br />

void RunL();<br />

void DoCancel();<br />

private:<br />

TState* iState; // Current state<br />

};<br />

CGdpStateMachine derives from CActive and implements the pure virtual functions<br />

declared in that class – namely, RunL() and DoCancel(). This means that any concrete<br />

state machine can use the features provided by CActive without actually having to redefine<br />

these functions.<br />

Derived concrete classes do, however, have to implement further abstract functions from<br />

CGdpStateMachine – namely, ErrorOnStateEntry() and ErrorOnStateExit(),<br />

which I will come to in a moment. In addition, the concrete state machine must provide<br />

appropriate means to interface with external objects.<br />

The state base class, TState, is defined as a nested class within CGdpStateMachine.<br />

Each specific concrete state within a task must provide an instance of a class derived from<br />

this base. The iState member in CGdpStateMachine points to the current state – it is<br />

private, so derived classes must access it through the various getters and setters provided.

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

Saved successfully!

Ooh no, something went wrong!