Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



How to implement a client-side session with subsessions

A typical session with the count server is illustrated in this section.


Creating a session with the server

Implement a session between the client and count server as follows:

RCountServ countserv;
User::LeaveIfError(countserv.Connect());

[Top]


Creating a subsession

The following code creates a subsession with the count server. Use Open() to call RSubSessionBase::CreateSubSession() which creates a corresponding CCounter subsession object in the server.

RCounter counterA;
counterA.Open(countserv);

[Top]


Communication via a subsession

Client interface functions are called for each client subsession. The subsessions are completely independent; changing the counter value in one has no effect on the other.

counterA.Increase();
counterA.IncreaseBy(2);
counterB.Increase();
counterA.IncreaseBy(7);
counterB.IncreaseBy(5);
counterA.Decrease();
counterB.DecreaseBy(3);
console->Printf(_L("counterA value: %d \n"), counterA.CounterValue());
console->Printf(_L("counterB value: %d \n"), counterB.CounterValue());

[Top]


Closing subsessions

Before terminating a session its subsessions should be closed with Close().

counterA.Close();

[Top]


Resource tracking

The server keeps track of counter resources within a session. Opening a subsession increases the resource count; closing a subsession decreases it.

Before creating the first subsession the client callsResourceCountMarkStart() to start server resource tracking. Before closing the session the client calls ResourceCountMarkEnd(); the server will panic the client at this point if the resource count is greater than 0; indicating that a resource has not been closed.

LOCAL_C void doExampleL()
 {
 RCountServ countserv;
 User::LeaveIfError(countserv.Connect());
 countserv.ResourceCountMarkStart();
 RCounter counterA;
 counterA.Open(countserv);
 RCounter counterB;
 counterB.Open(countserv);
 ...................... // increase, decrease counters here.
 TInt iSubsessions = countserv.ResourceCount();
   _LIT(KTxtResCount,"Resource count is.. %d \n");
 console->Printf(KTxtResCount, iSubsessions);
                       //close subsessions
   _LIT(KTxtClosing,"Closing counterA..\n");
 console->Printf(KTxtClosing);
 counterA.Close();
   _LIT(KTxtEnd,"Press END to see what happens when a subsession is left open \n");
 console->Printf(KTxtEnd);
   _LIT(KTxtAnother,"[press another key to continue normally]");
 console->Printf(KTxtAnother);
 TKeyCode code =console->Getch();
   _LIT(KTxtNewLine,"\n")
 console->Printf(KTxtNewLine);
 if (code != EKeyEnd)
  {
  counterB.Close();
  }
 countserv.ResourceCountMarkEnd();
 countserv.Close();
 }