sl@0: /*
sl@0: * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: * All rights reserved.
sl@0: * This component and the accompanying materials are made available
sl@0: * under the terms of "Eclipse Public License v1.0"
sl@0: * which accompanies this distribution, and is available
sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: *
sl@0: * Initial Contributors:
sl@0: * Nokia Corporation - initial contribution.
sl@0: *
sl@0: * Contributors:
sl@0: *
sl@0: * Description:
sl@0: *
sl@0: */
sl@0: 
sl@0: 
sl@0: 
sl@0: #ifndef MMFDEVSOUNDCALLBACKHANDLER_H
sl@0: #define MMFDEVSOUNDCALLBACKHANDLER_H
sl@0: 
sl@0: //  INCLUDES
sl@0: #include <e32base.h>
sl@0: #include <e32msgqueue.h>
sl@0: #include "mmfaudioclientserver.h"
sl@0: 
sl@0: // CLASS DECLARATION
sl@0: class RMMFDevSoundProxy;
sl@0: class MDevSoundObserver;
sl@0: 
sl@0: /**
sl@0: *  Utility class to handle Play Error callback from DevSound server.
sl@0: *
sl@0: *  @lib MMFDevSound.dll
sl@0: *  @since 
sl@0: */
sl@0: class CMsgQueueHandler : public CActive
sl@0: 	{
sl@0: public:  // Constructors and destructor
sl@0: 
sl@0: 	/**
sl@0: 	* Constructs, and returns a pointer to, a new
sl@0: 	* CMMFPlayErrorHandler object.
sl@0: 	* Leaves on failure..
sl@0: 	* @param RMMFDevSoundProxy* aDevSoundProxy A handle to DevSoundProxy to
sl@0: 	*        subcribe for event notification from server.
sl@0: 	* @param MDevSoundObserver& aDevSoundObserver A reference to
sl@0: 	*        MDevSoundObserver to which the events will be forwarded to.
sl@0: 	* @param aDevSoundCIObserver Observer which will receive Custom Interface events
sl@0: 	* @return CMMFPlayErrorHandler* A pointer to newly created object.
sl@0: 	*/
sl@0: 	static CMsgQueueHandler* NewL(RMMFDevSoundProxy* aDevSoundProxy,
sl@0: 								MDevSoundObserver& aDevSoundObserver,
sl@0: 								RMsgQueue<TMMFDevSoundQueueItem>* aMsgQueue,
sl@0: 								MMMFDevSoundCustomInterfaceObserver& aDevSoundCIObserver);
sl@0: 	/**
sl@0: 	* Destructor.
sl@0: 	*/
sl@0: 	~CMsgQueueHandler();
sl@0: 
sl@0: 	/**
sl@0: 	* Subscribes for Play Error event from DevSound server.
sl@0: 	* @since 
sl@0: 	* @return void
sl@0: 	*/
sl@0: 	void ReceiveEvents();
sl@0: 
sl@0: 	/**
sl@0: 	* Called by DevSound server when Play Error event occurs.
sl@0: 	* Leaves on failure.
sl@0: 	* @since 
sl@0: 	* @return void
sl@0: 	*/
sl@0: 	void RunL();
sl@0: 
sl@0: 	/**
sl@0: 	* Called by CActive object framework if RunL leaves.
sl@0: 	* @since 
sl@0: 	* @param TInt aError Reason for leave
sl@0: 	* @return TInt KErrNone if error is handled succesfully, else
sl@0: 	* corresponding error codel
sl@0: 	*/
sl@0: 	TInt RunError(TInt aError);
sl@0: 
sl@0: 	/**
sl@0: 	* Called by CActive object framework when client cancels active object.
sl@0: 	* @since 
sl@0: 	* @return void
sl@0: 	*/
sl@0: 	void DoCancel();
sl@0: 	/**
sl@0: 	* Called as part of Stop() process to recover any buffers etc
sl@0: 	*/
sl@0: 	void Finish();
sl@0: 
sl@0: private:
sl@0: 	/**
sl@0: 	* C++ default constructor.
sl@0: 	*/
sl@0: 	CMsgQueueHandler(RMMFDevSoundProxy* aDevSoundProxy,
sl@0: 					MDevSoundObserver& aDevSoundObserver,
sl@0: 					RMsgQueue<TMMFDevSoundQueueItem>* aMsgQueue,
sl@0: 					MMMFDevSoundCustomInterfaceObserver& aDevSoundCIObserver);
sl@0: 	/**
sl@0: 	* By default Symbian 2nd phase constructor is private.
sl@0: 	*/
sl@0: 	void ConstructL();
sl@0: 
sl@0: 	/*
sl@0: 	* Handles initialization completion event.
sl@0: 	*/
sl@0: 	void DoInitComplete();
sl@0: 
sl@0: 	/*
sl@0: 	* Handles play completion or cancel event.
sl@0: 	*/
sl@0: 	void DoPlayErrorComplete();
sl@0: 
sl@0: 	/*
sl@0: 	* Handles record completion or cancel event.
sl@0: 	*/
sl@0: 	void DoRecordErrorComplete();
sl@0: 
sl@0: 	/*
sl@0: 	* Handles CMMFDevSound object's data request event to supply
sl@0: 	* CMMFDevSound with the buffer that it needs to play.
sl@0: 	*/
sl@0: 	void DoBTBFCompleteL();
sl@0: 
sl@0: 	/*
sl@0: 	* Handles CMMFDevSound object's data request event to supply
sl@0: 	* CMMFDevSound with the buffer that it needs to record.
sl@0: 	*/
sl@0: 	void DoBTBECompleteL();
sl@0: 
sl@0: 	/*
sl@0: 	* Handles tone play completion event.
sl@0: 	*/
sl@0: 	void DoToneFinishedComplete();
sl@0: 
sl@0: 	/*
sl@0: 	* Sends DevSound server event completion notification to the client.
sl@0: 	*/
sl@0: 	void DoSendEventToClientComplete();
sl@0: 	
sl@0: 	/* Handles CMMFDevSound object's data request event to supply 
sl@0: 	* CMMFDevSound with the last buffer that it needs to record.
sl@0: 	*/
sl@0: 	void DoPausedRecordComplete();
sl@0: 	
sl@0: 	/*
sl@0: 	* Allocates local data buffer and links it with the global chunk.
sl@0: 	* @param aHandle Handle to a global chunk or 0 if chunk already exists.
sl@0: 	*/
sl@0: 	void AssignDataBufferToChunkL(TInt aHandle);
sl@0: 	/*
sl@0: 	* Update existing data buffer with latest buffer info from server
sl@0: 	* but using existing chunk
sl@0: 	*/
sl@0: 	void UpdateDataBufferL();
sl@0: 	
sl@0: 	static TInt AsyncQueueFinishCallback(TAny* aPtr);
sl@0: 	void DoAsyncQueueFinishCallback();
sl@0: 
sl@0: private:
sl@0: 	
sl@0: 	RMMFDevSoundProxy* iDevSoundProxy;
sl@0: 	MDevSoundObserver& iDevSoundObserver;
sl@0: 	TMMFDevSoundProxyHwBufPckg iSetPckg;
sl@0: 
sl@0: 	TMMFEventPckg iEventPckg;
sl@0: 
sl@0: 	RMsgQueue<TMMFDevSoundQueueItem>* iMsgQueue;
sl@0: 	TMMFDevSoundQueueItem   iCurrentItem;
sl@0: 	RChunk iChunk;
sl@0: 	TPtr8 iChunkDataPtr;
sl@0: 	CMMFPtrBuffer* iDataBuffer;
sl@0: 	CMMFDataBuffer* iEmptyBuffer;
sl@0: 	MMMFDevSoundCustomInterfaceObserver& iDevSoundCIObserver;
sl@0: 	CAsyncCallBack*				iAsyncQueueFinish;
sl@0: 	};
sl@0: 
sl@0: #endif      // MMFDEVSOUNDCALLBACKHANDLER_H
sl@0: 
sl@0: // End of File