multimediacommsengine/mmcesrv/mmceevent/src/mceeventsubscribemtestablishedstate.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 event is established.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <sipsubscriptionstateheader.h>
       
    24 #include <sipnotifydialogassoc.h>
       
    25 #include <sipdialog.h>
       
    26 #include "mcesipeventhelper.h"
       
    27 #include "mceeventsubscribemtestablishedstate.h"
       
    28 #include "mcesip.h"
       
    29 #include "mceeventslogs.h"
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CMceEventSubscribeMtEstablishedState::CMceEventSubscribeMtEstablishedState
       
    35 // C++ default constructor can NOT contain any code, that
       
    36 // might leave.
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CMceEventSubscribeMtEstablishedState::CMceEventSubscribeMtEstablishedState()
       
    40     {
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CMceEventSubscribeMtEstablishedState::~CMceEventSubscribeMtEstablishedState
       
    45 // Destructor
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CMceEventSubscribeMtEstablishedState::~CMceEventSubscribeMtEstablishedState()
       
    49     {
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CMceEventSubscribeMtEstablishedState::ProcessSubscribeStateL
       
    54 // Ápply concrete state.
       
    55 // Be noticed that it will be also update, unsubscribe
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 void CMceEventSubscribeMtEstablishedState::HandleL(CMceComEvent& aEvent )
       
    59     {
       
    60     MCEEVENTS_DEBUG("CMceEventSubscribeMtEstablishedState::HandleL, Entry");
       
    61     User::LeaveIfError( aEvent.SIPEvent().Dialog() ?
       
    62         KErrNone : KMceEventStateError );
       
    63         
       
    64     User::LeaveIfError( aEvent.SIPEvent().Dialog()->Type() == 
       
    65         SIPStrings::StringF( SipStrConsts::ENotify ) ?
       
    66         KErrNone : KMceEventStateError );
       
    67     
       
    68     // Set subscription state and parameters
       
    69     TInt nextState = KErrNotFound;		    
       
    70     CSIPSubscriptionStateHeader& subStateHeader = 
       
    71 		( static_cast< CSIPNotifyDialogAssoc* >
       
    72 		( aEvent.SIPEvent().Dialog() ) )->SubscriptionState();
       
    73 
       
    74     switch ( aEvent.PreviousAction() )
       
    75         {
       
    76         case EMceItcNotify:
       
    77             {
       
    78             subStateHeader.SetSubStateValueL( KStateActive );
       
    79             subStateHeader.SetExpiresParameterL( aEvent.RefreshInterval() );
       
    80             nextState = KMceEstablishingEventStateIndex;
       
    81 		    break;
       
    82             }
       
    83         case EMceItcTerminateEvent:
       
    84             {
       
    85             subStateHeader.SetSubStateValueL( KStateTerminated );
       
    86             RStringF expires = SIPStrings::StringF( SipStrConsts::EExpires );
       
    87             subStateHeader.DeleteParam( expires );
       
    88             nextState = KMceTerminatingEventStateIndex;
       
    89             break;
       
    90             }
       
    91         default:
       
    92             {
       
    93             // Other actions not supported
       
    94             User::Leave( KMceEventStateError );
       
    95             break;
       
    96             }
       
    97         }
       
    98     
       
    99     CSIPMessageElements* message = 
       
   100 	    MCESIPEventHelper::CreateMessageElementsLC( aEvent,
       
   101 	                                                SipStrConsts::ENotify );
       
   102     CSIPClientTransaction* transaction = 
       
   103 	    ( static_cast< CSIPNotifyDialogAssoc* >
       
   104 	    ( aEvent.SIPEvent().Dialog() ) )->SendNotifyL( message );
       
   105 	
       
   106 	CleanupStack::Pop( message );
       
   107 	CleanupStack::PushL( transaction );
       
   108     aEvent.SIPEvent().SetPendingTransactionL( transaction );
       
   109 	CleanupStack::Pop( transaction );
       
   110 	
       
   111 	aEvent.EventContext().SetCurrentStateL( aEvent, nextState );
       
   112 	MCEEVENTS_DEBUG("CMceEventSubscribeMtEstablishedState::HandleL, Exit");
       
   113 	}
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CMceEventSubscribeMtEstablishedState::HandleReceiveRequestL
       
   117 // Ápply concrete state.
       
   118 // Be noticed that it will be also update, unsubscribe
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 void CMceEventSubscribeMtEstablishedState::HandleReceiveRequestL(
       
   122 													CMceComEvent& aEvent )
       
   123 	{
       
   124 	MCEEVENTS_DEBUG("CMceEventSubscribeMtEstablishedState::HandleReceiveRequestL, Entry");
       
   125 	User::LeaveIfError( aEvent.SIPEvent().Dialog() ?
       
   126 	    KErrNone : KMceEventStateError );
       
   127         
       
   128 	User::LeaveIfError( aEvent.SIPEvent().Dialog()->Type() 
       
   129         == SIPStrings::StringF( SipStrConsts::ENotify ) ?
       
   130         KErrNone : KMceEventStateError );
       
   131     
       
   132     CSIPServerTransaction& serverTA = aEvent.SIPEvent().Request();
       
   133     CSIPServerTransaction* serverTACheck = &serverTA;
       
   134 	User::LeaveIfError( serverTACheck ? KErrNone : KMceEventStateError );
       
   135 	
       
   136 	//Received Subscribe from Mo there is noaction in the previous action
       
   137 	User::LeaveIfError( aEvent.PreviousAction() == KErrNotFound ?
       
   138 	    KErrNone : KMceEventStateError );
       
   139 	
       
   140     User::LeaveIfError( CSIPDialog::EConfirmed == 
       
   141         aEvent.SIPEvent().Dialog()->Dialog().State() ?
       
   142         KErrNone : KMceEventStateError );
       
   143     
       
   144     User::LeaveIfError( serverTA.RequestElements() ? KErrNone : KErrCorrupt );
       
   145 	
       
   146 	const CSIPMessageElements& subscribeMsg = 
       
   147 	    serverTA.RequestElements()->MessageElements();
       
   148 	//receiveing MO Subscribe Update or Mo Subscribe Terminate
       
   149 	//Check the expire header so knows which state should go
       
   150 	//Observer inform the incomingsubscribe and send response and notify
       
   151 		    
       
   152     TBool terminated = EFalse;
       
   153     CSIPResponseElements* response = 
       
   154         MCESIPEventHelper::SubscribeRequestReceivedLC( aEvent, subscribeMsg );
       
   155     if ( response->StatusCode() == KMceSipOK )
       
   156 		{
       
   157 
       
   158 		MCESIPEventHelper::HandleExpireHeaderL( subscribeMsg, terminated );
       
   159    
       
   160         aEvent.SIPEvent().Request().SendResponseL( response );
       
   161         
       
   162         CleanupStack::Pop( response );
       
   163         // Send notify
       
   164         TInt nextState = KErrNotFound;
       
   165         
       
   166 		CSIPNotifyDialogAssoc* dialogAssoc = 
       
   167     		static_cast <CSIPNotifyDialogAssoc* >
       
   168     		( aEvent.SIPEvent().Dialog() ); 
       
   169     
       
   170         CSIPSubscriptionStateHeader& subscrState = 
       
   171             dialogAssoc->SubscriptionState();
       
   172 		
       
   173 		if ( terminated )
       
   174             {
       
   175             subscrState.SetSubStateValueL( KStateTerminated );
       
   176 			RStringF expires = SIPStrings::StringF( SipStrConsts::EExpires );
       
   177             subscrState.DeleteParam( expires );
       
   178             nextState = KMceTerminatingEventStateIndex;
       
   179             }
       
   180 		else
       
   181             {
       
   182             //when subscription state is active
       
   183             subscrState.SetSubStateValueL( KStateActive );
       
   184 			subscrState.SetExpiresParameterL( aEvent.RefreshInterval() );
       
   185 			nextState = KMceEstablishedEventStateIndex;
       
   186             }
       
   187         
       
   188         CSIPMessageElements* notifyMsg = 
       
   189             MCESIPEventHelper::CreateMessageElementsLC( 
       
   190                                                 aEvent,
       
   191                                                 SipStrConsts::ENotify );
       
   192 		CSIPClientTransaction* tx = dialogAssoc->SendNotifyL( notifyMsg );
       
   193 		CleanupStack::Pop( notifyMsg );
       
   194 		CleanupStack::PushL( tx );
       
   195 		
       
   196 	    aEvent.SIPEvent().SetPendingTransactionL( tx );
       
   197 		CleanupStack::Pop( tx );	
       
   198 		
       
   199 	    aEvent.EventContext().SetCurrentStateL( aEvent, nextState );
       
   200         }
       
   201 	else
       
   202 	  	{
       
   203 	    aEvent.SIPEvent().Request().SendResponseL( response );
       
   204 	    CleanupStack::Pop( response );
       
   205 	    }
       
   206 
       
   207 	MCEEVENTS_DEBUG("CMceEventSubscribeMtEstablishedState::HandleReceiveRequestL, Exit");
       
   208 	}
       
   209 	
       
   210 // -----------------------------------------------------------------------------
       
   211 // CMceEventSubscribeMtEstablishedState::HandleResponseReceivedL
       
   212 // Ápply concrete state.
       
   213 // Be noticed that it will be also update, unsubscribe
       
   214 // -----------------------------------------------------------------------------
       
   215 //	
       
   216 void CMceEventSubscribeMtEstablishedState::HandleResponseReceivedL( 
       
   217 												CMceComEvent& aEvent )
       
   218 	{
       
   219 	MCEEVENTS_DEBUG("CMceEventSubscribeMtEstablishedState::HandleResponseReceivedL, Entry");
       
   220 	//MT
       
   221 	//Getting subscribe->sendResponse->Send Notify and now getting response
       
   222 	//Checking if getting the error after sending the Subscribe
       
   223 	User::LeaveIfError( &aEvent.SIPEvent().Response() ?
       
   224 	    KErrNone : KMceEventStateError );
       
   225 	    
       
   226 	User::LeaveIfError( aEvent.SIPEvent().Response().Type()==
       
   227 	    SIPStrings::StringF( SipStrConsts::ENotify ) ?
       
   228 	    KErrNone : KMceEventStateError );
       
   229 	
       
   230     //Get response from sending subscribe in Established state
       
   231     aEvent.SetPreviousAction( KErrNotFound ); 
       
   232     const CSIPResponseElements& response = 
       
   233     			*aEvent.SIPEvent().Response().ResponseElements();
       
   234     const CSIPResponseElements* responseCheck = &response;
       
   235     User::LeaveIfError( responseCheck ? KErrNone : KErrCorrupt );
       
   236 
       
   237     //Notify the subsession the response received
       
   238     //From the MtIdle 
       
   239     //Getting subscribe->sendResponse->Send Notify and now getting response
       
   240     TUint statusCode = response.StatusCode();
       
   241     if (statusCode >= KMceSipOK)
       
   242 		{
       
   243 		CMceEvent::TState nextClientState = CMceEvent::EPending;
       
   244 		TMceEventStateIndex nextState = KErrNotFound;
       
   245         
       
   246         if (statusCode < KMceSipMultipleChoices )
       
   247             {
       
   248             nextClientState = CMceEvent::EActive;
       
   249             nextState = KMceEstablishedEventStateIndex;
       
   250             }
       
   251         else 
       
   252             {
       
   253             nextClientState = CMceEvent::ETerminated;
       
   254             nextState = KMceTerminatedEventStateIndex;
       
   255             }
       
   256         aEvent.SIPEvent().ClientStateChangedL( nextClientState, ETrue );
       
   257         aEvent.EventContext().SetCurrentStateL( aEvent, nextState );
       
   258         }
       
   259     
       
   260 	MCEEVENTS_DEBUG("CMceEventSubscribeMtEstablishedState::HandleResponseReceivedL, Exit");
       
   261 	}
       
   262 
       
   263 //  End of File