realtimenetprots/sipfw/SIP/Transaction/inc/CTransaction.h
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2006-2009 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:
       
    15 * Name          : CTransaction.h
       
    16 * Part of       : Transaction
       
    17 * Version       : SIP/5.0
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 /**
       
    25  @internalComponent
       
    26 */
       
    27 
       
    28 #ifndef CTRANSACTION_H
       
    29 #define CTRANSACTION_H
       
    30 
       
    31 // INCLUDES
       
    32 #include <stringpool.h>
       
    33 #include "SipStackServerDefs.h"
       
    34 #include "SipLogs.h"    //for USE_SIP_LOGS
       
    35 #include "Lwtimer.h"
       
    36 #include "SendStatus.h"
       
    37 #include "TSIPTransportParams.h"
       
    38 #include "TimerValues.h"
       
    39 
       
    40 #include "TransactionBase.h"
       
    41 #include "sip.h"
       
    42 
       
    43 // FORWARD DECLARATIONS
       
    44 class CSIPMessage;
       
    45 class CTransmitter;
       
    46 class CUserAgentBase;
       
    47 class CTransactionState;
       
    48 class TTimerValues;
       
    49 
       
    50 class CTransactionTimer;
       
    51 
       
    52 // CLASS DECLARATION
       
    53 /*
       
    54  * The base class for all transactions.
       
    55  */
       
    56 class CTransaction :
       
    57 	public CTransactionBase,
       
    58 	public MExpirationHandler,
       
    59 	public MSendStatus
       
    60 	{
       
    61 public: // Destructor
       
    62 
       
    63 	~CTransaction();
       
    64 
       
    65 public:	// From CTransactionBase
       
    66 
       
    67     void ReceiveL(CSIPRequest* aRequest);
       
    68 
       
    69 	void ReceiveL(CSIPResponse* aResponse);
       
    70 
       
    71 	void LeaveOccurred(TInt aReason);
       
    72 
       
    73 	const TSIPTransportParams& TransportParams() const;
       
    74 
       
    75 	virtual void IcmpErrorL(const TInetAddr& aAddress,
       
    76 							CSipConnectionMgr::TICMPError aError) = 0;
       
    77 
       
    78 	void SendRequestL(CSIPRequest& aReq,
       
    79 					  const TInetAddr& aAddress,					  
       
    80 					  RStringF aProtocol,
       
    81 					  TBool aForceUDP,
       
    82 					  const TSIPTransportParams& aParams,
       
    83 					  CUri8* aOutboundProxy);
       
    84 
       
    85 	void SendResponseL(CSIPResponse* aResp,					   
       
    86 					   RStringF aProtocol,
       
    87 					   const TSIPTransportParams& aParams);
       
    88 
       
    89 	TBool ClearSendBuffer();
       
    90 
       
    91     void GetState(CSIPInternalStates::TState& aState);
       
    92 
       
    93 	void Terminated();
       
    94 
       
    95 	virtual void TerminatedL(TInt aReason);
       
    96 
       
    97 	TBool HasTerminated() const;
       
    98 
       
    99 	void DetachFromUserAgent();
       
   100 
       
   101 	RStringF TransportProtocol() const;
       
   102 
       
   103 public: // From MExpirationHandler
       
   104 
       
   105 	void TimerExpiredL(TTimerId aTimerId, TAny* aTimerParam);
       
   106 		
       
   107 public:	// From MSendStatus
       
   108 
       
   109 	void SendCompleteL();
       
   110 
       
   111 	void SendFailedL(TInt aError);
       
   112 
       
   113 	void LeaveFromTransmitter(TInt aReason);
       
   114 
       
   115 public: // New pure virtual functions
       
   116 
       
   117 	/**
       
   118 	 * Delete the Transaction specific timer. Each separate transaction type
       
   119 	 * has different timers. If this transaction has a matching timer, the
       
   120 	 * timer will be deleted.
       
   121 	 *
       
   122 	 * @param aTimer Timer to be deleted
       
   123 	 */
       
   124 	virtual void DeleteTimer(const CTransactionTimer& aTimer) = 0;
       
   125 
       
   126 	/**
       
   127 	 * Sends a SIP message to CTransmitter.
       
   128 	 *
       
   129 	 * @pre iOutgoingMsg != NULL, iTransmitter isn't active
       
   130 	 */
       
   131 	virtual void SendToTransmitterL() = 0;	
       
   132 
       
   133 protected: // New pure virtual functions
       
   134 
       
   135 	/**
       
   136 	 * Stops transactions's all timers.
       
   137 	 */
       
   138 	virtual void CancelAllTimers() = 0;
       
   139 
       
   140 public: // New functions
       
   141 
       
   142 	/**
       
   143 	 * Tells if the transaction is an INVITE (client/server) transaction or a
       
   144 	 * non-INVITE (client/server) transaction.
       
   145 	 *
       
   146 	 * @return ETrue if INVITE transaction, EFalse otherwise.
       
   147 	 */
       
   148 	virtual TBool IsInviteTransaction() const;
       
   149 
       
   150 	/**
       
   151 	 * Transaction enters a new state
       
   152 	 *
       
   153 	 * @param aNewState State which CTransaction enters	 
       
   154 	 */
       
   155 	void ChangeState(const CTransactionState& aNewState);	
       
   156 
       
   157 	/**
       
   158 	 * Sets the iTransportProtocol member according to the transport protocol
       
   159 	 * in the top Via header of the aMsg.
       
   160 	 *
       
   161 	 * @param aMsg SIP message
       
   162 	 * @return value ETrue: if successful, EFalse: otherwise
       
   163 	 */
       
   164 	TBool UpdateTransportProtocol(CSIPMessage& aMsg);
       
   165 
       
   166 	/**	
       
   167 	 * Checks if transaction is using unreliable transport.
       
   168 	 *
       
   169 	 * @return ETrue if an unreliable transport is used, EFalse otherwise
       
   170 	 */	
       
   171 	TBool IsUnreliableTransportUsed() const;
       
   172 
       
   173     /**	
       
   174 	 * Checks if the CTransmitter is currently sending.
       
   175 	 *	 
       
   176 	 * @return ETrue: CTransmitter is sending, EFalse: otherwise
       
   177 	 */	
       
   178 	TBool IsTransmitterSending() const;
       
   179 
       
   180 	/**	
       
   181 	 * Returns a pointer to the current state.
       
   182 	 *
       
   183 	 * @return Transaction's current state, ownership isn't transferred.
       
   184 	 */	
       
   185 	const CTransactionState* State() const;
       
   186 
       
   187 protected:
       
   188 
       
   189 	/**
       
   190 	 * Constructor
       
   191 	 *
       
   192 	 * @pre aTransmitter != NULL, aInitialState != NULL
       
   193 	 *
       
   194 	 * @param aUserAgent UserAgent owning the new CTransaction being created.
       
   195 	 * @param aTransmitter CTransmitter used for sending messages.
       
   196 	 * @param aTimers LwTimer subsystem
       
   197 	 * @param aInitialState Initial state of the CTransaction object
       
   198 	 * @param aTimerValues Values for calculating timer durations
       
   199 	 */
       
   200 	CTransaction(CUserAgentBase& aUserAgent,
       
   201 				 CTransmitter& aTransmitter,
       
   202 				 MTimerManager& aTimers,
       
   203 				 CTransactionState& aInitialState,
       
   204 				 TTimerValues& aTimerValues);
       
   205 
       
   206 	/**
       
   207 	 * Obtains the id of the transaction.
       
   208 	 *
       
   209 	 * @return TransactionId of the transaction
       
   210 	 */
       
   211 	virtual TTransactionId TransactionId() const;
       
   212 
       
   213 protected: // Data:
       
   214 
       
   215 	//UserAgent associated with this transaction. Can be NULL. Not owned.
       
   216 	CUserAgentBase* iUserAgent;
       
   217 
       
   218 	//CTransmitter used for sending messages, owned by UserAgent.
       
   219 	//In a special case the CInviteClientTransaction can own the CTransmitter.
       
   220 	CTransmitter* iTransmitter;
       
   221 
       
   222 	//Timer subsystem
       
   223 	MTimerManager& iTimers;
       
   224 
       
   225 	//Outgoing SIP message.
       
   226 	//
       
   227 	//In case of ClientTransaction, UAC owns the message, except when
       
   228 	//InviteClientTransaction has created the ACK (instead of UAC creating the
       
   229 	//ACK).
       
   230 	//
       
   231 	//In case of ServerTransaction, CTransaction owns the message. Except if
       
   232 	//InviteServerTransaction is sending a 2xx response, when the UAS owns it.	
       
   233 	CSIPMessage* iOutgoingMsg;
       
   234 
       
   235 	RStringF iTransportProtocol;
       
   236 
       
   237 	//Transport parameters to be used when sending the SIP message
       
   238 	TSIPTransportParams iTransportParams;
       
   239 
       
   240 	//Copy of the values in CTimerValueRetriever::TTimerValues, at the time the
       
   241 	//transaction was created. Later changes to
       
   242 	//CTimerValueRetriever::TTimerValues won't reflect here.
       
   243 	TTimerValues iTimerValues;
       
   244 
       
   245 	//ETrue when CTransaction has reached terminated state.
       
   246 	//There is no separate state object for the terminated state.
       
   247 	TBool iTerminated;
       
   248 
       
   249 private:
       
   250 
       
   251 #if defined(USE_SIP_LOGS)
       
   252 	/**
       
   253 	 * Write the transaction state to a log file.
       
   254 	 *
       
   255 	 * @param aState Transaction state
       
   256 	 */	
       
   257 	void WriteStateToLog(const CTransactionState& aState) const;
       
   258 #endif
       
   259 
       
   260 private: // Data
       
   261 
       
   262 	//Current state of the transaction FSM, not owned.
       
   263 	const CTransactionState* iState;
       
   264 
       
   265 	void __DbgTestInvariant() const;
       
   266 
       
   267 
       
   268 
       
   269 #ifdef CPPUNIT_TEST
       
   270 	friend class CTransactionUser_Test;
       
   271 	friend class ClientTransaction_Test;
       
   272 	friend class CServerTransaction_Test;
       
   273 	friend class CInviteServerTa_Test;
       
   274 	friend class CNormalCTa_Trying_Test;
       
   275 	friend class CNormalCTa_Proceeding_Test;
       
   276 	friend class CNormalCTa_Completed_Test;
       
   277 	friend class CNormalSTa_Trying_Test;
       
   278 	friend class CNormalSTa_Proceeding_Test;
       
   279 	friend class CNormalSTa_Completed_Test;
       
   280 	friend class CNormalUAS_GetTxOwner_Test;
       
   281 	friend class CNormalUAS_Start_Test;
       
   282 	friend class CUserAgentClient_Test;
       
   283 	friend class CUserAgentServer_Test;
       
   284 	friend class CInviteCTa_Calling_Test;
       
   285 #endif
       
   286 	};
       
   287 
       
   288 #endif // end of CTRANSACTION_H
       
   289 
       
   290 // End of File