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, the class RCountServ
,
derived from RSessionBase
, represents the client side session with
a server, called the count server in this example. Note that sessions are not
sharable.
class RCountServ : public RSessionBase
{
public:
RCountServ();
TInt Connect();
TVersion Version() const;
TInt Stop();
TInt SetFromString(TDesC& aString);
void Increase();
void Decrease();
void IncreaseBy(TInt anInt);
void DecreaseBy(TInt anInt);
void Reset();
TInt CounterValue();
};
The important points are:
Use Connect()
to start the count server. This
calls RSessionBase::CreateSession()
to create a session with the
server.
Use a client interface function, such as
Increase()
, to send a specific message to the server. The client
interface function builds the message using the appropriate operation code and
assembling a suitable message argument array, i.e. the four element array of
pointers to message arguments in the client address space.
The function Increase()
would be defined as
follows:
void RCountServ::Increase()
{
TAny *p[KMaxMessageArguments];
SendReceive(ECountServIncrease,&p[0]);
}
SendReceive()
is called, specifying an operation code
ECountServIncrease
and an array of argument pointers, which in
this case, is empty. Typically, operation codes are enum values defined in a
header file visible to both the client interface and the server.
Note that the function SetFromString()
takes a descriptor. It is important to note that the descriptor passed to this function must remain in existence until the server request completes. As, in practice, the server may not run until some arbitrary time after the client issues a request, then the descriptor cannot live on the program stack.