// -----------------------------------------------------------------------------
// CRa8CustomInterfaceMsgHdlr::DoFrameNumberL
// Handles the message from the proxy and calls the custom interface method.
// The data passed from the proxy is read from the message and passed to
// the custom interface.
// (other items were commented in a header).
// -----------------------------------------------------------------------------
//
void CRa8CustomInterfaceMsgHdlr::DoFrameNumberL(TMMFMessage& aMessage)
    {
	TInt frame = iRa8CustomInterface->FrameNumber();
	TPckgBuf<TInt> pckg(frame);
	aMessage.WriteDataToClientL(pckg);
    aMessage.Complete(KErrNone);
    }
TBool CMidiCustomCommandParser::DoPercussionKeyNameL(TMMFMessage& aMessage)
	{
	TPckgBuf<TMMFMidiConfig2> pckg;
	aMessage.ReadData1FromClientL(pckg);

	// Prevent memory leaks by deleting old key name - something must have gone wrong in the client
	// if it already exists
	delete iPercussionKeyName;
	iPercussionKeyName = NULL;

	const TDesC& percussionKeyName = iImplementor.MmcPercussionKeyNameL(pckg().iNote, pckg().iBankId, pckg().iCustom, pckg().iInstrumentId);

	iPercussionKeyName = CBufFlat::NewL(32);
	RBufWriteStream stream;
	stream.Open(*iPercussionKeyName);
	CleanupClosePushL(stream);
	stream << percussionKeyName;
	CleanupStack::PopAndDestroy();//s

	// Write the size of the descriptor back to the client
	TPckgBuf<TInt> descriptorSizePckg(iPercussionKeyName->Ptr(0).Length());	
	aMessage.WriteDataToClientL(descriptorSizePckg);	
	
	return ETrue;
	}
// ---------------------------------------------------------
// CErrorConcealmentIntfcMsgHdlr::DoSetFrameModeL
// Handles the message from the proxy and calls the custom interface method.
// The data passed from the proxy is read from the message and passed to
// the custom interface.
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CErrorConcealmentIntfcMsgHdlr::DoSetFrameModeL(TMMFMessage& aMessage)
    {
	TPckgBuf<TBool> pckg;
	aMessage.ReadData1FromClientL(pckg);
	TInt status = iErrorConcealmentIntfcCI->SetFrameMode(pckg());
    aMessage.Complete(status);
    }
// ---------------------------------------------------------
// CErrorConcealmentIntfcMsgHdlr::DoHandleRequestL
// Determines which custom interface to call.
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CErrorConcealmentIntfcMsgHdlr::DoHandleRequestL(TMMFMessage& aMessage)
	{
	switch(aMessage.Function())
		{
		case EEcimConcealError:
			{
    		DoConcealErrorForNextBufferL(aMessage);
			break;
			}
		case EEcimSetFrameMode:
			{
    		DoSetFrameModeL(aMessage);
			break;
			}
		case EEcimFrameModeRqrd:
			{
    		DoFrameModeRqrdForEcL(aMessage);
			break;
			}
		default:
			{
			aMessage.Complete(KErrNotSupported);
			}
		}
	}
// ---------------------------------------------------------
// CListenerOrientationMessageHandler::DoObserveL
// Receives the observation request message and depending
// on the status of the effect data queue, the message is
// completed immediately or saved for later completion.
// ---------------------------------------------------------
//
void CListenerOrientationMessageHandler::DoObserveL(
	TMMFMessage& aMessage )
	{

#ifdef _DEBUG
    RDebug::Print(_L("CListenerOrientationMessageHandler::DoObserveL"));
#endif

	if ( !iRegistered ) // Don't register again if we're registered.
		{
		iListenerOrientation->RegisterObserverL(*this);
		iRegistered = ETrue;
		}

	if ( iEffectDataQue->IsEmpty() )
		{
		// Message is saved and completed when an event occurs
		iMessage = new(ELeave) TMMFMessage(aMessage);
		}
	else
		{
		TEfOrientationDataPckg dataPckg;
		CEffectDataQueItem* item = iEffectDataQue->First();
		dataPckg.Copy(item->EffectData());
		aMessage.WriteDataToClient(dataPckg);
		aMessage.Complete(KErrNone);
		iEffectDataQue->Remove(*item);
		delete item;
		}
	}
// ---------------------------------------------------------
// CListenerOrientationMessageHandler::DoHandleRequestL
// Dispatches the message to the appropriate handler.
// ---------------------------------------------------------
//
void CListenerOrientationMessageHandler::DoHandleRequestL(
	TMMFMessage& aMessage )
	{
	switch( aMessage.Function() )
		{
		case ELofInitialize: // Request to initialize the bassboost
			{
			DoInitializeL(aMessage);
			break;
			}
		case ELofApply: // Request to apply the bassboost settings
			{
			DoApplyL(aMessage);
			break;
			}
		case ELofObserve: // Observation request
			{
			DoObserveL(aMessage);
			break;
			}
		default:
			{
			aMessage.Complete(KErrNotSupported);
			}
		}
	}
// ---------------------------------------------------------
// CEnvironmentalReverbMessageHandler::DoObserveL
// Receives the observation request message and depending
// on the status of the effect data queue, the message is
// completed immediately or saved for later completion.
// ---------------------------------------------------------
//
void CEnvironmentalReverbMessageHandler::DoObserveL(
	TMMFMessage& aMessage )
	{

#ifdef _DEBUG
    RDebug::Print(_L("CEnvironmentalReverbMessageHandler::DoObserveL"));
#endif

	if ( !iRegistered )
		{
		iEnvironmentalReverb->RegisterObserverL(*this);
		iRegistered = ETrue;
		}

	if ( iEffectDataQue->IsEmpty() )
		{
		//iMessage = &aMessage;
		iMessage = new(ELeave) TMMFMessage(aMessage);
		}
	else
		{
		TEfEnvReverbDataPckg dataPckg;
		CEffectDataQueItem* item = iEffectDataQue->First();
		dataPckg.Copy(item->EffectData());
		aMessage.WriteDataToClient(dataPckg);
		aMessage.Complete(KErrNone);
		iEffectDataQue->Remove(*item);
		delete item;
		}
	}
// ---------------------------------------------------------
// CIlbcEncoderIntfcMsgHdlr::DoHandleRequestL
// Determines which custom interface to call.
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CIlbcEncoderIntfcMsgHdlr::DoHandleRequestL(TMMFMessage& aMessage)
	{
	switch(aMessage.Function())
		{
		case EIlbceimSetEncoderMode:
			{
    		DoSetEncoderModeL(aMessage);
			break;
			}
		case EIlbceimSetVadMode:
			{
			DoSetVadModeL(aMessage);
			break;
			}
		case EIlbceimGetVadMode:
			{
			DoGetVadModeL(aMessage);
			break;
			}
		default:
			{
			aMessage.Complete(KErrNotSupported);
			}
		}
	}
// ---------------------------------------------------------
// CEnvironmentalReverbMessageHandler::DoHandleRequestL
// Dispatches the message to the appropriate handler.
// ---------------------------------------------------------
//
void CEnvironmentalReverbMessageHandler::DoHandleRequestL(
	TMMFMessage& aMessage )
	{
	switch( aMessage.Function() )
		{
		case EErfInitialize:
			{
			DoInitializeL(aMessage);
			break;
			}
		case EErfApply:
			{
			DoApplyL(aMessage);
			break;
			}
		case EErfObserve:
			{
			DoObserveL(aMessage);
			break;
			}
			
			
			
		default:
			{
			aMessage.Complete(KErrNotSupported);
			}
		}
	}
// ---------------------------------------------------------
// CIlbcEncoderIntfcMsgHdlr::DoSetVadModeL
// Handles the message from the proxy and calls the custom interface method.
// The data passed from the proxy is read from the message and passed to
// the custom interface.
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CIlbcEncoderIntfcMsgHdlr::DoSetVadModeL(TMMFMessage& aMessage)
	{
	TPckgBuf<TBool> pckgBuf;
	aMessage.ReadData1FromClientL(pckgBuf);
	TInt status = iIlbcEncoderIntfcCI->SetVadMode(pckgBuf());
    aMessage.Complete(status);
	}
// ---------------------------------------------------------
// CAacDecoderConfigMsgHdlr::DoSetAudioConfigL
// Handles the message from the proxy and calls the custom interface method.
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CAacDecoderConfigMsgHdlr::DoSetAudioConfigL(TMMFMessage& aMessage)
    {
	TPckgBuf<TAudioConfig> pckg;
	aMessage.ReadData1FromClientL(pckg);
	TInt status = iAacDecoderConfigCI->SetAudioConfig(pckg());
    aMessage.Complete(status);
    }
// ---------------------------------------------------------
// CEnvironmentalReverbMessageHandler::DoInitializeL
// ---------------------------------------------------------
//
void CEnvironmentalReverbMessageHandler::DoInitializeL(TMMFMessage& aMessage)
	{
#ifdef _DEBUG
    RDebug::Print(_L("CEnvironmentalReverbMessageHandler::DoInitializeL"));
#endif
	aMessage.WriteDataToClient(iEnvironmentalReverb->DoEffectData());
	aMessage.Complete(KErrNone);
	}
// Handles a request from the client. Called by the controller framework.
void CStreamControlCustomCommandParser::HandleRequest( TMMFMessage& aMessage )
    {
    TInt status = KErrNotSupported;
    if ( aMessage.Destination().InterfaceId() == KUidIFStreamControlCustomCommands )
        {
        status = DoHandleRequest( aMessage );
        }
    aMessage.Complete(status);
    }
// ---------------------------------------------------------
// CAacDecoderConfigMsgHdlr::HandleRequest
// Handles the messages from the proxy.
// Calls a subfunction which determines which custom interface to call.
// A subfunction is used to contain multiple leaving functions for a single
// trap.
// (other items were commented in a header).
// ---------------------------------------------------------
//
EXPORT_C void CAacDecoderConfigMsgHdlr::HandleRequest(TMMFMessage& aMessage)
	{
	ASSERT(aMessage.Destination().InterfaceId() == KUidAacDecoderConfig);
	TRAPD(error,DoHandleRequestL(aMessage));
	if(error)
		{
		aMessage.Complete(error);
		}
	}
// -----------------------------------------------------------------------------
// CRa8CustomInterfaceMsgHdlr::HandleRequest
// Handles the messages from the proxy.
// Calls a subfunction which determines which custom interface to call.
// A subfunction is used to contain multiple leaving functions for a single
// trap.
// (other items were commented in a header).
// -----------------------------------------------------------------------------
//
EXPORT_C void CRa8CustomInterfaceMsgHdlr::HandleRequest(TMMFMessage& aMessage)
	{
	ASSERT(aMessage.Destination().InterfaceId() == KUidRa8DecHwDeviceCI);
	TRAPD(error,DoHandleRequestL(aMessage));
	if (error)
		{
		aMessage.Complete(error);
		}
	}
// ---------------------------------------------------------
// CEnvironmentalReverbMessageHandler::HandleRequest
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CEnvironmentalReverbMessageHandler::HandleRequest(
	TMMFMessage& aMessage )
	{
	ASSERT(aMessage.Destination().InterfaceId() == KUidEnvironmentalReverbEffect);
	TRAPD(error,DoHandleRequestL(aMessage));
	if ( error )
		{
		aMessage.Complete(error);
		}
	}
TBool CMidiCustomCommandParser::DoSetPitchTranspositionL(TMMFMessage& aMessage)
	{
	TPckgBuf<TMMFMidiConfig1> pckg;
	aMessage.ReadData1FromClientL(pckg);
	TInt centsApplied;
	iImplementor.MmcSetPitchTranspositionL(pckg().iPitch, centsApplied);
	pckg().iPitch = centsApplied;
	aMessage.WriteDataToClientL(pckg);
	return ETrue;
	}
// ---------------------------------------------------------
// CIlbcEncoderIntfcMsgHdlr::HandleRequest
// Handles the messages from the proxy.
// Calls a subfunction which determines which custom interface to call.
// A subfunction is used to contain multiple leaving functions for a single
// trap.
// (other items were commented in a header).
// ---------------------------------------------------------
//
EXPORT_C void CIlbcEncoderIntfcMsgHdlr::HandleRequest(
                                                       TMMFMessage& aMessage)
	{
	ASSERT(aMessage.Destination().InterfaceId() == KUidIlbcEncoderIntfc);
	TRAPD(error,DoHandleRequestL(aMessage));
	if(error)
		{
		aMessage.Complete(error);
		}
	}
TBool CMidiCustomCommandParser::DoSendMessageWithTimeStampL(TMMFMessage& aMessage)
	{
	TPckgBuf<TMMFMidiConfig3> pckg;
	aMessage.ReadData1FromClientL(pckg);
	TInt bytesProcessed;
	iImplementor.MmcSendMessageL(*(pckg().iMidiMessage), pckg().iTimeStamp, bytesProcessed);
	pckg().iBytesProcessed = bytesProcessed;
	aMessage.WriteDataToClientL(pckg);
	return ETrue;
	}
// ---------------------------------------------------------
// CListenerOrientationMessageHandler::DoApplyL
// Extracts the data from the message. The client bassboost data
// is applied to the CI bassboost object.
// ---------------------------------------------------------
//
void CListenerOrientationMessageHandler::DoApplyL(
	TMMFMessage& aMessage )
	{
    TEfOrientationDataPckg orientationPckgFromClient;
    aMessage.ReadData1FromClient(orientationPckgFromClient);

	iListenerOrientation->SetEffectData(orientationPckgFromClient);
	iListenerOrientation->ApplyL();
	aMessage.Complete(KErrNone);
	}
TBool CMidiCustomCommandParser::DoLoadCustomBankDataL(TMMFMessage& aMessage)
	{
	TPckgBuf<TMMFMidiConfig2> pckg;
	aMessage.ReadData1FromClientL(pckg);
	TInt bankId;
	iImplementor.MmcLoadCustomBankDataL(*(pckg().iBankData), bankId);
	pckg().iBankId = bankId;
	aMessage.WriteDataToClientL(pckg);
	return ETrue;
	}
// ---------------------------------------------------------
// CListenerOrientationMessageHandler::HandleRequest
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CListenerOrientationMessageHandler::HandleRequest(
	TMMFMessage& aMessage )
	{
	ASSERT(aMessage.Destination().InterfaceId() == KUidListenerOrientationEffect);
	TRAPD(error,DoHandleRequestL(aMessage));
	if ( error )
		{
		aMessage.Complete(error);
		}
	}
TBool CMidiCustomCommandParser::DoCustomBankLoadedL(TMMFMessage& aMessage)
	{
	TPckgBuf<TMMFMidiConfig2> pckg;
	aMessage.ReadData1FromClientL(pckg);
	TBool bankLoaded;
	iImplementor.MmcCustomBankLoadedL(pckg().iBankId, bankLoaded);
	pckg().iBankLoaded = bankLoaded;
	aMessage.WriteDataToClientL(pckg);
	return ETrue;
	}
TBool CMidiCustomCommandParser::DoNumberOfInstrumentsL(TMMFMessage& aMessage)
	{
	TPckgBuf<TMMFMidiConfig2> pckg;
	aMessage.ReadData1FromClientL(pckg);
	TInt numInstruments;
	iImplementor.MmcNumberOfInstrumentsL(pckg().iBankId, pckg().iCustom, numInstruments);	
	pckg().iNumInstruments = numInstruments;
	aMessage.WriteDataToClientL(pckg);
	return ETrue;
	}
TBool CMidiCustomCommandParser::DoGetInstrumentIdL(TMMFMessage& aMessage)
	{
	TPckgBuf<TMMFMidiConfig2> pckg;
	aMessage.ReadData1FromClientL(pckg);
	TInt instrumentId;
	iImplementor.MmcGetInstrumentIdL(pckg().iBankId, pckg().iCustom, pckg().iInstrumentIndex, instrumentId);
	pckg().iInstrumentId = instrumentId;
	aMessage.WriteDataToClientL(pckg);
	return ETrue;
	}
TBool CMidiCustomCommandParser::DoChannelVolumeL(TMMFMessage& aMessage)
	{
	TPckgBuf<TMMFMidiConfig2> pckg;
	aMessage.ReadData1FromClientL(pckg);
	TReal32 channelVol;
	iImplementor.MmcChannelVolumeL(pckg().iChannel, channelVol);
	pckg().iChannelVol = channelVol;
	aMessage.WriteDataToClientL(pckg);
	return ETrue;
	}
TBool CMidiCustomCommandParser::DoIsChannelMuteL(TMMFMessage& aMessage)
	{
	TPckgBuf<TMMFMidiConfig2> pckg;
	aMessage.ReadData1FromClientL(pckg);
	TBool mute;
	iImplementor.MmcIsChannelMuteL(pckg().iChannel, mute);
	pckg().iMuted = mute;
	aMessage.WriteDataToClientL(pckg);
	return ETrue;
	}
// ---------------------------------------------------------
// CIlbcEncoderIntfcMsgHdlr::DoGetVadModeL
// Handles the message from the proxy and calls the custom interface.
// The custom interface returns the data requested and this function
// writes it back to the proxy.
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CIlbcEncoderIntfcMsgHdlr::DoGetVadModeL(TMMFMessage& aMessage)
	{
	TBool vadMode;
	TInt status = iIlbcEncoderIntfcCI->GetVadMode(vadMode);
	if (status == KErrNone)
    	{
    	TPckgBuf<TBool> pckgBuf;
	    pckgBuf() = vadMode;
    	aMessage.WriteDataToClientL(pckgBuf);
    	}
    aMessage.Complete(status);
	}
// ---------------------------------------------------------
// CErrorConcealmentIntfcMsgHdlr::DoFrameModeRqrdForEcL
// Handles the message from the proxy and calls the custom interface method.
// The custom interface returns the data requested and this function
// writes it back to the proxy.
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CErrorConcealmentIntfcMsgHdlr::DoFrameModeRqrdForEcL(TMMFMessage& aMessage)
    {
	TBool frameModeRqrd;
	TInt status = iErrorConcealmentIntfcCI->FrameModeRqrdForEC(frameModeRqrd);
	if (status == KErrNone)
    	{
    	TPckgBuf<TBool> pckg;
	    pckg() = frameModeRqrd;
    	aMessage.WriteDataToClientL(pckg);
    	}
    aMessage.Complete(status);
    }
// -----------------------------------------------------------------------------
// CRa8CustomInterfaceMsgHdlr::DoSetInitStringL
// Handles the message from the proxy and calls the custom interface method.
// The data passed from the proxy is read from the message and passed to
// the custom interface.
// (other items were commented in a header).
// -----------------------------------------------------------------------------
//
void CRa8CustomInterfaceMsgHdlr::DoSetInitStringL(TMMFMessage& aMessage)
    {
	TInt size = aMessage.SizeOfData1FromClient();
	HBufC8* dataBuf = HBufC8::NewL(size);
	CleanupStack::PushL( dataBuf );
	TPtr8 dataPtr = dataBuf->Des();
    aMessage.ReadData1FromClientL(dataPtr);
	TInt status = iRa8CustomInterface->SetInitString(dataPtr);
	CleanupStack::Pop(dataBuf);
	delete dataBuf;
    aMessage.Complete(status);
    }