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.

aStart.SignalL();<br />

CActiveScheduler::Start();<br />

// Destroy the scheduler<br />

#endif<br />

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

}<br />

First ConstructL() creates a real active scheduler and installs it as the thread's current<br />

scheduler. This essentially stores a pointer to the scheduler in a special location reserved by<br />

the kernel. You can get at this pointer using CActiveScheduler::Current() if you need<br />

to. Next the server object is constructed and stored in the iServer member. Finally, the<br />

client is signaled to indicate that the startup has succeeded. Then all that remains to do is to<br />

start the active scheduler, which starts the server processing requests.<br />

CActiveScheduler::Start() does not return until CActiveScheduler::Stop() is<br />

called – we'll see how this happens below.<br />

Server construction<br />

By the time we get to the CGsdpServer construction, we are in normal C++ territory: we<br />

have a cleanup stack and active scheduler, we don't have to think about the thread that's<br />

launched us – in short, the code has lost the flavor of a bootstrap. CGsdpServer's C++<br />

constructor passes two parameters down to the base CServer constructor: a zero active<br />

object priority, and flag specifying that sessions can be shared:<br />

CGsdpServer::CGsdpServer() : CServer(0, EShareableSessions)<br />

{<br />

}<br />

This indicates that the server does not have a higher or lower priority than any other active<br />

object in the thread, and that the server sessions can be shared between all threads in a<br />

process. By default, a session can only be used by the thread that creates it. Sharing<br />

sessions between threads is a useful facility that servers should support if possible, so we<br />

enable this here. The main work of construction is handled by<br />

CGsdpServer::ConstructL() which we looked at earlier.<br />

Server shutdown<br />

The server shuts down 2 s after its last client session is closed. The server keeps a count of<br />

client sessions using IncrementSessions() and DecrementSessions(), which are<br />

called from NewSessionL() and from the session destructor:<br />

void CGsdpServer::IncrementSessions()<br />

{<br />

iSessionCount++;<br />

iShutdown->Cancel();<br />

}<br />

void CGsdpServer::DecrementSessions()<br />

{<br />

iSessionCount--;<br />

if(iSessionCount > 0)

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

Saved successfully!

Ooh no, something went wrong!