sipproviderplugins/sipprovider/sipstatemachine/src/StateIdle.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 // CStateIdle implementation file.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22  
       
    23 #include <e32std.h>
       
    24 #include <e32base.h>
       
    25 
       
    26 #include "StateIdle.h"
       
    27 
       
    28 CStateIdle * CStateIdle::NewL( CSipStateMachine * aStateMachine )
       
    29 /**
       
    30 Instantiaion static function
       
    31 */
       
    32 	{
       
    33 	return new(ELeave) CStateIdle (aStateMachine);
       
    34 	}
       
    35 
       
    36 CStateIdle::CStateIdle ( CSipStateMachine * aStateMachine ) :
       
    37 CSipStateBase ( aStateMachine, TSipHLConsts::EStateSessionIdle )
       
    38 /**
       
    39 Constuctor
       
    40 */
       
    41 	{
       
    42 	// Open Logs
       
    43 	__FLOG_OPEN(_L8("SipStateMachine"), _L8("StateIdle"));
       
    44 	__FLOG_1(_L("[StateIdle]:[%x]::CStateIdle() "), this);
       
    45 	}
       
    46 CStateIdle::~CStateIdle ()
       
    47 /**
       
    48 Destructor
       
    49 */	
       
    50 	{
       
    51 	// Close Logging
       
    52 	__FLOG_0(_L("[StateIdle]: CStateIdle::~CStateIdle()"));
       
    53 	__FLOG_CLOSE;
       
    54 	}
       
    55 
       
    56 CSipStateBase * CStateIdle::ProcessClientL( TRequestStatus & aStatus )
       
    57 /**
       
    58 Function which process the request and responses from the client
       
    59 */
       
    60 	{
       
    61 	__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessClientL()"), this);
       
    62 	// Handle Requests from Client
       
    63 	switch (iClientRequest)
       
    64 		{
       
    65 		case TSipHLConsts::ERequestNone:
       
    66 			{
       
    67 			__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessClientL()   <<REQUEST NONE>> "), this);
       
    68 			iSipSM->SetSuspendRequest(ETrue);
       
    69 			iNext = this;		
       
    70 			break;
       
    71 			}
       
    72 		case TSipHLConsts::ERequestRegister:
       
    73 			{
       
    74 			__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessClientL()   <<REQUEST REGISTER>> "), this);
       
    75 			TRAPD(err,iSipSM->SendRegisterMessageL());
       
    76 			if(err != KErrNone)
       
    77 				{
       
    78 				iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
    79 				iSipSM->SetGeneralError(err);
       
    80 				iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
    81 				}
       
    82 			else
       
    83 				{
       
    84 				iSipSM->SetSuspendRequest(ETrue);
       
    85 				iNext = this;	
       
    86 				}
       
    87 			// Store this because this is required also in the case of failure
       
    88 			iSipSM->GetTe()->SetTransaction(iSipSM,iSipSM->GetCommandContext().iClientTx);
       
    89 			break;
       
    90 			}
       
    91 		case TSipHLConsts::ERequestInvite:
       
    92 			{
       
    93 			__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessClientL()   <<REQUEST INVITE>> "), this);
       
    94 			TRAPD(err,iSipSM->SendInviteMessageL());
       
    95 			if(err != KErrNone)
       
    96 				{
       
    97 				iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
    98 				iSipSM->SetGeneralError(err);
       
    99 				iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
   100 				}
       
   101 			else
       
   102 				{
       
   103 				iSipSM->SetSuspendRequest(ETrue);
       
   104 				iNext = this;	
       
   105 				}
       
   106 			iSipSM->GetTe()->SetTransaction(iSipSM,iSipSM->GetCommandContext().iClientTx);
       
   107 			iSipSM->GetTe()->SetDialogAssoc(iSipSM,iSipSM->GetCommandContext().iDialogAssoc);
       
   108 			break;				
       
   109 			}
       
   110 		case TSipHLConsts::ERequestBye:
       
   111 		case TSipHLConsts::ERequestCancel:
       
   112 			{
       
   113 			__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessClientL()   <<REQUEST BYE / REQUEST CANCEL>> "), this);
       
   114 			TRAPD(err,iSipSM->SendCancelL());
       
   115 			if(err != KErrNone)
       
   116 				{
       
   117 				iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
   118 				// Just set the error , as transition to terminated state is automatically happening
       
   119 				iSipSM->SetGeneralError(err);
       
   120 				}
       
   121 			else
       
   122 				{
       
   123 				iSipSM->SetSuspendRequest(ETrue);	
       
   124 				}
       
   125 			// Change to session terminated as its not sure that we will get 
       
   126 			// and Response to the cancel while in trying state
       
   127 			iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
   128 			iNext->ResetRequestResponse();
       
   129 			}
       
   130 			break;
       
   131 		case TSipHLConsts::ERequestSubscribe:
       
   132 			{
       
   133 			__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessClientL()   <<REQUEST SUBSCRIBE>> "), this);
       
   134 			TRAPD(err,iSipSM->SendSubscribeMessageL());
       
   135 			if(err != KErrNone)
       
   136 				{
       
   137 				iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
   138 				iSipSM->SetGeneralError(err);
       
   139 				iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
   140 				}
       
   141 			else
       
   142 				{
       
   143 				iSipSM->SetSuspendRequest(ETrue);
       
   144 				iNext = this;	
       
   145 				}
       
   146 			iSipSM->GetTe()->SetTransaction(iSipSM,iSipSM->GetCommandContext().iClientTx);
       
   147 			iSipSM->GetTe()->SetDialogAssoc(iSipSM,iSipSM->GetCommandContext().iSubsDialogAssoc);
       
   148 			}
       
   149 			break;
       
   150 		default:
       
   151 			{
       
   152 			__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessClientL()   <<REQUEST DEFAULT>> "), this);
       
   153 			if(iReqIdentifier == 1)
       
   154 				{
       
   155 				iSipSM->SetSuspendRequest(ETrue);
       
   156 				iNext = this;
       
   157 				}
       
   158 			}
       
   159 		}
       
   160 	TRequestStatus * stat = &aStatus;		
       
   161 	User::RequestComplete(stat,KErrNone);
       
   162 #ifdef __FLOG_ACTIVE	
       
   163 	// This indormation is required only when logging is enabled
       
   164 	TSipHLConsts::SIP_STATES	iD = (iNext != NULL)?iNext->GetStateId() : TSipHLConsts::EStateNone;
       
   165 	if(iD == KErrNotFound)
       
   166 		{
       
   167 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessClientL() <<Next State --> NULL>> "), this);
       
   168 		}
       
   169 	if(iD == TSipHLConsts::EStateSessionIdle)
       
   170 		{
       
   171 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessClientL() <<Next State --> StateIdle>> "), this);
       
   172 		}
       
   173 	else if(iD == TSipHLConsts::EStateSessionInitiation)
       
   174 		{
       
   175 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessClientL() <<Next State --> StateSessionInitiation>> "), this);
       
   176 		}
       
   177 	else if(iD == TSipHLConsts::EStateSessionEstablished)
       
   178 		{
       
   179 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessClientL() <<Next State --> StateSessionEstablished>> "), this);
       
   180 		}
       
   181 	else if(iD == TSipHLConsts::EStateSessionTerminated)
       
   182 		{
       
   183 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessClientL() <<Next State --> StateSessionTerminated>> "), this);	
       
   184 		}
       
   185 	else
       
   186 		{
       
   187 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessClientL() <<Next State --> Unknown, its a serious error>> "), this);		
       
   188 		}
       
   189 #endif	
       
   190 	return iNext;	
       
   191 	}
       
   192 
       
   193 CSipStateBase * CStateIdle::ProcessServerL( TRequestStatus & aStatus )
       
   194 /**
       
   195 Function which process the request and responses from the Server
       
   196 */
       
   197 	{
       
   198 	__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL()"), this);
       
   199 	TSipMsgBundle SipMsgBundle = iSipSM->GetSipMessageBundle();
       
   200 	// Handle response from server
       
   201 	switch (iServerResponse)
       
   202 		{
       
   203 		case TSipHLConsts::EResponseNone:
       
   204 			{
       
   205 			__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL()  <<RESPONSE NONE>>"), this);
       
   206 			iSipSM->SetSuspendRequest(ETrue);
       
   207 			iNext = this;		
       
   208 			break;	
       
   209 			}
       
   210 		case TSipHLConsts::EResponseRegister:
       
   211 		case TSipHLConsts::EResponseUnRegister:
       
   212 			{
       
   213 			__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL()  <<RESPONSE REGISTER/ RESPONSE UNREGISTER>>"), this);
       
   214 			if(SipMsgBundle.iStatusCode == 200)
       
   215 				{
       
   216 				iSipSM->SetSuspendRequest(ETrue);
       
   217 				iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionEstablished);
       
   218 				iNext->ResetRequestResponse();
       
   219 				}
       
   220 			else
       
   221 				{
       
   222 				iSipSM->SetSIPError(SipMsgBundle.iStatusCode);
       
   223 				this->SetClientRequest(TSipHLConsts::ERequestNone);
       
   224 				iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
   225 				iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
   226 				iNext->ResetRequestResponse();
       
   227 				}
       
   228 			}
       
   229 			break;
       
   230 		case TSipHLConsts::EResponseInvite:
       
   231 			{
       
   232 			__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL()  <<RESPONSE INVITE>>"), this);
       
   233 			if(SipMsgBundle.iStatusCode == 100)
       
   234 				{
       
   235 				__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL()  <<100 Trying>>"), this);
       
   236 				iSipSM->SetSuspendRequest(ETrue);
       
   237 				iNext = this;
       
   238 				iNext->ResetRequestResponse();
       
   239 				}
       
   240 			else if(SipMsgBundle.iStatusCode == 180)	
       
   241 				{
       
   242 				__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL()  <<180 Trying>>"), this);
       
   243 				iSipSM->SetSuspendRequest(ETrue);
       
   244 				iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionInitiation);
       
   245 				iNext->ResetRequestResponse();
       
   246 				}
       
   247 			else // error condition
       
   248 				{
       
   249 				__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL()  <<Error Condition neither 100 nor 180>>"), this);
       
   250 				iSipSM->SetSIPError(SipMsgBundle.iStatusCode);
       
   251 				iSipSM->SetOutgoingStatus(EFalse);
       
   252 				iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
   253 				iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
   254 				iNext->ResetRequestResponse();		
       
   255 				}
       
   256 			}
       
   257 			break;
       
   258 		case TSipHLConsts::EResponseSubscribe:
       
   259 			{
       
   260 			__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL()  <<RESPONSE SUBSCRIBE>>"), this);
       
   261 			if(SipMsgBundle.iStatusCode == 100)
       
   262 				{
       
   263 				__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL()  <<100 Trying>>"), this);
       
   264 				iSipSM->SetSuspendRequest(ETrue);
       
   265 				iNext = this;
       
   266 				iNext->ResetRequestResponse();
       
   267 				}
       
   268 			else if(SipMsgBundle.iStatusCode == 200 || SipMsgBundle.iStatusCode == 202)
       
   269 				{
       
   270 				__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL()  <<200 or 202>>"), this);
       
   271 				iSipSM->SetOutgoingStatus(EFalse);
       
   272 				iSipSM->SetSuspendRequest(ETrue);
       
   273 				iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionEstablished);
       
   274 				iNext->ResetRequestResponse();
       
   275 				iSipSM->CallEstablishedCallback();	
       
   276 				}
       
   277 			else
       
   278 				{
       
   279 				__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL()  <<Error neither 100. nore 200 0r 202>>"), this);
       
   280 				iSipSM->SetSIPError(SipMsgBundle.iStatusCode);
       
   281 				iSipSM->SetOutgoingStatus(EFalse);
       
   282 				iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
   283 				iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
   284 				iNext->ResetRequestResponse();	
       
   285 				}
       
   286 			}
       
   287 			break;
       
   288 		default:
       
   289 			{
       
   290 			__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL()  <<RESPONSE DEFAULT>>"), this);
       
   291 			if(iReqIdentifier == 4)
       
   292 				{
       
   293 				iSipSM->SetSuspendRequest(ETrue);
       
   294 				iNext = this;
       
   295 				}
       
   296 			}
       
   297 		}
       
   298 	// Handle Request from server
       
   299 	switch(iServerRequest)
       
   300 		{
       
   301 		case TSipHLConsts::ERequestInvite:
       
   302 			{
       
   303 			__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL()  <<REQUEST INVITE>>"), this);
       
   304 			iSipSM->GetTe()->SetDialogAssoc(iSipSM,SipMsgBundle.iDialog);
       
   305 			iSipSM->GetTe()->SetTransaction(iSipSM,SipMsgBundle.iServTransaction);
       
   306 			iSipSM->GetCommandContext().iDialogAssoc = (CSIPInviteDialogAssoc*)SipMsgBundle.iDialog;
       
   307 			iSipSM->GetCommandContext().iServerTx = SipMsgBundle.iServTransaction;
       
   308 			TRAPD(err,iSipSM->GenerateInviteResponseL(iSipSM->GetCommandContext().iServerTx, TSipHLConsts::EResponseRinging));
       
   309 			if(err != KErrNone)
       
   310 				{
       
   311 				iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
   312 				iSipSM->SetGeneralError(err);
       
   313 				iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
   314 				}
       
   315 			else
       
   316 				{
       
   317 				// Go to Next State as Session is Intiated
       
   318 				iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionInitiation);
       
   319 				iNext->ResetRequestResponse();
       
   320 				// since user input is required , SM will go to suspended state
       
   321 				iSipSM->SetSuspendRequest(ETrue);
       
   322 				// Send Incomin call Notification to User
       
   323 				iSipSM->CallIncomingCallback();	
       
   324 				}
       
   325 			}
       
   326 			break;
       
   327 		default:
       
   328 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL()  <<REQUEST DEFAULT>>"), this);
       
   329 			if(iReqIdentifier == 2)
       
   330 				{
       
   331 				iSipSM->SetSuspendRequest(ETrue);
       
   332 				iNext = this;
       
   333 				}
       
   334 		}
       
   335 	TRequestStatus * stat = &aStatus;		
       
   336 	User::RequestComplete (stat , KErrNone);
       
   337 #ifdef __FLOG_ACTIVE	
       
   338 	// This indormation is required only when logging is enabled
       
   339 	TSipHLConsts::SIP_STATES	iD = (iNext != NULL)?iNext->GetStateId() : TSipHLConsts::EStateNone;
       
   340 	if(iD == TSipHLConsts::EStateNone)
       
   341 		{
       
   342 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL() <<Next State --> NULL>> "), this);
       
   343 		}
       
   344 	if(iD == TSipHLConsts::EStateSessionIdle)
       
   345 		{
       
   346 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL() <<Next State --> StateIdle>> "), this);
       
   347 		}
       
   348 	else if(iD == TSipHLConsts::EStateSessionInitiation)
       
   349 		{
       
   350 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL() <<Next State --> StateSessionInitiation>> "), this);
       
   351 		}
       
   352 	else if(iD == TSipHLConsts::EStateSessionEstablished)
       
   353 		{
       
   354 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL() <<Next State --> StateSessionEstablished>> "), this);
       
   355 		}
       
   356 	else if(iD == TSipHLConsts::EStateSessionTerminated)
       
   357 		{
       
   358 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL() <<Next State --> StateSessionTerminated>> "), this);	
       
   359 		}
       
   360 	else
       
   361 		{
       
   362 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerL() <<Next State --> Unknown, its a serious error>> "), this);		
       
   363 		}
       
   364 #endif	
       
   365 	return iNext;
       
   366 	}
       
   367 	
       
   368 CSipStateBase * CStateIdle::ProcessServerErrorL(TRequestStatus & aStatus)
       
   369 /**
       
   370 Handles the Error condition for this state from the server
       
   371 */
       
   372 	{
       
   373 	__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerErrorL()"), this);
       
   374 	TSipMsgBundle SipMsgBundle = iSipSM->GetSipMessageBundle();
       
   375 	// Call the call back to Notify the client
       
   376 	iSipSM->SetGeneralError(SipMsgBundle.iErrCode);
       
   377 	iSipSM->SetSIPError(SipMsgBundle.iStatusCode);
       
   378 	iSipSM->CallTerminateCallback();
       
   379 	iSipSM->SetCallTerminateCallBack(EFalse);
       
   380 	// Get to The terminated state
       
   381 	iNext = iSipSM->GetNextState(TSipHLConsts::EStateSessionTerminated);
       
   382 	iSipSM->SetSIPStimulus(TSipHLConsts::EClientStimulus);
       
   383 	TRequestStatus * stat = &aStatus;		
       
   384 	User::RequestComplete(stat, KErrNone);
       
   385 	if(iNext)
       
   386 	{
       
   387 	    iNext->ResetRequestResponse();
       
   388 	}
       
   389 #ifdef __FLOG_ACTIVE	
       
   390 	// This indormation is required only when logging is enabled
       
   391 	TSipHLConsts::SIP_STATES	iD = (iNext != NULL)?iNext->GetStateId() : TSipHLConsts::EStateNone;
       
   392 	if(iD == KErrNotFound)
       
   393 		{
       
   394 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerErrorL() <<Next State --> NULL>> "), this);
       
   395 		}
       
   396 	if(iD == TSipHLConsts::EStateSessionIdle)
       
   397 		{
       
   398 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerErrorL() <<Next State --> StateIdle>> "), this);
       
   399 		}
       
   400 	else if(iD == TSipHLConsts::EStateSessionInitiation)
       
   401 		{
       
   402 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerErrorL() <<Next State --> StateSessionInitiation>> "), this);
       
   403 		}
       
   404 	else if(iD == TSipHLConsts::EStateSessionEstablished)
       
   405 		{
       
   406 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerErrorL() <<Next State --> StateSessionEstablished>> "), this);
       
   407 		}
       
   408 	else if(iD == TSipHLConsts::EStateSessionTerminated)
       
   409 		{
       
   410 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerErrorL() <<Next State --> StateSessionTerminated>> "), this);	
       
   411 		}
       
   412 	else
       
   413 		{
       
   414 		__FLOG_1(_L("[StateIdle]:CStateIdle[%x]::ProcessServerErrorL() <<Next State --> Unknown, its a serious error>> "), this);		
       
   415 		}
       
   416 #endif	
       
   417 	return iNext;
       
   418 	}
       
   419 
       
   420 
       
   421 
       
   422 
       
   423 
       
   424 
       
   425 
       
   426 
       
   427 
       
   428 
       
   429 
       
   430 
       
   431