connectionmonitoring/connmon/dataconnectionlogger/src/dclTimer.cpp
changeset 0 5a93021fdf25
child 73 70ee5458c95d
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Timer active object needed in logging data in timer mode.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <e32base.h>
       
    19 
       
    20 #include "dclTimer.h"
       
    21 #include "dcl_log.h"
       
    22 
       
    23 // ============================ MEMBER FUNCTIONS ===============================
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 // CDclTimerAO::CDclTimerAO
       
    27 // -----------------------------------------------------------------------------
       
    28 //
       
    29 CDclTimerAO::CDclTimerAO( CEngine* aEngine, TInt aTimerInterval )
       
    30     :
       
    31     CActive( CActive::EPriorityStandard ),
       
    32     iEngine( aEngine ),
       
    33     iTimerInterval( aTimerInterval )
       
    34     {
       
    35     }
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CDclTimerAO::ConstructL
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 void CDclTimerAO::ConstructL()
       
    42     {
       
    43     CActiveScheduler::Add( this );
       
    44 
       
    45     User::LeaveIfError( iTimer.CreateLocal() );
       
    46 
       
    47     iConnectionIds.Reset();
       
    48     }
       
    49 
       
    50 // Destructor
       
    51 CDclTimerAO::~CDclTimerAO()
       
    52     {
       
    53     Cancel();
       
    54     iTimer.Close();
       
    55     iConnectionIds.Close();
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CDclTimerAO::Add
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 void CDclTimerAO::Add( const TUint& aConnectionId )
       
    63     {
       
    64     iConnectionIds.Append( aConnectionId );
       
    65 
       
    66     NextTimerAfter();
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CDclTimerAO::Remove
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CDclTimerAO::Remove( const TUint& aConnectionId )
       
    74     {
       
    75     for ( TInt i=0; i < iConnectionIds.Count(); i++ )
       
    76         {
       
    77         if ( aConnectionId == iConnectionIds[ i ] )
       
    78             {
       
    79             // A connection has switched to threshold mode
       
    80             iConnectionIds.Remove( i );
       
    81             return;
       
    82             }
       
    83         }
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CDclTimerAO::NextTimerAfter
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CDclTimerAO::NextTimerAfter()
       
    91     {
       
    92     if ( !IsActive() )
       
    93         {
       
    94         iTimer.After( iStatus, iTimerInterval * 1000000 );
       
    95         SetActive();
       
    96         }
       
    97     }
       
    98 
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CDclTimerAO::DoCancel
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 void CDclTimerAO::DoCancel()
       
   105     {
       
   106     if ( IsActive() )
       
   107         {
       
   108         iTimer.Cancel();
       
   109         }
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CDclTimerAO::RunL
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 void CDclTimerAO::RunL()
       
   117     {
       
   118     TInt count( 0 );
       
   119 
       
   120     if ( iStatus.Int() == KErrNone )
       
   121         {
       
   122         LOG( Log::Printf( _L("Timer EVENT\n")));
       
   123 
       
   124         // Log all connections that are in timer mode
       
   125         count = iConnectionIds.Count();
       
   126 
       
   127         for ( TInt i = ( count - 1 ); i >= 0; i-- )
       
   128             {
       
   129             TInt ret = iEngine->LogDataInTimerModeL( iConnectionIds[ i ] );
       
   130 
       
   131             if ( ret != KErrNone )
       
   132                 {
       
   133                 // A connection has switched to threshold mode
       
   134                 iConnectionIds.Remove( i );
       
   135                 }
       
   136             }
       
   137 
       
   138         // Go on with the timer if there are still connections in timer mode
       
   139         if ( iConnectionIds.Count() > 0 )
       
   140             {
       
   141             NextTimerAfter();
       
   142             }
       
   143         }
       
   144     else
       
   145         {
       
   146         // Switch all connections back to threshold mode beacause timer failed
       
   147         LOG( Log::Printf( _L("Timer FAILED: %d.\n"), iStatus.Int()));
       
   148 
       
   149         count = iConnectionIds.Count();
       
   150 
       
   151         for ( TInt i = ( count - 1 ); i >= 0; i-- )
       
   152             {
       
   153             iEngine->SwitchToThresholdMode( iConnectionIds[ i ] );
       
   154             iConnectionIds.Remove( i );
       
   155             }
       
   156         }
       
   157     }
       
   158 
       
   159 // End-of-file