realtimenetprots/sipfw/ProfileAgent/profile_fsm/src/sipprflregistrationinprogressstate.cpp
changeset 0 307788aac0a8
child 26 822e1f077722
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2007-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 // Name        : sipprflregistrationinprogressstate.cpp
       
    15 // Part of     : sip profile fsm
       
    16 // implementation
       
    17 // Version     : %version: 2.1.1 %
       
    18 //
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include "sipprflregistrationinprogressstate.h"
       
    24 #include "sipprofileagentobserver.h"
       
    25 #include "sipclienttransaction.h"
       
    26 #include "sipresponseelements.h"
       
    27 #include "sipconcreteprofile.h"
       
    28 #include "sipregistrationbinding.h"
       
    29 #include "siperr.h"
       
    30 #include "sipgendefs.h"
       
    31 
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CSIPPrflRegistrationInProgressState::CSIPPrflRegistrationInProgressState
       
    37 // (other items were commented in a header).
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CSIPPrflRegistrationInProgressState::CSIPPrflRegistrationInProgressState(
       
    41     MSIPProfileFSMUser& aUser)
       
    42     : CSIPPrflStateBase(aUser,MSIPProfileContext::ERegistrationInProgress)
       
    43 	{
       
    44 	}
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CSIPPrflRegistrationInProgressState::CSIPImcPaInit
       
    48 // (other items were commented in a header).
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 EXPORT_C 
       
    52 CSIPPrflRegistrationInProgressState::~CSIPPrflRegistrationInProgressState()
       
    53 	{
       
    54 	}
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CSIPPrflRegistrationInProgressState::NewL()
       
    58 // (other items were commented in a header).
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 EXPORT_C CSIPPrflRegistrationInProgressState* 
       
    62 CSIPPrflRegistrationInProgressState::NewL(MSIPProfileFSMUser& aUser)
       
    63 	{
       
    64 	return new (ELeave) CSIPPrflRegistrationInProgressState(aUser);
       
    65 	}
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CSIPPrflRegistrationInProgressState::LinkStates()
       
    69 // (other items were commented in a header).
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 EXPORT_C void CSIPPrflRegistrationInProgressState::LinkStates(
       
    73 	CSIPPrflStateBase& aRegisterRequestedState,
       
    74 	CSIPPrflStateBase& aInitState,
       
    75 	CSIPPrflStateBase& aRegisteredState,
       
    76 	CSIPPrflStateBase& aRegisterDelayRequestedState)
       
    77 	{
       
    78 	iRegisterRequestedState = &aRegisterRequestedState;
       
    79 	iInitState = &aInitState;
       
    80 	iRegisteredState = &aRegisteredState;
       
    81 	iRegisterDelayRequestedState = &aRegisterDelayRequestedState;
       
    82 	}
       
    83 	
       
    84 // -----------------------------------------------------------------------------
       
    85 // CSIPPrflRegistrationInProgressState::ConcreteProfileState()
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 CSIPConcreteProfile::TStatus 
       
    89 CSIPPrflRegistrationInProgressState::ConcreteProfileState() const
       
    90     {
       
    91     return CSIPConcreteProfile::ERegistrationInProgress;
       
    92     }	
       
    93 	
       
    94 // -----------------------------------------------------------------------------
       
    95 // CSIPPrflRegistrationInProgressState::ResponseReceivedL()
       
    96 // (other items were commented in a header).
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CSIPPrflRegistrationInProgressState::ResponseReceived(
       
   100     MSIPProfileContext& aContext,
       
   101 	CSIPClientTransaction& aTransaction)
       
   102 	{
       
   103 	__ASSERT_DEBUG(aTransaction.ResponseElements()!=0, User::Invariant());
       
   104 	__ASSERT_DEBUG(aContext.Profile()!=0, User::Invariant());
       
   105 	__ASSERT_DEBUG(aContext.Registration()!=0, User::Invariant());
       
   106 	TUint status = aTransaction.ResponseElements()->StatusCode();
       
   107 	if (status >= K200Ok && status < K300MultipleChoices)
       
   108 		{
       
   109 		TInt err = KErrNone;
       
   110 		if (!aContext.AgentObserver().ProceedRegistration(
       
   111 		        *aContext.Profile(), KErrNone))
       
   112 			{
       
   113 			aContext.SetNextState(*iRegisteredState);
       
   114 			TRAP(err, iRegisteredState->DeregisterL(aContext));
       
   115 			}
       
   116 	    else
       
   117 	        {
       
   118 		    err = aContext.SetRegisteredAORs();
       
   119 		    if (err == KErrNone)
       
   120 		        {
       
   121 		        TRAP(err, aContext.SetNegotiatedSecurityMechanismL());
       
   122 		        if (err == KErrNone)
       
   123 		            {
       
   124 		            aContext.SetTransaction(0);
       
   125 		            aContext.SetNextState(*iRegisteredState);
       
   126 		            aContext.AgentObserver().SIPProfileStatusEvent(
       
   127 		                *aContext.Profile(),
       
   128 		                aContext.Registration()->ContextId());
       
   129 		            }
       
   130 		        }
       
   131 	        }
       
   132         if (err)
       
   133             {
       
   134             HandleError(aContext, err, iInitState);
       
   135             }
       
   136 		}
       
   137 	else if (status >= K300MultipleChoices)
       
   138 		{
       
   139 		HandleError(aContext, status, iInitState);
       
   140 		}
       
   141 	else
       
   142 		{
       
   143 		//1xx responses are not propagated
       
   144 		}
       
   145 	}
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CSIPPrflRegistrationInProgressState::ErrorOccured()
       
   149 // (other items were commented in a header).
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 void CSIPPrflRegistrationInProgressState::ErrorOccured(
       
   153 	MSIPProfileContext& aContext,
       
   154 	TInt aError)
       
   155 	{
       
   156 	__ASSERT_DEBUG(aContext.Profile()!=0, User::Invariant());
       
   157 	__ASSERT_DEBUG(aContext.Registration()!=0, User::Invariant());
       
   158 	CSIPConcreteProfile& profile = *aContext.Profile();
       
   159 	if ( aContext.RetryAfterTimer() )
       
   160 		{
       
   161 		//registration failed , re-try later
       
   162 		aContext.SetTransaction(0);
       
   163 		TUint32	contextId(aContext.Registration()->ContextId());
       
   164 		if( aContext.RetryTimerInUse() )
       
   165 			{
       
   166 			aContext.SetNextState(*iRegisterDelayRequestedState);
       
   167 			}
       
   168 		else
       
   169 			{
       
   170 			DoCleanup(aContext,contextId);
       
   171 			aContext.SetNextState(*iInitState);
       
   172 			}
       
   173 		aContext.AgentObserver().SIPProfileStatusEvent(profile,contextId);
       
   174 		}
       
   175 	else if ((aError == KErrSIPTransportFailure || 
       
   176 	     aError == KErrSIPResolvingFailure ||
       
   177 		 aError == KErrSIPICMPFailure) && 
       
   178 	    aContext.Connection().State()==CSIPConnection::ESuspended)
       
   179 		{
       
   180 		//registration failed due to the suspended connection, re-try later
       
   181 		aContext.SetTransaction(0);
       
   182 		aContext.SetNextState(*iRegisterRequestedState);
       
   183 		aContext.AgentObserver().SIPProfileStatusEvent(
       
   184 		    profile, aContext.Registration()->ContextId());
       
   185 		}
       
   186 	else if (aContext.RetryTimerInUse())
       
   187 		{
       
   188 		aContext.SetNextState(*iRegisterDelayRequestedState);
       
   189 		aContext.AgentObserver().SIPProfileErrorEvent(
       
   190 		    profile,aContext.Registration()->ContextId());
       
   191 		}
       
   192 	else
       
   193 		{
       
   194 		HandleError(aContext,aError,iInitState);
       
   195 		}
       
   196 	}
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CSIPPrflRegistrationInProgressState::ConnectionStateChanged()
       
   200 // (other items were commented in a header).
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 void CSIPPrflRegistrationInProgressState::ConnectionStateChanged(
       
   204 	MSIPProfileContext& aContext,
       
   205 	CSIPConnection::TState aState)
       
   206 	{
       
   207 	//only EInactive or ESuspended are possible
       
   208 	if (aState==CSIPConnection::EInactive)
       
   209 		{
       
   210 		__ASSERT_DEBUG(aContext.Profile()!=0, User::Invariant());
       
   211 		if (aContext.AgentObserver().ProceedRegistration(*aContext.Profile(), KErrNone))
       
   212 			{
       
   213 			aContext.SetTransaction(0); //transactions are deleted in the SIP stack
       
   214 			aContext.SetNextState(*iRegisterRequestedState);
       
   215 			__ASSERT_DEBUG(aContext.Registration()!=0, User::Invariant());
       
   216 			aContext.AgentObserver().SIPProfileStatusEvent(
       
   217 		    	*aContext.Profile(),
       
   218 		    	aContext.Registration()->ContextId());
       
   219 			}
       
   220 		else
       
   221 			{
       
   222 			HandleError(aContext,KErrGeneral,iInitState);
       
   223 			}
       
   224 		
       
   225 		}
       
   226 	/* When State EUnavailable is received, the registration Binding in the SIPStack 
       
   227 	 * is no longer present. Hence we have to do the cleanup here and propagate the 
       
   228 	 * error back to clients of profiles.
       
   229 	 */
       
   230     else if(aState==CSIPConnection::EUnavailable)
       
   231 		{
       
   232 		HandleError(aContext, KErrCouldNotConnect, iInitState);
       
   233 		}
       
   234     else
       
   235     	{
       
   236     	// make pclint happy
       
   237     	}
       
   238 	}
       
   239 	
       
   240 // -----------------------------------------------------------------------------
       
   241 // CSIPPrflRegistrationInProgressState::IsRegisterPending()
       
   242 // (other items were commented in a header).
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 TBool CSIPPrflRegistrationInProgressState::IsRegisterPending() const
       
   246     {
       
   247     return ETrue;
       
   248     }