natfw/natfwturnplugin/src/natfwturnrefreshtimer.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006 - 2007 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:    Starts sending keepalive -requests to TURN Client.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "natfwturnrefreshtimer.h"
       
    22 #include "natfwturnpluginlogs.h"
       
    23 #include "natfwrefreshobserver.h"
       
    24 
       
    25 
       
    26 // ======== MEMBER FUNCTIONS ========
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // C++ default constructor
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CNATFWTurnRefreshTimer::CNATFWTurnRefreshTimer( 
       
    33     MNATFWRefreshObserver& aObserver ) :
       
    34     CActive( EPriorityStandard ), iObserver( aObserver )
       
    35     {
       
    36     __TURNPLUGIN( "CNATFWTurnRefreshTimer::CNATFWTurnRefreshTimer" )
       
    37     CActiveScheduler::Add( this );
       
    38     }
       
    39 
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // Symbian constructor
       
    43 // Creates timer service.
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 void CNATFWTurnRefreshTimer::ConstructL()
       
    47     {
       
    48     __TURNPLUGIN( "CNATFWTurnRefreshTimer::ConstructL start" )
       
    49 
       
    50     User::LeaveIfError( iTimer.CreateLocal() );
       
    51 
       
    52     __TURNPLUGIN( "CNATFWTurnRefreshTimer::ConstructL end" )
       
    53     }
       
    54 
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // Symbian constructor
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CNATFWTurnRefreshTimer* CNATFWTurnRefreshTimer::NewL( 
       
    61     MNATFWRefreshObserver&aObserver )
       
    62     {
       
    63     __TURNPLUGIN( "CNATFWTurnRefreshTimer::NewL" )
       
    64     CNATFWTurnRefreshTimer* self = 
       
    65         CNATFWTurnRefreshTimer::NewLC( aObserver );
       
    66     CleanupStack::Pop( self );
       
    67     return self;
       
    68     }
       
    69 
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // Symbian constructor
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 CNATFWTurnRefreshTimer* CNATFWTurnRefreshTimer::NewLC( 
       
    76     MNATFWRefreshObserver&aObserver )
       
    77     {
       
    78     __TURNPLUGIN( "CNATFWTurnRefreshTimer::NewLC" )
       
    79     CNATFWTurnRefreshTimer* self = 
       
    80          new( ELeave ) CNATFWTurnRefreshTimer( aObserver );
       
    81     CleanupStack::PushL( self );
       
    82     self->ConstructL();
       
    83     return self;
       
    84     }
       
    85 
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // Destructor
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 CNATFWTurnRefreshTimer::~CNATFWTurnRefreshTimer()
       
    92     {
       
    93     __TURNPLUGIN( "CNATFWTurnRefreshTimer::~CNATFWTurnRefreshTimer" )
       
    94 
       
    95     Cancel();
       
    96     iTimer.Close();
       
    97     }
       
    98 
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // Receives interval as a parameter and waits for that time before activation.
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 void CNATFWTurnRefreshTimer::StartTurnRefresh( TUint aInterval )
       
   105     {
       
   106     __TURNPLUGIN( "CNATFWTurnRefreshTimer::StartTurnRefresh start" )
       
   107     
       
   108     iInterval = aInterval;  
       
   109     
       
   110     if ( iInterval > 0 )
       
   111         {
       
   112         if ( !IsActive() )
       
   113             {
       
   114             iTimer.After( iStatus, aInterval );
       
   115             SetActive();
       
   116             }
       
   117         }
       
   118     else
       
   119         {
       
   120         Cancel();
       
   121         }
       
   122 
       
   123     __TURNPLUGIN( "CNATFWTurnRefreshTimer::StartTurnRefresh end" )
       
   124     }
       
   125 
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // Checks refresher state.
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 TBool CNATFWTurnRefreshTimer::IsRunning() const
       
   132     {
       
   133     return IsActive();
       
   134     }
       
   135 
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // Sends BindingRefresh request to CNATFWTurnConnectionHandler through
       
   139 // MNATFWRefreshObserver after time in iInterval has passed.
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 void CNATFWTurnRefreshTimer::RunL()
       
   143     {
       
   144     __TURNPLUGIN( "CNATFWTurnRefreshTimer::RunL start" )
       
   145 
       
   146     iObserver.BindingRefreshL();
       
   147     StartTurnRefresh( iInterval );
       
   148 
       
   149     __TURNPLUGIN( "CNATFWTurnRefreshTimer::RunL end" )
       
   150     }
       
   151 
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // Cancels the current timer.
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 void CNATFWTurnRefreshTimer::DoCancel()
       
   158     {
       
   159     __TURNPLUGIN( "CNATFWTurnRefreshTimer::DoCancel" )
       
   160     iTimer.Cancel();
       
   161     }
       
   162     
       
   163 // End of file