sipvoipprovider/svphold/src/svpholdoutstate.cpp
changeset 0 a4daefaec16c
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2006-2008 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:  Local holded state for hold state machine.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include    <badesca.h>
       
    20 #include    <mcesession.h>
       
    21 #include    <mcertpsource.h>
       
    22 #include    <mcertpsink.h>
       
    23 #include    <mcemediastream.h>
       
    24 #include    <mceaudiostream.h>
       
    25 #include    "svpholdoutstate.h"
       
    26 #include    "svpholdcontext.h"
       
    27 #include    "svpholdcontroller.h"
       
    28 #include    "svpholdobserver.h"
       
    29 #include    "svpholdattributehandler.h"
       
    30 #include    "svpholdmediahandler.h"
       
    31 #include    "svplogger.h"
       
    32 
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // CSVPHoldOutState::CSVPHoldOutState
       
    36 // ---------------------------------------------------------------------------
       
    37 CSVPHoldOutState::CSVPHoldOutState()
       
    38     {
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CSVPHoldOutState::NewLC
       
    43 // ---------------------------------------------------------------------------
       
    44 CSVPHoldOutState* CSVPHoldOutState::NewLC()
       
    45     {
       
    46     CSVPHoldOutState* self = new ( ELeave ) CSVPHoldOutState;
       
    47     CleanupStack::PushL( self );
       
    48     return self;
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CSVPHoldOutState::~CSVPHoldOutState
       
    53 // ---------------------------------------------------------------------------
       
    54 CSVPHoldOutState::~CSVPHoldOutState()
       
    55     {
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CSVPHoldOutState::DoApplyL
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 void CSVPHoldOutState::DoApplyL( CSVPHoldContext& aContext )
       
    63     {
       
    64     SVPDEBUG1( "CSVPHoldOutState::DoApply" );
       
    65     CMceSession* session = aContext.SessionObject();
       
    66     const RPointerArray< CMceMediaStream >& streams = session->Streams();
       
    67     TSVPHoldStateIndex nextState = KSVPHoldEstablishingStateIndex;
       
    68     
       
    69     TInt audioStreamsHandled = 0;
       
    70     TInt streamCount = streams.Count();
       
    71     SVPDEBUG2( "CSVPHoldÓutState::DoApply - stream count = %i", streamCount ); 
       
    72 
       
    73     for ( TInt i = 0; i < streamCount; i++ )
       
    74         {
       
    75         CMceMediaStream* mediaStream = streams[ i ];
       
    76         TMceMediaType mediaType = mediaStream->Type();
       
    77         if ( KMceAudio == mediaType )
       
    78             {
       
    79             // This media is audio stream. Handling depends on the request
       
    80             SVPDEBUG2( "CSVPHoldOutState::DoApply - Hold request is = %i",
       
    81                         aContext.HoldRequest() );
       
    82 
       
    83             nextState = PerformRequestL( aContext, *mediaStream, *session );
       
    84             audioStreamsHandled++;                
       
    85             }
       
    86         }
       
    87     
       
    88     if ( 0 == audioStreamsHandled )
       
    89         {
       
    90         SVPDEBUG1(
       
    91         "CSVPHoldOutState::DoApply - No audio streams found!" );
       
    92         User::Leave( KErrSVPHoldStateError );
       
    93         }
       
    94         
       
    95     if ( aContext.ForceHoldOccured() )
       
    96         {
       
    97         nextState = KSVPHoldConnectedStateIndex;
       
    98         aContext.SetForceHold( EFalse ); 
       
    99         }
       
   100 
       
   101     aContext.SetCurrentStateL( aContext, nextState );
       
   102     SVPDEBUG1( "CSVPHoldOutState::DoApply - Handled" );    
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CSVPHoldOutState::PerformRequestL
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 TSVPHoldStateIndex 
       
   110 CSVPHoldOutState::PerformRequestL( CSVPHoldContext& aContext,
       
   111                                    CMceMediaStream& aMediaStream,
       
   112                                    CMceSession& aSession )
       
   113     {
       
   114     TSVPHoldStateIndex nextState = KSVPHoldEstablishingStateIndex;
       
   115     switch ( aContext.HoldRequest() )
       
   116         {
       
   117         case ESVPLocalResume:
       
   118             {
       
   119             ResumeSessionLocallyL( aContext, aMediaStream, aSession );
       
   120             break;
       
   121             }
       
   122 
       
   123         case ESVPRemoteDoubleHold:
       
   124             {
       
   125             RemoteSessionDoubleHoldL( aContext, aMediaStream, aSession );
       
   126             break;
       
   127             }                    
       
   128             
       
   129         case ESVPLocalHold:
       
   130         case ESVPLocalDoubleHold:
       
   131         case ESVPLocalDoubleHoldResume:
       
   132         case ESVPRemoteHold:
       
   133         case ESVPRemoteResume:
       
   134         case ESVPRemoteDoubleHoldResume:
       
   135             {
       
   136             // Cannot occur in Out state
       
   137             SVPDEBUG1( "CSVPHoldOutState::PerformRequestL - StateError" );
       
   138             User::Leave( KErrSVPHoldStateError );                    
       
   139             }
       
   140 
       
   141         default:
       
   142             {
       
   143             // No state change needed:
       
   144             nextState = KSVPHoldOutStateIndex;
       
   145             
       
   146             // Error in previous request solving
       
   147             SVPDEBUG2( "CSVPHoldOutState::PerformRequestL - Error, request %i",
       
   148                         aContext.HoldRequest() );
       
   149                         
       
   150             User::Leave( KErrSVPHoldStateError );
       
   151             }               
       
   152         }    
       
   153 
       
   154     return nextState;
       
   155     }
       
   156     
       
   157 // ---------------------------------------------------------------------------
       
   158 // CSVPHoldOutState::ResumeSessionLocallyL
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 void CSVPHoldOutState::ResumeSessionLocallyL( CSVPHoldContext& aContext,
       
   162                                               CMceMediaStream& aMediaStream,
       
   163                                               CMceSession& aSession )
       
   164     {
       
   165     SVPDEBUG1( "CSVPHoldOutState::ResumeSessionLocallyL - In" );
       
   166 
       
   167     // Handle media stream:
       
   168     aContext.MediaHandler().
       
   169         PerformMediaActionL( aMediaStream,
       
   170                              ESVPLocalResume );        		    
       
   171 
       
   172     aSession.UpdateL();
       
   173     SVPDEBUG1( "CSVPHoldOutState::ResumeSessionLocallyL - done" );    
       
   174     }
       
   175     
       
   176 // ---------------------------------------------------------------------------
       
   177 // CSVPHoldOutState::RemoteSessionDoubleHoldL
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 void CSVPHoldOutState::RemoteSessionDoubleHoldL( CSVPHoldContext& aContext,
       
   181                                                  CMceMediaStream& aMediaStream,
       
   182                                                  CMceSession& aSession )
       
   183     {
       
   184     SVPDEBUG1(
       
   185     "CSVPHoldOutState::RemoteSessionDoubleHoldL - In" );
       
   186     
       
   187     MDesC8Array* attributeLines = aMediaStream.MediaAttributeLinesL();
       
   188     CleanupDeletePushL( attributeLines );
       
   189     
       
   190     // Check that request has reasonable direction attribute:
       
   191     TSVPHoldRequestType attribute =
       
   192                   aContext.SolveRequestL( aSession,
       
   193                                           attributeLines );
       
   194 
       
   195     if ( ESVPNoType == attribute )
       
   196         {
       
   197         // Not hold request
       
   198         SVPDEBUG1( "CSVPHoldOutState::RemoteSessionDoubleHoldL:");
       
   199         SVPDEBUG1( "Not hold request" );
       
   200         
       
   201         User::Leave( KErrSVPHoldNotHoldRequest );
       
   202         }
       
   203     
       
   204     CleanupStack::PopAndDestroy( attributeLines );
       
   205     
       
   206     // Handle media stream:
       
   207     aContext.MediaHandler().
       
   208         PerformMediaActionL( aMediaStream,
       
   209                              ESVPRemoteDoubleHold );
       
   210     
       
   211     // Update session
       
   212     aSession.UpdateL();
       
   213     
       
   214     SVPDEBUG1( "CSVPHoldOutState::RemoteSessionDoubleHoldL - done" );    
       
   215     }
       
   216     
       
   217 // ---------------------------------------------------------------------------
       
   218 // CSVPHoldOutState::DoEnter
       
   219 // ---------------------------------------------------------------------------
       
   220 //
       
   221 void CSVPHoldOutState::DoEnter( CSVPHoldContext& aContext )
       
   222     {
       
   223     SVPDEBUG2( "CSVPHoldOutState::DoEnter - Request %i",
       
   224                 aContext.HoldRequest() );
       
   225     
       
   226     TInt err = KErrNone;
       
   227     TRAP( err, aContext.MediaHandler().DisableAudioL( aContext ) );
       
   228     
       
   229     // succesfull action is informed to client
       
   230     switch ( aContext.HoldRequest() )
       
   231         {
       
   232         case ESVPLocalHold:
       
   233             {
       
   234             SVPDEBUG1( 
       
   235             "CSVPHoldOutState::DoEnter - LocalHold" );
       
   236             if ( err )
       
   237                 {
       
   238                 aContext.HoldObserver().HoldRequestFailed();
       
   239                 }
       
   240                 
       
   241             else
       
   242                 {
       
   243                 aContext.HoldObserver().SessionLocallyHeld();
       
   244                 }
       
   245             
       
   246             break;
       
   247             }
       
   248             
       
   249         case ESVPRemoteDoubleHoldResume:
       
   250             {
       
   251             SVPDEBUG1(
       
   252             "CSVPHoldOutState::DoEnter - ESVPRemoteDoubleHoldResume" );
       
   253             if ( err )
       
   254                 {
       
   255                 //aContext.HoldObserver().ResumeRequestFailed();
       
   256                 }
       
   257                 
       
   258             else
       
   259                 {
       
   260                 aContext.HoldObserver().SessionRemoteResumed();
       
   261                 }
       
   262 
       
   263             break;            
       
   264             }
       
   265             
       
   266         default:
       
   267             {
       
   268             // Nothing to do; occurs only with state rollback
       
   269             SVPDEBUG1( "CSVPHoldOutState::DoEnter - Default" );
       
   270             break;
       
   271             }
       
   272         }
       
   273     }
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // CSVPHoldOutState::IsOutEstablishingStateActive
       
   277 // ---------------------------------------------------------------------------
       
   278 //
       
   279 TBool CSVPHoldOutState::IsOutEstablishingStateActive()
       
   280     {
       
   281     return EFalse;
       
   282     }
       
   283 
       
   284