watchdog/src/cwdtimer.cpp
changeset 0 671dee74050a
child 1 6f2c1c46032b
equal deleted inserted replaced
-1:000000000000 0:671dee74050a
       
     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 "CWDTimer.h"
       
    20 #include "WatchDogCommon.h"
       
    21 #include "MWDTimerHandler.h"
       
    22 #include <HarvesterServerLogger.h>
       
    23 // -----------------------------------------------------------------------------
       
    24 // CWDTimer::NewL
       
    25 // -----------------------------------------------------------------------------
       
    26 //
       
    27 CWDTimer* CWDTimer::NewL( MWDTimerHandler* aWDTimerHandler )
       
    28     {
       
    29     CWDTimer* self = CWDTimer::NewLC( aWDTimerHandler );
       
    30     CleanupStack::Pop();
       
    31     return self;
       
    32     }
       
    33 // -----------------------------------------------------------------------------
       
    34 // CWDTimer::NewLC
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CWDTimer* CWDTimer::NewLC( MWDTimerHandler* aWDTimerHandler )
       
    38     {
       
    39     CWDTimer* self = new ( ELeave ) CWDTimer( );
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructL( aWDTimerHandler );
       
    42     return self;
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CWDTimer::~CWDTimer()
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CWDTimer::~CWDTimer()
       
    50     {
       
    51     Cancel();
       
    52     iTimer.Close();
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CWDTimer::CWDTimer()
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CWDTimer::CWDTimer( ): CActive( CActive::EPriorityStandard )                        
       
    60     {
       
    61     
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CWDTimer::ConstructL()
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 void CWDTimer::ConstructL( MWDTimerHandler* aWDTimerHandler )
       
    69     {
       
    70     CActiveScheduler::Add( this );
       
    71     User::LeaveIfError( iTimer.CreateLocal() );
       
    72     iWDTimerHandler = aWDTimerHandler;
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CWDTimer::StartWDTimer()
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void CWDTimer::StartWDTimer()
       
    80     {
       
    81     CPIXLOGSTRING("CWDTimer::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 // CWDTimer::RunL()
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 void CWDTimer::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 , iWDTimerHandler->HandleWDTimerL() );
       
    98         if ( err == KErrNone)
       
    99             {
       
   100             //start the timer
       
   101             iTimer.After( iStatus , MONITORING_DELAY ); // Wait 60 seconds before checking the servers
       
   102             SetActive();
       
   103             }
       
   104         }
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CWDTimer::DoCancel()
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 void CWDTimer::DoCancel()
       
   112     {
       
   113     iTimer.Cancel();     
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CWDTimer::RunError()
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 TInt CWDTimer::RunError( TInt )
       
   121     {
       
   122     //Cancel the timer if there are any and start the new timer
       
   123     iTimer.Cancel();
       
   124     
       
   125     //start the timer
       
   126     iTimer.After( iStatus , MONITORING_DELAY );
       
   127     SetActive();
       
   128                 
       
   129     return KErrNone;
       
   130     }
       
   131 //End of file