A client side subsession is represented by an instance of a class
derived from RSubSessionBase
which provides the behaviour
for:
creating a subsession in the server
sending messages to the subsession.
In the following code fragment, the class RCounter
,
derived from RSubSessionBase
, represents the client side
subsession with a server, called the count server in this example. The
assumption is made that the client has already established a session with the
server as represented by the RCountServ
class.
class RCounter : public RSubSessionBase
{
public:
TInt Open(RCountServ &aServer);
void SetFromString(TDesC& aString);
void Close();
void Increase();
void Decrease();
void IncreaseBy(TInt anInt);
void DecreaseBy(TInt anInt);
void Reset();
TInt CounterValue();
};
class RCountServ : public RSessionBase
{
public:
RCountServ();
TInt Connect();
...
TVersion Version() const;
void Close();
};
The important points in this example are:
Open()
creates a subsession within the client-side
session. A reference to the client-side session is specified as the
function’s single argument. The function calls
RSubSessionBase::CreateSubSession()
which, in turn, causes a
server side subsession object to be created and its handle number to be
returned.
Client subsession interface functions, such as
CounterValue()
, send a specific message to the server.
TInt RCounter::CounterValue()
{
TInt res=0;
TPckgBuf<TInt> pckg;
if (SubSessionHandle())
{
TAny *p[KMaxMessageArguments];
p[0]=(TAny *) &pckg;
SendReceive(ECountServValue,&p[0]);
res = pckg();
}
return res;
}
Close()
closes the subsession.
The operation code passed to
RSubSessionBase::CreateSubSession()
must be interpreted by the
server as a request to create a subsession.
When sending a message to the server with a call to
RSubSessionBase::SendReceive()
, only three elements in the message
argument array can be used. This function always uses the fourth argument to
hold the client subsession handle number which is used to identify the
corresponding server side subsession object. The message argument array is
subsequently passed to a call to
RSessionBase::SendReceive()
.
The operation code passed to
RSubSessionBase::CloseSubSession()
must be interpreted by the
server as a request to close the subsession.