Symbian
Symbian OS Library

SYMBIAN OS V9.3

[Index] [Spacer] [Previous] [Next]



How to implement a simple client interface


Client side session with a server

A client side session is represented by an instance of a class derived from RSessionBase which provides the behaviour for connecting to the server and sending messages to it.

In the following code fragment, taken from the example that can be found at ...\examples\Base\IPC\ClientServer\simple, the class RCountServSession, derived from RSessionBase, represents the client side session with a server. In the example, this may be referred to as the "count server". Note that sessions are not sharable in this example, and it just shows the basic mechanics of the client/server interaction.

class RCountServSession : public RSessionBase
    {
public:
    RCountServSession();
    TInt Connect();
    TVersion Version() const;
    TInt UnsupportedRequest();
    TInt SetFromString(const TDesC& aString);
    void Increase();
    void Decrease();
    void IncreaseBy(TInt anInt);
    void DecreaseBy(TInt anInt);
    void Reset();
    TInt CounterValue();
    void BadRequest();
    void Close();
private:
    RThread iServerThread;
    };

The important points are:

As an example, the function SetFromString() is implemented as follows:

TInt RCountServSession::SetFromString(const TDesC& aString)
    {
    TIpcArgs args(&aString);
    return SendReceive(ECountServSetFromString, args);
    }

SendReceive() is called, specifying an operation code ECountServSetFromString and a TIpcArgs object containing argument values. In this case, there is only one argument - a pointer to a TDesC object containing the string to be passed to the server. Typically, operation codes are enum values defined in a header file visible to both the client interface and the server. Note that the client descriptor must remain in existence until the server request completes.