S60 5th Edition SDK Example Applications Guide |
#include <timeserver.h>
Inheritance diagram for CTimeServer:
Definition at line 30 of file timeserver.h.
Public Member Functions | |
void | IncrementSessions () |
void | DecrementSessions () |
Static Public Member Functions | |
static CTimeServer * | NewL () |
static CTimeServer * | NewLC () |
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 |
|
CTimeServer. C++ default constructor.
Definition at line 68 of file timeserver.cpp. Referenced by NewLC().
|
|
NewL. Two-phased constructor.
Definition at line 33 of file timeserver.cpp. References NewLC(). 00034 { 00035 CTimeServer* timeServer = CTimeServer::NewLC(); 00036 CleanupStack::Pop( timeServer ); 00037 return timeServer; 00038 }
|
|
NewLC. Two-phased constructor.
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 }
|
|
ThreadFunction. Main function for the server thread.
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 }
|
|
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 }
|
|
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 }
|
|
From CActive, RunError. Processes any errors.
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 }
|
|
ConstructL. 2nd phase constructor. Definition at line 58 of file timeserver.cpp. Referenced by NewLC().
|
|
PanicClient. Panics the client.
Definition at line 150 of file timeserver.cpp. Referenced by RunError().
|
|
PanicServer. Panics the server.
Definition at line 160 of file timeserver.cpp. Referenced by ThreadFunction().
|
|
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 }
|
|
From CServer, NewSessionL. Create a time server 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 }
|
|
iSessionCount, the number of open sessions. Definition at line 137 of file timeserver.h. Referenced by DecrementSessions(), and IncrementSessions(). |
© Nokia 2009 |