natplugins/natpnatfwsdpprovider/src/nspstatenegotiating.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 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:  Negotiating state implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <sdpdocument.h>
       
    19 #include "nspstatenegotiating.h"
       
    20 #include "nspevents.h"
       
    21 #include "nspsession.h"
       
    22 #include "nspactionset.h"
       
    23 #include "nspsessiondata.h"
       
    24 #include "nspdefs.h"
       
    25 
       
    26 #define MISMATCH( aData ) \
       
    27     ( aData.SubState() == CNSPSessionData::ESubMismatch ||\
       
    28       aData.SubState() == CNSPSessionData::ESubAll )
       
    29 #define REMOTELITE( aData ) \
       
    30     ( aData.SubState() == CNSPSessionData::ESubRemoteLite ||\
       
    31       aData.SubState() == CNSPSessionData::ESubAll )
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 // ---------------------------------------------------------------------------
       
    35 // CNSPStateNegotiating::CNSPStateNegotiating
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CNSPStateNegotiating::CNSPStateNegotiating()
       
    39     {
       
    40     }
       
    41 
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CNSPStateNegotiating::NewL
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CNSPStateNegotiating* CNSPStateNegotiating::NewL()
       
    48     {
       
    49     CNSPStateNegotiating* self = CNSPStateNegotiating::NewLC();
       
    50     CleanupStack::Pop( self );
       
    51     return self;
       
    52     }
       
    53 
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CNSPStateNegotiating::NewLC
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CNSPStateNegotiating* CNSPStateNegotiating::NewLC()
       
    60     {
       
    61     CNSPStateNegotiating* self = new ( ELeave ) CNSPStateNegotiating;
       
    62     CleanupStack::PushL( self );
       
    63     return self;
       
    64     }
       
    65 
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CNSPStateNegotiating::~CNSPStateNegotiating
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 CNSPStateNegotiating::~CNSPStateNegotiating()
       
    72     {
       
    73     }
       
    74 
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CNSPStateNegotiating::DoAcceptL
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 TBool CNSPStateNegotiating::DoAcceptL( TNSPStateMachineEvent& aEvent )
       
    81     {
       
    82     User::LeaveIfError(
       
    83             TNSPStateMachineEvent::ENat == aEvent.Request() ||
       
    84             TNSPStateMachineEvent::EUpdate == aEvent.Request() ||
       
    85             TNSPStateMachineEvent::EDecodeAnswer == aEvent.Request() ||
       
    86             TNSPStateMachineEvent::EReservationStatus == aEvent.Request() ||
       
    87             TNSPStateMachineEvent::ECloseSession == aEvent.Request() ?
       
    88                     KErrNone : KErrArgument );
       
    89     
       
    90     return ETrue;
       
    91     }
       
    92 
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CNSPStateNegotiating::DoStateEntryL
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 void CNSPStateNegotiating::DoStateEntryL( TNSPStateMachineEvent& aEvent )
       
    99     {
       
   100     CNSPSession& session = aEvent.Session();
       
   101     
       
   102     if ( OFFERER( session.Role() ) )
       
   103         {
       
   104         session.Actions().SetInboundCredentialsL();
       
   105         aEvent.Offer() = session.Data().ReleaseOffer();
       
   106         aEvent.CallbackType() = TEventReturnStatus::EOfferReady;
       
   107         }
       
   108     else
       
   109         {
       
   110         User::Leave( KErrArgument );
       
   111         }
       
   112     }
       
   113 
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CNSPStateNegotiating::DoReverse
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 void CNSPStateNegotiating::DoReverse( TNSPStateMachineEvent& aEvent )
       
   120     {
       
   121     aEvent.Session().Data().SetAnswer( NULL );
       
   122     aEvent.Session().Role() = CNSPSession::EUndefined;
       
   123     }
       
   124 
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CNSPStateNegotiating::DoApplyL
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CNSPStateNegotiating::DoApplyL( TNSPStateMachineEvent& aEvent )
       
   131     {
       
   132     switch( aEvent.Request() )
       
   133         {
       
   134         case TNSPStateMachineEvent::ENat:
       
   135             {
       
   136             ControlMediaL( aEvent );
       
   137             break;
       
   138             }
       
   139         
       
   140         case TNSPStateMachineEvent::EDecodeAnswer:
       
   141             {
       
   142             ApplyDecodeAnswerL( aEvent );
       
   143             break;
       
   144             }
       
   145         
       
   146         case TNSPStateMachineEvent::EReservationStatus:
       
   147             {
       
   148             aEvent.Status() = KNatAsync;
       
   149             break;
       
   150             }
       
   151         
       
   152         case TNSPStateMachineEvent::ECloseSession:
       
   153             {
       
   154             aEvent.Status() = KNatReady;
       
   155             break;
       
   156             }
       
   157         case TNSPStateMachineEvent::EUpdate:
       
   158             {
       
   159             break;
       
   160             }
       
   161         default:
       
   162             {
       
   163             User::Leave( KErrArgument );
       
   164             }
       
   165         }
       
   166     }
       
   167 
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // CNSPStateNegotiating::DoExitL
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 void CNSPStateNegotiating::DoExitL( TNSPStateMachineEvent& aEvent )
       
   174     {
       
   175     CNSPSession& session = aEvent.Session();
       
   176     
       
   177     switch( aEvent.Request() )
       
   178         {
       
   179         case TNSPStateMachineEvent::ENat:
       
   180             {
       
   181             break;
       
   182             }
       
   183         
       
   184         case TNSPStateMachineEvent::EDecodeAnswer:
       
   185             {
       
   186             session.Data().SetAnswer( aEvent.Answer()->CloneL() );
       
   187             session.Role() = CNSPSession::EOfferer;
       
   188             break;
       
   189             }
       
   190         
       
   191         default:
       
   192             {
       
   193             User::Leave( KErrArgument );
       
   194             }
       
   195         }
       
   196     }
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // CNSPStateNegotiating::ControlMediaL
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 void CNSPStateNegotiating::ControlMediaL( TNSPStateMachineEvent& aEvent ) const
       
   203     {
       
   204     TNSPStateMachineMediaEvent& event = MEDIAEVENT( aEvent );
       
   205     TNatReturnStatus status = event.Session().Actions().ControlMediaL(
       
   206     		event.StreamId(), event.Event(), event.Status(), event.Data() );
       
   207     
       
   208     if ( NSP_TRIGGER( status ) )
       
   209     	{
       
   210     	ApplyNatL( event );
       
   211     	}
       
   212     else
       
   213     	{
       
   214         event.Status() = status;
       
   215     	}
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // CNSPStateNegotiating::ApplyNatL
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 void CNSPStateNegotiating::ApplyNatL( TNSPStateMachineEvent& aEvent ) const
       
   223     {
       
   224     CNSPSession& session = aEvent.Session();
       
   225     
       
   226     if ( OFFERER( session.Role() ) )
       
   227         {
       
   228         CSdpDocument& answer = session.Data().Answer();
       
   229         session.Actions().GetCredentialsL( answer );
       
   230         session.Actions().GetCandidatesL( answer );
       
   231         aEvent.NextState() = ( session.Data().UseIce() ?
       
   232                 KStateIndexResolving : KStateIndexActivating );
       
   233         aEvent.Status() = KNatAsync;
       
   234         }
       
   235     else if ( ANSWERER( session.Role() ) )
       
   236         {
       
   237         session.Actions().FirstRoundL( session.Data().UpdatedSdp(), EFalse );
       
   238         aEvent.Offer() =  session.Data().ReleaseUpdatedSdp();
       
   239         aEvent.CallbackType() = TEventReturnStatus::EUpdateSdp;
       
   240         }
       
   241     else
       
   242         {
       
   243         User::Leave( KErrArgument );
       
   244         }
       
   245     }
       
   246 
       
   247 
       
   248 // ---------------------------------------------------------------------------
       
   249 // CNSPStateNegotiating::ApplyDecodeAnswerL
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 void CNSPStateNegotiating::ApplyDecodeAnswerL( TNSPStateMachineEvent& aEvent )
       
   253         const
       
   254     {
       
   255     TNatReturnStatus status = KNatReady;
       
   256     CNSPSession& session = aEvent.Session();
       
   257     CSdpDocument* answer = aEvent.Answer();
       
   258     
       
   259     session.Actions().RemoveStreamsL( *answer );
       
   260     status = session.Actions().GetSessionModifiersL( *answer,
       
   261         CNSPSession::EOfferer );
       
   262     
       
   263     CNSPSessionData& sessionData = session.Data();
       
   264     if ( KNatAsync == status && !REMOTELITE( sessionData ) )
       
   265         {
       
   266         session.Data().SetAnswer( answer->CloneL() );
       
   267         session.Role() = CNSPSession::EOfferer;
       
   268         session.Actions().RestartWithoutIce();
       
   269         session.Actions().LoadPluginL();
       
   270         session.Actions().FetchL();
       
   271         }
       
   272     else
       
   273         {
       
   274         session.Actions().GetCredentialsL( *answer );
       
   275         session.Actions().GetCandidatesL( *answer );
       
   276         aEvent.NextState() = ( session.Data().UseIce() ?
       
   277                 KStateIndexResolving : KStateIndexActivating );
       
   278         }
       
   279     
       
   280     aEvent.Status() = KNatAsync;
       
   281     }
       
   282 
       
   283 
       
   284 // end of file