keepalive/flextimer/test/testflextimer/flextimerservermonitor/src/flextimerservermonitorsession.cpp
changeset 32 5c4486441ae6
equal deleted inserted replaced
31:c16e04725da3 32:5c4486441ae6
       
     1 /*
       
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:
       
    15  *      Session implementation for FlexTimerServerMonitor server
       
    16  *
       
    17  */
       
    18 /*
       
    19  * %version: 1 %
       
    20  */
       
    21 
       
    22 // System include files
       
    23 
       
    24 // User include files go here:
       
    25 #include <rflextimer.h>
       
    26 #include "flextimerservermonitorsession.h"
       
    27 #include "flextimerservermonitorcommon.h"
       
    28 #include "flextimerservermonitorserver.h"
       
    29 #include "OstTraceDefinitions.h"
       
    30 #ifdef OST_TRACE_COMPILER_IN_USE
       
    31 #include "flextimerservermonitorsessionTraces.h"
       
    32 #endif
       
    33 
       
    34 // Constants
       
    35 
       
    36 // ======== MEMBER FUNCTIONS ========
       
    37 
       
    38 // --------------------------------------------------------------------------
       
    39 // Constructor
       
    40 // --------------------------------------------------------------------------
       
    41 //
       
    42 CFlexTimerServerMonitorSession::CFlexTimerServerMonitorSession()
       
    43     {
       
    44     }
       
    45 
       
    46 // --------------------------------------------------------------------------
       
    47 // Destructor
       
    48 // --------------------------------------------------------------------------
       
    49 //
       
    50 CFlexTimerServerMonitorSession::~CFlexTimerServerMonitorSession()
       
    51     {
       
    52     }
       
    53 
       
    54 // --------------------------------------------------------------------------
       
    55 // 2nd phase constructor
       
    56 // --------------------------------------------------------------------------
       
    57 //
       
    58 void CFlexTimerServerMonitorSession::ConstructL()
       
    59     {
       
    60     }
       
    61 
       
    62 // --------------------------------------------------------------------------
       
    63 // Two-phased constructor
       
    64 // --------------------------------------------------------------------------
       
    65 //
       
    66 CFlexTimerServerMonitorSession* CFlexTimerServerMonitorSession::NewL()
       
    67     {
       
    68     CFlexTimerServerMonitorSession* self =
       
    69             new (ELeave) CFlexTimerServerMonitorSession();
       
    70     CleanupStack::PushL( self );
       
    71     self->ConstructL();
       
    72     CleanupStack::Pop( self );
       
    73     return self;
       
    74     }
       
    75 
       
    76 // --------------------------------------------------------------------------
       
    77 // Handle clients' requests. Due the request implementations are simple
       
    78 // the actions are done in ServiceL and not dispatched to separate functions.
       
    79 // --------------------------------------------------------------------------
       
    80 //
       
    81 void CFlexTimerServerMonitorSession::ServiceL( const RMessage2& aMessage )
       
    82     {
       
    83     // This ain't the most elegant solution but here we go.
       
    84     //
       
    85     // Passing the server's reference as a parameter during session creation 
       
    86     // would be another solution.
       
    87     CFlexTimerServerMonitorServer* server = 
       
    88         static_cast<CFlexTimerServerMonitorServer*>( 
       
    89             const_cast<CServer2*>( Server() ) );
       
    90 
       
    91     // Dispatch and execute the client's request
       
    92     switch ( aMessage.Function() )
       
    93         {
       
    94         case EFlexTimerServerMonitorStartMonitoring:
       
    95             {
       
    96             aMessage.Complete( server->StartMonitoring() );
       
    97             break;
       
    98             }
       
    99         case EFlexTimerServerMonitorHasServerCrashed:
       
   100             {
       
   101             TBool hasCrashed;
       
   102 
       
   103             TInt ret = server->GetStatus( hasCrashed );
       
   104 
       
   105             TPckgBuf<TBool> pckg( hasCrashed );
       
   106             aMessage.WriteL( 0, pckg );
       
   107             aMessage.Complete( ret );
       
   108             break;
       
   109             }
       
   110         case EFlexTimerServerMonitorStopMonitoring:
       
   111             {
       
   112             aMessage.Complete( server->StopMonitoring() );
       
   113             break;
       
   114             }
       
   115         default:
       
   116             aMessage.Complete( KErrNotSupported );
       
   117         }
       
   118     }