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.

A RunL() function can stop the active scheduler by issuing<br />

CActiveScheduler::Stop(). When that RunL() returns, the function call to<br />

CActiveScheduler::Start() will complete.<br />

Stopping the active scheduler will bring down the thread's event- handling framework, which<br />

is not something you should do lightly. Only do it if you are the main active object that<br />

controls the thread.<br />

As a server programmer, you have to provide server bootstrap code that includes creating<br />

and starting the active scheduler for your server thread. I'll show you how to do that in<br />

<strong>Chapter</strong> 19.<br />

The active scheduler offers a nesting facility, whereby you can issue<br />

CActiveScheduler::Start() from within a RunL() function. This is used to keep the<br />

active scheduler going while ostensibly handling a synchronous function. The end of the<br />

'synchronous' function is indicated by a matching CActiveScheduler::Stop(). The net<br />

effect is like Yield() in some systems. This method is used by modal Uikon dialogs.<br />

You shouldn't nest the active scheduler however, unless you have thought carefully through<br />

the implications of doing so. In particular, you must ensure strict nesting of all<br />

CActiveScheduler::Start() and CActiveScheduler::Stop() functions – which is<br />

of course a natural property of modal dialogs.<br />

17.2.5 Adding Functionality to the Active Scheduler<br />

CActiveScheduler is a concrete class that can be used as is. It also provides two virtual<br />

functions that can be used if you need them for additional purposes:<br />

� If a RunL() called by the active scheduler leaves and that leave is not handled by the<br />

active object's RunError(), then Error(TInt) is called with the leave code. By<br />

default, this function panics.<br />

� WaitForAnyRequest() may be used to perform some standard processing before<br />

issuing User::WaitForAnyRequest(). By default, this function simply issues<br />

User::WaitForAnyRequest() and any override must also ensure that it calls<br />

User::WaitForAnyRequest().<br />

The Uikon environment sets up an active scheduler whose Error()function displays a<br />

natural-language version of the KErrXxx error code with which RunL() left.<br />

The CONE environment overrides CActiveScheduler::WaitForAnyRequest() to<br />

ensure that the window server's client-side buffer is flushed before issuing<br />

User::WaitForAnyRequest(). That means that any drawing done by the client during a<br />

RunL() is sent to the window server for execution so that while waiting for the next user<br />

input, there is no outstanding drawing.<br />

If you're implementing a server, it's useful to implement a scheduler with its own Error()<br />

function. We'll show how to do this in the GDSP server implementation, in <strong>Chapter</strong> 19.<br />

Don't write over-elaborate overrides for CActiveScheduler::Error() and<br />

CActiveScheduler::WaitForAnyRequest(). If they're too elaborate, you create<br />

dependencies between your active objects and your active scheduler, which means that<br />

your active objects won't run in any other environment than (say) the server for which you<br />

designed them. That might be fine – just make sure you've thought about it.

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

Saved successfully!

Ooh no, something went wrong!