devsound/a3fdevsound/src/mmfdevsoundproxy/mmfdevsoundcallbackhandler.cpp
changeset 15 c1e808730d6c
parent 0 40261b775718
equal deleted inserted replaced
13:efebd1779a59 15:c1e808730d6c
    16 
    16 
    17 
    17 
    18 // INCLUDE FILES
    18 // INCLUDE FILES
    19 #include "mmfdevsoundproxy.h"
    19 #include "mmfdevsoundproxy.h"
    20 #include "mmfdevsoundcallbackhandler.h"
    20 #include "mmfdevsoundcallbackhandler.h"
    21 
    21 #ifdef _DEBUG
       
    22 #include <e32debug.h>
       
    23 
       
    24 #define SYMBIAN_DEBPRN0(str)                RDebug::Print(str, this)
       
    25 #define SYMBIAN_DEBPRN1(str, val1)          RDebug::Print(str, this, val1)
       
    26 #define SYMBIAN_DEBPRN2(str, val1, val2)    RDebug::Print(str, this, val1, val2)
       
    27 #else
       
    28 #define SYMBIAN_DEBPRN0(str)
       
    29 #define SYMBIAN_DEBPRN1(str, val1)
       
    30 #define SYMBIAN_DEBPRN2(str, val1, val2)
       
    31 #endif //_DEBUG
    22 
    32 
    23 // ============================ MEMBER FUNCTIONS ==============================
    33 // ============================ MEMBER FUNCTIONS ==============================
    24 
    34 
    25 // ----------------------------------------------------------------------------
    35 // ----------------------------------------------------------------------------
    26 // CMsgQueueHandler::NewL
    36 // CMsgQueueHandler::NewL
    99 // Subscribes for Play Error event from the DevSound server.
   109 // Subscribes for Play Error event from the DevSound server.
   100 // ----------------------------------------------------------------------------
   110 // ----------------------------------------------------------------------------
   101 //
   111 //
   102 void CMsgQueueHandler::ReceiveEvents()
   112 void CMsgQueueHandler::ReceiveEvents()
   103 	{
   113 	{
   104 	if (!IsActive())
   114     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::ReceiveEvents - Enter"));	
       
   115     if (!IsActive())
   105 		{
   116 		{
   106 		iMsgQueue->NotifyDataAvailable(iStatus);
   117 		iMsgQueue->NotifyDataAvailable(iStatus);
   107 		SetActive();
   118 		SetActive();
   108 		}
   119 		}
       
   120     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::ReceiveEvents - Exit"));
   109 	}
   121 	}
   110 
   122 
   111 // ----------------------------------------------------------------------------
   123 // ----------------------------------------------------------------------------
   112 // CMsgQueueHandler::RunL
   124 // CMsgQueueHandler::RunL
   113 // Handles active object’s request completion event.
   125 // Handles active object’s request completion event.
   114 //
   126 //
   115 // ----------------------------------------------------------------------------
   127 // ----------------------------------------------------------------------------
   116 //
   128 //
   117 void CMsgQueueHandler::RunL()
   129 void CMsgQueueHandler::RunL()
   118 	{
   130 	{
   119 	TInt err = iMsgQueue->Receive(iCurrentItem);
   131     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::RunL - Enter"));
       
   132     TInt err = iMsgQueue->Receive(iCurrentItem);
   120 
   133 
   121 	if (err == KErrNone || err == KErrUnderflow)
   134 	if (err == KErrNone || err == KErrUnderflow)
   122 		{
   135 		{
   123 		// Signal that we're ready to process the next message
   136 		// Signal that we're ready to process the next message
   124 		ReceiveEvents();
   137 		ReceiveEvents();
   203 				{
   216 				{
   204 				break;
   217 				break;
   205 				}
   218 				}
   206 			}
   219 			}
   207 		}
   220 		}
       
   221 	SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::RunL - Exit"));
   208 	}
   222 	}
   209 
   223 
   210 // ----------------------------------------------------------------------------
   224 // ----------------------------------------------------------------------------
   211 // CMsgQueueHandler::RunError
   225 // CMsgQueueHandler::RunError
   212 // Called by CActive object framework if RunL leaves.
   226 // Called by CActive object framework if RunL leaves.
   213 // ----------------------------------------------------------------------------
   227 // ----------------------------------------------------------------------------
   214 //
   228 //
   215 TInt CMsgQueueHandler::RunError(TInt aError)
   229 TInt CMsgQueueHandler::RunError(TInt aError)
   216 	{
   230 	{
   217 	TMMFEvent event;
   231     SYMBIAN_DEBPRN1(_L("CMsgQueueHandler[0x%x]::RunError - Enter. Error [%d]"), aError);
       
   232     TMMFEvent event;
   218 	event.iErrorCode = aError;
   233 	event.iErrorCode = aError;
   219 	iDevSoundObserver.SendEventToClient(event);
   234 	iDevSoundObserver.SendEventToClient(event);
       
   235 	SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::RunError - Exit"));
   220 	return KErrNone;
   236 	return KErrNone;
   221 	}
   237 	}
   222 
   238 
   223 // ----------------------------------------------------------------------------
   239 // ----------------------------------------------------------------------------
   224 // CMsgQueueHandler::DoCancel
   240 // CMsgQueueHandler::DoCancel
   226 // request.
   242 // request.
   227 // ----------------------------------------------------------------------------
   243 // ----------------------------------------------------------------------------
   228 //
   244 //
   229 void CMsgQueueHandler::DoCancel()
   245 void CMsgQueueHandler::DoCancel()
   230 	{
   246 	{
   231 	iMsgQueue->CancelDataAvailable();
   247     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoCancel - Enter"));
       
   248     iMsgQueue->CancelDataAvailable();
       
   249     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoCancel - Exit"));
   232 	}
   250 	}
   233 
   251 
   234 // ----------------------------------------------------------------------------
   252 // ----------------------------------------------------------------------------
   235 // CMsgQueueHandler::DoInitComplete
   253 // CMsgQueueHandler::DoInitComplete
   236 // Handles initialization completion event.
   254 // Handles initialization completion event.
   237 // ----------------------------------------------------------------------------
   255 // ----------------------------------------------------------------------------
   238 //
   256 //
   239 void CMsgQueueHandler::DoInitComplete()
   257 void CMsgQueueHandler::DoInitComplete()
   240 	{
   258 	{
   241 	iDevSoundObserver.InitializeComplete(iCurrentItem.iErrorCode);
   259     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoInitComplete - Enter"));
       
   260     iDevSoundObserver.InitializeComplete(iCurrentItem.iErrorCode);
       
   261     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoInitComplete - Exit"));
   242 	}
   262 	}
   243 
   263 
   244 // ----------------------------------------------------------------------------
   264 // ----------------------------------------------------------------------------
   245 // CMsgQueueHandler::DoPlayErrorComplete
   265 // CMsgQueueHandler::DoPlayErrorComplete
   246 // Handles play completion or cancel event.
   266 // Handles play completion or cancel event.
   247 // ----------------------------------------------------------------------------
   267 // ----------------------------------------------------------------------------
   248 //
   268 //
   249 void CMsgQueueHandler::DoPlayErrorComplete()
   269 void CMsgQueueHandler::DoPlayErrorComplete()
   250 	{
   270 	{
   251 	iAsyncQueueFinish->CallBack(); // async call to Finish()
   271     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoPlayErrorComplete - Enter"));
       
   272     iAsyncQueueFinish->CallBack(); // async call to Finish()
   252 	iDevSoundObserver.PlayError(iCurrentItem.iErrorCode);
   273 	iDevSoundObserver.PlayError(iCurrentItem.iErrorCode);
       
   274 	SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoPlayErrorComplete - Exit"));
   253 	}
   275 	}
   254 
   276 
   255 // ----------------------------------------------------------------------------
   277 // ----------------------------------------------------------------------------
   256 // CMsgQueueHandler::DoBTBFCompleteL
   278 // CMsgQueueHandler::DoBTBFCompleteL
   257 // Handles CMMFDevSound object's data request event to supply CMMFDevSound
   279 // Handles CMMFDevSound object's data request event to supply CMMFDevSound
   258 // with the buffer that it needs to play.
   280 // with the buffer that it needs to play.
   259 // ----------------------------------------------------------------------------
   281 // ----------------------------------------------------------------------------
   260 //
   282 //
   261 void CMsgQueueHandler::DoBTBFCompleteL()
   283 void CMsgQueueHandler::DoBTBFCompleteL()
   262 	{
   284 	{
   263 	// Returns either chunk handle or NULL
   285     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoBTBFCompleteL - Enter"));
       
   286     // Returns either chunk handle or NULL
   264 	// any error is assumed to be due to a pending PlayError(), so the error here is ignored - the PlayError() call will ensure the client remains lively
   287 	// any error is assumed to be due to a pending PlayError(), so the error here is ignored - the PlayError() call will ensure the client remains lively
   265 	// the chunk has been closed by the server. No action should be taken.
   288 	// the chunk has been closed by the server. No action should be taken.
   266 	TBool requestChunk = iDataBuffer==NULL; // if we have no buffer, tell server we need a chunk handle
   289 	TBool requestChunk = iDataBuffer==NULL; // if we have no buffer, tell server we need a chunk handle
   267 	TInt handle = iDevSoundProxy->BufferToBeFilledData(requestChunk, iSetPckg);
   290 	TInt handle = iDevSoundProxy->BufferToBeFilledData(requestChunk, iSetPckg);
   268 	if(handle >= KErrNone)
   291 	if(handle >= KErrNone)
   279 		
   302 		
   280 		// Let the MMF fill the buffer with data
   303 		// Let the MMF fill the buffer with data
   281 		
   304 		
   282 		iDevSoundObserver.BufferToBeFilled(iDataBuffer);
   305 		iDevSoundObserver.BufferToBeFilled(iDataBuffer);
   283 		}
   306 		}
       
   307 	SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoBTBFCompleteL - Exit"));
   284 	}
   308 	}
   285 
   309 
   286 // ----------------------------------------------------------------------------
   310 // ----------------------------------------------------------------------------
   287 // CMsgQueueHandler::DoBTBECompleteL
   311 // CMsgQueueHandler::DoBTBECompleteL
   288 // Handles CMMFDevSound object's data request event to supply CMMFDevSound
   312 // Handles CMMFDevSound object's data request event to supply CMMFDevSound
   289 // with the buffer that it needs to record.
   313 // with the buffer that it needs to record.
   290 // ----------------------------------------------------------------------------
   314 // ----------------------------------------------------------------------------
   291 //
   315 //
   292 void CMsgQueueHandler::DoBTBECompleteL()
   316 void CMsgQueueHandler::DoBTBECompleteL()
   293 	{
   317 	{
   294 	// Returns either chunk handle or NULL
   318     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoBTBECompleteL - Enter"));
       
   319     // Returns either chunk handle or NULL
   295 	// any error is assumed to be due to a pending RecordError(), so the error here is ignored - the RecordError() call will ensure the client remains lively
   320 	// any error is assumed to be due to a pending RecordError(), so the error here is ignored - the RecordError() call will ensure the client remains lively
   296 	// the chunk has been closed by the server. No action should be taken.
   321 	// the chunk has been closed by the server. No action should be taken.
   297 	TInt handle = iDevSoundProxy->BufferToBeEmptiedData(iSetPckg);
   322 	TInt handle = iDevSoundProxy->BufferToBeEmptiedData(iSetPckg);
   298 	if(handle >= KErrNone)
   323 	if(handle >= KErrNone)
   299 		{
   324 		{
   303 			}
   328 			}
   304 		iDataBuffer->SetStatus(EFull);	
   329 		iDataBuffer->SetStatus(EFull);	
   305 		iDataBuffer->Data().SetLength(iSetPckg().iRequestSize);
   330 		iDataBuffer->Data().SetLength(iSetPckg().iRequestSize);
   306 		iDevSoundObserver.BufferToBeEmptied(iDataBuffer);
   331 		iDevSoundObserver.BufferToBeEmptied(iDataBuffer);
   307 		}
   332 		}
       
   333 	SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoBTBECompleteL - Exit"));
   308 	}
   334 	}
   309 
   335 
   310 // ----------------------------------------------------------------------------
   336 // ----------------------------------------------------------------------------
   311 // CMsgQueueHandler::DoRecordErrorComplete
   337 // CMsgQueueHandler::DoRecordErrorComplete
   312 // Handles record completion or cancel event.
   338 // Handles record completion or cancel event.
   313 // ----------------------------------------------------------------------------
   339 // ----------------------------------------------------------------------------
   314 //
   340 //
   315 void CMsgQueueHandler::DoRecordErrorComplete()
   341 void CMsgQueueHandler::DoRecordErrorComplete()
   316 	{
   342 	{
   317 	iAsyncQueueFinish->CallBack(); // async call to Finish()
   343     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoRecordErrorComplete - Enter"));
       
   344     iAsyncQueueFinish->CallBack(); // async call to Finish()
   318 	iDevSoundObserver.RecordError(iCurrentItem.iErrorCode);
   345 	iDevSoundObserver.RecordError(iCurrentItem.iErrorCode);
       
   346 	SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoRecordErrorComplete - Exit"));
   319 	}
   347 	}
   320 
   348 
   321 // ----------------------------------------------------------------------------
   349 // ----------------------------------------------------------------------------
   322 // CMsgQueueHandler::DoToneFinishedComplete
   350 // CMsgQueueHandler::DoToneFinishedComplete
   323 // Handles tone play completion event.
   351 // Handles tone play completion event.
   324 // ----------------------------------------------------------------------------
   352 // ----------------------------------------------------------------------------
   325 //
   353 //
   326 void CMsgQueueHandler::DoToneFinishedComplete()
   354 void CMsgQueueHandler::DoToneFinishedComplete()
   327 	{
   355 	{
   328 	iDevSoundObserver.ToneFinished(iCurrentItem.iErrorCode);
   356     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoToneFinishedComplete - Enter"));
       
   357     iDevSoundObserver.ToneFinished(iCurrentItem.iErrorCode);
       
   358     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoToneFinishedComplete - Exit"));
   329 	}
   359 	}
   330 
   360 
   331 // ----------------------------------------------------------------------------
   361 // ----------------------------------------------------------------------------
   332 // CMsgQueueHandler::DoSendEventToClientComplete
   362 // CMsgQueueHandler::DoSendEventToClientComplete
   333 // Sends DevSound server event completion notification to the client.
   363 // Sends DevSound server event completion notification to the client.
   334 // ----------------------------------------------------------------------------
   364 // ----------------------------------------------------------------------------
   335 //
   365 //
   336 void CMsgQueueHandler::DoSendEventToClientComplete()
   366 void CMsgQueueHandler::DoSendEventToClientComplete()
   337 	{
   367 	{
   338 	iDevSoundObserver.SendEventToClient(iCurrentItem.iEventPckg());
   368     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoSendEventToClientComplete - Enter"));
       
   369     iDevSoundObserver.SendEventToClient(iCurrentItem.iEventPckg());
       
   370     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoSendEventToClientComplete - Exit"));
   339 	}
   371 	}
   340 
   372 
   341 // ----------------------------------------------------------------------------
   373 // ----------------------------------------------------------------------------
   342 // CMsgQueueHandler::DoPausedRecordComplete
   374 // CMsgQueueHandler::DoPausedRecordComplete
   343 // Handles CMMFDevSound object's data request event to supply CMMFDevSound
   375 // Handles CMMFDevSound object's data request event to supply CMMFDevSound
   344 // with the last buffer that it needs to record.
   376 // with the last buffer that it needs to record.
   345 // ----------------------------------------------------------------------------
   377 // ----------------------------------------------------------------------------
   346 //
   378 //
   347 void CMsgQueueHandler::DoPausedRecordComplete()
   379 void CMsgQueueHandler::DoPausedRecordComplete()
   348 	{
   380 	{
   349 	ASSERT(iEmptyBuffer);
   381     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoPausedRecordComplete - Enter"));
       
   382     ASSERT(iEmptyBuffer);
   350 	iEmptyBuffer->SetLastBuffer(ETrue);
   383 	iEmptyBuffer->SetLastBuffer(ETrue);
   351 	iDevSoundObserver.BufferToBeEmptied(iEmptyBuffer);
   384 	iDevSoundObserver.BufferToBeEmptied(iEmptyBuffer);
       
   385 	SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoPausedRecordComplete - Exit"));
   352 	}
   386 	}
   353 
   387 
   354 // ----------------------------------------------------------------------------
   388 // ----------------------------------------------------------------------------
   355 // CMsgQueueHandler::AssignDataBufferToChunkL
   389 // CMsgQueueHandler::AssignDataBufferToChunkL
   356 // Updates chunk handle.
   390 // Updates chunk handle.
   357 // ----------------------------------------------------------------------------
   391 // ----------------------------------------------------------------------------
   358 //
   392 //
   359 void CMsgQueueHandler::AssignDataBufferToChunkL(TInt aHandle)
   393 void CMsgQueueHandler::AssignDataBufferToChunkL(TInt aHandle)
   360 	{
   394 	{
   361 	if ( iChunk.Handle() )
   395     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::AssignDataBufferToChunkL - Enter"));
       
   396     if ( iChunk.Handle() )
   362 		{
   397 		{
   363 		iChunk.Close();
   398 		iChunk.Close();
   364 		}
   399 		}
   365 	User::LeaveIfError(iChunk.SetReturnedHandle(aHandle));
   400 	User::LeaveIfError(iChunk.SetReturnedHandle(aHandle));
   366 	// Adjust ptr to map only requested size
   401 	// Adjust ptr to map only requested size
   372 	iChunkDataPtr.Set(iChunk.Base(), iSetPckg().iBufferSize, iSetPckg().iBufferSize);
   407 	iChunkDataPtr.Set(iChunk.Base(), iSetPckg().iBufferSize, iSetPckg().iBufferSize);
   373 	if (!iDataBuffer)
   408 	if (!iDataBuffer)
   374 		{
   409 		{
   375 		iDataBuffer = CMMFPtrBuffer::NewL();	
   410 		iDataBuffer = CMMFPtrBuffer::NewL();	
   376 		}
   411 		}
   377 	UpdateDataBufferL(); 
   412 	UpdateDataBufferL();
       
   413 	SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::AssignDataBufferToChunkL - Exit"));
   378 	}
   414 	}
   379 	
   415 	
   380 void CMsgQueueHandler::UpdateDataBufferL()
   416 void CMsgQueueHandler::UpdateDataBufferL()
   381 	{
   417 	{
   382 	ASSERT(iDataBuffer); // to get here, we should have a data buffer
   418     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::UpdateDataBufferL - Enter"));
       
   419     ASSERT(iDataBuffer); // to get here, we should have a data buffer
   383 	iDataBuffer->SetPtr(iChunkDataPtr);
   420 	iDataBuffer->SetPtr(iChunkDataPtr);
   384 	iDataBuffer->SetRequestSizeL(iSetPckg().iRequestSize);
   421 	iDataBuffer->SetRequestSizeL(iSetPckg().iRequestSize);
   385 	iDataBuffer->SetLastBuffer(EFalse);	
   422 	iDataBuffer->SetLastBuffer(EFalse);
       
   423 	SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::UpdateDataBufferL - Exit"));
   386 	}
   424 	}
   387 	
   425 	
   388 void CMsgQueueHandler::Finish()
   426 void CMsgQueueHandler::Finish()
   389 	{
   427 	{
   390 	if (iDataBuffer)
   428     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::Finish - Enter"));
       
   429     if (iDataBuffer)
   391 		{
   430 		{
   392 		delete iDataBuffer;
   431 		delete iDataBuffer;
   393 		iDataBuffer = NULL;
   432 		iDataBuffer = NULL;
   394 		}
   433 		}
   395 	if (iChunk.Handle())
   434 	if (iChunk.Handle())
   396 		{
   435 		{
   397 		iChunk.Close();
   436 		iChunk.Close();
   398 		}
   437 		}
       
   438 	SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::Finish - Exit"));
   399 	}
   439 	}
   400 
   440 
   401 // 	AsyncQueueStartCallback
   441 // 	AsyncQueueStartCallback
   402 
   442 
   403 
   443 
   404 TInt CMsgQueueHandler::AsyncQueueFinishCallback(TAny* aPtr)
   444 TInt CMsgQueueHandler::AsyncQueueFinishCallback(TAny* aPtr)
   405 	{
   445 	{
   406 	CMsgQueueHandler* self = static_cast<CMsgQueueHandler*>(aPtr);
   446     CMsgQueueHandler* self = static_cast<CMsgQueueHandler*>(aPtr);
   407 	self->DoAsyncQueueFinishCallback();
   447 	self->DoAsyncQueueFinishCallback();
   408 	return KErrNone;
   448 	return KErrNone;
   409 	}
   449 	}
   410 	
   450 	
   411 void CMsgQueueHandler::DoAsyncQueueFinishCallback()
   451 void CMsgQueueHandler::DoAsyncQueueFinishCallback()
   412 	{
   452 	{
   413 	Finish();
   453     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoAsyncQueueFinishCallback - Enter"));
       
   454     Finish();
       
   455     SYMBIAN_DEBPRN0(_L("CMsgQueueHandler[0x%x]::DoAsyncQueueFinishCallback - Exit"));
   414 	}
   456 	}
   415 
   457 
   416 
   458 
   417 // End of File
   459 // End of File