S60 5th Edition SDK
Example Applications Guide

CTimeServer Class Reference

#include <timeserver.h>

Inheritance diagram for CTimeServer:

List of all members.

Detailed Description

CTimeServer. An instance of class CTimeServer is the main server class for the ClientServerSync example application

Definition at line 30 of file timeserver.h.

Public Member Functions

void IncrementSessions ()
void DecrementSessions ()

Static Public Member Functions

static CTimeServerNewL ()
static CTimeServerNewLC ()
static TInt ThreadFunction (TAny *aNone)

Protected Member Functions

TInt RunError (TInt aError)

Private Member Functions

 CTimeServer (TInt aPriority)
void ConstructL ()
CSession2 * NewSessionL (const TVersion &aVersion, const RMessage2 &aMessage) const

Static Private Member Functions

static void PanicClient (const RMessage2 &aMessage, TTimeServPanic aReason)
static void PanicServer (TTimeServPanic aReason)
static void ThreadFunctionL ()

Private Attributes

TInt iSessionCount


Constructor & Destructor Documentation

CTimeServer::CTimeServer TInt  aPriority  )  [private]
 

CTimeServer. C++ default constructor.

Parameters:
aPriority priority for this thread.

Definition at line 68 of file timeserver.cpp.

Referenced by NewLC().

00069 : CServer2( aPriority ) 
00070     {
00071     // Implementation not required
00072     }


Member Function Documentation

CTimeServer * CTimeServer::NewL  )  [static]
 

NewL. Two-phased constructor.

Returns:
Pointer to created CTimeServer object.

Definition at line 33 of file timeserver.cpp.

References NewLC().

00034     {
00035     CTimeServer* timeServer = CTimeServer::NewLC();
00036     CleanupStack::Pop( timeServer );
00037     return timeServer;
00038     }

CTimeServer * CTimeServer::NewLC  )  [static]
 

NewLC. Two-phased constructor.

Returns:
Pointer to created CTimeServer object.

Definition at line 45 of file timeserver.cpp.

References ConstructL(), and CTimeServer().

Referenced by NewL(), and ThreadFunctionL().

00046     {
00047     CTimeServer* timeServer = new ( ELeave ) CTimeServer( EPriorityNormal );
00048     CleanupStack::PushL( timeServer );
00049     timeServer->ConstructL();
00050     return timeServer;
00051     }

TInt CTimeServer::ThreadFunction TAny *  aNone  )  [static]
 

ThreadFunction. Main function for the server thread.

Parameters:
aNone Not used.
Returns:
Error code.

Definition at line 202 of file timeserver.cpp.

References PanicServer(), and ThreadFunctionL().

00203     {
00204     CTrapCleanup* cleanupStack = CTrapCleanup::New();
00205     if ( !( cleanupStack ) )
00206         {
00207         PanicServer( ECreateTrapCleanup );
00208         }
00209 
00210     TRAPD( err, ThreadFunctionL() );
00211     if ( err != KErrNone )
00212         {
00213         PanicServer( ESrvCreateServer );
00214         }
00215 
00216     delete cleanupStack;
00217     cleanupStack = NULL;
00218 
00219     return KErrNone;
00220     }

void CTimeServer::IncrementSessions  ) 
 

IncrementSessions. Increments the count of the active sessions for this server.

Definition at line 100 of file timeserver.cpp.

References iSessionCount.

Referenced by CTimeServerSession::ConstructL().

00101     {
00102     iSessionCount++;
00103     }

void CTimeServer::DecrementSessions  ) 
 

DecrementSessions. Decrements the count of the active sessions for this server. If no more sessions are in use the server terminates.

Definition at line 110 of file timeserver.cpp.

References iSessionCount.

Referenced by CTimeServerSession::~CTimeServerSession().

00111     {
00112     iSessionCount--;
00113     if ( iSessionCount <= 0 )
00114         {
00115         CActiveScheduler::Stop();
00116         }
00117     }

TInt CTimeServer::RunError TInt  aError  )  [protected]
 

From CActive, RunError. Processes any errors.

Parameters:
aError The leave code reported.
Returns:
return KErrNone if leave is handled.

Definition at line 124 of file timeserver.cpp.

References PanicClient().

00125     {
00126     if ( aError == KErrBadDescriptor )
00127         {
00128         // A bad descriptor error implies a badly programmed client,
00129         // so panic it; otherwise report the error to the client
00130         PanicClient( Message(), EBadDescriptor );
00131         }
00132     else
00133         {
00134         Message().Complete( aError );
00135         }
00136 
00137     // The leave will result in an early return from CServer::RunL(), skipping
00138     // the call to request another message. So do that now in order to keep the
00139     // server running.
00140     ReStart();
00141 
00142     return KErrNone;    // Handled the error fully
00143     }

void CTimeServer::ConstructL  )  [private]
 

ConstructL. 2nd phase constructor.

Definition at line 58 of file timeserver.cpp.

Referenced by NewLC().

00059     {
00060     StartL( KTimeServerName );
00061     }

void CTimeServer::PanicClient const RMessage2 &  aMessage,
TTimeServPanic  aReason
[static, private]
 

PanicClient. Panics the client.

Parameters:
aMessage The message channel to the client.
aReason The reason code for the panic.

Definition at line 150 of file timeserver.cpp.

Referenced by RunError().

00151     {
00152     aMessage.Panic( KCSSyncServer, aPanic );
00153     }

void CTimeServer::PanicServer TTimeServPanic  aReason  )  [static, private]
 

PanicServer. Panics the server.

Parameters:
aReason the reason code for the panic.

Definition at line 160 of file timeserver.cpp.

Referenced by ThreadFunction().

00161     {
00162     User::Panic( KCSSyncServer, aPanic );
00163     }

void CTimeServer::ThreadFunctionL  )  [static, private]
 

ThreadFunctionL. Second stage startup for the server thread.

Definition at line 170 of file timeserver.cpp.

References NewLC().

Referenced by ThreadFunction().

00171     {
00172     // Construct active scheduler
00173     CActiveScheduler* activeScheduler = new ( ELeave ) CActiveScheduler;
00174     CleanupStack::PushL( activeScheduler );
00175 
00176     // Install active scheduler
00177     // We don't need to check whether an active scheduler is already installed
00178     // as this is a new thread, so there won't be one
00179     CActiveScheduler::Install( activeScheduler );
00180 
00181     // Construct our server
00182     CTimeServer::NewLC();    // Anonymous
00183 
00184     RSemaphore semaphore;
00185     User::LeaveIfError( semaphore.OpenGlobal( KTimeServerSemaphoreName ) );
00186 
00187     // Semaphore opened ok
00188     semaphore.Signal();
00189     semaphore.Close();
00190 
00191     // Start handling requests
00192     CActiveScheduler::Start();
00193 
00194     CleanupStack::PopAndDestroy( 2, activeScheduler ); //Anonymous CTimeServer
00195     }

CSession2 * CTimeServer::NewSessionL const TVersion &  aVersion,
const RMessage2 &  aMessage
const [private]
 

From CServer, NewSessionL. Create a time server session.

Parameters:
aVersion The client version.
aMessage Message from client.
Returns:
Pointer to new session.

Definition at line 79 of file timeserver.cpp.

References CTimeServerSession::NewL().

00081     {
00082     // Check we are the right version
00083     if ( !User::QueryVersionSupported( TVersion( KTimeServMajorVersionNumber,
00084                                                  KTimeServMinorVersionNumber,
00085                                                  KTimeServBuildVersionNumber ),
00086                                        aVersion ) )
00087         {
00088         User::Leave( KErrNotSupported );
00089         }
00090 
00091     // Make new session        
00092     return CTimeServerSession::NewL( *const_cast<CTimeServer*> ( this ) );
00093     }


Member Data Documentation

TInt CTimeServer::iSessionCount [private]
 

iSessionCount, the number of open sessions.

Definition at line 137 of file timeserver.h.

Referenced by DecrementSessions(), and IncrementSessions().


The documentation for this class was generated from the following files:

© Nokia 2009

Back to top