os/boardsupport/haitest/bspsvs/suite/bsp/sound/src/t_currentsoundformatdata.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/boardsupport/haitest/bspsvs/suite/bsp/sound/src/t_currentsoundformatdata.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,496 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +/**
    1.22 +@test
    1.23 +@internalComponent
    1.24 +
    1.25 +This contains CT_CurrentSoundFormatData
    1.26 +*/
    1.27 +
    1.28 +//	User includes
    1.29 +#include "t_currentsoundformatdata.h"
    1.30 +#include "sound_util.h"
    1.31 +
    1.32 +/*@{*/
    1.33 +///	Commands
    1.34 +_LIT(KCmdNew,						"new");
    1.35 +_LIT(KCmdDestructor,				"~");
    1.36 +_LIT(KCmd_iRate_get,				"irate_get");
    1.37 +_LIT(KCmd_iRate_set,				"irate_set");
    1.38 +_LIT(KCmd_iEncoding_get,			"iencoding_get");
    1.39 +_LIT(KCmd_iEncoding_set,			"iencoding_set");
    1.40 +_LIT(KCmd_iChannels_get,			"ichannels_get");
    1.41 +_LIT(KCmd_iChannels_set,			"ichannels_set");
    1.42 +_LIT(KCmd_iBufferSize_get,			"ibuffer_size_get");
    1.43 +_LIT(KCmd_iBufferSize_set,			"ibuffer_size_set");
    1.44 +
    1.45 +/*@{*/
    1.46 +///	Parameters
    1.47 +
    1.48 +_LIT(KRate,							"rate");
    1.49 +_LIT(KRateExpected,					"rate_expected");
    1.50 +_LIT(KEncoding,						"encoding");
    1.51 +_LIT(KEncodingExpected,				"encoding_expected");
    1.52 +_LIT(KChannels,						"channels");
    1.53 +_LIT(KChannelsExpected,				"channels_expected");
    1.54 +_LIT(KBufferSize,					"buffer_size");
    1.55 +_LIT(KBufferSizeExpected,			"buffer_size_expected");
    1.56 +// possible parameter for new to indicate loading settings from 
    1.57 +// SoundFormatsSupported object
    1.58 +_LIT(KNewFromSoundFormatsSupported,	"new_from_sound_formats_supported");
    1.59 +// for SoundFormatsSupported object
    1.60 +_LIT(KSoundFormatsSupportedObject,	"SoundFormatsSupportedObject");
    1.61 +// Enums declared in INI file
    1.62 +
    1.63 +///	Logging
    1.64 +_LIT(KLogNew,						"New object created successfully");
    1.65 +_LIT(KLogNewError,					"Error in creating object error code=%d");
    1.66 +/*@}*/
    1.67 +
    1.68 +/**
    1.69 + * Two phase constructor
    1.70 + */
    1.71 +CT_CurrentSoundFormatData* CT_CurrentSoundFormatData::NewL()
    1.72 +	{
    1.73 +	CT_CurrentSoundFormatData*	ret=new (ELeave) CT_CurrentSoundFormatData();
    1.74 +	CleanupStack::PushL(ret);
    1.75 +	ret->ConstructL();
    1.76 +	CleanupStack::Pop(ret);
    1.77 +	return ret;
    1.78 +	}
    1.79 +
    1.80 +/**
    1.81 +* Constructor. First phase construction
    1.82 +*/
    1.83 +CT_CurrentSoundFormatData::CT_CurrentSoundFormatData()
    1.84 +:	CDataWrapperBase()
    1.85 +,	iCurrentFormat(NULL)
    1.86 +	{
    1.87 +	}
    1.88 +
    1.89 +/**
    1.90 + * Second phase construction
    1.91 + */
    1.92 +void CT_CurrentSoundFormatData::ConstructL()
    1.93 +	{	
    1.94 +	}
    1.95 +
    1.96 +/**
    1.97 +* Destructor
    1.98 +*/
    1.99 +CT_CurrentSoundFormatData::~CT_CurrentSoundFormatData()
   1.100 +	{
   1.101 +	DoCleanup();
   1.102 +	}
   1.103 +
   1.104 +/**
   1.105 + * Helper method for doing cleanup operation
   1.106 + */
   1.107 +void CT_CurrentSoundFormatData::DoCleanup()
   1.108 +	{
   1.109 +	delete iCurrentFormat;
   1.110 +	iCurrentFormat=NULL;	
   1.111 +	}
   1.112 +
   1.113 +/**
   1.114 + * Return a pointer to the object that the data wraps
   1.115 + *
   1.116 + * @return pointer to the object that the data wraps
   1.117 + */
   1.118 +TAny* CT_CurrentSoundFormatData::GetObject()
   1.119 +
   1.120 +	{
   1.121 +	return iCurrentFormat;
   1.122 +	}
   1.123 +
   1.124 +/**
   1.125 + * Set the wrapped data object with new value
   1.126 + */
   1.127 +void CT_CurrentSoundFormatData::SetObjectL(TAny* aAny)
   1.128 +
   1.129 +	{
   1.130 +	DoCleanup();
   1.131 +	iCurrentFormat=static_cast<RMdaDevSound::TCurrentSoundFormat*>(aAny);
   1.132 +	}
   1.133 +
   1.134 +/**
   1.135 + * Clear the wrapped data object pointer w/o de-initialization
   1.136 + */
   1.137 +void CT_CurrentSoundFormatData::DisownObjectL()
   1.138 +
   1.139 +	{
   1.140 +	iCurrentFormat=NULL;
   1.141 +	}
   1.142 +
   1.143 +/**
   1.144 + * Return static cleanup function
   1.145 + */
   1.146 +inline TCleanupOperation CT_CurrentSoundFormatData::CleanupOperation()
   1.147 +
   1.148 +	{
   1.149 +	return CleanupOperation;
   1.150 +	}
   1.151 +
   1.152 +/**
   1.153 + * Static cleanup function
   1.154 + */
   1.155 +void CT_CurrentSoundFormatData::CleanupOperation( TAny* aAny )
   1.156 +	{
   1.157 +	RMdaDevSound::TCurrentSoundFormat* format = static_cast<RMdaDevSound::TCurrentSoundFormat*> ( aAny );
   1.158 +	delete format;
   1.159 +	}
   1.160 +
   1.161 +/**
   1.162 +* Process a command read from the ini file
   1.163 +*
   1.164 +* @param aDataWrapper	test step requiring command to be processed
   1.165 +* @param aCommand	the command to process
   1.166 +* @param aSection		the entry in the ini file requiring the command to be processed
   1.167 +*
   1.168 +* @return ETrue if the command is processed
   1.169 +*/
   1.170 +TBool CT_CurrentSoundFormatData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
   1.171 +	{
   1.172 +	TBool	ret=ETrue;
   1.173 +	if ( aCommand==KCmdNew )
   1.174 +		{
   1.175 +		DoCmdNewL(aSection);
   1.176 +		}
   1.177 +	else if ( aCommand==KCmdDestructor )
   1.178 +		{
   1.179 +		DoCmdDestructor();
   1.180 +		}
   1.181 +	else if ( aCommand==KCmd_iRate_get )
   1.182 +		{
   1.183 +		DoCmd_iRate_get(aSection);
   1.184 +		}
   1.185 +	else if ( aCommand==KCmd_iEncoding_get )
   1.186 +		{
   1.187 +		DoCmd_iEncoding_getL(aSection);
   1.188 +		}
   1.189 +	else if ( aCommand==KCmd_iChannels_get )
   1.190 +		{
   1.191 +		DoCmd_iChannels_get(aSection);
   1.192 +		}
   1.193 +	else if ( aCommand==KCmd_iBufferSize_get )
   1.194 +		{
   1.195 +		DoCmd_iBufferSize_get(aSection);
   1.196 +		}
   1.197 +	else if ( aCommand==KCmd_iRate_set )
   1.198 +		{
   1.199 +		DoCmd_iRate_set(aSection);
   1.200 +		}
   1.201 +	else if ( aCommand==KCmd_iEncoding_set )
   1.202 +		{
   1.203 +		DoCmd_iEncoding_set(aSection);
   1.204 +		}
   1.205 +	else if ( aCommand==KCmd_iChannels_set )
   1.206 +		{
   1.207 +		DoCmd_iChannels_set(aSection);
   1.208 +		}
   1.209 +	else if ( aCommand==KCmd_iBufferSize_set )
   1.210 +		{
   1.211 +		DoCmd_iBufferSize_set(aSection);
   1.212 +		}
   1.213 +	else
   1.214 +		{
   1.215 +		ret=CDataWrapperBase::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
   1.216 +		}
   1.217 +
   1.218 +	return ret;
   1.219 +	}
   1.220 +
   1.221 +/**
   1.222 + * Function for creating new instance of RMdaDevSound::TCurrentSoundFormat
   1.223 + * 
   1.224 + * @param aSection 			section name where can be indicated to create new
   1.225 + * 							from SoundFormatsSupported object values
   1.226 + * 							KNewFromSoundFormatsSupported - create from 
   1.227 + * 							SoundFormatsSupported object
   1.228 + *
   1.229 + * @return					void
   1.230 + *
   1.231 + * @leave					System wide error
   1.232 + */
   1.233 +void CT_CurrentSoundFormatData::DoCmdNewL(const TDesC& aSection)
   1.234 +	{
   1.235 +	DoCleanup();
   1.236 +	
   1.237 +	TRAPD(err, iCurrentFormat = new (ELeave) RMdaDevSound::TCurrentSoundFormat());	
   1.238 +	if ( err!=KErrNone )
   1.239 +		{
   1.240 +		ERR_PRINTF2(KLogNewError, err);
   1.241 +		SetError(err);
   1.242 +		}
   1.243 +	else
   1.244 +		{
   1.245 +		INFO_PRINTF1(KLogNew);
   1.246 +		TBool new_object;
   1.247 +		if (GET_OPTIONAL_BOOL_PARAMETER(KNewFromSoundFormatsSupported(), aSection, new_object))
   1.248 +			{
   1.249 +			DoInitiateSupportedFormatsL(aSection);
   1.250 +			}
   1.251 +		}
   1.252 +	}
   1.253 +
   1.254 +/**
   1.255 + * Function to perform cleanup opertation
   1.256 + */
   1.257 +void CT_CurrentSoundFormatData::DoCmdDestructor()
   1.258 +	{
   1.259 +	DoCleanup();
   1.260 +	}
   1.261 +
   1.262 +/**
   1.263 + * Get function for iRate
   1.264 + * 
   1.265 + * @param aSection 			section name where expected value can be read
   1.266 + *							KRateExpected - expected rate
   1.267 + * 		
   1.268 + * @return					void
   1.269 + *
   1.270 + * @leave					no
   1.271 + */
   1.272 +void CT_CurrentSoundFormatData::DoCmd_iRate_get(const TDesC& aSection)
   1.273 +	{	
   1.274 +	TInt	expected;
   1.275 +	if (GET_OPTIONAL_INT_PARAMETER(KRateExpected(), aSection, expected))
   1.276 +		{
   1.277 +		if(iCurrentFormat->iRate != expected)
   1.278 +			{
   1.279 +			ERR_PRINTF3(_L("Expected result != iRate, expected=%d, iRate=%d"), expected, iCurrentFormat->iRate);
   1.280 +			SetBlockResult(EFail);
   1.281 +			}
   1.282 +		else
   1.283 +			{
   1.284 +			INFO_PRINTF1(_L("iRate == expected result!"));
   1.285 +			}
   1.286 +		}
   1.287 +	else
   1.288 +		{
   1.289 +		INFO_PRINTF2(_L("iRate=%d"), iCurrentFormat->iRate);
   1.290 +		}
   1.291 +	}
   1.292 +	
   1.293 +
   1.294 +/**
   1.295 + * Set function for iRate
   1.296 + * 
   1.297 + * @param aSection 			section name where value to set can be read
   1.298 + * 							KRate - rate to set
   1.299 + *
   1.300 + * @return					void
   1.301 + *
   1.302 + * @leave					no
   1.303 + */
   1.304 +void CT_CurrentSoundFormatData::DoCmd_iRate_set(const TDesC& aSection)
   1.305 +	{	
   1.306 +	GET_MANDATORY_INT_PARAMETER(KRate(), aSection, iCurrentFormat->iRate);
   1.307 +	}
   1.308 +
   1.309 +/**
   1.310 + * Get function for iEncoding
   1.311 + * 
   1.312 + * @param aSection 			section name where expected value can be read
   1.313 + * 							KEncodingExpected - expected encoding
   1.314 + *
   1.315 + * @return					void
   1.316 + *
   1.317 + * @leave					no
   1.318 + */
   1.319 +void CT_CurrentSoundFormatData::DoCmd_iEncoding_getL(const TDesC& aSection)
   1.320 +	{	
   1.321 +	TUint expEncoding;
   1.322 +	if(GetOrFromConfig(aSection, KEncodingExpected(), TSoundUtil::iEnumTableSoundEncoding, expEncoding ))
   1.323 +		{
   1.324 +		TUint encodings = iCurrentFormat->iEncoding;
   1.325 +		if(expEncoding != encodings)
   1.326 +			{
   1.327 +			ERR_PRINTF3(_L("iEncoding != expected result! iEncodings=0x%x, expected result=0x%x"), encodings, expEncoding);
   1.328 +			SetBlockResult(EFail);
   1.329 +			}
   1.330 +		else
   1.331 +			{
   1.332 +			INFO_PRINTF3(_L("iEncoding == expected result!, iEncodings=0x%x, expected=0x%x"), encodings, expEncoding);
   1.333 +			}			
   1.334 +		}
   1.335 +	else
   1.336 +		{
   1.337 +		INFO_PRINTF2(_L("iEncoding=0x%x"), iCurrentFormat->iEncoding);
   1.338 +		}
   1.339 +	}
   1.340 +
   1.341 +/**
   1.342 + * Set function for iEncoding
   1.343 + * 
   1.344 + * @param aSection 			section name where value to set can be read
   1.345 + * 							KEncoding - encoding to set
   1.346 + *
   1.347 + * @return					void
   1.348 + *
   1.349 + * @leave					no
   1.350 + */
   1.351 +void CT_CurrentSoundFormatData::DoCmd_iEncoding_set(const TDesC& aSection)
   1.352 +	{	
   1.353 +	TUint encoding;
   1.354 +	if(GetOrFromConfig(aSection, KEncoding(), TSoundUtil::iEnumTableSoundEncoding, encoding ))
   1.355 +		{
   1.356 +		iCurrentFormat->iEncoding = (RMdaDevSound::TMdaSoundEncoding)encoding;
   1.357 +		INFO_PRINTF2(_L("iEncoding=0x%x"), iCurrentFormat->iEncoding);
   1.358 +		}
   1.359 +	else
   1.360 +		{
   1.361 +		ERR_PRINTF1(_L("Could not get encoding from TMdaSoundEncoding in INI file"));
   1.362 +		SetBlockResult(EFail);
   1.363 +		}
   1.364 +	}
   1.365 +
   1.366 +/**
   1.367 + * Get function for iChannels
   1.368 + * 
   1.369 + * @param aSection 			section name where expected value can be read
   1.370 + * 							KChannelsExpected - channels expected
   1.371 + *
   1.372 + * @return					void
   1.373 + *
   1.374 + * @leave					no
   1.375 + */
   1.376 +void CT_CurrentSoundFormatData::DoCmd_iChannels_get(const TDesC& aSection)
   1.377 +	{
   1.378 +	TInt	expected;
   1.379 +	if (GET_OPTIONAL_INT_PARAMETER(KChannelsExpected(), aSection, expected))
   1.380 +		{
   1.381 +		if(iCurrentFormat->iChannels != expected)
   1.382 +			{
   1.383 +			ERR_PRINTF3(_L("Expected result != iChannels, expected=%d, iChannels=%d"), expected, iCurrentFormat->iChannels);
   1.384 +			SetBlockResult(EFail);
   1.385 +			}
   1.386 +		else
   1.387 +			{
   1.388 +			INFO_PRINTF1(_L("iChannels == expected result!"));
   1.389 +			}
   1.390 +		}
   1.391 +	else
   1.392 +		{
   1.393 +		INFO_PRINTF2(_L("iChannels=%d"), iCurrentFormat->iChannels);
   1.394 +		}
   1.395 +	}
   1.396 +
   1.397 +/**
   1.398 + * Set function for iChannels
   1.399 + * 
   1.400 + * @param aSection 			section name where value to set can be read
   1.401 + * 							KChannels - channels to set
   1.402 + *
   1.403 + * @return					void
   1.404 + *
   1.405 + * @leave					no
   1.406 + */
   1.407 +void CT_CurrentSoundFormatData::DoCmd_iChannels_set(const TDesC& aSection)
   1.408 +	{
   1.409 +	GET_MANDATORY_INT_PARAMETER(KChannels(), aSection, iCurrentFormat->iChannels);
   1.410 +	}
   1.411 +
   1.412 +/**
   1.413 + * Get function for iBufferSize
   1.414 + * 
   1.415 + * @param aSection 			section name where expected value can be read
   1.416 + * 							KBufferSizeExpected - buffer size expected
   1.417 + *
   1.418 + * @return					void
   1.419 + *
   1.420 + * @leave					no
   1.421 + */
   1.422 +void CT_CurrentSoundFormatData::DoCmd_iBufferSize_get(const TDesC& aSection)
   1.423 +	{
   1.424 +	TInt	expected;
   1.425 +	if (GET_OPTIONAL_INT_PARAMETER(KBufferSizeExpected(), aSection, expected))
   1.426 +		{
   1.427 +		if(iCurrentFormat->iBufferSize != expected)
   1.428 +			{
   1.429 +			ERR_PRINTF3(_L("Expected result != iBufferSize, expected=%d, iBufferSize=%d"), expected, iCurrentFormat->iBufferSize);
   1.430 +			SetBlockResult(EFail);
   1.431 +			}
   1.432 +		else
   1.433 +			{
   1.434 +			INFO_PRINTF1(_L("iBufferSize == expected result!"));
   1.435 +			}
   1.436 +		}
   1.437 +	else
   1.438 +		{
   1.439 +		INFO_PRINTF2(_L("iBufferSize=%d"), iCurrentFormat->iBufferSize);
   1.440 +		}
   1.441 +	}
   1.442 +
   1.443 +/**
   1.444 + * Set function for iBufferSize
   1.445 + * 
   1.446 + * @param aSection 			section name where value to set can be read
   1.447 + * 							KBufferSize - buffer size to set
   1.448 + *
   1.449 + * @return					void
   1.450 + *
   1.451 + * @leave					no
   1.452 + */
   1.453 +void CT_CurrentSoundFormatData::DoCmd_iBufferSize_set(const TDesC& aSection)
   1.454 +	{
   1.455 +	GET_MANDATORY_INT_PARAMETER(KBufferSize(), aSection, iCurrentFormat->iBufferSize);
   1.456 +	}
   1.457 +
   1.458 +/**
   1.459 + * Function to set current sound format with first valid values from 
   1.460 + * TSoundFormatsSupported object. Function will set iBufferSize, iChannels,
   1.461 + * iRate and iEncoding variable
   1.462 + * 
   1.463 + * @param aSection 			section name which contains SoundFormatsSupported object
   1.464 + *							KSoundFormatsSupportedObject - SoundFormatsSupported object
   1.465 + * 							name 
   1.466 + * 
   1.467 + * @return					void
   1.468 + *
   1.469 + * @leave					System wide error
   1.470 + */
   1.471 +void CT_CurrentSoundFormatData::DoInitiateSupportedFormatsL(const TDesC& aSection)
   1.472 +	{
   1.473 +	INFO_PRINTF1(_L("Calling DoInitiateSupportedFormats(), Setting iCurrentFormat variables from TSoundFormatsSupported"));
   1.474 +	TPtrC		objectName;	
   1.475 +	if (GET_MANDATORY_STRING_PARAMETER(KSoundFormatsSupportedObject, aSection, objectName))
   1.476 +		{		
   1.477 +		RMdaDevSound::TSoundFormatsSupported* soundFormat =
   1.478 +			static_cast<RMdaDevSound::TSoundFormatsSupported*>(GetDataObjectL(objectName));	
   1.479 +		iCurrentFormat->iBufferSize = soundFormat->iMinBufferSize;
   1.480 +		iCurrentFormat->iChannels = soundFormat->iChannels;
   1.481 +		iCurrentFormat->iRate = soundFormat->iMinRate;
   1.482 +		if (soundFormat->iEncodings & RMdaDevSound::EMdaSoundEncoding8BitPCM) 
   1.483 +			{
   1.484 +			iCurrentFormat->iEncoding = RMdaDevSound::EMdaSoundEncoding8BitPCM;
   1.485 +			}
   1.486 +		else if(soundFormat->iEncodings & RMdaDevSound::EMdaSoundEncoding16BitPCM)
   1.487 +			{
   1.488 +			iCurrentFormat->iEncoding = RMdaDevSound::EMdaSoundEncoding16BitPCM;
   1.489 +			}
   1.490 +		else if(soundFormat->iEncodings & RMdaDevSound::EMdaSoundEncoding8BitALaw)
   1.491 +			{
   1.492 +			iCurrentFormat->iEncoding = RMdaDevSound::EMdaSoundEncoding8BitALaw;
   1.493 +			}
   1.494 +		else if(soundFormat->iEncodings & RMdaDevSound::EMdaSoundEncoding8BitMuLaw)
   1.495 +			{
   1.496 +			iCurrentFormat->iEncoding = RMdaDevSound::EMdaSoundEncoding8BitMuLaw;
   1.497 +			}
   1.498 +		}	
   1.499 +	}