Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

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



How to implement a client-side session with the count server

The count server is a simple example of a server which does not support sharable sessions.

The following (abridged) code fragment illustrates a client-side session with this server. In this example, the server is started by the client. The main steps are:

  1. Create a client side session, an RCountServ instance and call Connect() which calls StartThread() to start a new count server thread.

    On starting, the thread function ThreadFunction() does the following:

    creates an active scheduler, class CActiveScheduler.

    creates an active object, class CCountServServer; adds this to the active scheduler and issues a request.

    starts the active scheduler.

    calls CreateSession() to start a session with the count server.

  2. Calls various client interface functions to increase and decrease the counter; Increase(), Decrease() etc.

  3. Use the return value Stop() of the final client interface function, to indicate that this service is not implemented in the server; the user is notified that this is the case.

  4. Terminate the session with Close().

LOCAL_C void doExampleL()
 {
 _LIT(KTxt11,"Testing the count server \n\n");
 console->Printf(KTxt11);

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

 _LIT(KTxt9,"Initialize counter with ");
 _LIT(KTxtLegalString,"224");
 console->Printf(KTxt9);
 console->Printf(KTxtLegalString);
 ret = ss.SetFromString(KTxtLegalString);

 _LIT(KFormat2,"\ncounter value: %d \n");
 console->Printf(KFormat2,ss.CounterValue());
 ss.Increase();
 ss.IncreaseBy(2);
 ss.Decrease();

 console->Printf(KFormat2,ss.CounterValue());

 _LIT(KTxtSorry,"Sorry, this function is not supported\n");
 ret = ss.Stop();
 if (ret==KErrNotSupported)
  {
  console->Printf(KTxtSorry);
  }
 ss.Close();
 }