iaupdate/IAD/backgroundchecker/src/iaupdatebgremindertimer.cpp
changeset 60 245df5276b97
parent 53 ae54820ef82c
child 63 819e5a99c9bd
child 67 3a625661d1ce
equal deleted inserted replaced
53:ae54820ef82c 60:245df5276b97
     1 /*
       
     2 * Copyright (c) 2008-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:   Implementation of background checker
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include    <e32std.h>
       
    20 #include    <centralrepository.h>
       
    21 #include    "iaupdatebgremindertimer.h"
       
    22 #include    "iaupdateprivatecrkeys.h"
       
    23 #include    "iaupdatebgconst.h"
       
    24 
       
    25 // ----------------------------------------------------------
       
    26 // CIAUpdateBGReminderTimer::NewL()
       
    27 // ----------------------------------------------------------
       
    28 CIAUpdateBGReminderTimer* CIAUpdateBGReminderTimer::NewL(MIAUpdateBGReminderTimerCallBack* aCallback)
       
    29     {
       
    30     CIAUpdateBGReminderTimer* self = new(ELeave)CIAUpdateBGReminderTimer(aCallback);
       
    31     CleanupStack::PushL(self);
       
    32     self->ConstructL();
       
    33     CleanupStack::Pop(self);
       
    34     return self;
       
    35     }
       
    36     
       
    37 
       
    38 // ----------------------------------------------------------
       
    39 // CIAUpdateBGReminderTimer::ConstructL()
       
    40 // ----------------------------------------------------------
       
    41 void CIAUpdateBGReminderTimer::ConstructL()
       
    42     {
       
    43     CTimer::ConstructL();
       
    44     CActiveScheduler::Add( this );
       
    45     iInternalFile = CIAUpdateBGInternalFileHandler::NewL();
       
    46     }
       
    47     
       
    48     
       
    49 // ----------------------------------------------------------
       
    50 // CIAUpdateBGReminderTimer::~CIAUpdateBGReminderTimer()
       
    51 // ----------------------------------------------------------
       
    52 CIAUpdateBGReminderTimer::~CIAUpdateBGReminderTimer()
       
    53     {
       
    54     Cancel();
       
    55     delete iInternalFile;
       
    56     }
       
    57 
       
    58 
       
    59 // ----------------------------------------------------------
       
    60 // CIAUpdateBGReminderTimer::CIAUpdateBGReminderTimer()
       
    61 // ----------------------------------------------------------
       
    62 CIAUpdateBGReminderTimer::CIAUpdateBGReminderTimer(MIAUpdateBGReminderTimerCallBack* aCallback):CTimer( EPriorityStandard ), iCallback ( aCallback )
       
    63     {   
       
    64     }
       
    65 
       
    66 
       
    67 // ----------------------------------------------------------
       
    68 // CIAUpdateBGReminderTimer::RunL()
       
    69 // ----------------------------------------------------------
       
    70 void CIAUpdateBGReminderTimer::RunL()
       
    71     {
       
    72     
       
    73     if( iRuns == 0 )
       
    74         {
       
    75         //timer expired call the callback
       
    76         iCallback->ReminderTimerCallBack();
       
    77         }
       
    78     else
       
    79         {
       
    80         TTime currenttime;
       
    81         currenttime.UniversalTime();
       
    82                  
       
    83         if ( currenttime >= iNextRemindTime )
       
    84             {
       
    85             StartL( StartNow );
       
    86             }
       
    87         else
       
    88             {
       
    89             iInternalFile->ReadControllerDataL();
       
    90             TTime nextremindtime = iInternalFile->NextRemindTime();
       
    91             TTimeIntervalMinutes timetowait;
       
    92             currenttime.MinutesFrom( nextremindtime, timetowait );
       
    93             StartL( timetowait );
       
    94             }                           
       
    95          }  
       
    96     }
       
    97   
       
    98 // ----------------------------------------------------------
       
    99 // CIAUpdateBGReminderTimer::DoCancel()
       
   100 // ----------------------------------------------------------
       
   101 void CIAUpdateBGReminderTimer::DoCancel()
       
   102     {
       
   103     }
       
   104 // ----------------------------------------------------------
       
   105 // CIAUpdateBGReminderTimer::RunError()
       
   106 // ----------------------------------------------------------
       
   107 TInt CIAUpdateBGReminderTimer::RunError(TInt /*aError*/)
       
   108     {
       
   109     return KErrNone;
       
   110     }
       
   111 
       
   112 // ----------------------------------------------------------
       
   113 // CIAUpdateBGReminderTimer::StartReminderTimerL()
       
   114 // ----------------------------------------------------------
       
   115 void CIAUpdateBGReminderTimer::StartReminderTimerL(TTimeIntervalMinutes& aTimetoWait )
       
   116     {
       
   117     if ( IsActive() )
       
   118         {
       
   119         Cancel();
       
   120         }
       
   121     
       
   122     //show after one week
       
   123     StartL( aTimetoWait );    
       
   124     }
       
   125 
       
   126 
       
   127 // ----------------------------------------------------------
       
   128 // CIAUpdateBGReminderTimer::CancelReminderTimerL()
       
   129 // ----------------------------------------------------------
       
   130 void CIAUpdateBGReminderTimer::CancelReminderTimerL()
       
   131     {    
       
   132     Cancel();
       
   133     }
       
   134 
       
   135 
       
   136 // ----------------------------------------------------------
       
   137 // CIAUpdateBGReminderTimer::StartL()
       
   138 // ----------------------------------------------------------
       
   139 void CIAUpdateBGReminderTimer::StartL( TTimeIntervalMinutes aWaitTime )
       
   140     {   
       
   141     Cancel();
       
   142     /*
       
   143     RTimer::After maximum delay is 35 minutes, 47 seconds this is because it is 32bit integer. 
       
   144     Thats why aWaitTime is divided to 30min runs.  
       
   145     */
       
   146     iRuns = 0;
       
   147     if(aWaitTime.Int() > HalfHourInMinuts )
       
   148         {
       
   149         iRuns = aWaitTime.Int() / HalfHourInMinuts;
       
   150         TTimeIntervalMinutes halfhour( HalfHourInMinuts );    
       
   151         After( ConvertToMicroseconds( halfhour ) );
       
   152         }
       
   153     else{
       
   154         After( ConvertToMicroseconds( aWaitTime ) );
       
   155         }
       
   156 
       
   157     }
       
   158 
       
   159 // ----------------------------------------------------------
       
   160 // CIAUpdateBGReminderTimer::ConvertToMicroseconds()
       
   161 // ----------------------------------------------------------
       
   162 TTimeIntervalMicroSeconds32 CIAUpdateBGReminderTimer::ConvertToMicroseconds( TTimeIntervalMinutes aInterval )
       
   163     {
       
   164     return aInterval.Int()*60*1000*1000;
       
   165     }
       
   166 
       
   167 // End of file
       
   168