examples/SDKExamples/ClientServerSync/server/src/timesession.cpp

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

Generated by  doxygen 1.6.2