os/boardsupport/haitest/bspsvs/suite/bsp/sound/src/t_currentsoundformatdata.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2005-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 *
    16 */
    17 
    18 /**
    19 @test
    20 @internalComponent
    21 
    22 This contains CT_CurrentSoundFormatData
    23 */
    24 
    25 //	User includes
    26 #include "t_currentsoundformatdata.h"
    27 #include "sound_util.h"
    28 
    29 /*@{*/
    30 ///	Commands
    31 _LIT(KCmdNew,						"new");
    32 _LIT(KCmdDestructor,				"~");
    33 _LIT(KCmd_iRate_get,				"irate_get");
    34 _LIT(KCmd_iRate_set,				"irate_set");
    35 _LIT(KCmd_iEncoding_get,			"iencoding_get");
    36 _LIT(KCmd_iEncoding_set,			"iencoding_set");
    37 _LIT(KCmd_iChannels_get,			"ichannels_get");
    38 _LIT(KCmd_iChannels_set,			"ichannels_set");
    39 _LIT(KCmd_iBufferSize_get,			"ibuffer_size_get");
    40 _LIT(KCmd_iBufferSize_set,			"ibuffer_size_set");
    41 
    42 /*@{*/
    43 ///	Parameters
    44 
    45 _LIT(KRate,							"rate");
    46 _LIT(KRateExpected,					"rate_expected");
    47 _LIT(KEncoding,						"encoding");
    48 _LIT(KEncodingExpected,				"encoding_expected");
    49 _LIT(KChannels,						"channels");
    50 _LIT(KChannelsExpected,				"channels_expected");
    51 _LIT(KBufferSize,					"buffer_size");
    52 _LIT(KBufferSizeExpected,			"buffer_size_expected");
    53 // possible parameter for new to indicate loading settings from 
    54 // SoundFormatsSupported object
    55 _LIT(KNewFromSoundFormatsSupported,	"new_from_sound_formats_supported");
    56 // for SoundFormatsSupported object
    57 _LIT(KSoundFormatsSupportedObject,	"SoundFormatsSupportedObject");
    58 // Enums declared in INI file
    59 
    60 ///	Logging
    61 _LIT(KLogNew,						"New object created successfully");
    62 _LIT(KLogNewError,					"Error in creating object error code=%d");
    63 /*@}*/
    64 
    65 /**
    66  * Two phase constructor
    67  */
    68 CT_CurrentSoundFormatData* CT_CurrentSoundFormatData::NewL()
    69 	{
    70 	CT_CurrentSoundFormatData*	ret=new (ELeave) CT_CurrentSoundFormatData();
    71 	CleanupStack::PushL(ret);
    72 	ret->ConstructL();
    73 	CleanupStack::Pop(ret);
    74 	return ret;
    75 	}
    76 
    77 /**
    78 * Constructor. First phase construction
    79 */
    80 CT_CurrentSoundFormatData::CT_CurrentSoundFormatData()
    81 :	CDataWrapperBase()
    82 ,	iCurrentFormat(NULL)
    83 	{
    84 	}
    85 
    86 /**
    87  * Second phase construction
    88  */
    89 void CT_CurrentSoundFormatData::ConstructL()
    90 	{	
    91 	}
    92 
    93 /**
    94 * Destructor
    95 */
    96 CT_CurrentSoundFormatData::~CT_CurrentSoundFormatData()
    97 	{
    98 	DoCleanup();
    99 	}
   100 
   101 /**
   102  * Helper method for doing cleanup operation
   103  */
   104 void CT_CurrentSoundFormatData::DoCleanup()
   105 	{
   106 	delete iCurrentFormat;
   107 	iCurrentFormat=NULL;	
   108 	}
   109 
   110 /**
   111  * Return a pointer to the object that the data wraps
   112  *
   113  * @return pointer to the object that the data wraps
   114  */
   115 TAny* CT_CurrentSoundFormatData::GetObject()
   116 
   117 	{
   118 	return iCurrentFormat;
   119 	}
   120 
   121 /**
   122  * Set the wrapped data object with new value
   123  */
   124 void CT_CurrentSoundFormatData::SetObjectL(TAny* aAny)
   125 
   126 	{
   127 	DoCleanup();
   128 	iCurrentFormat=static_cast<RMdaDevSound::TCurrentSoundFormat*>(aAny);
   129 	}
   130 
   131 /**
   132  * Clear the wrapped data object pointer w/o de-initialization
   133  */
   134 void CT_CurrentSoundFormatData::DisownObjectL()
   135 
   136 	{
   137 	iCurrentFormat=NULL;
   138 	}
   139 
   140 /**
   141  * Return static cleanup function
   142  */
   143 inline TCleanupOperation CT_CurrentSoundFormatData::CleanupOperation()
   144 
   145 	{
   146 	return CleanupOperation;
   147 	}
   148 
   149 /**
   150  * Static cleanup function
   151  */
   152 void CT_CurrentSoundFormatData::CleanupOperation( TAny* aAny )
   153 	{
   154 	RMdaDevSound::TCurrentSoundFormat* format = static_cast<RMdaDevSound::TCurrentSoundFormat*> ( aAny );
   155 	delete format;
   156 	}
   157 
   158 /**
   159 * Process a command read from the ini file
   160 *
   161 * @param aDataWrapper	test step requiring command to be processed
   162 * @param aCommand	the command to process
   163 * @param aSection		the entry in the ini file requiring the command to be processed
   164 *
   165 * @return ETrue if the command is processed
   166 */
   167 TBool CT_CurrentSoundFormatData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
   168 	{
   169 	TBool	ret=ETrue;
   170 	if ( aCommand==KCmdNew )
   171 		{
   172 		DoCmdNewL(aSection);
   173 		}
   174 	else if ( aCommand==KCmdDestructor )
   175 		{
   176 		DoCmdDestructor();
   177 		}
   178 	else if ( aCommand==KCmd_iRate_get )
   179 		{
   180 		DoCmd_iRate_get(aSection);
   181 		}
   182 	else if ( aCommand==KCmd_iEncoding_get )
   183 		{
   184 		DoCmd_iEncoding_getL(aSection);
   185 		}
   186 	else if ( aCommand==KCmd_iChannels_get )
   187 		{
   188 		DoCmd_iChannels_get(aSection);
   189 		}
   190 	else if ( aCommand==KCmd_iBufferSize_get )
   191 		{
   192 		DoCmd_iBufferSize_get(aSection);
   193 		}
   194 	else if ( aCommand==KCmd_iRate_set )
   195 		{
   196 		DoCmd_iRate_set(aSection);
   197 		}
   198 	else if ( aCommand==KCmd_iEncoding_set )
   199 		{
   200 		DoCmd_iEncoding_set(aSection);
   201 		}
   202 	else if ( aCommand==KCmd_iChannels_set )
   203 		{
   204 		DoCmd_iChannels_set(aSection);
   205 		}
   206 	else if ( aCommand==KCmd_iBufferSize_set )
   207 		{
   208 		DoCmd_iBufferSize_set(aSection);
   209 		}
   210 	else
   211 		{
   212 		ret=CDataWrapperBase::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
   213 		}
   214 
   215 	return ret;
   216 	}
   217 
   218 /**
   219  * Function for creating new instance of RMdaDevSound::TCurrentSoundFormat
   220  * 
   221  * @param aSection 			section name where can be indicated to create new
   222  * 							from SoundFormatsSupported object values
   223  * 							KNewFromSoundFormatsSupported - create from 
   224  * 							SoundFormatsSupported object
   225  *
   226  * @return					void
   227  *
   228  * @leave					System wide error
   229  */
   230 void CT_CurrentSoundFormatData::DoCmdNewL(const TDesC& aSection)
   231 	{
   232 	DoCleanup();
   233 	
   234 	TRAPD(err, iCurrentFormat = new (ELeave) RMdaDevSound::TCurrentSoundFormat());	
   235 	if ( err!=KErrNone )
   236 		{
   237 		ERR_PRINTF2(KLogNewError, err);
   238 		SetError(err);
   239 		}
   240 	else
   241 		{
   242 		INFO_PRINTF1(KLogNew);
   243 		TBool new_object;
   244 		if (GET_OPTIONAL_BOOL_PARAMETER(KNewFromSoundFormatsSupported(), aSection, new_object))
   245 			{
   246 			DoInitiateSupportedFormatsL(aSection);
   247 			}
   248 		}
   249 	}
   250 
   251 /**
   252  * Function to perform cleanup opertation
   253  */
   254 void CT_CurrentSoundFormatData::DoCmdDestructor()
   255 	{
   256 	DoCleanup();
   257 	}
   258 
   259 /**
   260  * Get function for iRate
   261  * 
   262  * @param aSection 			section name where expected value can be read
   263  *							KRateExpected - expected rate
   264  * 		
   265  * @return					void
   266  *
   267  * @leave					no
   268  */
   269 void CT_CurrentSoundFormatData::DoCmd_iRate_get(const TDesC& aSection)
   270 	{	
   271 	TInt	expected;
   272 	if (GET_OPTIONAL_INT_PARAMETER(KRateExpected(), aSection, expected))
   273 		{
   274 		if(iCurrentFormat->iRate != expected)
   275 			{
   276 			ERR_PRINTF3(_L("Expected result != iRate, expected=%d, iRate=%d"), expected, iCurrentFormat->iRate);
   277 			SetBlockResult(EFail);
   278 			}
   279 		else
   280 			{
   281 			INFO_PRINTF1(_L("iRate == expected result!"));
   282 			}
   283 		}
   284 	else
   285 		{
   286 		INFO_PRINTF2(_L("iRate=%d"), iCurrentFormat->iRate);
   287 		}
   288 	}
   289 	
   290 
   291 /**
   292  * Set function for iRate
   293  * 
   294  * @param aSection 			section name where value to set can be read
   295  * 							KRate - rate to set
   296  *
   297  * @return					void
   298  *
   299  * @leave					no
   300  */
   301 void CT_CurrentSoundFormatData::DoCmd_iRate_set(const TDesC& aSection)
   302 	{	
   303 	GET_MANDATORY_INT_PARAMETER(KRate(), aSection, iCurrentFormat->iRate);
   304 	}
   305 
   306 /**
   307  * Get function for iEncoding
   308  * 
   309  * @param aSection 			section name where expected value can be read
   310  * 							KEncodingExpected - expected encoding
   311  *
   312  * @return					void
   313  *
   314  * @leave					no
   315  */
   316 void CT_CurrentSoundFormatData::DoCmd_iEncoding_getL(const TDesC& aSection)
   317 	{	
   318 	TUint expEncoding;
   319 	if(GetOrFromConfig(aSection, KEncodingExpected(), TSoundUtil::iEnumTableSoundEncoding, expEncoding ))
   320 		{
   321 		TUint encodings = iCurrentFormat->iEncoding;
   322 		if(expEncoding != encodings)
   323 			{
   324 			ERR_PRINTF3(_L("iEncoding != expected result! iEncodings=0x%x, expected result=0x%x"), encodings, expEncoding);
   325 			SetBlockResult(EFail);
   326 			}
   327 		else
   328 			{
   329 			INFO_PRINTF3(_L("iEncoding == expected result!, iEncodings=0x%x, expected=0x%x"), encodings, expEncoding);
   330 			}			
   331 		}
   332 	else
   333 		{
   334 		INFO_PRINTF2(_L("iEncoding=0x%x"), iCurrentFormat->iEncoding);
   335 		}
   336 	}
   337 
   338 /**
   339  * Set function for iEncoding
   340  * 
   341  * @param aSection 			section name where value to set can be read
   342  * 							KEncoding - encoding to set
   343  *
   344  * @return					void
   345  *
   346  * @leave					no
   347  */
   348 void CT_CurrentSoundFormatData::DoCmd_iEncoding_set(const TDesC& aSection)
   349 	{	
   350 	TUint encoding;
   351 	if(GetOrFromConfig(aSection, KEncoding(), TSoundUtil::iEnumTableSoundEncoding, encoding ))
   352 		{
   353 		iCurrentFormat->iEncoding = (RMdaDevSound::TMdaSoundEncoding)encoding;
   354 		INFO_PRINTF2(_L("iEncoding=0x%x"), iCurrentFormat->iEncoding);
   355 		}
   356 	else
   357 		{
   358 		ERR_PRINTF1(_L("Could not get encoding from TMdaSoundEncoding in INI file"));
   359 		SetBlockResult(EFail);
   360 		}
   361 	}
   362 
   363 /**
   364  * Get function for iChannels
   365  * 
   366  * @param aSection 			section name where expected value can be read
   367  * 							KChannelsExpected - channels expected
   368  *
   369  * @return					void
   370  *
   371  * @leave					no
   372  */
   373 void CT_CurrentSoundFormatData::DoCmd_iChannels_get(const TDesC& aSection)
   374 	{
   375 	TInt	expected;
   376 	if (GET_OPTIONAL_INT_PARAMETER(KChannelsExpected(), aSection, expected))
   377 		{
   378 		if(iCurrentFormat->iChannels != expected)
   379 			{
   380 			ERR_PRINTF3(_L("Expected result != iChannels, expected=%d, iChannels=%d"), expected, iCurrentFormat->iChannels);
   381 			SetBlockResult(EFail);
   382 			}
   383 		else
   384 			{
   385 			INFO_PRINTF1(_L("iChannels == expected result!"));
   386 			}
   387 		}
   388 	else
   389 		{
   390 		INFO_PRINTF2(_L("iChannels=%d"), iCurrentFormat->iChannels);
   391 		}
   392 	}
   393 
   394 /**
   395  * Set function for iChannels
   396  * 
   397  * @param aSection 			section name where value to set can be read
   398  * 							KChannels - channels to set
   399  *
   400  * @return					void
   401  *
   402  * @leave					no
   403  */
   404 void CT_CurrentSoundFormatData::DoCmd_iChannels_set(const TDesC& aSection)
   405 	{
   406 	GET_MANDATORY_INT_PARAMETER(KChannels(), aSection, iCurrentFormat->iChannels);
   407 	}
   408 
   409 /**
   410  * Get function for iBufferSize
   411  * 
   412  * @param aSection 			section name where expected value can be read
   413  * 							KBufferSizeExpected - buffer size expected
   414  *
   415  * @return					void
   416  *
   417  * @leave					no
   418  */
   419 void CT_CurrentSoundFormatData::DoCmd_iBufferSize_get(const TDesC& aSection)
   420 	{
   421 	TInt	expected;
   422 	if (GET_OPTIONAL_INT_PARAMETER(KBufferSizeExpected(), aSection, expected))
   423 		{
   424 		if(iCurrentFormat->iBufferSize != expected)
   425 			{
   426 			ERR_PRINTF3(_L("Expected result != iBufferSize, expected=%d, iBufferSize=%d"), expected, iCurrentFormat->iBufferSize);
   427 			SetBlockResult(EFail);
   428 			}
   429 		else
   430 			{
   431 			INFO_PRINTF1(_L("iBufferSize == expected result!"));
   432 			}
   433 		}
   434 	else
   435 		{
   436 		INFO_PRINTF2(_L("iBufferSize=%d"), iCurrentFormat->iBufferSize);
   437 		}
   438 	}
   439 
   440 /**
   441  * Set function for iBufferSize
   442  * 
   443  * @param aSection 			section name where value to set can be read
   444  * 							KBufferSize - buffer size to set
   445  *
   446  * @return					void
   447  *
   448  * @leave					no
   449  */
   450 void CT_CurrentSoundFormatData::DoCmd_iBufferSize_set(const TDesC& aSection)
   451 	{
   452 	GET_MANDATORY_INT_PARAMETER(KBufferSize(), aSection, iCurrentFormat->iBufferSize);
   453 	}
   454 
   455 /**
   456  * Function to set current sound format with first valid values from 
   457  * TSoundFormatsSupported object. Function will set iBufferSize, iChannels,
   458  * iRate and iEncoding variable
   459  * 
   460  * @param aSection 			section name which contains SoundFormatsSupported object
   461  *							KSoundFormatsSupportedObject - SoundFormatsSupported object
   462  * 							name 
   463  * 
   464  * @return					void
   465  *
   466  * @leave					System wide error
   467  */
   468 void CT_CurrentSoundFormatData::DoInitiateSupportedFormatsL(const TDesC& aSection)
   469 	{
   470 	INFO_PRINTF1(_L("Calling DoInitiateSupportedFormats(), Setting iCurrentFormat variables from TSoundFormatsSupported"));
   471 	TPtrC		objectName;	
   472 	if (GET_MANDATORY_STRING_PARAMETER(KSoundFormatsSupportedObject, aSection, objectName))
   473 		{		
   474 		RMdaDevSound::TSoundFormatsSupported* soundFormat =
   475 			static_cast<RMdaDevSound::TSoundFormatsSupported*>(GetDataObjectL(objectName));	
   476 		iCurrentFormat->iBufferSize = soundFormat->iMinBufferSize;
   477 		iCurrentFormat->iChannels = soundFormat->iChannels;
   478 		iCurrentFormat->iRate = soundFormat->iMinRate;
   479 		if (soundFormat->iEncodings & RMdaDevSound::EMdaSoundEncoding8BitPCM) 
   480 			{
   481 			iCurrentFormat->iEncoding = RMdaDevSound::EMdaSoundEncoding8BitPCM;
   482 			}
   483 		else if(soundFormat->iEncodings & RMdaDevSound::EMdaSoundEncoding16BitPCM)
   484 			{
   485 			iCurrentFormat->iEncoding = RMdaDevSound::EMdaSoundEncoding16BitPCM;
   486 			}
   487 		else if(soundFormat->iEncodings & RMdaDevSound::EMdaSoundEncoding8BitALaw)
   488 			{
   489 			iCurrentFormat->iEncoding = RMdaDevSound::EMdaSoundEncoding8BitALaw;
   490 			}
   491 		else if(soundFormat->iEncodings & RMdaDevSound::EMdaSoundEncoding8BitMuLaw)
   492 			{
   493 			iCurrentFormat->iEncoding = RMdaDevSound::EMdaSoundEncoding8BitMuLaw;
   494 			}
   495 		}	
   496 	}