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 ClientServerAsync example application.

Definition at line 30 of file timeserver.h.

Public Member Functions

virtual ~CTimeServer ()
void IncrementSessions ()
void DecrementSessions ()
void WaitForTickL ()
void Beat ()
void Synchronize ()

Static Public Member Functions

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

Protected Member Functions

TInt RunError (TInt aError)

Private Member Functions

 CTimeServer (TInt aPriority)
void ConstructL ()
void SendTimeToSessions ()
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 aPanic)
static void ThreadFunctionL ()

Private Attributes

TInt iSessionCount
CHeartbeat * iHeartbeat


Constructor & Destructor Documentation

CTimeServer::~CTimeServer  )  [virtual]
 

~CTimeServer. Destructor.

Definition at line 78 of file timeserver.cpp.

References iHeartbeat.

00079     {
00080     delete iHeartbeat;
00081     iHeartbeat = NULL;
00082     }

CTimeServer::CTimeServer TInt  aPriority  )  [private]
 

CTimeServer. C++ default constructor.

Parameters:
aPriority priority for this thread.

Definition at line 67 of file timeserver.cpp.

Referenced by NewLC().

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


Member Function Documentation

CTimeServer * CTimeServer::NewL  )  [static]
 

NewL. Two-phased constructor.

Returns:
Pointer to created CTimeServer object.

Definition at line 32 of file timeserver.cpp.

References NewLC().

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

CTimeServer * CTimeServer::NewLC  )  [static]
 

NewLC. Two-phased constructor.

Returns:
Pointer to created CTimeServer object.

Definition at line 44 of file timeserver.cpp.

References ConstructL(), and CTimeServer().

Referenced by NewL(), and ThreadFunctionL().

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

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

ThreadFunction. Main function for the server thread.

Parameters:
aStarted A semaphore to be flagged when server has been started.
Returns:
Error code.

Definition at line 264 of file timeserver.cpp.

References PanicServer(), and ThreadFunctionL().

00265     {
00266     CTrapCleanup* cleanupStack = CTrapCleanup::New();
00267     if ( !( cleanupStack ) )
00268         {
00269         PanicServer( ECreateTrapCleanup );
00270         }
00271 
00272     TRAPD( err, ThreadFunctionL() );
00273     if ( err != KErrNone )
00274         {
00275         PanicServer( ESrvCreateServer );
00276         }
00277 
00278     delete cleanupStack;
00279     cleanupStack = NULL;
00280 
00281     return KErrNone;
00282     }

void CTimeServer::IncrementSessions  ) 
 

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

Definition at line 111 of file timeserver.cpp.

References iSessionCount.

Referenced by CTimeServerSession::ConstructL().

00112     {
00113     iSessionCount++;
00114     }

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 121 of file timeserver.cpp.

References iSessionCount.

Referenced by CTimeServerSession::~CTimeServerSession().

00122     {
00123     iSessionCount--;
00124     if ( iSessionCount <= 0 )
00125         {
00126         CActiveScheduler::Stop();
00127         }
00128     }

void CTimeServer::WaitForTickL  ) 
 

WaitForTickL. Activates the heartbeat.

Definition at line 181 of file timeserver.cpp.

References iHeartbeat.

Referenced by CTimeServerSession::RequestTimeL().

00182     {
00183     if ( !iHeartbeat )
00184         {
00185         iHeartbeat = CHeartbeat::NewL( EPriorityHigh );
00186         iHeartbeat->Start( ETwelveOClock, this );
00187         }
00188     }

void CTimeServer::Beat  ) 
 

From MBeating, Beat. A clock tick has occured.

Definition at line 195 of file timeserver.cpp.

References SendTimeToSessions().

00196     {
00197     SendTimeToSessions();
00198     }

void CTimeServer::Synchronize  ) 
 

From MBeating, Synchronize. Several clock ticks have occured.

Definition at line 205 of file timeserver.cpp.

References SendTimeToSessions().

00206     {
00207     SendTimeToSessions();
00208     }

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 135 of file timeserver.cpp.

References PanicClient().

00136     {
00137     if ( aError == KErrBadDescriptor )
00138         {
00139         // A bad descriptor error implies a badly programmed client,
00140         // so panic it; otherwise report the error to the client
00141         PanicClient( Message(), EBadDescriptor );
00142         }
00143     else
00144         {
00145         Message().Complete( aError );
00146         }
00147 
00148     // The leave will result in an early return from CServer::RunL(), skipping
00149     // the call to request another message. So do that now in order to keep the
00150     // server running.
00151     ReStart();
00152 
00153     return KErrNone;    // Handled the error fully
00154     }

void CTimeServer::ConstructL  )  [private]
 

ConstructL. 2nd phase constructor.

Definition at line 57 of file timeserver.cpp.

Referenced by NewLC().

00058     {
00059     StartL( KTimeServerName );
00060     }

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 161 of file timeserver.cpp.

Referenced by RunError().

00162     {
00163     aMessage.Panic( KCSAsyncServer, aPanic );
00164     }

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

PanicServer. Panics the server.

Parameters:
aPanic The panic code.

Definition at line 171 of file timeserver.cpp.

Referenced by ThreadFunction().

00172     {
00173     User::Panic( KCSAsyncServer, aPanic );
00174     }

void CTimeServer::ThreadFunctionL  )  [static, private]
 

ThreadFunctionL. Second stage startup for the server thread.

Definition at line 232 of file timeserver.cpp.

References NewLC().

Referenced by ThreadFunction().

00233     {
00234     // Construct active scheduler
00235     CActiveScheduler* activeScheduler = new ( ELeave ) CActiveScheduler;
00236     CleanupStack::PushL( activeScheduler );
00237 
00238     // Install active scheduler
00239     // We don't need to check whether an active scheduler is already installed
00240     // as this is a new thread, so there won't be one
00241     CActiveScheduler::Install( activeScheduler );
00242 
00243     // Construct our server
00244     CTimeServer::NewLC();    // Anonymous
00245 
00246     RSemaphore semaphore;
00247     User::LeaveIfError( semaphore.OpenGlobal( KTimeServerSemaphoreName ) );
00248 
00249     // Semaphore opened ok
00250     semaphore.Signal();
00251     semaphore.Close();
00252 
00253     // Start handling requests
00254     CActiveScheduler::Start();
00255 
00256     CleanupStack::PopAndDestroy( 2, activeScheduler ); //Anonymous CTimeServer
00257     }

void CTimeServer::SendTimeToSessions  )  [private]
 

SendTimeToSessions. Informs all the clients that a time change has occured.

Definition at line 215 of file timeserver.cpp.

References CTimeServerSession::SendTimeToClient().

Referenced by Beat(), and Synchronize().

00216     {
00217     iSessionIter.SetToFirst();
00218     CTimeServerSession* session;
00219     session = reinterpret_cast<CTimeServerSession*>( iSessionIter++ );
00220     while ( session )
00221         {
00222         session->SendTimeToClient();
00223         session = reinterpret_cast<CTimeServerSession*>( iSessionIter++ );
00224         }
00225     }

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

From CServer, NewSessionL. Creates a time server session.

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

Definition at line 89 of file timeserver.cpp.

References CTimeServerSession::NewL().

00091     {
00092     // Check we are the right version
00093     if ( !User::QueryVersionSupported( TVersion( KTimeServMajorVersionNumber,
00094                                                  KTimeServMinorVersionNumber,
00095                                                  KTimeServBuildVersionNumber ),
00096                                        aVersion ) )
00097         {
00098         User::Leave( KErrNotSupported );
00099         }
00100 
00101     // Make new session
00102     //RThread client = Message().Client();
00103     return CTimeServerSession::NewL( *const_cast<CTimeServer*> ( this ) );
00104     }


Member Data Documentation

TInt CTimeServer::iSessionCount [private]
 

iSessionCount, the number of session owned by this server.

Definition at line 170 of file timeserver.h.

Referenced by DecrementSessions(), and IncrementSessions().

CHeartbeat* CTimeServer::iHeartbeat [private]
 

iHeartbeat, a periodic timer used to update the client. Owned by CTimeServer object.

Definition at line 176 of file timeserver.h.

Referenced by WaitForTickL(), and ~CTimeServer().


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

© Nokia 2009

Back to top