multimediacommsengine/tsrc/MMCTestDriver/MCETester/src/TTcMCECommandBase.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 
       
    19 #include "CTcMCEContext.h"
       
    20 #include "MCEConstants.h"
       
    21 #include "TTcMceCommandBase.h"
       
    22 #include "CTcMCEProfileContainer.h"
       
    23 #include <MCESession.h>
       
    24 #include <MCEEvent.h>
       
    25 #include <MCERefer.h>
       
    26 #include <MceMediaStream.h>
       
    27 
       
    28 
       
    29 TTcMceCommandBase::TTcMceCommandBase( MTcTestContext& aContext )
       
    30 	: TTcCommandBase( static_cast< CTcContextBase& >( aContext ) ),
       
    31 	  iContext( static_cast< CTcMCEContext& >( aContext ) ),
       
    32 	  iPushed( 0 )
       
    33 	{
       
    34 	}
       
    35 
       
    36 //
       
    37 // - Parameter extraction functions -------------------------------------------
       
    38 //
       
    39 
       
    40 TInt TTcMceCommandBase::ExtractProfileIdL()
       
    41     {
       
    42     TPtrC8 profileIdStr = ExtractIdL( KParamProfileId );
       
    43 	TInt profileId( 0 );
       
    44 	TLex8 lexer( profileIdStr );
       
    45 	User::LeaveIfError( lexer.Val( profileId ) );
       
    46 	return profileId;
       
    47     }
       
    48 
       
    49 CSIPProfile& TTcMceCommandBase::GetProfileL( CTcMCEProfileContainer& aProfileContainer )
       
    50 	{
       
    51 	// Get profile from the registry
       
    52     return aProfileContainer.GetProfileByIdL( ExtractProfileIdL() );
       
    53 	}
       
    54 	
       
    55 CTcMCEProfileContainer& TTcMceCommandBase::SelectProfileL()
       
    56 	{
       
    57 	TPtrC8 value = ExtractIdL( KRegistryId, EFalse );
       
    58 	if( value != KNullDesC8 )
       
    59 		{
       
    60 		CTcMCEProfileContainer* conn
       
    61 							= reinterpret_cast< CTcMCEProfileContainer* >(
       
    62 								iContext.Registry().ObjectPtrL( value ) );
       
    63 		return *conn;
       
    64 		}
       
    65 	else
       
    66 		{
       
    67 		return iContext.Profile();
       
    68 		}
       
    69 	}
       
    70 	
       
    71 CDesC8Array* TTcMceCommandBase::ExtractArrayL( const TDesC8& aName,
       
    72 											   TBool aIsMandatory ) 
       
    73 	{
       
    74 	CTcArray* tcArray = FindArrayL(aName, aIsMandatory);
       
    75 	if ( !tcArray )
       
    76 		{
       
    77 		return NULL;
       
    78 		}
       
    79 		
       
    80 	CDesC8Array* array = new(ELeave)CDesC8ArraySeg(1);
       
    81 	CleanupStack::PushL( array );
       
    82 	
       
    83 	const MDesC8Array& aItems = tcArray->AsMDesCArray(); 
       
    84 	TInt count = aItems.MdcaCount();
       
    85 
       
    86 	for( TInt i = 0; i < count; i++ )
       
    87 		{
       
    88 		array->AppendL( aItems.MdcaPoint( i ) );
       
    89 		}
       
    90 		
       
    91 	CleanupStack::Pop( array );	
       
    92 	return array;			
       
    93 	}
       
    94 	
       
    95 CDesC8Array* TTcMceCommandBase::ExtractHeadersL( TBool aIsMandatory ) 
       
    96 	{
       
    97 	CDesC8Array* array = ExtractArrayL(KParamSipHeaders, aIsMandatory );
       
    98 	if ( array )
       
    99 		{
       
   100 		if ( array->Count() > 0 )
       
   101 			{
       
   102 			return array;
       
   103 			}
       
   104 		}
       
   105 	delete array;
       
   106 	return NULL;
       
   107 	}
       
   108 
       
   109 HBufC8* TTcMceCommandBase::HBufCParameterL( TPtrC8 ptr )
       
   110 	{
       
   111 	HBufC8* buf = NULL;
       
   112 	// MCE API should accept null parameters, but as long as it does not,
       
   113 	// zero-length descriptors are used instead. When problem is corrected,
       
   114 	// remove comments.
       
   115 	//if (ptr != KNullDesC8 )
       
   116 	//	{
       
   117 		buf = ptr.AllocL();
       
   118 	//	}	
       
   119 	return buf;
       
   120 	}
       
   121 	
       
   122 //
       
   123 // - Response creation functions ----------------------------------------------
       
   124 //
       
   125 
       
   126 CTcStructure& TTcMceCommandBase::FindCreateTestClientIdsL()
       
   127 	{
       
   128 	// Find the TestClientIds structure, it may be in several places
       
   129 	// (there might already be a ReceivedMsg item in the return list)
       
   130 	// It may also be missing altogether, if this is the first time
       
   131 	// AddIdResponseL() is called.
       
   132 	TInt pos = iContext.ReturnList().FindParameter( KResponseTestClientIds,
       
   133 													MTcTyped::EStructure );
       
   134 	if( pos == KErrNotFound )
       
   135 		{
       
   136 		// Figure out the correct position for the structure: just
       
   137 		// after the ReceivedMsg if it exists.
       
   138 		pos = iContext.ReturnList().FindParameter( KResponseHeaders,
       
   139 												   MTcTyped::EArray );
       
   140 		if( pos == KErrNotFound )
       
   141 			{
       
   142 			pos = 0;	// no headers, insert at the beginning
       
   143 			}
       
   144 		else
       
   145 			{
       
   146 			pos++;	// insert after headers
       
   147 			}
       
   148 
       
   149 		// Add a structure to the response parameter list for TestClient Ids
       
   150 		CTcStructure* tcIDs = CTcStructure::NewLC();
       
   151 		tcIDs->SetName( KResponseTestClientIds );
       
   152 		iContext.ReturnList().InsertParameterL( tcIDs, pos );
       
   153 		CleanupStack::Pop( tcIDs);
       
   154 
       
   155 		// All IDs, in no spesific order (in alphabetical order in SIPTester)
       
   156         // (this has to be function-local in order to compile for THUMB)
       
   157 		// Confirm that you don't have comma after last Id!
       
   158 		const TDesC8* const TIdNames[] = {
       
   159 			&KProfileObj, // Profile's name in TesterCores registry
       
   160 			&KSessionId,
       
   161 			&KEventId,
       
   162 			&KReferId,
       
   163 			&KStreamId,
       
   164 			&KCodecId,
       
   165 			&KSourceId,
       
   166 			&KSinkId
       
   167 			};
       
   168 
       
   169 		// Add an entry for ALL possible Ids. This is done to go around
       
   170 		// a Telelogic Tau logging problem related to template mismatches
       
   171 		TInt count = sizeof( TIdNames ) / sizeof( const TDesC8* );
       
   172 		for( TInt i = 0; i < count; i++ )
       
   173 			{
       
   174 			CTcNameValue* nameValue = CTcNameValue::NewLC();
       
   175 			nameValue->SetL( *TIdNames[ i ], 0 );
       
   176 			tcIDs->AddItemL( nameValue );
       
   177 			CleanupStack::Pop( nameValue );
       
   178 			}
       
   179 		}
       
   180 
       
   181 	return iContext.ReturnList().AsStructure( pos );
       
   182 	}
       
   183 
       
   184 void TTcMceCommandBase::AddIdResponseL( const TDesC8& aName,
       
   185 										const CBase* aObject )
       
   186 	{
       
   187 	// Register object and fetch its name
       
   188 	iContext.Registry().AddObjectL(	const_cast< CBase* >( aObject ) );
       
   189 	TPtrC8 idName = iContext.Registry().ObjectNameL( aObject );	
       
   190 	CTcStructure& tcIDs = FindCreateTestClientIdsL();
       
   191 	CTcNameValue* idNameValue = tcIDs.ItemL( aName );
       
   192 	idNameValue->SetValueL( idName );
       
   193 	}
       
   194 	
       
   195 void TTcMceCommandBase::AddIdResponseL( const TDesC8& aName,
       
   196 										const CBase& aObject )
       
   197 	{
       
   198 	// Register object and fetch its name
       
   199 	iContext.Registry().AddObjectL(	aObject );
       
   200 	TPtrC8 idName = iContext.Registry().ObjectNameL( &aObject );
       
   201 
       
   202 	CTcStructure& tcIDs = FindCreateTestClientIdsL();
       
   203 	CTcNameValue* idNameValue = tcIDs.ItemL( aName );
       
   204 	idNameValue->SetValueL( idName );
       
   205 	}
       
   206 
       
   207 void TTcMceCommandBase::AddHeadersL( const CDesC8Array* aHeaders ) 
       
   208 	{
       
   209 	if ( aHeaders ) 
       
   210 		{
       
   211 		if ( aHeaders->Count() > 0 )
       
   212 			{
       
   213 			AddArrayResponseL( KResponseHeaders, *aHeaders );
       
   214 			}
       
   215 		}
       
   216 	}
       
   217 
       
   218 void TTcMceCommandBase::AddTextualSessionStateL( TInt aState) 
       
   219 	{
       
   220 	switch( aState ) 
       
   221 		{
       
   222 		case CMceSession::EIdle: AddTextResponseL(KResponseStateText, KIdle); break;
       
   223 		case CMceSession::EOffering: AddTextResponseL(KResponseStateText, KOffering); break;
       
   224 		case CMceSession::EIncoming: AddTextResponseL(KResponseStateText, KIncoming); break;
       
   225 		case CMceSession::EAnswering: AddTextResponseL(KResponseStateText, KAnswering); break;
       
   226 		case CMceSession::EProceeding: AddTextResponseL(KResponseStateText, KProceeding); break;
       
   227 		case CMceSession::EEstablished: AddTextResponseL(KResponseStateText, KEstablished); break;
       
   228 		case CMceSession::EReserving: AddTextResponseL(KResponseStateText, KUpdating); break;
       
   229 		case CMceSession::ECancelling: AddTextResponseL(KResponseStateText, KCancelling); break;
       
   230 		case CMceSession::ETerminating: AddTextResponseL(KResponseStateText, KTerminating); break;
       
   231 		case CMceSession::ETerminated: AddTextResponseL(KResponseStateText, KTerminated); break;
       
   232 		//case CMceSession::EOnHold: AddTextResponseL(KResponseStateText, KOnHold); break;
       
   233 		//case CMceSession::EReferred: AddTextResponseL(KResponseStateText, KReferred); break;
       
   234 		default: AddTextResponseL(KResponseStateText, KUnknownState); break;
       
   235 		}
       
   236 	}
       
   237 
       
   238 
       
   239 void TTcMceCommandBase::AddTextualMediaStreamStateL( TInt aState) 
       
   240 	{
       
   241 	switch( aState ) 
       
   242 		{
       
   243 		case CMceMediaStream::EUninitialized: AddTextResponseL(KResponseMediaStreamStateText, KUninitialized); break;
       
   244 		case CMceMediaStream::EInitialized: AddTextResponseL(KResponseMediaStreamStateText, KInitialized); break;
       
   245 		case CMceMediaStream::EBuffering: AddTextResponseL(KResponseMediaStreamStateText, KBuffering); break;
       
   246 		//case CMceMediaStream::EIdle: AddTextResponseL(KResponseMediaStreamStateText, KIdle); break;
       
   247 		case CMceMediaStream::EIdle: AddTextResponseL(KResponseMediaStreamStateText, KmsIdle); break;
       
   248 		case CMceMediaStream::EStreaming: AddTextResponseL(KResponseMediaStreamStateText, KStreaming); break;
       
   249 		case CMceMediaStream::EDisabled: AddTextResponseL(KResponseMediaStreamStateText, KDisabled); break;
       
   250 		case CMceMediaStream::ENoResources: AddTextResponseL(KResponseMediaStreamStateText, KNoResources); break;
       
   251 		case CMceMediaStream::ETranscodingRequired: AddTextResponseL(KResponseMediaStreamStateText, KTranscodingRequired); break;
       
   252 		case CMceMediaStream::ETranscoding: AddTextResponseL(KResponseMediaStreamStateText, KTranscoding); break;
       
   253 		 
       
   254 		default: AddTextResponseL(KResponseMediaStreamStateText, KUnknownState); break;
       
   255 		}
       
   256 	}	
       
   257 	
       
   258 // MediaStream state is removed. There are only 2 state enable and disable
       
   259 void TTcMceCommandBase::AddTextualStreamStateL( TBool aState, TBool aBound ) 
       
   260 	{
       
   261 	TPtrC8 addedText;
       
   262 	
       
   263 	if ( aBound )
       
   264 	    {
       
   265 	    addedText.Set(KResponseBoundStreamStateText);
       
   266 	    }
       
   267 	else
       
   268 	    {
       
   269 	    addedText.Set(KResponseStreamStateText);
       
   270 	    }
       
   271 	
       
   272 	if ( aState)
       
   273 		{
       
   274 		AddTextResponseL( addedText, KStreamEnable);	
       
   275 		}
       
   276 	else
       
   277 		{
       
   278 		AddTextResponseL( addedText, KStreamDisable);		
       
   279 		}
       
   280 	}
       
   281 
       
   282 void TTcMceCommandBase::AddTextualEventStateL( TInt aState ) 
       
   283 	{
       
   284 	
       
   285 	switch( aState ) 
       
   286 		{
       
   287 		case CMceEvent::EIdle: 
       
   288 			{
       
   289 			AddTextResponseL(KResponseEventStateText, KIdle); 
       
   290 			break;
       
   291 			}
       
   292 		case CMceEvent::EPending: 
       
   293 			{
       
   294 			AddTextResponseL(KResponseEventStateText, KPending); 
       
   295 			break;
       
   296 			}
       
   297 		case CMceEvent::EActive: 
       
   298 			{	
       
   299 			AddTextResponseL(KResponseEventStateText, KActive); 
       
   300 			break;
       
   301 			}
       
   302 		case CMceEvent::ETerminated: 
       
   303 			{
       
   304 			AddTextResponseL(KResponseEventStateText, KTerminated); 
       
   305 			break;
       
   306 			}
       
   307 		default: 
       
   308 			{
       
   309 			AddTextResponseL(KResponseEventStateText, KUnknownState); 
       
   310 			break;
       
   311 			}
       
   312 		}
       
   313 	
       
   314 	}
       
   315 
       
   316 void TTcMceCommandBase::AddTextualReferStateL( TInt aState ) 
       
   317 	{
       
   318 	
       
   319 	switch( aState ) 
       
   320 		{
       
   321 		case CMceRefer::EIdle: 
       
   322 			{
       
   323 			AddTextResponseL(KResponseReferStateText, KIdle); 
       
   324 			break;
       
   325 			}
       
   326 		case CMceRefer::EAccepted: 
       
   327 			{	
       
   328 			AddTextResponseL(KResponseReferStateText, KAccepted); 
       
   329 			break;
       
   330 			}
       
   331 		case CMceRefer::ETerminated: 
       
   332 			{
       
   333 			AddTextResponseL(KResponseReferStateText, KTerminated); 
       
   334 			break;
       
   335 			}
       
   336 		default: 
       
   337 			{
       
   338 			AddTextResponseL(KResponseReferStateText, KUnknownState); 
       
   339 			break;
       
   340 			}
       
   341 		}
       
   342 
       
   343 	}