multimediacommsengine/tsrc/testdriver/siptester/src/CTcSIPConnectionContainer.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "CTcSIPConnectionContainer.h"
       
    19 #include "TTcSIPReceived.h"
       
    20 #include "CTcSIPContext.h"
       
    21 #include "SipConstants.h"
       
    22 
       
    23 #include "TesterConstants.h"
       
    24 #include "ErrorHandling.h"
       
    25 
       
    26 // SIP stack includes
       
    27 #include <sip.h>
       
    28 #include <sipconnection.h>
       
    29 #include <sipdialog.h>
       
    30 #include <sipdialogassocbase.h>
       
    31 #include <sipheaderbase.h>
       
    32 #include <sipcseqheader.h>
       
    33 #include <sipextensionheader.h>
       
    34 #include <siprefresh.h>
       
    35 #include <sipregistrationbinding.h>
       
    36 #include <sipresponseelements.h>
       
    37 #include <sipclienttransaction.h>
       
    38 #include <sipmessageelements.h>
       
    39 
       
    40 CTcSIPConnectionContainer* CTcSIPConnectionContainer::NewL(
       
    41 													CTcSIPContext& aContext,
       
    42 													const TDesC8& aIAPName )
       
    43 	{
       
    44 	CTcSIPConnectionContainer* self =
       
    45 						new( ELeave ) CTcSIPConnectionContainer( aContext,
       
    46 																 aIAPName );
       
    47 
       
    48 	CleanupStack::PushL( self );
       
    49 	self->ConstructL();
       
    50 	CleanupStack::Pop( self );
       
    51 
       
    52 	return self;
       
    53 	}
       
    54 
       
    55 CTcSIPConnectionContainer::~CTcSIPConnectionContainer()
       
    56 	{
       
    57 	delete iSipConnection;
       
    58 	delete iTimer;
       
    59 	iReceiveQueue.Reset();
       
    60 	}
       
    61 
       
    62 CTcSIPConnectionContainer::CTcSIPConnectionContainer( CTcSIPContext& aContext,
       
    63 													  const TDesC8& aIAPName )
       
    64 	: iContext( aContext ), iReceiveQueue( 1 ), iIAPName( aIAPName )
       
    65 	{
       
    66 	}
       
    67 
       
    68 void CTcSIPConnectionContainer::ConstructL()
       
    69 	{
       
    70 	iTimer = CDeltaTimer::NewL( CActive::EPriorityStandard );
       
    71 	TCallBack cb( ReceiveTimeout, this );
       
    72 	iReceiveTimeout.Set( cb );
       
    73 
       
    74 	TInt iapId = iContext.IAPIdL( iIAPName );
       
    75 	iSipConnection = CSIPConnection::NewL( iContext.SIP(), iapId, *this );
       
    76 	// SIPConnection doesn't call the callback function if there already
       
    77 	// is a connection (e.g. from ProfileServer)
       
    78 	if( iSipConnection->State() == CSIPConnection::EInit )
       
    79 		{
       
    80 		iActiveWait.Start();
       
    81 		}
       
    82 	}
       
    83 
       
    84 //
       
    85 // -- CSIPConnection notifiers ------------------------------------------------
       
    86 //
       
    87 
       
    88 // Note that adding an object by-reference to the registry does NOT transfer
       
    89 // ownership. Adding by-pointer does transfer ownership, however.
       
    90 // Most/all SIP objects should be in the registry at this stage anyway,
       
    91 // just make sure that's the case.
       
    92 
       
    93 void CTcSIPConnectionContainer::IncomingRequest(
       
    94 										CSIPServerTransaction* aTransaction )
       
    95 	{
       
    96 	TRAPD( err, {
       
    97 		iContext.Registry().AddObjectL( aTransaction );
       
    98 		TTcSIPReceived received;
       
    99 		received.Set( aTransaction );
       
   100 		received.SetEvent( TTcSIPReceived::EIncomingRequest );
       
   101 		QueueReceivedL( received );
       
   102 		} )
       
   103 	__ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) );
       
   104 	}
       
   105 
       
   106 void CTcSIPConnectionContainer::IncomingRequest(
       
   107 										CSIPServerTransaction* aTransaction,
       
   108 										CSIPDialog& aDialog )
       
   109 	{
       
   110 	TRAPD( err, {
       
   111 		iContext.Registry().AddObjectL( aTransaction );
       
   112 		iContext.Registry().AddObjectL( aDialog );
       
   113 		TTcSIPReceived received;
       
   114 		received.Set( aTransaction );
       
   115 		received.Set( &aDialog );
       
   116 		received.SetEvent( TTcSIPReceived::EIncomingRequest );
       
   117 		QueueReceivedL( received );
       
   118 		} )
       
   119 	__ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) );
       
   120 	}
       
   121 
       
   122 void CTcSIPConnectionContainer::IncomingResponse(
       
   123 										CSIPClientTransaction& aTransaction )
       
   124 	{
       
   125 	TRAPD( err, {
       
   126 		iContext.Registry().AddObjectL( aTransaction );
       
   127 		TTcSIPReceived received;
       
   128 		received.Set( &aTransaction );
       
   129 		received.SetEvent( TTcSIPReceived::EIncomingResponse );
       
   130 		QueueReceivedL( received );
       
   131 		} )
       
   132 	__ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) );
       
   133 	}
       
   134 
       
   135 void CTcSIPConnectionContainer::IncomingResponse(
       
   136 										CSIPClientTransaction& aTransaction,
       
   137 										CSIPDialogAssocBase& aDialogAssoc )
       
   138 	{
       
   139 	TRAPD( err, {
       
   140 		iContext.Registry().AddObjectL( aTransaction );
       
   141 		iContext.Registry().AddObjectL( aDialogAssoc );
       
   142 		TTcSIPReceived received;
       
   143 		received.Set( &aTransaction );
       
   144 		received.Set( &aDialogAssoc );
       
   145 		received.SetEvent( TTcSIPReceived::EIncomingResponse );
       
   146 		QueueReceivedL( received );
       
   147 		} )
       
   148 	__ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) );
       
   149 	}
       
   150 
       
   151 void CTcSIPConnectionContainer::IncomingResponse(
       
   152 										CSIPClientTransaction& aTransaction,
       
   153 										CSIPInviteDialogAssoc* aDialogAssoc )
       
   154 	{
       
   155 	TRAPD( err, {
       
   156 		iContext.Registry().AddObjectL( aTransaction );
       
   157 		iContext.Registry().AddObjectL( aDialogAssoc );
       
   158 		TTcSIPReceived received;
       
   159 		received.Set( &aTransaction );
       
   160 		received.Set( aDialogAssoc );
       
   161 		received.SetEvent( TTcSIPReceived::EIncomingResponse );
       
   162 		QueueReceivedL( received );
       
   163 		} )
       
   164 	__ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) );
       
   165 	}
       
   166 
       
   167 void CTcSIPConnectionContainer::IncomingResponse(
       
   168 										CSIPClientTransaction& aTransaction,
       
   169 										CSIPRegistrationBinding& aRegistration )
       
   170 	{
       
   171 	TRAPD( err, {
       
   172 		iContext.Registry().AddObjectL( aTransaction );
       
   173 		iContext.Registry().AddObjectL( aRegistration );
       
   174 		TTcSIPReceived received;
       
   175 		received.Set( &aTransaction );
       
   176 		received.Set( &aRegistration );
       
   177 		received.SetEvent( TTcSIPReceived::EIncomingResponse );
       
   178 		QueueReceivedL( received );
       
   179 		} )
       
   180 	__ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) );
       
   181 	}
       
   182 
       
   183 void CTcSIPConnectionContainer::ErrorOccured(
       
   184 										TInt aError,
       
   185 										CSIPTransactionBase& aTransaction )
       
   186 	{
       
   187 	TRAPD( err, {
       
   188 		iContext.Registry().AddObjectL( aTransaction );
       
   189 		TTcSIPReceived received;
       
   190 		received.Set( &aTransaction );
       
   191 		received.SetError( aError );
       
   192 		received.SetEvent( TTcSIPReceived::EErrorOccured );
       
   193 		QueueReceivedL( received );
       
   194 		} )
       
   195 	__ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) );
       
   196 	}
       
   197 
       
   198 void CTcSIPConnectionContainer::ErrorOccured( TInt aError,
       
   199 										CSIPClientTransaction& aTransaction,
       
   200 										CSIPRegistrationBinding& aRegistration )
       
   201 	{
       
   202 	TRAPD( err, {
       
   203 		iContext.Registry().AddObjectL( aTransaction );
       
   204 		iContext.Registry().AddObjectL( aRegistration );
       
   205 		TTcSIPReceived received;
       
   206 		received.Set( &aTransaction );
       
   207 		received.Set( &aRegistration );
       
   208 		received.SetError( aError );
       
   209 		received.SetEvent( TTcSIPReceived::EErrorOccured );
       
   210 		QueueReceivedL( received );
       
   211 		} )
       
   212 	__ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) );
       
   213 	}
       
   214 
       
   215 void CTcSIPConnectionContainer::ErrorOccured( TInt aError,
       
   216 										CSIPTransactionBase& aTransaction,
       
   217 										CSIPDialogAssocBase& aDialogAssoc )
       
   218 	{
       
   219 	TRAPD( err, {
       
   220 		iContext.Registry().AddObjectL( aTransaction );
       
   221 		iContext.Registry().AddObjectL( aDialogAssoc );
       
   222 		TTcSIPReceived received;
       
   223 		received.Set( &aTransaction );
       
   224 		received.Set( &aDialogAssoc );
       
   225 		received.SetError( aError );
       
   226 		received.SetEvent( TTcSIPReceived::EErrorOccured );
       
   227 		QueueReceivedL( received );
       
   228 		} )
       
   229 	__ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) );
       
   230 	}
       
   231 
       
   232 void CTcSIPConnectionContainer::ErrorOccured(
       
   233 										TInt aError,
       
   234 										CSIPRefresh& aSIPRefresh )
       
   235 	{
       
   236 	TRAPD( err, {
       
   237 		iContext.Registry().AddObjectL( aSIPRefresh );
       
   238 		TTcSIPReceived received;
       
   239 		received.Set( &aSIPRefresh );
       
   240 		received.SetError( aError );
       
   241 		received.SetEvent( TTcSIPReceived::EErrorOccured );
       
   242 		QueueReceivedL( received );
       
   243 		} )
       
   244 	__ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) );
       
   245 	}
       
   246 
       
   247 void CTcSIPConnectionContainer::ErrorOccured(
       
   248 										TInt aError,
       
   249 										CSIPRegistrationBinding& aRegistration )
       
   250 	{
       
   251 	TRAPD( err, {
       
   252 		iContext.Registry().AddObjectL( aRegistration );
       
   253 		TTcSIPReceived received;
       
   254 		received.Set( &aRegistration );
       
   255 		received.SetError( aError );
       
   256 		received.SetEvent( TTcSIPReceived::EErrorOccured );
       
   257 		QueueReceivedL( received );
       
   258 		} )
       
   259 	__ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) );
       
   260 	}
       
   261 
       
   262 void CTcSIPConnectionContainer::ErrorOccured(
       
   263 										TInt aError,
       
   264 										CSIPDialogAssocBase& aDialogAssoc )
       
   265 
       
   266 	{
       
   267 	TRAPD( err, {
       
   268 		iContext.Registry().AddObjectL( aDialogAssoc );
       
   269 		TTcSIPReceived received;
       
   270 		received.Set( &aDialogAssoc );
       
   271 		received.SetError( aError );
       
   272 		received.SetEvent( TTcSIPReceived::EErrorOccured );
       
   273 		QueueReceivedL( received );
       
   274 		} )
       
   275 	__ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) );
       
   276 	}
       
   277 
       
   278 void CTcSIPConnectionContainer::InviteCompleted(
       
   279 										CSIPClientTransaction& aTransaction )
       
   280 	{
       
   281 	TRAPD( err, {
       
   282 		iContext.Registry().AddObjectL( aTransaction );
       
   283 		TTcSIPReceived received;
       
   284 		received.Set( &aTransaction );
       
   285 		received.SetEvent( TTcSIPReceived::EInviteCompleted );
       
   286 		QueueReceivedL( received );
       
   287 		} )
       
   288 	__ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) );
       
   289 	}
       
   290 
       
   291 void CTcSIPConnectionContainer::InviteCanceled( 
       
   292 										CSIPServerTransaction& aTransaction )
       
   293 	{
       
   294 	TRAPD( err, {
       
   295 		iContext.Registry().AddObjectL( &aTransaction );
       
   296 		TTcSIPReceived received;
       
   297 		received.Set( &aTransaction );
       
   298 		received.SetError( KSIPErrInviteCanceled );
       
   299 		received.SetEvent( TTcSIPReceived::EInviteCanceled );
       
   300 		QueueReceivedL( received );
       
   301 		} )
       
   302 	__ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) );
       
   303 	}
       
   304 
       
   305 void CTcSIPConnectionContainer::ConnectionStateChanged(
       
   306 										CSIPConnection::TState aState )
       
   307 	{
       
   308 	iConnectionState = aState;
       
   309 	if( iActiveWait.IsStarted() )
       
   310 		{
       
   311 		iActiveWait.AsyncStop();
       
   312 		}
       
   313 	}
       
   314 
       
   315 //
       
   316 // -- Public functions --------------------------------------------------------
       
   317 //
       
   318 
       
   319 TTcSIPReceived CTcSIPConnectionContainer::ReceivedItemL( TInt aTimeout )
       
   320 	{
       
   321 	if( iReceiveQueue.Count() == 0 )
       
   322 		{
       
   323 		// wait for items to arrive
       
   324 		iTimer->Queue( aTimeout * KSecondAsMicros, iReceiveTimeout );
       
   325 		iActiveWait.Start();
       
   326 		}
       
   327 
       
   328 	// Is the queue still empty ? (i.e. timeout occurred)
       
   329 	if( iReceiveQueue.Count() == 0 )
       
   330 		{
       
   331 		User::Leave( KErrTimedOut );
       
   332 		}
       
   333 
       
   334 	// Get the first (oldest) item from the array
       
   335 	TTcSIPReceived item = iReceiveQueue[ 0 ];
       
   336 
       
   337 	// ..and remove it from the array
       
   338 	iReceiveQueue.Delete( 0 );
       
   339 	iReceiveQueue.Compress();
       
   340 	return item;
       
   341 	}
       
   342 
       
   343 //
       
   344 // -- Internal utility functions ----------------------------------------------
       
   345 //
       
   346 
       
   347 void CTcSIPConnectionContainer::QueueReceivedL( TTcSIPReceived& aItem )
       
   348 	{
       
   349 	iReceiveQueue.AppendL( aItem );
       
   350 	if( iActiveWait.IsStarted() )
       
   351 		{
       
   352 		iTimer->Remove( iReceiveTimeout );
       
   353 		iActiveWait.AsyncStop();
       
   354 		}
       
   355 	}
       
   356 
       
   357 TInt CTcSIPConnectionContainer::ReceiveTimeout( TAny* aSelf )
       
   358 	{
       
   359 	CTcSIPConnectionContainer& self =
       
   360 				*reinterpret_cast< CTcSIPConnectionContainer* >( aSelf );
       
   361 	if( self.iActiveWait.IsStarted() )
       
   362 		{
       
   363 		self.iActiveWait.AsyncStop();
       
   364 		}
       
   365 
       
   366 	return KErrNone;
       
   367 	}