os/boardsupport/haitest/bspsvs/suite/bsp/sound/src/t_mdadevsounddata.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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_MdaDevSoundData
    23 */
    24 
    25 //	User includes
    26 #include "t_mdadevsounddata.h"
    27 #include "t_sounddriverserver.h"
    28 
    29 /*@{*/
    30 ///	Parameters
    31 
    32 _LIT(KSoundFormatsSupportedObject,	"SoundFormatsSupportedObject");
    33 _LIT(KCurrentSoundFormatObject,		"CurrentSoundFormatObject");
    34 
    35 _LIT(KUUnit,						"unit");
    36 _LIT(KUUnitEnum,					"UnitEnum");
    37 _LIT(KUToFile,						"to_file");
    38 _LIT(KUBlockSize,					"block_size");
    39 _LIT(KUVersion,						"version");
    40 
    41 _LIT(KUFromFile,					"from_file");
    42 _LIT(KUDataSize,					"data_size");
    43 _LIT(KUVolumeExpected,				"volume_expected");
    44 _LIT(KUVolume,						"volume");
    45 _LIT(KUBytesPlayed,					"bytes_played");
    46 _LIT(KUCancel,						"cancel");
    47 _LIT(KUFlush,						"flush");
    48 
    49 _LIT(KUSoundLevel,					"sound_level");
    50 _LIT(KUSoundLevelExpected,			"sound_level_expected");
    51 
    52 _LIT(KUFileToDelete,				"file_to_delete");
    53 
    54 _LIT(KLDDName,						"ldd");
    55 _LIT(KPDDName,						"pdd");
    56 
    57 
    58 
    59 /*@{*/
    60 ///	Commands
    61 _LIT(KCmdUtilityDeleteFile,			"utilityDeleteFile");
    62 
    63 _LIT(KCmdRecordData,				"RecordData");
    64 _LIT(KCmdCancelRecordData,			"CancelRecordData");
    65 _LIT(KCmdFlushRecordBuffer,			"FlushRecordBuffer");
    66 _LIT(KCmdRecordLevel,				"RecordLevel");
    67 _LIT(KCmdSetRecordLevel,			"SetRecordLevel");
    68 _LIT(KCmdNotifyRecordError,			"NotifyRecordError");
    69 _LIT(KCmdCancelNotifyRecordError,	"CancelNotifyRecordError");
    70 
    71 _LIT(KCmdPlayVolume,				"PlayVolume");
    72 _LIT(KCmdSetPlayVolume,				"SetPlayVolume");
    73 _LIT(KCmdPlayData,					"PlayData");
    74 _LIT(KCmdCancelPlayData,			"CancelPlayData");
    75 _LIT(KCmdFlushPlayBuffer,			"FlushPlayBuffer");
    76 _LIT(KCmdNotifyPlayError,			"NotifyPlayError");
    77 _LIT(KCmdCancelNotifyPlayError,		"CancelNotifyPlayError");
    78 
    79 _LIT(KCmdBytesPlayed,				"BytesPlayed");
    80 _LIT(KCmdResetBytesPlayed,			"ResetBytesPlayed");
    81 _LIT(KCmdPausePlayBuffer,			"PausePlayBuffer");
    82 _LIT(KCmdResumePlaying,				"ResumePlaying");
    83 
    84 _LIT(KCmdPlayFormatsSupported,		"PlayFormatsSupported");
    85 _LIT(KCmdGetPlayFormat,				"GetPlayFormat");
    86 _LIT(KCmdSetPlayFormat,				"SetPlayFormat");
    87 _LIT(KCmdRecordFormatsSupported,	"RecordFormatsSupported");
    88 _LIT(KCmdGetRecordFormat,			"GetRecordFormat");
    89 _LIT(KCmdSetRecordFormat,			"SetRecordFormat");
    90 
    91 _LIT(KCmdNew,						"new");
    92 _LIT(KCmdOpen,						"Open");
    93 _LIT(KCmdClose,						"Close");
    94 _LIT(KCmdDestructor,				"~");
    95 _LIT(KCmdIsMdaSound,				"IsMdaSound");
    96 _LIT(KCmdVersionRequired,			"VersionRequired");
    97 /*@}*/
    98 
    99 /**
   100  * Two phase constructor
   101  */
   102 CT_MdaDevSoundData* CT_MdaDevSoundData::NewL(RMdaDevSound* aServerStore)
   103 	{
   104 	CT_MdaDevSoundData*	ret = new (ELeave) CT_MdaDevSoundData(aServerStore);
   105 	CleanupStack::PushL(ret);
   106 	ret->ConstructL();
   107 	CleanupStack::Pop(ret);
   108 	return ret;	
   109 	}
   110 
   111 /**
   112  * Protected constructor. First phase construction
   113  */
   114 CT_MdaDevSoundData::CT_MdaDevSoundData(RMdaDevSound* aServerStore)
   115 	:iServerStore(aServerStore)
   116 	{
   117 	}
   118 
   119 /**
   120 * Protected constructor. Second phase construction
   121 */
   122 void CT_MdaDevSoundData::ConstructL()
   123 	{
   124 	}
   125 
   126 /**
   127  * Destructor.
   128  */
   129 CT_MdaDevSoundData::~CT_MdaDevSoundData()
   130 	{	
   131 	DoCleanup();
   132 
   133 	iNotifyPlayError.ResetAndDestroy();
   134 	iNotifyRecordError.ResetAndDestroy();
   135 	iPlay.ResetAndDestroy();
   136 	iRecord.ResetAndDestroy();
   137 	}
   138 
   139 /**
   140  * Contains cleanup implementation
   141  */
   142 void CT_MdaDevSoundData::DoCleanup()
   143 	{
   144 	if(iMdaDevSound)
   145 		{
   146 		INFO_PRINTF1(_L("Deleting current RMdaDevSound"));
   147 		delete iMdaDevSound;
   148 		iMdaDevSound = NULL;
   149 		}
   150 	}
   151 
   152 /**
   153  * Return a pointer to the object that the data wraps
   154  *
   155  * @return pointer to the object that the data wraps
   156  */
   157 TAny* CT_MdaDevSoundData::GetObject()
   158 	{
   159 	return iMdaDevSound;
   160 	}
   161 
   162 /**
   163  * Set the wrapped data object with new value
   164  */
   165 void CT_MdaDevSoundData::SetObjectL( TAny* aAny )
   166 	{
   167 	DoCleanup();
   168 	iMdaDevSound = static_cast<RMdaDevSound*> ( aAny );
   169 	*iServerStore = *iMdaDevSound; 
   170 	}
   171 
   172 /**
   173  * Clear the wrapped data object pointer w/o de-initialization
   174  */
   175 void CT_MdaDevSoundData::DisownObjectL()
   176 	{
   177 	iMdaDevSound = NULL;
   178 	iServerStore->SetHandle(KNullHandle);
   179 	}
   180 
   181 /**
   182  * Return static cleanup function
   183  */
   184 inline TCleanupOperation CT_MdaDevSoundData::CleanupOperation()
   185 	{
   186 	return CleanupOperation;
   187 	}
   188 
   189 /**
   190  * Static cleanup function
   191  */
   192 void CT_MdaDevSoundData::CleanupOperation( TAny* aAny )
   193 	{
   194 	RMdaDevSound* sound = static_cast<RMdaDevSound*> ( aAny );
   195 	delete sound;
   196 	}
   197 
   198 /**
   199  * Process a command read from the ini file
   200  *
   201  * @param aCommand	the command to process
   202  * @param aSection		the entry in the ini file requiring the command to be processed
   203  *
   204  * @return ETrue if the command is processed
   205  */
   206 TBool CT_MdaDevSoundData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
   207 	{
   208 	TBool	ret=ETrue;
   209 	if (aCommand == KCmdNew)
   210 		{
   211 		DoCmdNewL();
   212 		}
   213 	else if (aCommand == KCmdClose)
   214 		{
   215 		DoCmdClose();
   216 		}
   217 	else if (aCommand == KCmdDestructor)
   218 		{
   219 		DoCmdDestructor();
   220 		}
   221 	else if (aCommand == KCmdOpen)
   222 		{
   223 		DoCmdOpen(aSection);
   224 		}
   225 	else if (aCommand == KCmdIsMdaSound)
   226 		{
   227 		DoCmdIsMdaSound();
   228 		}
   229 	else if (aCommand == KCmdVersionRequired)
   230 		{
   231 		DoCmdVersionRequired(aSection);
   232 		}
   233 	else if (aCommand == KCmdPlayFormatsSupported)
   234 		{
   235 		DoCmdPlayFormatsSupportedL(aSection);
   236 		}
   237 	else if (aCommand == KCmdGetPlayFormat)
   238 		{
   239 		DoCmdGetPlayFormatL(aSection);
   240 		}
   241 	else if (aCommand == KCmdSetPlayFormat)
   242 		{
   243 		DoCmdSetPlayFormatL(aSection);
   244 		}
   245 	else if (aCommand == KCmdRecordFormatsSupported)
   246 		{
   247 		DoCmdRecordFormatsSupportedL(aSection);
   248 		}
   249 	else if (aCommand == KCmdGetRecordFormat)
   250 		{
   251 		DoCmdGetRecordFormatL(aSection);
   252 		}
   253 	else if (aCommand == KCmdSetRecordFormat)
   254 		{
   255 		DoCmdSetRecordFormatL(aSection);
   256 		}
   257 	else if (aCommand == KCmdPlayVolume)
   258 		{
   259 		DoCmdPlayVolume(aSection);
   260 		}
   261 	else if (aCommand == KCmdSetPlayVolume)
   262 		{
   263 		DoCmdSetPlayVolume(aSection);
   264 		}
   265 	else if (aCommand == KCmdPlayData)
   266 		{
   267 		DoCmdPlayDataL(aSection, aAsyncErrorIndex);
   268 		}
   269 	else if (aCommand == KCmdCancelPlayData)
   270 		{
   271 		DoCmdCancelPlayData();
   272 		}
   273 	else if (aCommand == KCmdFlushPlayBuffer)
   274 		{
   275 		DoCmdFlushPlayBuffer();
   276 		}
   277 	else if (aCommand == KCmdFlushPlayBuffer)
   278 		{
   279 		DoCmdNotifyPlayErrorL(aAsyncErrorIndex);
   280 		}
   281 	else if (aCommand == KCmdFlushPlayBuffer)
   282 		{
   283 		DoCmdCancelNotifyPlayError();
   284 		}
   285 	else if (aCommand == KCmdNotifyPlayError)
   286 		{
   287 		DoCmdNotifyPlayErrorL(aAsyncErrorIndex);
   288 		}
   289 	else if (aCommand == KCmdCancelNotifyPlayError)
   290 		{
   291 		DoCmdCancelNotifyPlayError();
   292 		}
   293 	else if (aCommand == KCmdBytesPlayed)
   294 		{
   295 		DoCmdBytesPlayed(aSection);
   296 		}
   297 	else if (aCommand == KCmdResetBytesPlayed)
   298 		{
   299 		DoCmdResetBytesPlayed();
   300 		}
   301 	else if (aCommand == KCmdPausePlayBuffer)
   302 		{
   303 		DoCmdPausePlayBuffer();
   304 		}
   305 	else if (aCommand == KCmdResumePlaying)
   306 		{
   307 		DoCmdResumePlaying();
   308 		}
   309 	else if (aCommand == KCmdRecordData)
   310 		{
   311 		DoCmdRecordDataL(aSection, aAsyncErrorIndex);
   312 		}
   313 	else if (aCommand == KCmdCancelRecordData)
   314 		{
   315 		DoCmdCancelRecordData();
   316 		}
   317 	else if (aCommand == KCmdFlushRecordBuffer)
   318 		{
   319 		DoCmdFlushRecordBuffer();
   320 		}
   321 	else if (aCommand == KCmdRecordLevel)
   322 		{
   323 		DoCmdRecordLevel(aSection);
   324 		}
   325 	else if (aCommand == KCmdSetRecordLevel)
   326 		{
   327 		DoCmdSetRecordLevel(aSection);
   328 		}
   329 	else if (aCommand == KCmdNotifyRecordError)
   330 		{
   331 		DoCmdNotifyRecordErrorL(aAsyncErrorIndex);
   332 		}
   333 	else if (aCommand == KCmdCancelNotifyRecordError)
   334 		{
   335 		DoCmdCancelNotifyRecordError();
   336 		}
   337 	else if (aCommand == KCmdUtilityDeleteFile)
   338 		{
   339 		DoCmdUtilityDeleteFileL(aSection);
   340 		}
   341 	else
   342 		{
   343 		ret=CDataWrapperBase::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
   344 		}
   345 
   346 	return ret;
   347 	}
   348 
   349 /** 
   350  * Creates new RMdaDevSound class instance 
   351  */
   352 void CT_MdaDevSoundData::DoCmdNewL()
   353 	{
   354 	INFO_PRINTF1(_L("Create new RMdaDevSound class instance"));
   355 	
   356 	//Deletes previous RMdaDevsound class instance if it was already created.
   357 	DoCleanup();
   358 
   359 	// do create
   360 	TRAPD(err, iMdaDevSound = new (ELeave) RMdaDevSound());
   361 	if ( err!=KErrNone )
   362 		{
   363 		ERR_PRINTF2(_L("new error %d"), err);
   364 		SetError( err );
   365 		}
   366 	}
   367 
   368 /** 
   369  * Close RMdaDevSound handle 
   370  */
   371 void CT_MdaDevSoundData::DoCmdClose()
   372 	{
   373 	INFO_PRINTF1(_L("Closing RMdaDevSound"));
   374 	iServerStore->SetHandle(KNullHandle);
   375 	iMdaDevSound->Close();
   376 	}
   377 
   378 /** 
   379  * Destroy RMdaDevSound the object 
   380  */
   381 void CT_MdaDevSoundData::DoCmdDestructor()
   382 	{
   383 	INFO_PRINTF1(_L("Destroying the RMdaDevSound object"));
   384 	//close RMdaDevSound first
   385 	iServerStore->SetHandle(KNullHandle);
   386 	iMdaDevSound->Close();
   387 	DoCleanup();
   388 	}
   389 
   390 /** 
   391  * Connects a client to the sound driver server 
   392  * 
   393  * @param aSection 			section name which contains unit
   394  * 							KUUnit - unit to open
   395  *
   396  * @return					void
   397  *
   398  * @leave					no
   399  */
   400 void CT_MdaDevSoundData::DoCmdOpen(const TDesC& aSection)
   401 	{
   402 	//Loading device drivers
   403 	TPtrC lddName;
   404 	TPtrC pddName;
   405 	if(GET_OPTIONAL_STRING_PARAMETER(KLDDName(), aSection, lddName) &&
   406 		GET_OPTIONAL_STRING_PARAMETER(KPDDName(), aSection, pddName))
   407 		{
   408 		TInt err = TSoundUtil::LoadSoundDrivers(lddName, pddName);	
   409 		if( (err != KErrNone) && (err != KErrAlreadyExists ))
   410 			{
   411 			ERR_PRINTF4(_L("Open() -> LoadSoundDrivers(%S, %S) error %d"), &lddName, &pddName, err);
   412 			SetError( err );		
   413 			}
   414 		}
   415 	//Finish Loading device drivers
   416 			
   417 	TInt	unit = KNullUnit;
   418 	TPtrC	unitName;
   419 	if (GET_OPTIONAL_STRING_PARAMETER(KUUnit(), aSection, unitName))
   420 		{
   421 		GetHexFromConfig(KUUnitEnum(), unitName, unit );
   422 		}
   423 	TInt err = iMdaDevSound->Open(unit);
   424 	*iServerStore = *iMdaDevSound;
   425 	INFO_PRINTF2(_L("Call Open(unit = %d)"), unit);
   426 	
   427 	if ( err!=KErrNone )
   428 		{
   429 		ERR_PRINTF2(_L("Open() error %d"), err);
   430 		SetError( err );
   431 		}		
   432 	}	
   433 	
   434 	
   435 	
   436 
   437 /** 
   438  * Checks if driver is MdaSound
   439  */
   440 void CT_MdaDevSoundData::DoCmdIsMdaSound()
   441 	{
   442 	INFO_PRINTF1(_L("CT_MdaDevSoundData::DoCmdIsMdaSound Called"));
   443 	
   444 	TInt err = iMdaDevSound->IsMdaSound();	
   445 	if(err!=KErrNone)
   446 		{
   447 		ERR_PRINTF2(_L("IsMdaSound() error %d"), err);
   448 		SetError(err);
   449 		}
   450 	
   451 	}
   452 
   453 /** 
   454  * Checks driver version required
   455  * 
   456  * @param aSection 			section name with expected version
   457  *							KUVersion - version expected
   458  * 
   459  * @return					void
   460  *
   461  * @leave					no
   462  */
   463 void CT_MdaDevSoundData::DoCmdVersionRequired(const TDesC& aSection)
   464 	{
   465 	INFO_PRINTF1(_L("CT_MdaDevSoundData::VersionRequired Called"));
   466 	
   467 	TVersion version = iMdaDevSound->VersionRequired();
   468 	TPtrC versionNameFromSystem = version.Name();
   469 	TPtrC versionName;
   470 	if(GET_MANDATORY_STRING_PARAMETER(KUVersion(), aSection, versionName))
   471 		{
   472 		if(versionNameFromSystem != versionName)
   473 			{
   474 			ERR_PRINTF1(_L("iMdaDevSound->VersionRequired() != expected"));
   475 			ERR_PRINTF3(_L("version.Name()=%S, expected=%S"), &versionNameFromSystem, &versionName);
   476 			SetBlockResult(EFail);
   477 			}
   478 		else
   479 			{
   480 			INFO_PRINTF1(_L("iMdaDevSound->VersionRequired() == expected"));
   481 			}
   482 		}
   483 	
   484 	}
   485 
   486 /** 
   487  * Gets PlayFormatsSupported
   488  * 
   489  * @param aSection 			Section name which contains SoundFormatsSupported 
   490  * 							object name
   491  *  						KSoundFormatsSupportedObject - SoundFormatsSupported 
   492  * 							object name
   493  *
   494  * @return					void
   495  *
   496  * @leave					System wide error
   497  */
   498 void CT_MdaDevSoundData::DoCmdPlayFormatsSupportedL(const TDesC& aSection)
   499 	{	
   500 	INFO_PRINTF1(_L("Getting PlayFormatsSupported!"));
   501 	
   502 	TPtrC		objectName;	
   503 	if (GET_MANDATORY_STRING_PARAMETER(KSoundFormatsSupportedObject, aSection, objectName))
   504 		{		
   505 		RMdaDevSound::TSoundFormatsSupported* soundFormat = static_cast<RMdaDevSound::TSoundFormatsSupported*>(GetDataObjectL(objectName));		
   506 		RMdaDevSound::TSoundFormatsSupportedBuf soundFormatsSupportedBuf(*soundFormat);		
   507 		iMdaDevSound->PlayFormatsSupported(soundFormatsSupportedBuf);		
   508 		*soundFormat = soundFormatsSupportedBuf();		
   509 		}		
   510 	}
   511 
   512 /** 
   513  * Gets current PlayFormat
   514  * 
   515  * @param aSection 			Section name which contains CurrentSoundFormat 
   516  * 							object name
   517  *  						KCurrentSoundFormatObject - CurrentSoundFormat 
   518  * 							object name
   519  *
   520  * @return					void
   521  *
   522  * @leave					System wide error
   523  */
   524 void CT_MdaDevSoundData::DoCmdGetPlayFormatL(const TDesC& aSection)
   525 	{
   526 	INFO_PRINTF1(_L("Getting PlayFormat!"));
   527 	
   528 	TPtrC		objectName;	
   529 	if (GET_MANDATORY_STRING_PARAMETER(KCurrentSoundFormatObject, aSection, objectName))
   530 		{		
   531 		RMdaDevSound::TCurrentSoundFormat* soundFormat = static_cast<RMdaDevSound::TCurrentSoundFormat*>(GetDataObjectL(objectName));		
   532 		RMdaDevSound::TCurrentSoundFormatBuf currentSoundFormatBuf(*soundFormat);		
   533 		iMdaDevSound->GetPlayFormat(currentSoundFormatBuf);		
   534 		*soundFormat = currentSoundFormatBuf();
   535 		}		
   536 	}
   537 
   538 /** 
   539  * Sets current PlayFormat
   540  * 
   541  * @param aSection 			Section name which contains CurrentSoundFormat 
   542  * 							object name
   543  * 							KCurrentSoundFormatObject - CurrentSoundFormat 
   544  * 							object name
   545  *
   546  * @return					void
   547  *
   548  * @leave					System wide error
   549  */
   550 void CT_MdaDevSoundData::DoCmdSetPlayFormatL(const TDesC& aSection)
   551 	{
   552 	INFO_PRINTF1(_L("Setting PlayFormat!"));
   553 	
   554 	TPtrC		objectName;	
   555 	if (GET_MANDATORY_STRING_PARAMETER(KCurrentSoundFormatObject, aSection, objectName))
   556 		{		
   557 		RMdaDevSound::TCurrentSoundFormat* soundFormat = static_cast<RMdaDevSound::TCurrentSoundFormat*>(GetDataObjectL(objectName));		
   558 		RMdaDevSound::TCurrentSoundFormatBuf currentSoundFormatBuf(*soundFormat);		
   559 		TInt err = iMdaDevSound->SetPlayFormat(currentSoundFormatBuf);
   560 		if(err != KErrNone)
   561 			{
   562 			ERR_PRINTF2(_L("error in SetPlayFormatL %d"), err);
   563 			SetError( err );
   564 			}
   565 		else
   566 			{
   567 			*soundFormat = currentSoundFormatBuf();
   568 			}
   569 		}
   570 	}
   571 
   572 /** 
   573  * Gets RecordFormatsSupported
   574  * 
   575  * @param aSection 			Section name which contains SoundFormatsSupported 
   576  * 							object name
   577  * 							KSoundFormatsSupportedObject - SoundFormatsSupported 
   578  * 							object name
   579  *
   580  * @return					void
   581  *
   582  * @leave					System wide error
   583  */
   584 void CT_MdaDevSoundData::DoCmdRecordFormatsSupportedL(const TDesC& aSection)
   585 	{
   586 	INFO_PRINTF1(_L("Getting RecordFormatsSupported!"));
   587 
   588 	TPtrC		objectName;
   589 	if (GET_MANDATORY_STRING_PARAMETER(KSoundFormatsSupportedObject, aSection, objectName))
   590 		{		
   591 		RMdaDevSound::TSoundFormatsSupported* soundFormat = static_cast<RMdaDevSound::TSoundFormatsSupported*>(GetDataObjectL(objectName));		
   592 		RMdaDevSound::TSoundFormatsSupportedBuf soundFormatsSupportedBuf(*soundFormat);		
   593 		iMdaDevSound->RecordFormatsSupported(soundFormatsSupportedBuf);		
   594 		*soundFormat = soundFormatsSupportedBuf();		
   595 		}
   596 	}
   597 
   598 /** 
   599  * Gets current RecordFormat
   600  * 
   601  * @param aSection 			Section name which contains CurrentSoundFormat 
   602  * 							object name
   603  *  						KCurrentSoundFormatObject - CurrentSoundFormat 
   604  * 							object name
   605  *
   606  * @return					void
   607  *
   608  * @leave					System wide error
   609  */
   610 void CT_MdaDevSoundData::DoCmdGetRecordFormatL(const TDesC& aSection)
   611 	{
   612 	INFO_PRINTF1(_L("Getting RecordFormat!"));
   613 	
   614 	TPtrC		objectName;	
   615 	if (GET_MANDATORY_STRING_PARAMETER(KCurrentSoundFormatObject, aSection, objectName))
   616 		{		
   617 		RMdaDevSound::TCurrentSoundFormat* soundFormat = static_cast<RMdaDevSound::TCurrentSoundFormat*>(GetDataObjectL(objectName));		
   618 		RMdaDevSound::TCurrentSoundFormatBuf currentSoundFormatBuf(*soundFormat);		
   619 		iMdaDevSound->GetRecordFormat(currentSoundFormatBuf);		
   620 		*soundFormat = currentSoundFormatBuf();
   621 		}
   622 	}
   623 
   624 /** 
   625  * Sets current RecordFormat
   626  * 
   627  * @param aSection 			Section name which contains CurrentSoundFormat 
   628  * 							object name
   629  * 							KCurrentSoundFormatObject - CurrentSoundFormat 
   630  * 							object name
   631  *
   632  * @return					void
   633  *
   634  * @leave					System wide error
   635  */
   636 void CT_MdaDevSoundData::DoCmdSetRecordFormatL(const TDesC& aSection)
   637 	{
   638 	INFO_PRINTF1(_L("Setting RecordFormat!"));
   639 	
   640 	TPtrC		objectName;	
   641 	if (GET_MANDATORY_STRING_PARAMETER(KCurrentSoundFormatObject, aSection, objectName))
   642 		{		
   643 		RMdaDevSound::TCurrentSoundFormat* soundFormat = static_cast<RMdaDevSound::TCurrentSoundFormat*>(GetDataObjectL(objectName));		
   644 		RMdaDevSound::TCurrentSoundFormatBuf currentSoundFormatBuf(*soundFormat);		
   645 		TInt err = iMdaDevSound->SetRecordFormat(currentSoundFormatBuf);
   646 		if(err != KErrNone)
   647 			{
   648 			ERR_PRINTF2(_L("error in SetRecordFormatL %d"), err);
   649 			SetError( err );
   650 			}
   651 		else
   652 			{
   653 			*soundFormat = currentSoundFormatBuf();
   654 			}
   655 		}
   656 	}
   657 
   658 /** 
   659  * Gets current PlayVolume
   660  * 
   661  * @param aSection 			Section name which contains expected value
   662  * 							KUVolumeExpected - expected volume level
   663  *
   664  * @return					void
   665  *
   666  * @leave					no
   667  */
   668 void	CT_MdaDevSoundData::DoCmdPlayVolume(const TDesC& aSection)
   669 	{
   670 	TInt volume = 0;
   671 	INFO_PRINTF2(_L("calling PlayVolume(), value before execution = %d"), volume);
   672 	volume = iMdaDevSound->PlayVolume();
   673 	
   674 	TInt	expected;
   675 	if (GET_OPTIONAL_INT_PARAMETER(KUVolumeExpected(), aSection, expected))
   676 		{
   677 		if(volume != expected)
   678 			{
   679 			ERR_PRINTF3(_L("Expected result != volume, expected = %d, volume = %d"),
   680 							expected, volume);
   681 			SetBlockResult(EFail);
   682 			}
   683 		else
   684 			{
   685 			INFO_PRINTF2(_L("volume = %d"), volume);
   686 			}
   687 		}
   688 	else
   689 		{
   690 		INFO_PRINTF2(_L("volume = %d"), volume);
   691 		}
   692 	}
   693 
   694 /** 
   695  * Sets current PlayVolume
   696  * 
   697  * @param aSection 			Section name which contains value to set
   698  * 							KUVolume - volume to set
   699  *
   700  * @return					void
   701  *
   702  * @leave					no
   703  */
   704 void	CT_MdaDevSoundData::DoCmdSetPlayVolume(const TDesC& aSection)
   705 	{
   706 	TInt volume = 0;
   707 	INFO_PRINTF2(_L("calling SetPlayVolume(), value before execution = %d"), volume);
   708 	if (GET_OPTIONAL_INT_PARAMETER(KUVolume(), aSection, volume))
   709 		{
   710 		iMdaDevSound->SetPlayVolume(volume);
   711 		INFO_PRINTF2(_L("after execution value = %d"), volume);
   712 		}
   713 	else
   714 		{
   715 		INFO_PRINTF2(_L("volume after execution = %d"), volume);
   716 		}
   717 	}
   718 
   719 /** 
   720  * Play audio from file. DoCmdPlayDataL is asynchronous function
   721  * 
   722  * @param aSection 			Section name which can contain values to set
   723  * 							KUDataSize - data size, 
   724  * 							KUFromFile - file name to play, 
   725  * 							KUBlockSize - block size
   726  * 							
   727  *
   728  * @return					void
   729  *
   730  * @leave					System wide error
   731  */
   732 void	CT_MdaDevSoundData::DoCmdPlayDataL(const TDesC& aSection, 
   733 											const TInt aAsyncErrorIndex)
   734 	{
   735 	INFO_PRINTF1(_L("calling PlayData()"));
   736 	
   737 	CT_SoundActiveCallback* active = CT_SoundActiveCallback::NewL(*this);
   738 	iPlay.Append(active);
   739 		
   740 	active->iSoundData = new(ELeave) TSoundUtil::RAudioBuffer();
   741 	TSoundUtil::RAudioBuffer* soundData = active->iSoundData;
   742 
   743 	TInt dataSize = TSoundUtil::KAudioBufferMaxSize;
   744 	GET_OPTIONAL_INT_PARAMETER(KUDataSize, aSection, dataSize);
   745 	soundData->Close();
   746 	soundData->CreateL(dataSize);
   747 
   748 	TPtrC	fileName;
   749 	TInt err = KErrNone;
   750 	if (GET_OPTIONAL_STRING_PARAMETER(KUFromFile, aSection, fileName))
   751 		{
   752 		err = soundData->LoadAudioDataL(fileName);
   753 		if (err)
   754 			{
   755 			SetBlockResult(EFail);
   756 			ERR_PRINTF2(_L("Audio file loading failed with error code %d"), err);
   757 			}
   758 		}
   759 
   760 	if (!err)
   761 		{
   762 		active->SetSection(aSection);
   763 		IncOutstanding();
   764 
   765 		TInt blockSize = TSoundUtil::KDefaultBlockSize;
   766 		GET_OPTIONAL_INT_PARAMETER(KUBlockSize, aSection, blockSize);
   767 		blockSize = Min(blockSize, soundData->Length());
   768 		active->iBufferBlock.Set(&soundData->operator[](0), blockSize, blockSize);
   769 		iMdaDevSound->PlayData(active->iStatus, active->iBufferBlock);
   770 		active->Activate(aAsyncErrorIndex);
   771 		TBool stopPlay = EFalse;
   772 		if (GET_OPTIONAL_BOOL_PARAMETER(KUCancel, aSection, stopPlay))
   773 			{
   774 			if ( stopPlay )
   775 				{
   776 				iMdaDevSound->CancelPlayData();
   777 				INFO_PRINTF1(_L("CancelPlayData() executed"));
   778 				}
   779 			}
   780 		if (GET_OPTIONAL_BOOL_PARAMETER(KUFlush, aSection, stopPlay))
   781 			{
   782 			if ( stopPlay )
   783 				{
   784 				iMdaDevSound->FlushPlayBuffer();
   785 				INFO_PRINTF1(_L("FlushPlayBuffer() executed"));
   786 				}
   787 			}
   788 		}
   789 	}
   790 
   791 /** 
   792  * Cancel playing
   793  */
   794 void	CT_MdaDevSoundData::DoCmdCancelPlayData()
   795 	{
   796 	INFO_PRINTF1(_L("calling CancelPlayData()"));
   797 	
   798 	if (iPlay.Count() > 0)
   799 		{
   800 		INFO_PRINTF2(_L("CancelPlayData called on active object with iStatus == %d"),
   801 				iPlay[iPlay.Count() - 1]->iStatus.Int());
   802 		}
   803 	else
   804 		{
   805 		INFO_PRINTF1(_L("No active objects found"));
   806 		}
   807 	
   808 	iMdaDevSound->CancelPlayData();
   809 	}
   810 
   811 /** 
   812  * Flush play buffer
   813  */
   814 void	CT_MdaDevSoundData::DoCmdFlushPlayBuffer()
   815 	{
   816 	INFO_PRINTF1(_L("calling FlushPlayBuffer()"));
   817 
   818 	if (iPlay.Count() > 0)
   819 		{
   820 		INFO_PRINTF2(_L("FLushPlayBuffer called on active object with iStatus == %d"),
   821 				iPlay[iPlay.Count() - 1]->iStatus.Int());
   822 		}
   823 	else
   824 		{
   825 		INFO_PRINTF1(_L("No active objects found"));
   826 		}
   827 	
   828 	iMdaDevSound->FlushPlayBuffer();
   829 	}
   830 
   831 /** 
   832  * Asynchronous function that starts notifying play error
   833  */
   834 void	CT_MdaDevSoundData::DoCmdNotifyPlayErrorL(const TInt aAsyncErrorIndex)
   835 	{
   836 	INFO_PRINTF1(_L("calling NotifyPlayError()"));
   837 	
   838 	CActiveCallback* active = CActiveCallback::NewL(*this);
   839 	iNotifyPlayError.Append(active);
   840 	iMdaDevSound->NotifyPlayError(active->iStatus);
   841 		
   842 	//acitvate callback object
   843 	active->Activate(aAsyncErrorIndex);
   844 	IncOutstanding();
   845 	}
   846 
   847 /** 
   848  * Cancel notifying play error
   849  */
   850 void	CT_MdaDevSoundData::DoCmdCancelNotifyPlayError()
   851 	{
   852 	INFO_PRINTF1(_L("calling CancelNotifyPlayError()"));
   853 	
   854 	iMdaDevSound->CancelNotifyPlayError();
   855 	}
   856 
   857 /** 
   858  * Gets bytes played
   859  * 
   860  * @param aSection 			Section name which can contain expected value
   861  * 							KUBytesPlayed - bytes played
   862  *
   863  * @return					void
   864  *
   865  * @leave					no
   866  */
   867 void	CT_MdaDevSoundData::DoCmdBytesPlayed(const TDesC& aSection)
   868 	{
   869 	INFO_PRINTF1(_L("calling BytesPlayed()"));
   870 	
   871 	TInt bytesPlayed = iMdaDevSound->BytesPlayed();
   872 	INFO_PRINTF2(_L("Bytes played: %d"), bytesPlayed);
   873 
   874 	TInt expected = 0;
   875 	if (GET_OPTIONAL_INT_PARAMETER(KUBytesPlayed, aSection, expected))
   876 		{
   877 		if (expected != bytesPlayed)
   878 			{
   879 			ERR_PRINTF3(_L("Bytes played %d != %d expected"), bytesPlayed, expected);
   880 			SetBlockResult(EFail);
   881 			}
   882 		}
   883 	}
   884 
   885 /** 
   886  * Resets bytes played
   887  */
   888 void	CT_MdaDevSoundData::DoCmdResetBytesPlayed()
   889 	{
   890 	INFO_PRINTF1(_L("calling ResetBytesPlayed()"));
   891 	
   892 	iMdaDevSound->ResetBytesPlayed();
   893 	}
   894 
   895 /** 
   896  * Pause playing
   897  */
   898 void	CT_MdaDevSoundData::DoCmdPausePlayBuffer()
   899 	{
   900 	INFO_PRINTF1(_L("calling PausePlayBuffer()"));
   901 	
   902 	iMdaDevSound->PausePlayBuffer();
   903 	}
   904 
   905 /** 
   906  * Resume playing
   907  */
   908 void	CT_MdaDevSoundData::DoCmdResumePlaying()
   909 	{
   910 	INFO_PRINTF1(_L("calling ResumePlaying()"));
   911 	
   912 	iMdaDevSound->ResumePlaying();		
   913 	}
   914 
   915 /** 
   916  * DoCmdRecordDataL is asynchronous function to record audio.
   917  * 
   918  * @param aSection 			Section name which can contain value to set
   919  * 							KUDataSize - data size to record, 
   920  * 							KUToFile - file to record audio,
   921  * 							KUBlockSize - block size
   922  *
   923  * @return					void
   924  *
   925  * @leave					System wide error
   926  */
   927 void CT_MdaDevSoundData::DoCmdRecordDataL(const TDesC& aSection, const TInt aAsyncErrorIndex)
   928 	{
   929 	INFO_PRINTF1(_L("calling RecordData()"));	
   930 	
   931 	CT_SoundActiveCallback* active = CT_SoundActiveCallback::NewL(*this);
   932 	iRecord.Append(active);
   933 	
   934 	active->iSoundData = new(ELeave) TSoundUtil::RAudioBuffer();
   935 	TSoundUtil::RAudioBuffer* soundData = active->iSoundData;
   936 
   937 	TInt dataSize = TSoundUtil::KAudioBufferMaxSize;
   938 	GET_OPTIONAL_INT_PARAMETER(KUDataSize, aSection, dataSize);
   939 	soundData->Close();
   940 	soundData->CreateL(dataSize);
   941 	soundData->SetLength(dataSize);
   942 
   943 	TInt blockSize = TSoundUtil::KDefaultBlockSize;
   944 	GET_OPTIONAL_INT_PARAMETER(KUBlockSize, aSection, blockSize);
   945 	active->iBufferBlock.Set(&soundData->operator[](0), 0, Min(blockSize, soundData->Length()));
   946 	iMdaDevSound->RecordData(active->iStatus, active->iBufferBlock);
   947 
   948 	active->SetSection(aSection);
   949 	IncOutstanding();
   950 	active->Activate(aAsyncErrorIndex);
   951 	TBool stopRecord = EFalse;
   952 	if (GET_OPTIONAL_BOOL_PARAMETER(KUCancel, aSection, stopRecord))
   953 		{
   954 		if ( stopRecord )
   955 			{
   956 			iMdaDevSound->CancelPlayData();
   957 			INFO_PRINTF1(_L("CancelRecordData() executed"));
   958 			}
   959 		}
   960 	if (GET_OPTIONAL_BOOL_PARAMETER(KUFlush, aSection, stopRecord))
   961 		{
   962 		if ( stopRecord )
   963 			{
   964 			iMdaDevSound->FlushRecordBuffer();
   965 			INFO_PRINTF1(_L("FlushRecordBuffer() executed"));
   966 			}
   967 		}
   968 	}
   969 
   970 /** 
   971  * Cancels recording in progress
   972  */
   973 void CT_MdaDevSoundData::DoCmdCancelRecordData()
   974 	{
   975 	INFO_PRINTF1(_L("calling CancelRecordData()"));
   976 	
   977 	if (iRecord.Count() > 0)
   978 		{
   979 		INFO_PRINTF2(_L("CancelRecordData called on active object with iStatus == %d"),
   980 				iRecord[iRecord.Count() - 1]->iStatus.Int());
   981 		}
   982 	else
   983 		{
   984 		INFO_PRINTF1(_L("No active objects found"));
   985 		}
   986 	
   987 	iMdaDevSound->CancelRecordData();
   988 	}
   989 
   990 /** 
   991  * Flushes record buffer
   992  */
   993 void CT_MdaDevSoundData::DoCmdFlushRecordBuffer()
   994 	{
   995 	INFO_PRINTF1(_L("calling FlushRecordBuffer()"));
   996 	
   997 	if (iRecord.Count() > 0)
   998 		{
   999 		INFO_PRINTF2(_L("FlushRecordBuffer called on active object with iStatus == %d"),
  1000 				iRecord[iRecord.Count() - 1]->iStatus.Int());
  1001 		}
  1002 	else
  1003 		{
  1004 		INFO_PRINTF1(_L("No active objects found"));
  1005 		}
  1006 	
  1007 	iMdaDevSound->FlushRecordBuffer();
  1008 	}
  1009 
  1010 /** 
  1011  * Gets record volume level
  1012  * 
  1013  * @param aSection 			Section name which can contain expected value
  1014  * 							KUSoundLevelExpected - expected sound level
  1015  *
  1016  * @return					void
  1017  *
  1018  * @leave					no
  1019  */
  1020 void CT_MdaDevSoundData::DoCmdRecordLevel(const TDesC& aSection)
  1021 	{	
  1022 	TInt level = 0;
  1023 	INFO_PRINTF1(_L("calling RecordLevel()"));
  1024 	level = iMdaDevSound->RecordLevel();
  1025 	
  1026 	TInt	expected;
  1027 	if (GET_OPTIONAL_INT_PARAMETER(KUSoundLevelExpected(), aSection, expected))
  1028 		{
  1029 		if(level != expected)
  1030 			{
  1031 			ERR_PRINTF3(_L("Expected result != level, expected = %d, level = %d"),
  1032 							expected, level);
  1033 			SetBlockResult(EFail);
  1034 			}
  1035 		else
  1036 			{
  1037 			INFO_PRINTF2(_L("level = %d"), level);
  1038 			}
  1039 		}
  1040 	else
  1041 		{
  1042 		INFO_PRINTF2(_L("level = %d"), level);
  1043 		}
  1044 	}
  1045 
  1046 /** 
  1047  * Sets record volume level
  1048  * 
  1049  * @param aSection 			Section name which can contain value to set
  1050  * 							KUSoundLevel - sound level to set
  1051  *
  1052  * @return					void
  1053  *
  1054  * @leave					no
  1055  */
  1056 void CT_MdaDevSoundData::DoCmdSetRecordLevel(const TDesC& aSection)
  1057 	{
  1058 	TInt level = 0;
  1059 	INFO_PRINTF2(_L("calling SetRecordLevel(), level before execution = %d"), level);
  1060 	
  1061 	if(GET_OPTIONAL_INT_PARAMETER(KUSoundLevel, aSection, level))
  1062 		{
  1063 		iMdaDevSound->SetRecordLevel(level);
  1064 		INFO_PRINTF2(_L("after execution level = %d"), level);
  1065 		}	
  1066 	else
  1067 		{
  1068 		INFO_PRINTF2(_L("level after execution = %d"), level);
  1069 		}
  1070 	}
  1071 
  1072 /** 
  1073  * DoCmdNotifyRecordErrorL is asynchronous function that starts notifying recording
  1074  * error
  1075  */
  1076 void CT_MdaDevSoundData::DoCmdNotifyRecordErrorL(const TInt aAsyncErrorIndex)
  1077 	{
  1078 	INFO_PRINTF1(_L("calling NotifyRecordError()"));
  1079 	
  1080 	CActiveCallback* active = CActiveCallback::NewL(*this);
  1081 	iNotifyRecordError.Append(active);
  1082 	
  1083 	iMdaDevSound->NotifyRecordError(active->iStatus);
  1084 	
  1085 	//acitvate callback object
  1086 	active->Activate(aAsyncErrorIndex);
  1087 	IncOutstanding();	
  1088 	}
  1089 
  1090 /** 
  1091  * Cancels notifying recording error
  1092  */
  1093 void CT_MdaDevSoundData::DoCmdCancelNotifyRecordError()
  1094 	{
  1095 	INFO_PRINTF1(_L("calling CancelNotifyRecordError()"));
  1096 	
  1097 	iMdaDevSound->CancelNotifyRecordError();
  1098 	}
  1099 
  1100 /** 
  1101  * Deletes file specified
  1102  * 
  1103  * @param aSection 			Section name which contains file name to delete
  1104  * 							KUFileToDelete - File to delete 
  1105  *
  1106  * @return					void
  1107  *
  1108  * @leave					System wide error
  1109  */
  1110 void CT_MdaDevSoundData::DoCmdUtilityDeleteFileL(const TDesC& aSection)
  1111 	{
  1112 	INFO_PRINTF1(_L("DoCmdUtilityDeleteFileL called!"));
  1113 	
  1114 	TPtrC	file;	
  1115 	if (GET_MANDATORY_STRING_PARAMETER(KUFileToDelete, aSection, file))
  1116 		{
  1117 		TInt err;
  1118 		err = TSoundUtil::DeleteFileL(file);
  1119 		if(err != KErrNone)
  1120 			{
  1121 			ERR_PRINTF2(_L("Deleting file failed with error code %d"), err);
  1122 			SetBlockResult(EFail);
  1123 			}
  1124 		else
  1125 			{
  1126 			INFO_PRINTF1(_L("File deleted successfully"));
  1127 			}
  1128 		}
  1129 	}
  1130 
  1131 /** 
  1132  * Handle asynchronous events here
  1133  */
  1134 void CT_MdaDevSoundData::RunL(CActive* aActive, TInt aIndex)
  1135 	{
  1136 	INFO_PRINTF1(_L("CT_MdaDevSoundData::RunL Called"));
  1137 	TBool	foundActiveObject = EFalse;
  1138 	TInt	index=0;
  1139 	TInt	count=0;
  1140 	TBool	completed=ETrue;
  1141 
  1142 	// See if it is in iNotifyPlayError
  1143 	count=iNotifyPlayError.Count();
  1144 	for( index=0; (index<count) && (!foundActiveObject); ++index )
  1145  		{
  1146  		if( aActive == iNotifyPlayError[index] )
  1147 			{
  1148 			INFO_PRINTF1(_L("RunL iNotifyPlayError called"));
  1149 			foundActiveObject = ETrue;
  1150 			iNotifyPlayError.Remove(index);
  1151 	 		}
  1152 		}
  1153 
  1154 	// See if it is in iNotifyRecordError
  1155 	count=iNotifyRecordError.Count();
  1156 	for( index=0; (index<count) && (!foundActiveObject); ++index )
  1157  		{
  1158  		if( aActive == iNotifyRecordError[index] )
  1159 			{
  1160 			INFO_PRINTF1(_L("RunL iNotifyRecordError called"));
  1161 			foundActiveObject = ETrue;
  1162 			iNotifyRecordError.Remove(index);
  1163 	 		}
  1164 		}
  1165 
  1166 	// See if it is in iPlay
  1167 	count=iPlay.Count();
  1168 	for( index=0; (index<count) && (!foundActiveObject); ++index )
  1169  		{
  1170  		if( aActive == iPlay[index] )
  1171 			{
  1172 			foundActiveObject = ETrue;
  1173 			INFO_PRINTF1(_L("RunL iPlay called"));
  1174 			
  1175 			TSoundUtil::RAudioBuffer* soundData = iPlay[index]->iSoundData;
  1176 
  1177 			iPlay[index]->iDataPosition += iPlay[index]->iBufferBlock.Length();
  1178 			INFO_PRINTF3(_L("Played %d bytes, %d bytes played total"), iPlay[index]->iBufferBlock.Length(),
  1179 					iPlay[index]->iDataPosition);
  1180 
  1181 			if ( ( iPlay[index]->iDataPosition >= soundData->Length() ) || aActive->iStatus.Int() )
  1182 				{
  1183 				iPlay.Remove(index);
  1184 				}
  1185 			else
  1186 				{
  1187 				TInt blockSize = TSoundUtil::KDefaultBlockSize;
  1188 				GET_OPTIONAL_INT_PARAMETER(KUBlockSize, *(iPlay[index]->iSection), blockSize);
  1189 				blockSize = Min(blockSize, soundData->Length() - iPlay[index]->iDataPosition);
  1190 				iPlay[index]->iBufferBlock.Set(&soundData->operator[](iPlay[index]->iDataPosition), blockSize, blockSize);
  1191 				iMdaDevSound->PlayData(iPlay[index]->iStatus, iPlay[index]->iBufferBlock);
  1192 				iPlay[index]->Activate(aIndex);
  1193 				completed = EFalse;
  1194 				}
  1195 	 		}
  1196 		}
  1197 
  1198 	// See if it is in iRecord
  1199 	count=iRecord.Count();
  1200 	for( index=0; (index<count) && (!foundActiveObject); ++index )
  1201  		{
  1202  		if( aActive == iRecord[index] )
  1203 			{
  1204 			foundActiveObject = ETrue;	
  1205 			INFO_PRINTF1(_L("RunL iRecord called"));
  1206 			iRecord[index]->iDataPosition += iRecord[index]->iBufferBlock.Length();
  1207 			INFO_PRINTF3(_L("Stored %d bytes, %d bytes total"),
  1208 					iRecord[index]->iBufferBlock.Length(),
  1209 					iRecord[index]->iDataPosition);
  1210 
  1211 			TSoundUtil::RAudioBuffer* buffer = iRecord[index]->iSoundData;
  1212 				
  1213 			TInt	err = aActive->iStatus.Int();
  1214 			if( err == KErrNone )
  1215 				{				
  1216 				if(iRecord[index]->iDataPosition >= buffer->Length() ||
  1217 						iRecord[index]->iBufferBlock.Length() == 0)
  1218 					{
  1219 					TPtrC fileName;
  1220 					if(GET_OPTIONAL_STRING_PARAMETER(KUToFile, *(iRecord[index]->iSection), fileName))
  1221 						{
  1222 						TInt err;
  1223 						err = buffer->SaveAudioDataL(fileName);
  1224 						if (err)
  1225 							{
  1226 							SetBlockResult(EFail);
  1227 							ERR_PRINTF2(_L("Saving to file failed with error code %d"), err);
  1228 							}
  1229 						}		
  1230 					iRecord.Remove(index);
  1231 					}				
  1232 				else
  1233 					{
  1234 					TInt blockSize = TSoundUtil::KDefaultBlockSize;
  1235 					//if specified in INI file get block size
  1236 					GET_OPTIONAL_INT_PARAMETER(KUBlockSize, *(iRecord[index]->iSection), blockSize);
  1237 					iRecord[index]->iBufferBlock.Set(&buffer->operator[](iRecord[index]->iDataPosition), 0, Min(blockSize, buffer->Length() - iRecord[index]->iDataPosition));
  1238 					iMdaDevSound->RecordData(iRecord[index]->iStatus, iRecord[index]->iBufferBlock);
  1239 					iRecord[index]->Activate(aIndex);
  1240 					completed = EFalse;
  1241 					}
  1242 				}//err == KErrNone
  1243 			else
  1244 				{
  1245 				iRecord.Remove(index);
  1246 				}					
  1247 			}//aActive == iRecord[index]
  1248 		}//for
  1249 	
  1250  	if( foundActiveObject )
  1251  		{
  1252 		if ( completed )
  1253 			{						
  1254 			if (aActive)
  1255 				{
  1256 				TInt	err = aActive->iStatus.Int();
  1257 				if( err != KErrNone )
  1258 					{
  1259 					ERR_PRINTF2(_L("RunL Error %d"), err);
  1260 					SetAsyncError( aIndex, err );
  1261 					}
  1262 				}
  1263 
  1264 			// Reset the outstanding request state
  1265 			delete aActive;
  1266 			DecOutstanding();
  1267 			}
  1268 		}
  1269  	else
  1270  		{
  1271  		ERR_PRINTF1(_L("An unchecked active object completed"));
  1272  		SetBlockResult(EFail);
  1273  		}
  1274 	}
  1275 
  1276 /** 
  1277  * Cancels asynchronous events
  1278  */
  1279 void CT_MdaDevSoundData::DoCancel(CActive* aActive, TInt aIndex)
  1280 	{
  1281 	TBool	foundActiveObject = EFalse;
  1282 
  1283 	TInt	index=0;
  1284 	TInt	count=0;
  1285 
  1286 	// See if it is in iNotifyPlayError
  1287 	count=iNotifyPlayError.Count();
  1288 	for( index=0; (index<count) && (!foundActiveObject); ++index )
  1289  		{
  1290  		if( aActive == iNotifyPlayError[index] )
  1291 			{
  1292 			INFO_PRINTF1(_L("DoCancel iNotifyPlayError called"));
  1293 			foundActiveObject = ETrue;
  1294 			iNotifyPlayError.Remove(index);
  1295 	 		}
  1296 		}
  1297 
  1298 	// See if it is in iNotifyRecordError
  1299 	count=iNotifyRecordError.Count();
  1300 	for( index=0; (index<count) && (!foundActiveObject); ++index )
  1301  		{
  1302  		if( aActive == iNotifyRecordError[index] )
  1303 			{
  1304 			INFO_PRINTF1(_L("DoCancel iNotifyRecordError called"));
  1305 			foundActiveObject = ETrue;
  1306 			iNotifyRecordError.Remove(index);
  1307 	 		}
  1308 		}
  1309 
  1310 	// See if it is in iPlay
  1311 	count=iPlay.Count();
  1312 	for( index=0; (index<count) && (!foundActiveObject); ++index )
  1313  		{
  1314  		if( aActive == iPlay[index] )
  1315 			{
  1316 			INFO_PRINTF1(_L("DoCancel iPlay called"));
  1317 			foundActiveObject = ETrue;
  1318 			iPlay.Remove(index);
  1319 	 		}
  1320 		}
  1321 
  1322 	// See if it is in iRecord
  1323 	count=iRecord.Count();
  1324 	for( index=0; (index<count) && (!foundActiveObject); ++index )
  1325  		{
  1326  		if( aActive == iRecord[index] )
  1327 			{
  1328 			INFO_PRINTF1(_L("DoCancel iRecord called"));
  1329 			foundActiveObject = ETrue;
  1330 			iRecord.Remove(index);
  1331 	 		}
  1332 		}
  1333 	
  1334 	if( foundActiveObject )
  1335  		{
  1336 		if (aActive)
  1337 			{
  1338 			TInt	err = aActive->iStatus.Int();
  1339 			if( err != KErrNone ) 
  1340 				{
  1341 				ERR_PRINTF2(_L("DoCancel Error %d"), err);
  1342 				SetAsyncError( aIndex, err );
  1343 				}
  1344 			}
  1345 
  1346 		// Reset the outstanding request state
  1347 		delete aActive;
  1348 		DecOutstanding();
  1349 		}
  1350 	else
  1351 		{
  1352  		ERR_PRINTF1(_L("An unchecked active object canceled"));
  1353  		SetBlockResult(EFail);
  1354 		}
  1355 	}