realtimenetprots/sipfw/SIP/ConnectionMgr/src/TStateActiveResolving.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name        : TStateActiveResolving.cpp
       
    15 // Part of     : ConnectionMgr
       
    16 // Implementation
       
    17 // Version     : SIP/4.0
       
    18 //
       
    19 
       
    20 
       
    21 
       
    22 #include "TStateActiveResolving.h"
       
    23 #include "msipconnectioncontext.h"
       
    24 #include "SipLogs.h"
       
    25 
       
    26 // ----------------------------------------------------------------------------
       
    27 // TStateActiveResolving::Enter
       
    28 // ----------------------------------------------------------------------------
       
    29 //
       
    30 void TStateActiveResolving::Enter( TInt /*aError*/ )
       
    31 	{
       
    32 	__SIP_LOG( "TStateActiveResolving::Enter" )
       
    33 	iTimerValue = KInitialResolvingTimer;
       
    34 	iCumulativeTimerValue = KInitialResolvingTimer;
       
    35 	TInt err( KErrNone );
       
    36 
       
    37     // Pass KErrNone for StartMonitoringL at this stage
       
    38     // since error is needed only for context availability
       
    39     // monitoring which is at this point unnecessary
       
    40 	if ( !iContext.DoTransportResourcesExist() )
       
    41 	    {
       
    42 	    TRAP( err,
       
    43     		{
       
    44     		iContext.CreateTransportResourcesL();
       
    45     		iContext.StartMonitoringL( KErrNone );
       
    46     		} );
       
    47     	if ( err )
       
    48     		{
       
    49     		EnterState( MStateModel::EUnavailable, err );
       
    50     		return;
       
    51     		}
       
    52 	    }
       
    53 
       
    54 	if ( HasAddress() )
       
    55 		{
       
    56 		// Address has to exist, otherwise resolving hasn't been done at this
       
    57 		// point and we cannot enter to resolved state
       
    58 		EnterActiveResolvedState();
       
    59 		}
       
    60 	else
       
    61 		{		
       
    62 		TRAP( err, iTimerId = iTimer.StartL( this, KInitialResolvingTimer ) );
       
    63 		if( err )
       
    64 			{
       
    65 			EnterState( MStateModel::EUnavailable, err );
       
    66 			}
       
    67 		}
       
    68 	}
       
    69 
       
    70 // ----------------------------------------------------------------------------
       
    71 // TStateActiveResolving::Exit
       
    72 // ----------------------------------------------------------------------------
       
    73 //
       
    74 void TStateActiveResolving::Exit()
       
    75 
       
    76 	{
       
    77 	iTimer.Stop( iTimerId );
       
    78 	}
       
    79 
       
    80 // ----------------------------------------------------------------------------
       
    81 // TStateActiveResolving::NetworkStateChanged
       
    82 // ----------------------------------------------------------------------------
       
    83 //
       
    84 void TStateActiveResolving::NetworkStateChanged(
       
    85     MSIPNetworkObserver::TNetworkState aState,
       
    86     TInt aError )
       
    87 	{
       
    88 	  __SIP_INT_LOG2( "TStateActiveResolving::NetworkStateChanged", aState, aError )
       
    89 	if( aError)
       
    90 		{
       
    91 		if (iContext.ConnectionType()==MSIPConnectionContext::ELanBearer)
       
    92 		{
       
    93 		EnterState( MStateModel::EInactiveMonitoring, aError ); // For Any Error on WLAN, Enable Recovery Timers.
       
    94 		}
       
    95 		else
       
    96 		{
       
    97 		EnterState( MStateModel::EUnavailable, aError ); //For other bearers No recovery possible.
       
    98 		}
       
    99 		return;
       
   100 		}
       
   101 	if( aState == MSIPNetworkObserver::ENetworkSuspended )
       
   102 		{
       
   103 		EnterState( MStateModel::ESuspended );
       
   104 		}
       
   105 	else if( aState == MSIPNetworkObserver::ENetworkInactive )
       
   106 		{
       
   107 		EnterState( MStateModel::EInactiveMonitoring );
       
   108 		}
       
   109 	else if( aState == MSIPNetworkObserver::EConnectionLost )
       
   110 		{
       
   111 		EnterState( MStateModel::EInactiveConnecting );
       
   112 		}		
       
   113 	else
       
   114 		{
       
   115 		// do nothing, "else" required by PC-Lint..
       
   116 		}
       
   117 	}
       
   118 
       
   119 // ----------------------------------------------------------------------------
       
   120 // TStateActiveResolving::TimerExpiredL
       
   121 // ----------------------------------------------------------------------------
       
   122 //
       
   123 void TStateActiveResolving::TimerExpiredL( TTimerId /*aTimerId*/,
       
   124 								 		   TAny* /*aTimerParam*/ )
       
   125 	{
       
   126     if( HasAddress() )
       
   127         {
       
   128         EnterActiveResolvedState();
       
   129         }
       
   130     else
       
   131 	    {
       
   132 		iTimerId = iTimer.StartL( this, CalculateTimerValue() );
       
   133 		}
       
   134 	}
       
   135 
       
   136 // ----------------------------------------------------------------------------
       
   137 // TStateActiveResolving::HasAddress
       
   138 // ----------------------------------------------------------------------------
       
   139 //
       
   140 TBool TStateActiveResolving::HasAddress()
       
   141 	{
       
   142 	TInetAddr address;
       
   143 	iContext.ResolveLocalAddress( address );
       
   144 	return ( !address.IsWildAddr() );
       
   145 	}
       
   146 
       
   147 // ----------------------------------------------------------------------------
       
   148 // TStateActiveResolving::CalculateTimerValue
       
   149 // ----------------------------------------------------------------------------
       
   150 //
       
   151 TUint TStateActiveResolving::CalculateTimerValue()
       
   152     {
       
   153     if ( iCumulativeTimerValue >= KStartDoublingTimerValue )
       
   154         {
       
   155         if ( iTimerValue < KMaximumResolvingTimer )
       
   156             {
       
   157             iTimerValue *= 2;
       
   158             }
       
   159         }
       
   160     iCumulativeTimerValue += iTimerValue;    
       
   161     return iTimerValue;
       
   162     }
       
   163 
       
   164 // ----------------------------------------------------------------------------
       
   165 // TStateActiveResolving::EnterActiveResolvedState
       
   166 // ----------------------------------------------------------------------------
       
   167 //
       
   168 void TStateActiveResolving::EnterActiveResolvedState()
       
   169     {
       
   170     TRAPD( err, iContext.CreateDefaultTransportsL() )
       
   171     if ( err )
       
   172         {
       
   173         EnterState( MStateModel::EUnavailable, err );
       
   174         }
       
   175     else
       
   176         {
       
   177         EnterState( MStateModel::EActiveResolved );
       
   178         }
       
   179     }