realtimenetprots/sipfw/SIP/Transaction/src/NormalClientTa.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2006-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          : NormalClientTa.cpp
       
    15 // Part of       : Transaction
       
    16 // Version       : SIP/5.0
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "SipAssert.h"
       
    22 #include "Lwtimer.h"
       
    23 #include "sipresponse.h"
       
    24 
       
    25 #include "NormalClientTa.h"
       
    26 #include "TransactionState.h"
       
    27 #include "TransactionTimer.h"
       
    28 #include "TimerValues.h"
       
    29 #include "RestoreTransactionState.h"
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CNormalClientTransaction::NewL
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CNormalClientTransaction* CNormalClientTransaction::NewL(
       
    36 										CUserAgentBase& aUserAgent,
       
    37 										CTransmitter& aTransmitter,
       
    38 										MTimerManager& aTimers,
       
    39 										CTransactionState& aInitialState,
       
    40 										TTimerValues& aTimerValues,
       
    41 										MTransactionStore& aTransactionStore)
       
    42 	{
       
    43 	return new (ELeave) CNormalClientTransaction(aUserAgent,					
       
    44 								                 aTransmitter,
       
    45 								                 aTimers,
       
    46 								                 aInitialState,
       
    47 								                 aTimerValues,
       
    48 								                 aTransactionStore);
       
    49 	}
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CNormalClientTransaction::CNormalClientTransaction
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CNormalClientTransaction::CNormalClientTransaction(CUserAgentBase& aUserAgent,
       
    56 										CTransmitter& aTransmitter,
       
    57 										MTimerManager& aTimers,
       
    58 										CTransactionState& aInitialState,
       
    59 										TTimerValues& aTimerValues,
       
    60 										MTransactionStore& aTransactionStore) :
       
    61 	CClientTransaction(aUserAgent,
       
    62 					   aTransmitter,
       
    63 					   aTimers,
       
    64 					   aInitialState,
       
    65 					   aTimerValues,
       
    66 					   aTransactionStore)
       
    67 	{
       
    68 	}
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CNormalClientTransaction::~CNormalClientTransaction
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CNormalClientTransaction::~CNormalClientTransaction()
       
    75 	{
       
    76     //Scope operator to silence lint warning
       
    77     CNormalClientTransaction::CancelAllTimers();
       
    78 	}
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CNormalClientTransaction::IncreaseTimerEtoT2
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CNormalClientTransaction::IncreaseTimerEtoT2()
       
    85 	{
       
    86 	__TEST_INVARIANT;
       
    87 	__ASSERT_DEBUG(!iTimerE,
       
    88 		User::Panic(_L("CNormCTa:IncreaseTimerEtoT2"), KErrAlreadyExists));
       
    89 
       
    90 	iTimerEDuration = iTimerValues.T2();
       
    91 
       
    92 	__TEST_INVARIANT;	
       
    93 	}
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CNormalClientTransaction::StartTimerEL
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CNormalClientTransaction::StartTimerEL()
       
   100 	{
       
   101 	__TEST_INVARIANT;
       
   102 	__SIP_ASSERT_LEAVE(!iTimerE, KErrAlreadyExists);
       
   103 
       
   104 	iTimerValues.DoubleUptoT2(iTimerEDuration);
       
   105 	iTimerE = CTimerRetransmit::NewL(iTimers, this, iTimerEDuration);
       
   106 
       
   107 	__TEST_INVARIANT;
       
   108 	}
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CNormalClientTransaction::StopTimerE
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CNormalClientTransaction::StopTimerE()
       
   115 	{
       
   116 	__TEST_INVARIANT;
       
   117 
       
   118 	delete iTimerE;
       
   119 	iTimerE = NULL;
       
   120 
       
   121 	__TEST_INVARIANT;
       
   122 	}
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CNormalClientTransaction::StartTimerFUnlessExistsL
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 void CNormalClientTransaction::StartTimerFUnlessExistsL()
       
   129 	{
       
   130 	__TEST_INVARIANT;
       
   131 
       
   132 	if (!iTimerF)
       
   133 		{
       
   134 		iTimerF = CTimerTerminateTa::NewL(iTimers,
       
   135 										  this,
       
   136 										  iTimerValues.Duration64xT1(),
       
   137 										  KErrTimedOut);
       
   138 		}
       
   139 
       
   140 	__TEST_INVARIANT;
       
   141 	}
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CNormalClientTransaction::StopTimerF
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 void CNormalClientTransaction::StopTimerF()
       
   148 	{
       
   149 	__TEST_INVARIANT;
       
   150 
       
   151 	delete iTimerF;
       
   152 	iTimerF = NULL;
       
   153 
       
   154 	__TEST_INVARIANT;
       
   155 	}
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CNormalClientTransaction::StartTimerKL
       
   159 // Duration is 0s for reliable and T4 for unreliable transports.
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 void CNormalClientTransaction::StartTimerKL()
       
   163 	{
       
   164 	__TEST_INVARIANT;
       
   165 	__SIP_ASSERT_LEAVE(!iTimerK, KErrAlreadyExists);
       
   166 
       
   167 	TUint32 duration = 0;	
       
   168 	if (IsUnreliableTransportUsed())
       
   169 		{
       
   170 		duration = iTimerValues.T4();
       
   171 		}
       
   172 
       
   173 	iTimerK = CTimerTerminateTa::NewL(iTimers, this, duration);
       
   174 
       
   175 	__TEST_INVARIANT;
       
   176 	}
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // CNormalClientTransaction::StopTimerK
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 void CNormalClientTransaction::StopTimerK()
       
   183 	{
       
   184 	__TEST_INVARIANT;
       
   185 
       
   186 	delete iTimerK;
       
   187 	iTimerK = NULL;
       
   188 
       
   189 	__TEST_INVARIANT;
       
   190 	}
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CNormalClientTransaction::DeleteTimer
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 void CNormalClientTransaction::DeleteTimer(const CTransactionTimer& aTimer)
       
   197 	{
       
   198     __TEST_INVARIANT;
       
   199 
       
   200 	if (&aTimer == iTimerE)
       
   201 		{
       
   202 		StopTimerE();
       
   203 		}
       
   204 
       
   205 	if (&aTimer == iTimerF)
       
   206 		{
       
   207 		StopTimerF();
       
   208 		}
       
   209 
       
   210 	if (&aTimer == iTimerK)
       
   211 		{
       
   212 		StopTimerK();		
       
   213 		}
       
   214 
       
   215     __TEST_INVARIANT;
       
   216 	}
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CNormalClientTransaction::CancelAllTimers
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 void CNormalClientTransaction::CancelAllTimers()
       
   223 	{
       
   224 	__TEST_INVARIANT;
       
   225 
       
   226 	StopTimerE();
       
   227 	StopTimerF();
       
   228 	StopTimerK();
       
   229 	
       
   230 	__TEST_INVARIANT;
       
   231 	}
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CNormalClientTransaction::Ptr
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 CNormalClientTransaction&
       
   238 CNormalClientTransaction::Ptr(CTransaction& aTransaction)
       
   239 	{	
       
   240 	return static_cast<CNormalClientTransaction&>(aTransaction);
       
   241 	}
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // CNormalClientTransaction::ReceiveResponseL
       
   245 // Stop timers when transaction can no longer return to previous state.
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 void CNormalClientTransaction::ReceiveResponseL(CSIPResponse* aResponse,
       
   249                                     const CTransactionState& aCurrentState,
       
   250                                     const CTransactionState& aProceeding,
       
   251                                     const CTransactionState& aCompleted)
       
   252     {
       
   253     __TEST_INVARIANT;
       
   254     __SIP_ASSERT_LEAVE(aResponse, KErrArgument);
       
   255 
       
   256     if (ShouldTaHandleResponse(aResponse))
       
   257         {
       
   258 		TUint respCode = aResponse->ResponseCode();
       
   259         if (respCode >= 200)
       
   260             {
       
   261             StartTimerKL();
       
   262             ChangeState(aCompleted);
       
   263 			}
       
   264 		else
       
   265 			{
       
   266 			ChangeState(aProceeding);
       
   267 			}
       
   268 
       
   269         TRestoreTransactionState restoreState(*this, aCurrentState, iTimerK);
       
   270         CleanupStack::PushL(restoreState.CleanupItem());
       
   271 
       
   272 		PassResponseToUserAgentL(aResponse);
       
   273 
       
   274         CleanupStack::Pop(); //cleanupItem
       
   275 
       
   276         if (respCode >= 200)
       
   277             {
       
   278             StopTimerE();
       
   279 	        StopTimerF();
       
   280             }
       
   281 		}
       
   282 
       
   283 	__TEST_INVARIANT;
       
   284     }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CNormalClientTransaction::__DbgTestInvariant
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 
       
   291 void CNormalClientTransaction::__DbgTestInvariant() const
       
   292 	{
       
   293 	if (iTimerEDuration > iTimerValues.T2())
       
   294 		{
       
   295 		User::Invariant();
       
   296 		}
       
   297 	}