sipproviderplugins/sipprovider/sipstatemachine/src/StateSessionEstablished.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // CStateSessionEstablished implementation file.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22  
       
    23 #include <e32std.h>
       
    24 #include <e32base.h>
       
    25 
       
    26 #include "StateSessionEstablished.h"
       
    27 
       
    28 CStateSessionEstablished * CStateSessionEstablished::NewL( CSipStateMachine * aStateMachine )
       
    29 /**
       
    30 Instantiaion static function
       
    31 */
       
    32 	{
       
    33 	return new(ELeave) CStateSessionEstablished (aStateMachine);
       
    34 	}
       
    35 
       
    36 CStateSessionEstablished::CStateSessionEstablished ( CSipStateMachine * aStateMachine ) :
       
    37 CSipStateBase (aStateMachine, TSipHLConsts::EStateSessionEstablished )
       
    38 /**
       
    39 Constuctor
       
    40 */
       
    41 	{
       
    42 	iDoneUnSubscribe = EFalse;
       
    43 	// Open Logs
       
    44 	__FLOG_OPEN(_L8("SipStateMachine"), _L8("StateSessionEstablished"));
       
    45 	__FLOG_1(_L("[StateSessionEstablished]:[%x]::CStateSessionEstablished() "), this);
       
    46 	}
       
    47 
       
    48 CStateSessionEstablished::~CStateSessionEstablished ()
       
    49 /**
       
    50 Destructor
       
    51 */	
       
    52 	{
       
    53 	// Close Logging
       
    54 	__FLOG_0(_L("[StateSessionEstablished]: CStateSessionEstablished::~CStateSessionEstablished()"));
       
    55 	__FLOG_CLOSE;
       
    56 	}
       
    57 	
       
    58 CSipStateBase * CStateSessionEstablished::ProcessClientL(TRequestStatus & aStatus)
       
    59 /**
       
    60 Function which process the request and responses from the client
       
    61 */
       
    62 	{
       
    63 	__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessClientL()"), this);
       
    64 	switch(iClientRequest)
       
    65 		{
       
    66 		case TSipHLConsts::ERequestUnRegister:
       
    67 			{
       
    68 			__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessClientL() <<REQUEST UNREGISTER>>"), this);
       
    69 			TRAPD(err,iSipSM->SendUnRegisterMessageL());
       
    70 			if(err != KErrNone)
       
    71 				{
       
    72 				iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
    73 				iSipSM->SetGeneralError(err);
       
    74 				iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
    75 				}
       
    76 			else
       
    77 				{
       
    78 				iSipSM->SetSuspendRequest(ETrue);
       
    79 				iNext = this;
       
    80 				}
       
    81 			iSipSM->GetTe()->SetTransaction(iSipSM,iSipSM->GetCommandContext().iClientTx);
       
    82 			}
       
    83 			break;
       
    84 		case TSipHLConsts::ERequestUnSubscribe:
       
    85 			{
       
    86 			__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessClientL() <<REQUEST UNSUBSCRIBE>>"), this);
       
    87 			TRAPD(err,iSipSM->SendUnSubscribeMessageL());
       
    88 			if(err != KErrNone)
       
    89 				{
       
    90 				iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
    91 				iSipSM->SetGeneralError(err);
       
    92 				iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
    93 				}
       
    94 			else
       
    95 				{
       
    96 				iSipSM->SetSuspendRequest(ETrue);
       
    97 				iNext = this;
       
    98 				}
       
    99 			iSipSM->GetTe()->SetTransaction(iSipSM,iSipSM->GetCommandContext().iClientTx);
       
   100 			}
       
   101 			break;
       
   102 		case TSipHLConsts::ERequestAck:
       
   103 			{
       
   104 			__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessClientL() <<REQUEST ACK>>"), this);
       
   105 			TRAPD(err,iSipSM->SendAckForInviteL());
       
   106 			if(err != KErrNone)
       
   107 				{
       
   108 				iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
   109 				iSipSM->SetGeneralError(err);
       
   110 				iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
   111 				}
       
   112 			else
       
   113 				{
       
   114 				iSipSM->SetSuspendRequest(ETrue);
       
   115 				iNext = this;
       
   116 				iSipSM->CallEstablishedCallback();	
       
   117 				}
       
   118 			}
       
   119 			break;
       
   120 		case TSipHLConsts::ERequestBye:
       
   121 			{
       
   122 			__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessClientL() <<REQUEST BYE>>"), this);
       
   123 			TRAPD(err,iSipSM->SendByeL());
       
   124 			if(err != KErrNone)
       
   125 				{
       
   126 				iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
   127 				iSipSM->SetGeneralError(err);
       
   128 				iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
   129 				}
       
   130 			else
       
   131 				{
       
   132 				iSipSM->GetTe()->SetTransaction(iSipSM,iSipSM->GetCommandContext().iClientTx);
       
   133 				iSipSM->SetSuspendRequest(ETrue);
       
   134 				iNext = this;					
       
   135 				}
       
   136 			}
       
   137 			break;
       
   138 		default:
       
   139 			{
       
   140 			__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessClientL() <<REQUEST DEFAULT>>"), this);
       
   141 			if(iReqIdentifier == 1)
       
   142 				{
       
   143 				iSipSM->SetSuspendRequest(ETrue);
       
   144 				iNext = this;
       
   145 				}
       
   146 			}
       
   147 		}
       
   148 	TRequestStatus * stat = &aStatus;		
       
   149 	User::RequestComplete (stat, KErrNone);
       
   150 #ifdef __FLOG_ACTIVE	
       
   151 	// This indormation is required only when logging is enabled
       
   152 	TSipHLConsts::SIP_STATES	iD = (iNext != NULL)?iNext->GetStateId() : TSipHLConsts::EStateNone;
       
   153 	if(iD == TSipHLConsts::EStateNone)
       
   154 		{
       
   155 		__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessClientL() <<Next State --> NULL>> "), this);
       
   156 		}
       
   157 	if(iD == TSipHLConsts::EStateSessionIdle)
       
   158 		{
       
   159 		__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessClientL() <<Next State --> StateIdle>> "), this);
       
   160 		}
       
   161 	else if(iD == TSipHLConsts::EStateSessionInitiation)
       
   162 		{
       
   163 		__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessClientL() <<Next State --> StateSessionInitiation>> "), this);
       
   164 		}
       
   165 	else if(iD == TSipHLConsts::EStateSessionEstablished)
       
   166 		{
       
   167 		__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessClientL() <<Next State --> StateSessionEstablished>> "), this);
       
   168 		}
       
   169 	else if(iD == TSipHLConsts::EStateSessionTerminated)
       
   170 		{
       
   171 		__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessClientL() <<Next State --> StateSessionTerminated>> "), this);	
       
   172 		}
       
   173 	else
       
   174 		{
       
   175 		__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessClientL() <<Next State --> Unknown, its a serious error>> "), this);		
       
   176 		}
       
   177 #endif	
       
   178 	return iNext;
       
   179 	}
       
   180 
       
   181 CSipStateBase * CStateSessionEstablished::ProcessServerL( TRequestStatus & aStatus )
       
   182 /**
       
   183 Function which process the request and responses from the Serevr
       
   184 */
       
   185 	{
       
   186 	__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessServerL()"), this);
       
   187 	TSipMsgBundle SipMsgBundle = iSipSM->GetSipMessageBundle();
       
   188 	switch(iServerResponse)
       
   189 		{
       
   190 		case TSipHLConsts::EResponseNone:
       
   191 			{
       
   192 			__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessServerL() <<RESPONSE NONE>>"), this);	
       
   193 			}
       
   194 			break;
       
   195 		case TSipHLConsts::EResponseUnRegister: // This means unregister over here
       
   196 			{
       
   197 			__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessServerL() <<RESPONSE UNREGISTER>>"), this);	
       
   198 			if(SipMsgBundle.iStatusCode != 200)
       
   199 				{
       
   200 				iSipSM->SetSIPError(SipMsgBundle.iStatusCode);
       
   201 				}
       
   202 			iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
   203 			iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
   204 			iNext->ResetRequestResponse();
       
   205 			}
       
   206 			break;
       
   207 		case TSipHLConsts::EResponseBye:
       
   208 			{
       
   209 			__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessServerL() <<RESPONSE BYE>>"), this);	
       
   210 			if(SipMsgBundle.iStatusCode != 200)
       
   211 				{
       
   212 				iSipSM->SetSIPError(SipMsgBundle.iStatusCode);
       
   213 				}
       
   214 			iSipSM->SetSuspendRequest(EFalse);
       
   215 			iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
   216 			iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
   217 			iNext->ResetRequestResponse();
       
   218 			}
       
   219 			break;
       
   220 		case TSipHLConsts::EResponseSubscribe:
       
   221 			{
       
   222 			__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessServerL() <<RESPONSE SUBSCRIBE>>"), this);	
       
   223 			if(SipMsgBundle.iStatusCode != 200)
       
   224 				{
       
   225 				iSipSM->SetSIPError(SipMsgBundle.iStatusCode);
       
   226 				}
       
   227 			// This is For unsubscribe if comes
       
   228 			// at this stage
       
   229 			// After being unsubscribed wait for a final notify
       
   230 			iDoneUnSubscribe = ETrue;
       
   231 			iSipSM->SetSuspendRequest(ETrue);
       
   232 			iNext = this;
       
   233 			iNext->ResetRequestResponse();		
       
   234 			}
       
   235 			break;
       
   236 		default:
       
   237 			{
       
   238 			__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessServerL() <<RESPONSE DEFAULT>>"), this);	
       
   239 			if(iReqIdentifier == 4)
       
   240 				{
       
   241 				iSipSM->SetSuspendRequest(ETrue);
       
   242 				iNext = this;				
       
   243 				}
       
   244 			}
       
   245 		}
       
   246 	switch (iServerRequest)
       
   247 		{
       
   248 		case TSipHLConsts::ERequestNone:
       
   249 			{
       
   250 			__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessServerL() <<REQUEST NONE>>"), this);	
       
   251 			}
       
   252 			break;	
       
   253 		case TSipHLConsts::ERequestBye:
       
   254 			{
       
   255 			__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessServerL() <<REQUEST BYE>>"), this);	
       
   256 			TRAPD(err,iSipSM->SendByeResponseL());
       
   257 			if(err != KErrNone)
       
   258 				{
       
   259 				iSipSM->SetGeneralError(err);
       
   260 				}
       
   261 			iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
   262 			iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
   263 			iNext->ResetRequestResponse();
       
   264 			}
       
   265 			break;
       
   266 		case TSipHLConsts::ERequestAck:
       
   267 			{
       
   268 			__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessServerL() <<REQUEST ACK>>"), this);	
       
   269 			iSipSM->CallEstablishedCallback();
       
   270 			}
       
   271 			break;
       
   272 		case TSipHLConsts::ERequestNotify:
       
   273 			{
       
   274 			__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessServerL() <<REQUEST NOTIFY>>"), this);	
       
   275 			HBufC8 * notificationData = iSipSM->GenerateNotificationData();
       
   276 			TRAPD(err,iSipSM->GenerateSubscribeResponseL(iSipSM->GetCommandContext().iServerTx, TSipHLConsts::EResponse200OK));
       
   277 			if(err != KErrNone)
       
   278 				{
       
   279 				iSipSM->SetGeneralError(err);
       
   280 				iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
   281 				iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
   282 				}
       
   283 			else
       
   284 				{
       
   285 				if (iDoneUnSubscribe)
       
   286 					{
       
   287 					iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
   288 					iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
   289 					iNext->ResetRequestResponse();
       
   290 					}
       
   291 				else
       
   292 					{
       
   293 					iSipSM->SetSuspendRequest(ETrue);
       
   294 					iNext = this;
       
   295 					iNext->ResetRequestResponse();		
       
   296 					}
       
   297 				}
       
   298 			// we will not call notification to the client as RSubConnection::Stop() will terminate the 
       
   299 			// client and we dont have anything to call the event upon
       
   300 			// This is against the SIP functionality over here, But this is done in view of the current limitations
       
   301 			// of the rsubconnection APIs, In future this needs to be changes with evolving APIs.
       
   302 			if(!iDoneUnSubscribe)
       
   303 				{
       
   304 				iSipSM->CallNotificationCallback(*notificationData);				
       
   305 				}
       
   306 			// delete Notification Data as not required
       
   307 			delete notificationData;
       
   308 			notificationData = NULL;
       
   309 			}
       
   310 			break;
       
   311 		default:
       
   312 			{
       
   313 			__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessServerL() <<REQUEST DEFAULT>>"), this);	
       
   314 			if(iReqIdentifier == 2)
       
   315 				{
       
   316 				iSipSM->SetSuspendRequest(ETrue);
       
   317 				iNext = this;					
       
   318 				}
       
   319 			}
       
   320 		}
       
   321 	TRequestStatus * stat = &aStatus;
       
   322 	User::RequestComplete(stat, KErrNone);
       
   323 #ifdef __FLOG_ACTIVE	
       
   324 	// This indormation is required only when logging is enabled
       
   325 	TSipHLConsts::SIP_STATES	iD = (iNext != NULL)?iNext->GetStateId() : TSipHLConsts::EStateNone;
       
   326 	if(iD == KErrNotFound)
       
   327 		{
       
   328 		__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessServerL() <<Next State --> NULL>> "), this);
       
   329 		}
       
   330 	if(iD == TSipHLConsts::EStateSessionIdle)
       
   331 		{
       
   332 		__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessServerL() <<Next State --> StateIdle>> "), this);
       
   333 		}
       
   334 	else if(iD == TSipHLConsts::EStateSessionInitiation)
       
   335 		{
       
   336 		__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessServerL() <<Next State --> StateSessionInitiation>> "), this);
       
   337 		}
       
   338 	else if(iD == TSipHLConsts::EStateSessionEstablished)
       
   339 		{
       
   340 		__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessServerL() <<Next State --> StateSessionEstablished>> "), this);
       
   341 		}
       
   342 	else if(iD == TSipHLConsts::EStateSessionTerminated)
       
   343 		{
       
   344 		__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessServerL() <<Next State --> StateSessionTerminated>> "), this);	
       
   345 		}
       
   346 	else
       
   347 		{
       
   348 		__FLOG_1(_L("[StateSessionEstablished]:CStateSessionEstablished[%x]::ProcessServerL() <<Next State --> Unknown, its a serious error>> "), this);		
       
   349 		}
       
   350 #endif	
       
   351 	return iNext;	
       
   352 	}
       
   353 
       
   354 CSipStateBase * CStateSessionEstablished::ProcessServerErrorL(TRequestStatus & aStatus)
       
   355 /**
       
   356 Handles the Error condition for this state from the server
       
   357 */
       
   358 	{
       
   359 	__FLOG_1(_L("[StateSessionEstablished]:StateSessionEstablished[%x]::ProcessServerErrorL()"), this);	
       
   360 	TSipMsgBundle SipMsgBundle = iSipSM->GetSipMessageBundle();
       
   361 	// Call the call back to Notify the client
       
   362 	iSipSM->SetGeneralError(SipMsgBundle.iErrCode);
       
   363 	iSipSM->SetSIPError(SipMsgBundle.iStatusCode);
       
   364 	iSipSM->CallTerminateCallback();
       
   365 	iSipSM->SetCallTerminateCallBack(EFalse);
       
   366 	// Get to The terminated state
       
   367 	iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
   368 	iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
   369 	if(iNext)
       
   370 	{
       
   371 	    iNext->ResetRequestResponse();
       
   372 	}
       
   373 	TRequestStatus * stat = &aStatus;
       
   374 	User::RequestComplete(stat, KErrNone);
       
   375 #ifdef __FLOG_ACTIVE	
       
   376 	// This indormation is required only when logging is enabled
       
   377 	TSipHLConsts::SIP_STATES	iD = (iNext != NULL)?iNext->GetStateId() : TSipHLConsts::EStateNone;
       
   378 	if(iD == KErrNotFound)
       
   379 		{
       
   380 		__FLOG_1(_L("[StateSessionEstablished]:StateSessionEstablished[%x]::ProcessServerErrorL() <<Next State --> NULL>> "), this);
       
   381 		}
       
   382 	if(iD == TSipHLConsts::EStateSessionIdle)
       
   383 		{
       
   384 		__FLOG_1(_L("[StateSessionEstablished]:StateSessionEstablished[%x]::ProcessServerErrorL() <<Next State --> StateIdle>> "), this);
       
   385 		}
       
   386 	else if(iD == TSipHLConsts::EStateSessionInitiation)
       
   387 		{
       
   388 		__FLOG_1(_L("[StateSessionEstablished]:StateSessionEstablished[%x]::ProcessServerErrorL() <<Next State --> StateSessionInitiation>> "), this);
       
   389 		}
       
   390 	else if(iD == TSipHLConsts::EStateSessionEstablished)
       
   391 		{
       
   392 		__FLOG_1(_L("[StateSessionEstablished]:StateSessionEstablished[%x]::ProcessServerErrorL() <<Next State --> StateSessionEstablished>> "), this);
       
   393 		}
       
   394 	else if(iD == TSipHLConsts::EStateSessionTerminated)
       
   395 		{
       
   396 		__FLOG_1(_L("[StateSessionEstablished]:StateSessionEstablished[%x]::ProcessServerErrorL() <<Next State --> StateSessionTerminated>> "), this);	
       
   397 		}
       
   398 	else
       
   399 		{
       
   400 		__FLOG_1(_L("[StateSessionEstablished]:StateSessionEstablished[%x]::ProcessServerErrorL() <<Next State --> Unknown, its a serious error>> "), this);		
       
   401 		}
       
   402 #endif	
       
   403 	return iNext;
       
   404 	}
       
   405 
       
   406