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