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.

Figure 17.2<br />

It is also worth mentioning here a change from Symbian OS v5. The CActive class now<br />

provides an error handling function called RunError(). This is a virtual function for which<br />

CActive provides a default implementation. The active scheduler calls the<br />

RunError()function of an active object if a leave occurs in that object's RunL(). This will<br />

be explained in more detail later in the chapter.<br />

17.1.1 Construction and Destruction<br />

Let's walk through the implementations of all the functions declared above. First, the easy<br />

bits: here are two of the members involved in construction and destruction.<br />

CDelayedHello* CDelayedHello::NewL()<br />

{<br />

CDelayedHello* self = new(ELeave) CDelayedHello;<br />

CleanupStack::PushL(self);<br />

self->ConstructL();<br />

CleanupStack::Pop(self);<br />

return self;<br />

}<br />

CDelayedHello::CDelayedHello()<br />

: CActive(0)<br />

{<br />

CActiveScheduler::Add(this);<br />

}<br />

NewL() is a static function that follows the standard constructor- encapsulation pattern that<br />

we saw in <strong>Chapter</strong> 6.<br />

The C++ constructor is required for any derived active object class; inside it, you call<br />

CActive's constructor to specify the active object's priority, which is used for tiebreaking<br />

when more than one event occurs while another is being handled. You should specify zero<br />

here unless there are good reasons to specify something lower or something higher. I'll<br />

cover those reasons below. The new object adds itself to the active scheduler, so that the<br />

active scheduler can include it in event handling.<br />

void CDelayedHello::ConstructL()<br />

{<br />

iEnv = CEikonEnv::Static();<br />

User::LeaveIfError(iTimer.CreateLocal());

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

Saved successfully!

Ooh no, something went wrong!