harvester/harvesterserver/src/cgaurdtimer.cpp
changeset 23 d4d56f5e7c55
child 24 65456528cac2
equal deleted inserted replaced
20:556534771396 23:d4d56f5e7c55
       
     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:  This application is to monitor Harvester and Search Server
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cgaurdtimer.h"
       
    20 #include "HarvesterServerLogger.h"
       
    21 
       
    22 #define MONITORING_DELAY 2147483647 // Max time that RTimer::After() can allow ie. 35Min.
       
    23 // -----------------------------------------------------------------------------
       
    24 // CGaurdTimer::NewL
       
    25 // -----------------------------------------------------------------------------
       
    26 //
       
    27 CGaurdTimer* CGaurdTimer::NewL( MGaurdTimerHandler* aGaurdTimerHandler )
       
    28     {
       
    29     CGaurdTimer* self = CGaurdTimer::NewLC( aGaurdTimerHandler );
       
    30     CleanupStack::Pop();
       
    31     return self;
       
    32     }
       
    33 // -----------------------------------------------------------------------------
       
    34 // CGaurdTimer::NewLC
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CGaurdTimer* CGaurdTimer::NewLC( MGaurdTimerHandler* aGaurdTimerHandler )
       
    38     {
       
    39     CGaurdTimer* self = new ( ELeave ) CGaurdTimer( );
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructL( aGaurdTimerHandler );
       
    42     return self;
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CGaurdTimer::~CGaurdTimer()
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CGaurdTimer::~CGaurdTimer()
       
    50     {
       
    51     Cancel();
       
    52     iTimer.Close();
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CGaurdTimer::CGaurdTimer()
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CGaurdTimer::CGaurdTimer( ): CActive( CActive::EPriorityStandard )                        
       
    60     {
       
    61     
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CGaurdTimer::ConstructL()
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 void CGaurdTimer::ConstructL( MGaurdTimerHandler* aGaurdTimerHandler )
       
    69     {
       
    70     CActiveScheduler::Add( this );
       
    71     User::LeaveIfError( iTimer.CreateLocal() );
       
    72     iGaurdTimerHandler = aGaurdTimerHandler;
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CGaurdTimer::StartgaurdTimer()
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void CGaurdTimer::StartgaurdTimer()
       
    80     {
       
    81     CPIXLOGSTRING("CGaurdTimer::StartWDTimer(): Entered");    
       
    82     //start the timer
       
    83     iTimer.After( iStatus , MONITORING_DELAY ); // Wait 60 seconds before checking the servers
       
    84     SetActive();    
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CGaurdTimer::RunL()
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 void CGaurdTimer::RunL()
       
    92     {
       
    93     //check for the Harvester server and the search server
       
    94     if( iStatus.Int() == KErrNone )
       
    95         {
       
    96         TInt err = KErrNone;
       
    97         TRAP ( err , iGaurdTimerHandler->HandleGaurdTimerL() );        
       
    98         }
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CGaurdTimer::DoCancel()
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 void CGaurdTimer::DoCancel()
       
   106     {
       
   107     iTimer.Cancel();     
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CGaurdTimer::RunError()
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 TInt CGaurdTimer::RunError( TInt )
       
   115     {
       
   116     //Cancel the timer if there are any and start the new timer
       
   117     iTimer.Cancel();
       
   118     
       
   119     //start the timer
       
   120     iTimer.After( iStatus , MONITORING_DELAY );
       
   121     SetActive();
       
   122                 
       
   123     return KErrNone;
       
   124     }
       
   125 //End of file