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.

The CSharableSession class provides utility functions to access the server and the<br />

current message and the CSession class provides utility functions to read and write data<br />

between server and client address spaces.<br />

You should implement ServiceL() to handle a message from the client. Interpret the<br />

request code and parameters in the RMes-sage from the client; when ServiceL() is<br />

complete, use aMes-sage.Complete() to pass a result back to the client.<br />

Handling asynchronous client requests is more complex than handling simple, synchronous,<br />

requests. The aMessage parameter to Servi ceL() must be stored because the next time<br />

ServiceL() is called it will be different. Each asynchronous request supported by the<br />

server will require an active object to service it. When the asynchronous operation is<br />

completed, the stored RMessage must be retrieved and Complete()called on it. Note that<br />

if the active object request function returns an error, the client request should be completed<br />

at that point.<br />

Note<br />

The other functions provided by the CSharableSession API are either for<br />

specialist use or deprecated, so I haven't described them here.<br />

RMessage – a server-side message<br />

When a client issues a message, it arrives at the server as an RMessage object. You can<br />

use the functions of RMessage to access the request code and message parameters. You<br />

also get a Client() function that returns an RThread for the client, and convenience<br />

functions to read from, write to, panic, terminate, or kill the client thread. You call<br />

Complete() to complete the handling of a message.<br />

Here is the complete definition of RMessage:<br />

class RMessage<br />

{<br />

public:<br />

friend class CServer;<br />

enum TSessionMessages EConnect = -1, EDisConnect = -2 ;<br />

public: IMPORT_C RMessage();<br />

IMPORT_C RMessage(const RMessage& aMessage);<br />

IMPORT_C RMessage& operator=(const RMessage& aMessage);<br />

IMPORT_C void Complete(TInt aReason) const;<br />

IMPORT_C void ReadL(const TAny* aPtr, TDes8& aDes) const;<br />

IMPORT_C void ReadL(const TAny* aPtr, TDes8& aDes, TInt<br />

anOffset)<br />

const;<br />

IMPORT_C void ReadL(const TAny* aPtr, TDes16& aDes) const;<br />

IMPORT_C void ReadL(const TAny* aPtr, TDes16& aDes, TInt<br />

anOffset)<br />

const;<br />

IMPORT_C void WriteL(const TAny* aPtr, const TDesC8& aDes)<br />

const;<br />

IMPORT_C void WriteL(const TAny* aPtr, const TDesC8& aDes,

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

Saved successfully!

Ooh no, something went wrong!