simpleengine/siputils/src/simplerefreshtimer.cpp
changeset 0 c8caa15ef882
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     1 /*
       
     2 * Copyright (c) 2006 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:    Refresh timer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <e32std.h>
       
    26 #include "simplerefreshtimer.h"
       
    27 #include "simplesipconncallback.h"
       
    28 
       
    29 #ifdef _DEBUG
       
    30 #include "simpledebugutils.h"
       
    31 #endif
       
    32 
       
    33 
       
    34 // CONSTANTS
       
    35 
       
    36 const TInt KUseAfterLimit = 240;
       
    37 
       
    38 // ======== LOCAL FUNCTIONS ========
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // Refresh timer
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 
       
    45 // ======== MEMBER FUNCTIONS ========
       
    46 
       
    47 CSimpleRefreshTimer::CSimpleRefreshTimer(
       
    48     MSimpleSipConnCallback& aEngine, CSimpleRequest& aReq  )
       
    49     : CActive( CActive::EPriorityStandard),
       
    50       iEngine(aEngine), iRequest( aReq )
       
    51 
       
    52     {
       
    53     // Add this to the scheduler
       
    54     (void) iTimer.CreateLocal();
       
    55     CActiveScheduler::Add(this);
       
    56     }
       
    57 
       
    58 CSimpleRefreshTimer::~CSimpleRefreshTimer()
       
    59     {
       
    60     Cancel();
       
    61     iTimer.Close();
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CSimpleRefreshTimer::Start
       
    66 // -----------------------------------------------------------------------------
       
    67 void CSimpleRefreshTimer::Start( TInt aWaitSeconds )
       
    68     {
       
    69 #ifdef _DEBUG
       
    70     TSimpleLogger::Log(_L("RefreshTimer: Start %d sec" ), aWaitSeconds );
       
    71 #endif
       
    72 
       
    73     // Cancel is needed because of the timer may be reset.
       
    74     Cancel();
       
    75 
       
    76     if ( aWaitSeconds <= 0)
       
    77         {
       
    78         return;
       
    79         }
       
    80 
       
    81     iSeconds = aWaitSeconds;
       
    82     
       
    83     // The At function caused a CUserbase-Panic 46 in very small
       
    84     // time values. 1-4 seconds. Now if the KeepAlive time
       
    85     // is smaller than UseAfterLimit, then we use the After function
       
    86     // If it is larger then use the At function
       
    87     // The reason not to use the After function for every situation is
       
    88     // that the TInt overflows after 35 minutes. 1000000*60*36 > 2^31
       
    89     if( iSeconds <= KUseAfterLimit )
       
    90         {
       
    91         iTimer.After( iStatus, iSeconds * 1000000 );
       
    92         }
       
    93     else
       
    94         {
       
    95         TTime myKeepAlive;
       
    96         myKeepAlive.HomeTime();
       
    97         myKeepAlive += TTimeIntervalSeconds( iSeconds );
       
    98         iTimer.At( iStatus, myKeepAlive );
       
    99         }
       
   100     iStatus = KRequestPending;
       
   101     SetActive();
       
   102 
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CSimpleRefreshTimer::DoCancel
       
   107 // -----------------------------------------------------------------------------
       
   108 void CSimpleRefreshTimer::DoCancel( )
       
   109     {
       
   110 #ifdef _DEBUG
       
   111     TSimpleLogger::Log(_L("RefreshTimer: DoCancel" ));
       
   112 #endif
       
   113     iTimer.Cancel();
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CSimpleRefreshTimer::RunL
       
   118 // -----------------------------------------------------------------------------
       
   119 void CSimpleRefreshTimer::RunL(  )
       
   120     {
       
   121 #ifdef _DEBUG
       
   122     TSimpleLogger::Log(_L("RefreshTimer: RunL" ));
       
   123 #endif
       
   124     // Inside StartToRefreshL this entity may be deleted,
       
   125     // thus after the method call do not do anything in RunL.
       
   126     iEngine. StartToRefreshL( iRequest );
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CSimpleRefreshTimer::RunError
       
   131 // -----------------------------------------------------------------------------
       
   132 TInt CSimpleRefreshTimer::RunError(TInt /*aError*/)
       
   133     {
       
   134 #ifdef _DEBUG
       
   135     TSimpleLogger::Log(_L("RefreshTimer: RunError" ));
       
   136 #endif
       
   137     return KErrNone;
       
   138     }
       
   139     
       
   140     
       
   141 // ---------------------------------------------------------------------------
       
   142 // Expiry timer
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 
       
   146 // ======== MEMBER FUNCTIONS ========
       
   147 
       
   148 CSimpleExpiryTimer::CSimpleExpiryTimer(
       
   149     MSimpleSipConnCallback& aEngine, CSimpleRequest& aReq  )
       
   150     : CActive( CActive::EPriorityStandard),
       
   151       iEngine(aEngine), iRequest( aReq )
       
   152 
       
   153     {
       
   154     // Add this to the scheduler
       
   155     (void) iTimer.CreateLocal();
       
   156     CActiveScheduler::Add(this);
       
   157     }
       
   158 
       
   159 CSimpleExpiryTimer::~CSimpleExpiryTimer()
       
   160     {
       
   161     Cancel();
       
   162     iTimer.Close();
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // CSimpleExpiryTimer::Start
       
   167 // -----------------------------------------------------------------------------
       
   168 void CSimpleExpiryTimer::Start( TInt aWaitSeconds )
       
   169     {
       
   170 #ifdef _DEBUG
       
   171     TSimpleLogger::Log(_L("ExpiryTimer: Start %d sec" ), aWaitSeconds );
       
   172 #endif
       
   173 
       
   174     // Cancel is needed because of the timer may be reset.
       
   175     Cancel();
       
   176 
       
   177     if ( aWaitSeconds <= 0 )
       
   178         {
       
   179         return;
       
   180         }
       
   181 
       
   182     iSeconds = aWaitSeconds;
       
   183 
       
   184     // The At function caused a CUserbase-Panic 46 in very small
       
   185     // time values. 1-4 seconds. Now if the KeepAlive time
       
   186     // is smaller than UseAfterLimit, then we use the After function
       
   187     // If it is larger then use the At function
       
   188     // The reason not to use the After function for every situation is
       
   189     // that the TInt overflows after 35 minutes. 1000000*60*36 > 2^31
       
   190     if( iSeconds <= KUseAfterLimit )
       
   191         {
       
   192         iTimer.After( iStatus, iSeconds * 1000000 );
       
   193         }
       
   194     else
       
   195         {
       
   196         TTime myKeepAlive;
       
   197         myKeepAlive.HomeTime();
       
   198         myKeepAlive += TTimeIntervalSeconds( iSeconds );
       
   199         iTimer.At( iStatus, myKeepAlive );
       
   200         }
       
   201     iStatus = KRequestPending;
       
   202     SetActive();
       
   203 
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CSimpleExpiryTimer::DoCancel
       
   208 // -----------------------------------------------------------------------------
       
   209 void CSimpleExpiryTimer::DoCancel( )
       
   210     {
       
   211 #ifdef _DEBUG
       
   212     TSimpleLogger::Log(_L("ExpiryTimer: DoCancel" ));
       
   213 #endif
       
   214     iTimer.Cancel();
       
   215     }
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CSimpleExpiryTimer::RunL
       
   219 // -----------------------------------------------------------------------------
       
   220 void CSimpleExpiryTimer::RunL(  )
       
   221     {
       
   222 #ifdef _DEBUG
       
   223     TSimpleLogger::Log(_L("ExpiryTimer: RunL" ));
       
   224 #endif
       
   225     iEngine.StartToCheckExpiryL( iRequest );
       
   226     // Inside StartToCheckExpiryL this entity may be deleted,
       
   227     // thus after the method call do not do anything in RunL.    
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CSimpleExpiryTimer::RunError
       
   232 // -----------------------------------------------------------------------------
       
   233 TInt CSimpleExpiryTimer::RunError(TInt /*aError*/)
       
   234     {
       
   235 #ifdef _DEBUG
       
   236     TSimpleLogger::Log(_L("ExpiryTimer: RunError" ));
       
   237 #endif
       
   238     return KErrNone;
       
   239     }
       
   240     
       
   241