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.

Bootstrap code for a server should create an active scheduler, a cleanup stack, and a server<br />

object; create a name for the server (stored in iName), and then issue Start() (or<br />

StartL()) to cause the server to issue its first request. The server name must be specified<br />

by any client wishing to connect to the server, as the aServer parameter to<br />

RSessionBase::CreateSession().<br />

The server's RunL() function renews the request to the kernel automatically. However, it<br />

doesn't renew the request if (say) the session's ServiceL() function leaves. You have to<br />

handle this from the active scheduler's Error() function, and issue ReStart() to renew<br />

the request.<br />

When the server handles a connect message, it invokes NewSessionL() to create a new<br />

server-side CSharableSession-derived object. Oddly this function is const: you usually<br />

need to cast away const-ness when you implement this function in order to be able to<br />

increment usage counts and do other housekeeping in your derived server class.<br />

When the server handles a disconnect message, it simply deletes the affected session,<br />

which also causes its C++ destructor to be invoked.<br />

Unlike in earlier versions of Symbian OS, the server does not store the message – it is<br />

available to the session's ServiceL() routine and that must store it if necessary.<br />

You can iterate through the sessions owned by the server, using the protected<br />

iSessionIter member.<br />

CSession and CSharableSession – a server-side session<br />

In earlier versions of Symbian OS, the CSession class was used on the server side to<br />

encapsulate a client-side session. The CSession class was thread-specific – that is, it was<br />

owned by one thread on the client side. Symbian OS v6.x introduced sharable sessions with<br />

the CSharable-Session class. A CSharableSession object can be shared between<br />

multiple threads in the same process on the client side. When you design your server, you<br />

can choose whether to provide sharable or unsharable sessions. Classes derived directly<br />

from CSharableSession rather than from CSession will not be able to make use of the<br />

thread-specific functions in CSession to transfer data between the server and the client<br />

thread so it may be easier to derive from CSession if you do not need to share a session<br />

between threads. Note that a sharable session requires the client-side session to call<br />

Share() and possibly Attach() to actually be shared – these functions are described<br />

under the RSessionBase class details.<br />

The CSession class derives from CSharableSession and whichever you choose forms<br />

the base class for the server side end of a session. You implement its ServiceL() function<br />

to interpret and handle client requests. These classes also provide many convenience<br />

functions for accessing the client and the current message. The relevant parts of<br />

CSharableSession and CSession are<br />

Class CSharableSession : public CBase<br />

{<br />

public:<br />

friend class CServer;<br />

IMPORT_C ~CSharableSession() =0;<br />

IMPORT_C virtual void CreateL(const Cserver& aServer);

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

Saved successfully!

Ooh no, something went wrong!