locationcentre/lcserver/src/lcservershutdowntimer.cpp
branchRCL_3
changeset 9 4721bd00d3da
parent 8 3a25f69541ff
child 11 e15b7f06eba6
equal deleted inserted replaced
8:3a25f69541ff 9:4721bd00d3da
     1 /*
       
     2 * Copyright (c) 2007 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:  Shutdown timer for Location Centre server.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDES
       
    20 #include <centralrepository.h>
       
    21 
       
    22 // USER INCLUDES
       
    23 #include "lcservershutdowntimer.h"
       
    24 #include "lcprivatecrkeys.h"
       
    25 
       
    26 // CONSTANT DEFINTIONS
       
    27 TInt KMilliSectoMicroConversion = 1000;
       
    28 
       
    29 // ----- Member funtions for CLcServerShutDownTimerShutDownTimer -------------
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // CLcServerShutDownTimer::CLcServerShutDownTimer
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 CLcServerShutDownTimer::CLcServerShutDownTimer()
       
    36     :CTimer( CActive::EPriorityLow )
       
    37     {
       
    38     // C++ Default constructor. No allocations or functions which can Leave
       
    39     // should be called from here.
       
    40     
       
    41     // The timer needs to be added to the Active scheduler explicitly. So 
       
    42     // adding it here
       
    43     CActiveScheduler::Add( this );
       
    44     }
       
    45          
       
    46 // ---------------------------------------------------------------------------
       
    47 // CLcServerShutDownTimer::~CLcServerShutDownTimer
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CLcServerShutDownTimer::~CLcServerShutDownTimer()
       
    51     {
       
    52     // C++ Destructor. Free all resources associated with this class.
       
    53     Cancel();
       
    54     }
       
    55         
       
    56 // ---------------------------------------------------------------------------
       
    57 // CLcServerShutDownTimer* CLcServerShutDownTimer::NewL
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CLcServerShutDownTimer* CLcServerShutDownTimer::NewL()
       
    61     {
       
    62     CLcServerShutDownTimer* self = NewLC();
       
    63     CleanupStack::Pop( self );
       
    64     return self;         
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CLcServerShutDownTimer* CLcServerShutDownTimer::NewLC
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 CLcServerShutDownTimer* CLcServerShutDownTimer::NewLC()
       
    72     {
       
    73     // Symbian Two phased constructor. Leaves the object on the Clean-up
       
    74     // stack.
       
    75     CLcServerShutDownTimer* self = new ( ELeave )CLcServerShutDownTimer();
       
    76     CleanupStack::PushL( self );
       
    77     self->ConstructL();
       
    78     return self;         
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // void CLcServerShutDownTimer::ConstructL
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 void CLcServerShutDownTimer::ConstructL()
       
    86     {
       
    87     // Read the shutdown timer value from the Location Centre Central
       
    88     // repository
       
    89     CRepository* repository = CRepository::NewLC( KCRUidLocationCentre );    
       
    90     repository->Get( KLcShutdownTimerValue, iShutDownTimerValue );    
       
    91     CleanupStack::PopAndDestroy( repository );
       
    92     
       
    93     // Convert the Shutdown timer value into microseconds
       
    94     iShutDownTimerValue *= KMilliSectoMicroConversion;
       
    95     
       
    96     // Call the base class ConstructL
       
    97     CTimer::ConstructL();     
       
    98     }  
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // void CLcServerShutDownTimer::ConstructL
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 void CLcServerShutDownTimer::StartTimer()
       
   105     {
       
   106     // Check if there is a request outstanding. Incase, a request is
       
   107     // outstanding then do nothing. If not start a new timer request
       
   108     
       
   109     if ( !IsActive())
       
   110         {
       
   111         CTimer::After( iShutDownTimerValue );
       
   112         }
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // void CLcServerShutDownTimer::ConstructL
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 void CLcServerShutDownTimer::StopTimer()
       
   120     {
       
   121     Cancel();
       
   122     }
       
   123     
       
   124 // ---------------------------------------------------------------------------
       
   125 // CLcServerShutDownTimer::RunL
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 void CLcServerShutDownTimer::RunL()
       
   129     {
       
   130     // Timer is not cancelled by the server. Hence, we can assume tha there
       
   131     // are no new connection requests to the server. Its safe to shutdown
       
   132     // the server
       
   133     CActiveScheduler::Stop();
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // CLcServerShutDownTimer::RunError
       
   138 // ---------------------------------------------------------------------------
       
   139 //        
       
   140 TInt CLcServerShutDownTimer::RunError( TInt aError )
       
   141     {
       
   142     return aError;
       
   143     }
       
   144 // End of File
       
   145