multimediacommsengine/mmcesrv/mmceserver/src/mcenatstateidle.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "mcenatstateidle.h"
       
    21 #include "mcenatsipsession.h"
       
    22 #include "mceactionset.h"
       
    23 #include "mceclientserver.h"
       
    24 #include "mcenatevents.h"
       
    25 #include "mcenatactions.h"
       
    26 #include "mcesrvlogs.h"
       
    27 #include "mcestate.h"
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CMceNatStateIdle::CMceNatStateIdle
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CMceNatStateIdle::CMceNatStateIdle()
       
    34 	{
       
    35 	}
       
    36 
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CMceNatStateIdle::~CMceNatStateIdle
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CMceNatStateIdle::~CMceNatStateIdle()
       
    43 	{
       
    44 	}
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CMceNatStateIdle::Accept
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 TBool CMceNatStateIdle::Accept( TMceNatStateTransitionEvent& aEvent )
       
    51     {
       
    52     if ( EMceNatUpdated == aEvent.NatCode() ||
       
    53          EMceNatError == aEvent.NatCode() ||
       
    54          EMceNatICMPError == aEvent.NatCode())
       
    55         {
       
    56         return ETrue;
       
    57         }
       
    58     else
       
    59         {
       
    60         return EFalse;
       
    61         }
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CMceNatStateIdle::EntryL
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 void CMceNatStateIdle::EntryL( TMceNatStateTransitionEvent& aEvent )
       
    69 	{
       
    70 	if ( CMceCsSubSession::EInSession == aEvent.Session().Type() &&
       
    71 			( &aEvent.Session().Request()) && 
       
    72 			MceSip::HasContent( aEvent.Session().Request()  ))
       
    73 		{
       
    74 		aEvent.Session().ServerInitializedL();
       
    75 		}
       
    76 	}
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CMceNatStateIdle::ExitL
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CMceNatStateIdle::ExitL( TMceNatStateTransitionEvent& aEvent )
       
    83 	{
       
    84 	MCESRV_DEBUG( "*** CMceNatStateIdle::ExitL, Entry" );
       
    85 	
       
    86 	switch ( aEvent.NatCode() )
       
    87 	    {
       
    88 	    case EMceNatError:
       
    89 	    case EMceNatICMPError:
       
    90 	        {
       
    91 	        ExitErrorL( aEvent );
       
    92 	        break;
       
    93 	        }
       
    94 	    default:
       
    95 	        {
       
    96 	        ExitDefaultL( aEvent );
       
    97 	        break;
       
    98 	        }
       
    99 	    }
       
   100     
       
   101 	MCESRV_DEBUG( "*** CMceNatStateIdle::ExitL, Exit" );
       
   102 	}
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CMceNatStateIdle::ExitErrorL
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 void CMceNatStateIdle::ExitErrorL( TMceNatStateTransitionEvent& aEvent )
       
   109     {
       
   110     
       
   111     TMceStateIndex sipState = aEvent.Session().CurrentState().Id();
       
   112     
       
   113     if (( aEvent.NatCode() == EMceNatICMPError && 
       
   114     		KMceStateEstablished == sipState ) || 
       
   115     		aEvent.NatCode() == EMceNatError )
       
   116     	{
       
   117     	aEvent.Session().Actions().ClientErrorOccured( aEvent.ParamStatus() );
       
   118     	User::Leave( aEvent.ParamStatus() );		
       
   119     	}
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CMceNatStateIdle::ExitDefaultL
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CMceNatStateIdle::ExitDefaultL( TMceNatStateTransitionEvent& aEvent )
       
   127     {       
       
   128     if ( CMceCsSubSession::EInSession == aEvent.Session().Type() )
       
   129         {
       
   130         if ( &aEvent.Session().Request() && 
       
   131         		!MceSip::HasContent( aEvent.Session().Request() ))
       
   132         	{
       
   133     		aEvent.NatActions().SetOffered( KMceNatOfferSdp );
       
   134     		aEvent.NatActions().StateChangedL( aEvent, KMceNatStateCreateOffer );				
       
   135         	}
       
   136         else
       
   137         	{
       
   138         	aEvent.NatActions().SetOffered( KMceNatOfferSdp );
       
   139         	aEvent.NatActions().StateChangedL( aEvent, KMceNatStateCreateAnswer );		
       
   140         	}
       
   141         
       
   142         }
       
   143     else if ( CMceCsSubSession::EOutSession == aEvent.Session().Type() )
       
   144         {
       
   145         aEvent.NatActions().SetOffered( KMceNatOfferSdp );
       
   146         aEvent.NatActions().StateChangedL( aEvent, KMceNatStateCreateOffer );
       
   147         }
       
   148     else
       
   149         {
       
   150         User::Leave( KErrArgument );
       
   151         }
       
   152     }
       
   153