Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 This contains CT_CurrentSoundFormatData
26 #include "t_currentsoundformatdata.h"
27 #include "sound_util.h"
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");
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
61 _LIT(KLogNew, "New object created successfully");
62 _LIT(KLogNewError, "Error in creating object error code=%d");
66 * Two phase constructor
68 CT_CurrentSoundFormatData* CT_CurrentSoundFormatData::NewL()
70 CT_CurrentSoundFormatData* ret=new (ELeave) CT_CurrentSoundFormatData();
71 CleanupStack::PushL(ret);
73 CleanupStack::Pop(ret);
78 * Constructor. First phase construction
80 CT_CurrentSoundFormatData::CT_CurrentSoundFormatData()
82 , iCurrentFormat(NULL)
87 * Second phase construction
89 void CT_CurrentSoundFormatData::ConstructL()
96 CT_CurrentSoundFormatData::~CT_CurrentSoundFormatData()
102 * Helper method for doing cleanup operation
104 void CT_CurrentSoundFormatData::DoCleanup()
106 delete iCurrentFormat;
111 * Return a pointer to the object that the data wraps
113 * @return pointer to the object that the data wraps
115 TAny* CT_CurrentSoundFormatData::GetObject()
118 return iCurrentFormat;
122 * Set the wrapped data object with new value
124 void CT_CurrentSoundFormatData::SetObjectL(TAny* aAny)
128 iCurrentFormat=static_cast<RMdaDevSound::TCurrentSoundFormat*>(aAny);
132 * Clear the wrapped data object pointer w/o de-initialization
134 void CT_CurrentSoundFormatData::DisownObjectL()
141 * Return static cleanup function
143 inline TCleanupOperation CT_CurrentSoundFormatData::CleanupOperation()
146 return CleanupOperation;
150 * Static cleanup function
152 void CT_CurrentSoundFormatData::CleanupOperation( TAny* aAny )
154 RMdaDevSound::TCurrentSoundFormat* format = static_cast<RMdaDevSound::TCurrentSoundFormat*> ( aAny );
159 * Process a command read from the ini file
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
165 * @return ETrue if the command is processed
167 TBool CT_CurrentSoundFormatData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
170 if ( aCommand==KCmdNew )
174 else if ( aCommand==KCmdDestructor )
178 else if ( aCommand==KCmd_iRate_get )
180 DoCmd_iRate_get(aSection);
182 else if ( aCommand==KCmd_iEncoding_get )
184 DoCmd_iEncoding_getL(aSection);
186 else if ( aCommand==KCmd_iChannels_get )
188 DoCmd_iChannels_get(aSection);
190 else if ( aCommand==KCmd_iBufferSize_get )
192 DoCmd_iBufferSize_get(aSection);
194 else if ( aCommand==KCmd_iRate_set )
196 DoCmd_iRate_set(aSection);
198 else if ( aCommand==KCmd_iEncoding_set )
200 DoCmd_iEncoding_set(aSection);
202 else if ( aCommand==KCmd_iChannels_set )
204 DoCmd_iChannels_set(aSection);
206 else if ( aCommand==KCmd_iBufferSize_set )
208 DoCmd_iBufferSize_set(aSection);
212 ret=CDataWrapperBase::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
219 * Function for creating new instance of RMdaDevSound::TCurrentSoundFormat
221 * @param aSection section name where can be indicated to create new
222 * from SoundFormatsSupported object values
223 * KNewFromSoundFormatsSupported - create from
224 * SoundFormatsSupported object
228 * @leave System wide error
230 void CT_CurrentSoundFormatData::DoCmdNewL(const TDesC& aSection)
234 TRAPD(err, iCurrentFormat = new (ELeave) RMdaDevSound::TCurrentSoundFormat());
237 ERR_PRINTF2(KLogNewError, err);
242 INFO_PRINTF1(KLogNew);
244 if (GET_OPTIONAL_BOOL_PARAMETER(KNewFromSoundFormatsSupported(), aSection, new_object))
246 DoInitiateSupportedFormatsL(aSection);
252 * Function to perform cleanup opertation
254 void CT_CurrentSoundFormatData::DoCmdDestructor()
260 * Get function for iRate
262 * @param aSection section name where expected value can be read
263 * KRateExpected - expected rate
269 void CT_CurrentSoundFormatData::DoCmd_iRate_get(const TDesC& aSection)
272 if (GET_OPTIONAL_INT_PARAMETER(KRateExpected(), aSection, expected))
274 if(iCurrentFormat->iRate != expected)
276 ERR_PRINTF3(_L("Expected result != iRate, expected=%d, iRate=%d"), expected, iCurrentFormat->iRate);
277 SetBlockResult(EFail);
281 INFO_PRINTF1(_L("iRate == expected result!"));
286 INFO_PRINTF2(_L("iRate=%d"), iCurrentFormat->iRate);
292 * Set function for iRate
294 * @param aSection section name where value to set can be read
295 * KRate - rate to set
301 void CT_CurrentSoundFormatData::DoCmd_iRate_set(const TDesC& aSection)
303 GET_MANDATORY_INT_PARAMETER(KRate(), aSection, iCurrentFormat->iRate);
307 * Get function for iEncoding
309 * @param aSection section name where expected value can be read
310 * KEncodingExpected - expected encoding
316 void CT_CurrentSoundFormatData::DoCmd_iEncoding_getL(const TDesC& aSection)
319 if(GetOrFromConfig(aSection, KEncodingExpected(), TSoundUtil::iEnumTableSoundEncoding, expEncoding ))
321 TUint encodings = iCurrentFormat->iEncoding;
322 if(expEncoding != encodings)
324 ERR_PRINTF3(_L("iEncoding != expected result! iEncodings=0x%x, expected result=0x%x"), encodings, expEncoding);
325 SetBlockResult(EFail);
329 INFO_PRINTF3(_L("iEncoding == expected result!, iEncodings=0x%x, expected=0x%x"), encodings, expEncoding);
334 INFO_PRINTF2(_L("iEncoding=0x%x"), iCurrentFormat->iEncoding);
339 * Set function for iEncoding
341 * @param aSection section name where value to set can be read
342 * KEncoding - encoding to set
348 void CT_CurrentSoundFormatData::DoCmd_iEncoding_set(const TDesC& aSection)
351 if(GetOrFromConfig(aSection, KEncoding(), TSoundUtil::iEnumTableSoundEncoding, encoding ))
353 iCurrentFormat->iEncoding = (RMdaDevSound::TMdaSoundEncoding)encoding;
354 INFO_PRINTF2(_L("iEncoding=0x%x"), iCurrentFormat->iEncoding);
358 ERR_PRINTF1(_L("Could not get encoding from TMdaSoundEncoding in INI file"));
359 SetBlockResult(EFail);
364 * Get function for iChannels
366 * @param aSection section name where expected value can be read
367 * KChannelsExpected - channels expected
373 void CT_CurrentSoundFormatData::DoCmd_iChannels_get(const TDesC& aSection)
376 if (GET_OPTIONAL_INT_PARAMETER(KChannelsExpected(), aSection, expected))
378 if(iCurrentFormat->iChannels != expected)
380 ERR_PRINTF3(_L("Expected result != iChannels, expected=%d, iChannels=%d"), expected, iCurrentFormat->iChannels);
381 SetBlockResult(EFail);
385 INFO_PRINTF1(_L("iChannels == expected result!"));
390 INFO_PRINTF2(_L("iChannels=%d"), iCurrentFormat->iChannels);
395 * Set function for iChannels
397 * @param aSection section name where value to set can be read
398 * KChannels - channels to set
404 void CT_CurrentSoundFormatData::DoCmd_iChannels_set(const TDesC& aSection)
406 GET_MANDATORY_INT_PARAMETER(KChannels(), aSection, iCurrentFormat->iChannels);
410 * Get function for iBufferSize
412 * @param aSection section name where expected value can be read
413 * KBufferSizeExpected - buffer size expected
419 void CT_CurrentSoundFormatData::DoCmd_iBufferSize_get(const TDesC& aSection)
422 if (GET_OPTIONAL_INT_PARAMETER(KBufferSizeExpected(), aSection, expected))
424 if(iCurrentFormat->iBufferSize != expected)
426 ERR_PRINTF3(_L("Expected result != iBufferSize, expected=%d, iBufferSize=%d"), expected, iCurrentFormat->iBufferSize);
427 SetBlockResult(EFail);
431 INFO_PRINTF1(_L("iBufferSize == expected result!"));
436 INFO_PRINTF2(_L("iBufferSize=%d"), iCurrentFormat->iBufferSize);
441 * Set function for iBufferSize
443 * @param aSection section name where value to set can be read
444 * KBufferSize - buffer size to set
450 void CT_CurrentSoundFormatData::DoCmd_iBufferSize_set(const TDesC& aSection)
452 GET_MANDATORY_INT_PARAMETER(KBufferSize(), aSection, iCurrentFormat->iBufferSize);
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
460 * @param aSection section name which contains SoundFormatsSupported object
461 * KSoundFormatsSupportedObject - SoundFormatsSupported object
466 * @leave System wide error
468 void CT_CurrentSoundFormatData::DoInitiateSupportedFormatsL(const TDesC& aSection)
470 INFO_PRINTF1(_L("Calling DoInitiateSupportedFormats(), Setting iCurrentFormat variables from TSoundFormatsSupported"));
472 if (GET_MANDATORY_STRING_PARAMETER(KSoundFormatsSupportedObject, aSection, objectName))
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)
481 iCurrentFormat->iEncoding = RMdaDevSound::EMdaSoundEncoding8BitPCM;
483 else if(soundFormat->iEncodings & RMdaDevSound::EMdaSoundEncoding16BitPCM)
485 iCurrentFormat->iEncoding = RMdaDevSound::EMdaSoundEncoding16BitPCM;
487 else if(soundFormat->iEncodings & RMdaDevSound::EMdaSoundEncoding8BitALaw)
489 iCurrentFormat->iEncoding = RMdaDevSound::EMdaSoundEncoding8BitALaw;
491 else if(soundFormat->iEncodings & RMdaDevSound::EMdaSoundEncoding8BitMuLaw)
493 iCurrentFormat->iEncoding = RMdaDevSound::EMdaSoundEncoding8BitMuLaw;