S60 5th Edition SDK Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : timeserver.h 00004 * Part of : CSAsync 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2004-2006 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 00017 #ifndef __CTIMESERVER_H__ 00018 #define __CTIMESERVER_H__ 00019 00020 // INCLUDE FILES 00021 #include <e32base.h> 00022 #include "AsyncServer.pan" 00023 00024 // CLASS DECLARATION 00025 /** 00026 * CTimeServer. 00027 * An instance of class CTimeServer is the main server class 00028 * for the ClientServerAsync example application. 00029 */ 00030 class CTimeServer : public CServer2, public MBeating 00031 { 00032 public : // Constructors and destructors 00033 00034 /** 00035 * NewL. 00036 * Two-phased constructor. 00037 * @return Pointer to created CTimeServer object. 00038 */ 00039 static CTimeServer* NewL(); 00040 00041 /** 00042 * NewLC. 00043 * Two-phased constructor. 00044 * @return Pointer to created CTimeServer object. 00045 */ 00046 static CTimeServer* NewLC(); 00047 00048 /** 00049 * ~CTimeServer. 00050 * Destructor. 00051 */ 00052 virtual ~CTimeServer(); 00053 00054 public: // New functions 00055 00056 /** 00057 * ThreadFunction. 00058 * Main function for the server thread. 00059 * @param aStarted A semaphore to be flagged when server 00060 * has been started. 00061 * @return Error code. 00062 */ 00063 static TInt ThreadFunction( TAny* aStarted ); 00064 00065 /** 00066 * IncrementSessions. 00067 * Increments the count of the active sessions for this server. 00068 */ 00069 void IncrementSessions(); 00070 00071 /** 00072 * DecrementSessions. 00073 * Decrements the count of the active sessions for this server. 00074 * If no more sessions are in use the server terminates. 00075 */ 00076 void DecrementSessions(); 00077 00078 /** 00079 * WaitForTickL. 00080 * Activates the heartbeat. 00081 */ 00082 void WaitForTickL(); 00083 00084 public: // Functions from base classes 00085 00086 /** 00087 * From MBeating, Beat. 00088 * A clock tick has occured. 00089 */ 00090 void Beat(); 00091 00092 /** 00093 * From MBeating, Synchronize. 00094 * Several clock ticks have occured. 00095 */ 00096 void Synchronize(); 00097 00098 protected: // Functions from base classes 00099 00100 /** 00101 * From CActive, RunError. 00102 * Processes any errors. 00103 * @param aError The leave code reported. 00104 * @result return KErrNone if leave is handled. 00105 */ 00106 TInt RunError( TInt aError ); 00107 00108 private: // Constructors and destructors 00109 00110 /** 00111 * CTimeServer. 00112 * C++ default constructor. 00113 * @param aPriority priority for this thread. 00114 */ 00115 CTimeServer( TInt aPriority ); 00116 00117 /** 00118 * ConstructL. 00119 * 2nd phase constructor. 00120 */ 00121 void ConstructL(); 00122 00123 private: // New methods 00124 00125 /** 00126 * PanicClient. 00127 * Panics the client. 00128 * @param aMessage The message channel to the client. 00129 * @param aReason The reason code for the panic. 00130 */ 00131 static void PanicClient( const RMessage2& aMessage, 00132 TTimeServPanic aReason ); 00133 00134 /** 00135 * PanicServer. 00136 * Panics the server. 00137 * @param aPanic The panic code. 00138 */ 00139 static void PanicServer( TTimeServPanic aPanic ); 00140 00141 /** 00142 * ThreadFunctionL. 00143 * Second stage startup for the server thread. 00144 */ 00145 static void ThreadFunctionL(); 00146 00147 /** 00148 * SendTimeToSessions. 00149 * Informs all the clients that a time change has occured. 00150 */ 00151 void SendTimeToSessions(); 00152 00153 private: // Functions from base classes 00154 00155 /** 00156 * From CServer, NewSessionL. 00157 * Creates a time server session. 00158 * @param aVersion The client version. 00159 * @param aMessage Message from client. 00160 * @return Pointer to new session. 00161 */ 00162 CSession2* NewSessionL( const TVersion& aVersion, 00163 const RMessage2& aMessage ) const; 00164 00165 private: // Data 00166 00167 /** 00168 * iSessionCount, the number of session owned by this server. 00169 */ 00170 TInt iSessionCount; 00171 00172 /** 00173 * iHeartbeat, a periodic timer used to update the client. 00174 * Owned by CTimeServer object. 00175 */ 00176 CHeartbeat* iHeartbeat; 00177 }; 00178 00179 #endif // __CTIMESERVER_H__ 00180 00181 // End of File
© Nokia 2009 |