00001 /* 00002 * ============================================================================== 00003 * Name : timesession.cpp 00004 * Part of : CSSync 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 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 // INCLUDE FILES 00018 #include <e32svr.h> 00019 00020 #include "TimeSession.h" 00021 #include "ClientServerCommon.h" 00022 #include "TimeServer.h" 00023 00024 // ========================= MEMBER FUNCTIONS ================================== 00025 00026 // ----------------------------------------------------------------------------- 00027 // CTimeServerSession::NewL() 00028 // Two-phased constructor. 00029 // ----------------------------------------------------------------------------- 00030 // 00031 CTimeServerSession* CTimeServerSession::NewL( CTimeServer& aServer ) 00032 { 00033 CTimeServerSession* self = CTimeServerSession::NewLC( aServer ); 00034 CleanupStack::Pop( self ); 00035 return self; 00036 } 00037 00038 // ----------------------------------------------------------------------------- 00039 // CTimeServerSession::NewLC() 00040 // Two-phased constructor. 00041 // ----------------------------------------------------------------------------- 00042 // 00043 CTimeServerSession* CTimeServerSession::NewLC( CTimeServer& aServer ) 00044 { 00045 CTimeServerSession* self = new ( ELeave ) CTimeServerSession( aServer ); 00046 CleanupStack::PushL( self ); 00047 self->ConstructL(); 00048 return self; 00049 } 00050 00051 // ----------------------------------------------------------------------------- 00052 // CTimeServerSession::ConstructL() 00053 // Symbian 2nd phase constructor can leave. 00054 // ----------------------------------------------------------------------------- 00055 // 00056 void CTimeServerSession::ConstructL() 00057 { 00058 iServer.IncrementSessions(); 00059 } 00060 00061 // ----------------------------------------------------------------------------- 00062 // CTimeServerSession::CTimeServerSession() 00063 // C++ default constructor can NOT contain any code, that might leave. 00064 // ----------------------------------------------------------------------------- 00065 // 00066 CTimeServerSession::CTimeServerSession( CTimeServer& aServer ) 00067 : iServer( aServer ) 00068 { 00069 // Implementation not required 00070 } 00071 00072 // ----------------------------------------------------------------------------- 00073 // CTimeServerSession::~CTimeServerSession() 00074 // Destructor. 00075 // ----------------------------------------------------------------------------- 00076 // 00077 CTimeServerSession::~CTimeServerSession() 00078 { 00079 iServer.DecrementSessions(); 00080 } 00081 00082 // ----------------------------------------------------------------------------- 00083 // CTimeServerSession::ServiceL() 00084 // Service request from client. 00085 // ----------------------------------------------------------------------------- 00086 // 00087 void CTimeServerSession::ServiceL( const RMessage2& aMessage ) 00088 { 00089 switch ( aMessage.Function() ) 00090 { 00091 case ETimeServRequestTime : 00092 RequestTimeL( aMessage ); 00093 break; 00094 00095 default: 00096 PanicClient( aMessage, EBadRequest ); 00097 break; 00098 } 00099 aMessage.Complete( KErrNone ); 00100 } 00101 00102 // ----------------------------------------------------------------------------- 00103 // CTimeServerSession::RequestTimeL() 00104 // Called as a result of the client requesting the time. 00105 // ----------------------------------------------------------------------------- 00106 // 00107 00108 void CTimeServerSession::RequestTimeL( const RMessage2& aMessage ) 00109 { 00110 TTime time; 00111 time.HomeTime(); 00112 00113 TPtr8 ptr( reinterpret_cast<TUint8*>( &time ), sizeof( time ), 00114 sizeof( time ) ); 00115 00116 // Write time data to the descriptor which is the first message argument 00117 aMessage.WriteL( 0, ptr, 0 ); 00118 } 00119 00120 00121 // ----------------------------------------------------------------------------- 00122 // CTimeServerSession::PanicClient() 00123 // Causes the client thread to panic. 00124 // ----------------------------------------------------------------------------- 00125 // 00126 void CTimeServerSession::PanicClient( const RMessagePtr2& aMessage, 00127 TInt aPanic ) const 00128 { 00129 aMessage.Panic( KCSSyncServer,aPanic ); // Note: this panics the client thread, 00130 // not server 00131 } 00132 00133 // End of File