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.

The Start flashing menu item starts the Hello world! text in the center of the display flashing<br />

and Stop flashing stops it. The flashing is implemented by an active object that creates<br />

regular timer events and then handles them. Its event handling changes the visibility of the<br />

Hello World! text and redraws the view.<br />

We'll start by looking at CDelayedHello, a derived active object class that implements Set<br />

Hello and its associated Cancel. Then I'll explain some of the underlying fundamentals,<br />

before taking a closer look at CFlashingHello (which implements Start flashing and<br />

Stop flashing) along with some other active object patterns.<br />

class CDelayedHello : public CActive<br />

{<br />

public:<br />

// Construct/destruct<br />

static CDelayedHello* NewL();<br />

~CDelayedHello();<br />

// Request<br />

void SetHello(TTimeIntervalMicroSeconds32 aDelay);<br />

private:<br />

// Construct/destruct<br />

CDelayedHello();<br />

void ConstructL(CEikonEnv* aEnv);<br />

// From CActive<br />

void RunL();<br />

void DoCancel();<br />

private:<br />

RTimer iTimer; // Has<br />

CEikonEnv* iEnv; // Uses<br />

};<br />

From the class declaration, you can see that CDelayedHello:<br />

� Is-a active object, derived from CActive<br />

� Has-a event generator – an RTimer, whose API we'll see below<br />

� Includes an active-object request function, SetHello() that requests an event<br />

from the RTimer<br />

� Implements RunL(), to handle the event generated when the request completes<br />

� Implements DoCancel(), to cancel any outstanding request.<br />

All active object classes share this pattern. They are derived from CActive and implement<br />

its RunL() and DoCancel() functions. They include an event generator and at least one<br />

request function (Figure 17.2).

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

Saved successfully!

Ooh no, something went wrong!