multimediacommsengine/mmcesrv/mmceevent/src/mceeventrefermtestablishingstate.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:    MT refer is received and waiting for action from client.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <sipsubscriptionstateheader.h>
       
    23 #include <sipnotifydialogassoc.h>
       
    24 #include <sipresponseelements.h>
       
    25 #include "mceeventrefermtestablishingstate.h"
       
    26 #include "mcesipeventhelper.h"
       
    27 #include "mcesip.h"
       
    28 #include "mceeventslogs.h"
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CMceEventReferMtEstablishingState::CMceEventReferMtEstablishingState
       
    34 // C++ default constructor can NOT contain any code, that
       
    35 // might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CMceEventReferMtEstablishingState::CMceEventReferMtEstablishingState()
       
    39     {
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CMceEventReferMtEstablishingState::~CMceEventReferMtEstablishingState
       
    44 // Destructor
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CMceEventReferMtEstablishingState::~CMceEventReferMtEstablishingState()
       
    48     {
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CMceEventReferMtEstablishingState::ProcessReferStateL
       
    53 // Ápply concrete state.
       
    54 // Be noticed that it will be also update, unRefer
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 void CMceEventReferMtEstablishingState::HandleL( 
       
    58 												CMceComEvent& aEvent )
       
    59     {
       
    60     MCEEVENTS_DEBUG("CMceEventReferMtEstablishingState::HandleL, Entry");
       
    61     //Check after the receiving Refer, client want to accept/Reject the event
       
    62     User::LeaveIfError( aEvent.SIPEvent().Dialog() ?
       
    63         KErrNone : KMceEventStateError );
       
    64         
       
    65     User::LeaveIfError( aEvent.SIPEvent().Dialog()->Type() 
       
    66         == SIPStrings::StringF( SipStrConsts::ENotify ) ?
       
    67        KErrNone : KMceEventStateError );
       
    68         
       
    69     CSIPServerTransaction& serverTran = aEvent.SIPEvent().Request();    
       
    70     CSIPServerTransaction* serverTranCheck = &serverTran;    
       
    71     User::LeaveIfError( serverTranCheck ? KErrNone : KMceEventStateError );
       
    72     
       
    73     const CSIPRequestElements* request = serverTran.RequestElements();
       
    74     User::LeaveIfError( request ? KErrNone : KErrCorrupt );
       
    75      
       
    76     CSIPResponseElements* response =NULL;	
       
    77 
       
    78     switch ( aEvent.PreviousAction() )
       
    79         {
       
    80         case EMceItcAcceptEvent:
       
    81             {
       
    82             //return 202
       
    83             RStringF phrase = 
       
    84         	    SIPStrings::Pool().OpenFStringL( KMceSipPhraseAccepted );
       
    85         	CleanupClosePushL( phrase );
       
    86             response = MCESIPEventHelper::CreateResponseL( 
       
    87                                                     aEvent,
       
    88                                                     KMceSipAccepted,
       
    89                                                     phrase );
       
    90     	    CleanupStack::PopAndDestroy(); // phrase	
       
    91     	    break;
       
    92             }
       
    93         case EMceItcRejectEvent:
       
    94             {
       
    95             //RejectEvent
       
    96             response = MCESIPEventHelper::CreateResponseL( aEvent,
       
    97                                                            KMceSipDecline );
       
    98             aEvent.EventContext().SetCurrentStateL( 
       
    99                                             aEvent, 
       
   100                                             KMceTerminatedEventStateIndex );
       
   101         	break;
       
   102             }
       
   103         case EMceItcRespondEvent:
       
   104             {
       
   105             //Respond event 
       
   106         	RStringF phrase = 
       
   107         	    SIPStrings::Pool().OpenFStringL( aEvent.ReasonPhrase() );
       
   108         	CleanupClosePushL( phrase );
       
   109         	response = MCESIPEventHelper::CreateResponseL( 
       
   110                                                     aEvent,
       
   111                                                     aEvent.StatusCode(),
       
   112                                                     phrase,
       
   113                                                     ETrue /* aAddClientData */);
       
   114             CleanupStack::PopAndDestroy(); // phrase                                                    
       
   115         	break;
       
   116             }
       
   117         default:
       
   118             {
       
   119             User::Leave( KMceEventStateError );
       
   120             break;
       
   121             }
       
   122         }
       
   123     
       
   124     CleanupStack::PushL( response );
       
   125     
       
   126     serverTran.SendResponseL( response );
       
   127    	CleanupStack::Pop( response );
       
   128 	
       
   129 	//then send Notify
       
   130 	TUint statusCode = response->StatusCode();
       
   131    	
       
   132 	if ( statusCode == KMceSipAccepted || statusCode == aEvent.StatusCode() )
       
   133 		{
       
   134 		if(response->StatusCode() >= KMceSipOK)
       
   135 			{
       
   136 	        if ( statusCode < KMceSipMultipleChoices 
       
   137 	          && aEvent.ReferType() == CMceRefer::ENoSuppression )
       
   138 				{
       
   139 				CSIPSubscriptionStateHeader& subStateHeader = 
       
   140 				( static_cast< CSIPNotifyDialogAssoc* >
       
   141 				( aEvent.SIPEvent().Dialog() ) )->SubscriptionState();
       
   142 				
       
   143 	        	subStateHeader.SetSubStateValueL( KStateActive );
       
   144 	        	subStateHeader.SetExpiresParameterL( aEvent.RefreshInterval() );
       
   145 	        	CSIPMessageElements* msgElem = 
       
   146 	        	    MCESIPEventHelper::CreateReferNotifyMessageElementsLC( aEvent );
       
   147 	        	                    
       
   148 				CSIPClientTransaction* transaction = 
       
   149 					( static_cast< CSIPNotifyDialogAssoc* >
       
   150 					( aEvent.SIPEvent().Dialog() ) )->SendNotifyL( msgElem );
       
   151 					
       
   152 				CleanupStack::Pop( msgElem );
       
   153 				CleanupStack::PushL( transaction );
       
   154 				aEvent.SIPEvent().SetPendingTransactionL( transaction );
       
   155 				CleanupStack::Pop( transaction );
       
   156 				aEvent.EventContext().SetCurrentStateL( 
       
   157 		                                    aEvent, 
       
   158 		                                    KMceEstablishedEventStateIndex );
       
   159 				}
       
   160 			else
       
   161 				{
       
   162 				// Terminated, if received error response or the 
       
   163 				// REFER is supppressed.
       
   164 				aEvent.EventContext().SetCurrentStateL( 
       
   165 		                                    aEvent, 
       
   166 		                                    KMceTerminatedEventStateIndex );
       
   167 				}
       
   168 			}
       
   169 		}
       
   170 	MCEEVENTS_DEBUG("CMceEventReferMtEstablishingState::HandleL, Exit");		
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CMceEventReferMtEstablishingState::HandleReceiveRequestL
       
   175 // Ápply concrete state.
       
   176 // Be noticed that it will be also update, unRefer
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 void CMceEventReferMtEstablishingState::HandleReceiveRequestL( 
       
   180 												CMceComEvent& /*aEvent*/ )
       
   181 	{
       
   182 	}
       
   183 	
       
   184 // -----------------------------------------------------------------------------
       
   185 // CMceEventReferMtEstablishingState::HandleResponseReceivedL
       
   186 // Ápply concrete state.
       
   187 // Be noticed that it will be also update, unRefer
       
   188 // -----------------------------------------------------------------------------
       
   189 //	
       
   190 void CMceEventReferMtEstablishingState::HandleResponseReceivedL(
       
   191 													CMceComEvent& aEvent )
       
   192 	{
       
   193 	MCEEVENTS_DEBUG("CMceEventReferMtEstablishingState::HandleResponseReceivedL, Entry");
       
   194     User::LeaveIfError( aEvent.PreviousAction() == EMceItcNotify ?
       
   195         KErrNone : KMceEventStateError );
       
   196     
       
   197     User::LeaveIfError( &aEvent.SIPEvent().Response() ?
       
   198         KErrNone : KMceEventStateError );
       
   199         
       
   200     User::LeaveIfError( aEvent.SIPEvent().Response().Type()==
       
   201 	    SIPStrings::StringF(SipStrConsts::ENotify) ?
       
   202 	    KErrNone : KMceEventStateError );
       
   203 	
       
   204     aEvent.SetPreviousAction( KErrNotFound ); 
       
   205     
       
   206     const CSIPResponseElements* response = 
       
   207         aEvent.SIPEvent().Response().ResponseElements();
       
   208     User::LeaveIfError( response ? KErrNone : KErrCorrupt );
       
   209 
       
   210     TUint statusCode = response->StatusCode();
       
   211     if ( statusCode >= KMceSipOK )
       
   212 		{
       
   213 		CMceRefer::TState nextClientState = CMceRefer::EPending;
       
   214 		TMceEventStateIndex nextState = KErrNotFound;
       
   215         if ( statusCode < KMceSipMultipleChoices )
       
   216             {
       
   217             nextClientState = CMceRefer::EAccepted;
       
   218             nextState = KMceEstablishedEventStateIndex;
       
   219             }
       
   220         else 
       
   221             {
       
   222             nextClientState = CMceRefer::ETerminated;
       
   223             nextState = KMceTerminatedEventStateIndex;
       
   224             }
       
   225         aEvent.SIPEvent().ClientStateChangedL( nextClientState, ETrue );
       
   226         aEvent.EventContext().SetCurrentStateL( aEvent, nextState );
       
   227         }
       
   228 	MCEEVENTS_DEBUG("CMceEventReferMtEstablishingState::HandleResponseReceivedL, Exit");        
       
   229     }
       
   230 
       
   231 //  End of File