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 | |
virtual | ~CTimeServer () |
void | IncrementSessions () |
void | DecrementSessions () |
void | WaitForTickL () |
void | Beat () |
void | Synchronize () |
Static Public Member Functions | |
static CTimeServer * | NewL () |
static CTimeServer * | NewLC () |
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 |
|
~CTimeServer. Destructor. Definition at line 78 of file timeserver.cpp. References iHeartbeat. 00079 { 00080 delete iHeartbeat; 00081 iHeartbeat = NULL; 00082 }
|
|
CTimeServer. C++ default constructor.
Definition at line 67 of file timeserver.cpp. Referenced by NewLC().
|
|
NewL. Two-phased constructor.
Definition at line 32 of file timeserver.cpp. References NewLC(). 00033 { 00034 CTimeServer* timeServer = CTimeServer::NewLC(); 00035 CleanupStack::Pop( timeServer ); 00036 return timeServer; 00037 }
|
|
NewLC. Two-phased constructor.
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 }
|
|
ThreadFunction. Main function for the server thread.
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 }
|
|
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 }
|
|
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 }
|
|
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 }
|
|
From MBeating, Beat. A clock tick has occured. Definition at line 195 of file timeserver.cpp. References SendTimeToSessions(). 00196 { 00197 SendTimeToSessions(); 00198 }
|
|
From MBeating, Synchronize. Several clock ticks have occured. Definition at line 205 of file timeserver.cpp. References SendTimeToSessions(). 00206 { 00207 SendTimeToSessions(); 00208 }
|
|
From CActive, RunError. Processes any errors.
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 }
|
|
ConstructL. 2nd phase constructor. Definition at line 57 of file timeserver.cpp. Referenced by NewLC().
|
|
PanicClient. Panics the client.
Definition at line 161 of file timeserver.cpp. Referenced by RunError().
|
|
PanicServer. Panics the server.
Definition at line 171 of file timeserver.cpp. Referenced by ThreadFunction().
|
|
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 }
|
|
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 }
|
|
From CServer, NewSessionL. Creates a time server 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 }
|
|
iSessionCount, the number of session owned by this server. Definition at line 170 of file timeserver.h. Referenced by DecrementSessions(), and IncrementSessions(). |
|
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(). |
© Nokia 2009 |