sl@0: // Copyright (c) 2007-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: #include <ecom/implementationproxy.h>
sl@0: #include <ecom/implementationproxy.h>
sl@0: #include <ecom/ecom.h>
sl@0: #include <s32mem.h>
sl@0: 
sl@0: #include "errorconcealmentci.h"
sl@0: 
sl@0: 
sl@0: // MUX //
sl@0: 
sl@0: TInt CMMFErrorConcealmentIntfcMux::OpenInterface(TUid /*aInterfaceId*/)
sl@0: 	{
sl@0: 	// attempt to open the interface link with the
sl@0: 	// remote slave device
sl@0: 	iRemoteHandle = -1;
sl@0: 	TUid slaveId = {KMmfUidCustomInterfaceErrorConcealmentIntfcDeMux};
sl@0: 
sl@0: 	TInt handle = iUtility->OpenSlave(slaveId, KNullDesC8);
sl@0: 	if (handle >= 0)
sl@0: 		{
sl@0: 		iRemoteHandle = handle;
sl@0: 		}
sl@0: 
sl@0: 	return iRemoteHandle;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: void CMMFErrorConcealmentIntfcMux::Release()
sl@0: 	{
sl@0: 	// close the slave device if it exists
sl@0: 	if (iRemoteHandle > 0)
sl@0: 		{
sl@0: 		// we assume the slave is closed correctly
sl@0: 		iUtility->CloseSlave(iRemoteHandle);
sl@0: 		}
sl@0: 
sl@0: 	TUid key = iKey;
sl@0: 	delete this;
sl@0: 
sl@0: 	// tell ECom to destroy us
sl@0: 	REComSession::DestroyedImplementation(key);
sl@0: 	}
sl@0: 
sl@0: 
sl@0: void CMMFErrorConcealmentIntfcMux::PassDestructorKey(TUid aDestructorKey)
sl@0: 	{
sl@0: 	// store the destructor key
sl@0: 	iKey = aDestructorKey;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: void CMMFErrorConcealmentIntfcMux::CompleteConstructL(MMMFDevSoundCustomInterfaceMuxUtility* aCustomUtility)
sl@0: 	{
sl@0: 	// store a pointer to the utility
sl@0: 	iUtility = aCustomUtility;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: MMMFDevSoundCustomInterfaceMuxPlugin* CMMFErrorConcealmentIntfcMux::NewL()
sl@0: 	{
sl@0: 	CMMFErrorConcealmentIntfcMux* self = new (ELeave) CMMFErrorConcealmentIntfcMux;
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: TAny* CMMFErrorConcealmentIntfcMux::CustomInterface(TUid /*aInterfaceId*/)
sl@0: 	{
sl@0: 	MMMFErrorConcealmentIntfc* interface = this;
sl@0: 	return interface;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: CMMFErrorConcealmentIntfcMux::CMMFErrorConcealmentIntfcMux() :
sl@0: 	iRemoteHandle(-1)
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: 
sl@0: CMMFErrorConcealmentIntfcMux::~CMMFErrorConcealmentIntfcMux()
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: 
sl@0: // from MErrorConcealmentIntfc
sl@0: TInt CMMFErrorConcealmentIntfcMux::ConcealErrorForNextBuffer()
sl@0: 	{
sl@0: 	TInt result = KErrBadHandle;
sl@0: 
sl@0: 	if (iRemoteHandle > 0)
sl@0: 		{
sl@0: 		// any return code other than zero is an error
sl@0: 		result = iUtility->SendSlaveSyncCommand(iRemoteHandle,
sl@0: 												EMMFDevSoundCIErrorConcealmentIntfcConcealErrorForNextBuffer,
sl@0: 												KNullDesC8);
sl@0: 		}
sl@0: 
sl@0: 	return result;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: // from MErrorConcealmentIntfc
sl@0: TInt CMMFErrorConcealmentIntfcMux::SetFrameMode(TBool aFrameModeOn)
sl@0: 	{
sl@0: 	TInt result = KErrBadHandle;
sl@0: 
sl@0: 	if (iRemoteHandle > 0)
sl@0: 		{
sl@0: 		// send the cng in the sync command
sl@0: 		TPckgBuf<TBool> frameModeOn(aFrameModeOn);
sl@0: 
sl@0: 		// any return code other than zero is an error
sl@0: 		result = iUtility->SendSlaveSyncCommand(iRemoteHandle,
sl@0: 												EMMFDevSoundCIErrorConcealmentIntfcSetFrameMode,
sl@0: 												frameModeOn);
sl@0: 		}
sl@0: 
sl@0: 	return result;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: // from MErrorConcealmentIntfc
sl@0: TInt CMMFErrorConcealmentIntfcMux::FrameModeRqrdForEC(TBool& aFrameModeRqrd)
sl@0: 	{
sl@0: 	TInt result = KErrBadHandle;
sl@0: 
sl@0: 	if (iRemoteHandle > 0)
sl@0: 		{
sl@0: 		// holds the returned value.
sl@0: 		TPckgBuf<TBool> retFrameModeRqrd;
sl@0: 
sl@0: 		// any return code other than zero is an error
sl@0: 		result = iUtility->SendSlaveSyncCommandResult(iRemoteHandle,
sl@0: 													  EMMFDevSoundCIErrorConcealmentIntfcFrameModeRqrdForEC,
sl@0: 													  KNullDesC8,
sl@0: 													  retFrameModeRqrd);
sl@0: 
sl@0: 		// assign return values to aFrameModeRqrd. Do nothing if there is an error
sl@0: 		if(result == KErrNone)
sl@0: 			{
sl@0: 			aFrameModeRqrd = retFrameModeRqrd();
sl@0: 			}
sl@0: 		}
sl@0: 
sl@0: 	return result;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: 
sl@0: // DEMUX //	
sl@0: 
sl@0: TInt CMMFErrorConcealmentIntfcDeMux::OpenInterface(TUid /*aInterfaceId*/)
sl@0: 	{
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: void CMMFErrorConcealmentIntfcDeMux::Release()
sl@0: 	{
sl@0: 	TUid key = iKey;
sl@0: 
sl@0: 	delete this;
sl@0: 
sl@0: 	// tell ECom to destroy us
sl@0: 	REComSession::DestroyedImplementation(key);
sl@0: 	}
sl@0: 
sl@0: 
sl@0: void CMMFErrorConcealmentIntfcDeMux::PassDestructorKey(TUid aDestructorKey)
sl@0: 	{
sl@0: 	// store the destructor key
sl@0: 	iKey = aDestructorKey;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: void CMMFErrorConcealmentIntfcDeMux::SetInterfaceTarget(MMMFDevSoundCustomInterfaceTarget* aTarget)
sl@0: 	{
sl@0: 	iTarget = aTarget;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: void CMMFErrorConcealmentIntfcDeMux::CompleteConstructL(MMMFDevSoundCustomInterfaceDeMuxUtility* aCustomUtility)
sl@0: 	{
sl@0: 	// store a pointer to the utility
sl@0: 	iUtility = aCustomUtility;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: void CMMFErrorConcealmentIntfcDeMux::RefreshL()
sl@0: 	{
sl@0: 	// refetch the Error Concealment intfc custom interface if we already have a target
sl@0: 	if (iTarget)
sl@0: 		{
sl@0: 		iInterfaceErrorConcealmentIntfc = static_cast <MMMFErrorConcealmentIntfc*> (iTarget->CustomInterface(KUidErrorConcealmentIntfc));
sl@0: 
sl@0: 		if (!iInterfaceErrorConcealmentIntfc)
sl@0: 			{
sl@0: 			iInterfaceErrorConcealmentIntfc = NULL;
sl@0: 			User::Leave(KErrNotSupported);
sl@0: 			}
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: 
sl@0: MMMFDevSoundCustomInterfaceDeMuxPlugin* CMMFErrorConcealmentIntfcDeMux::NewL()
sl@0: 	{
sl@0: 	CMMFErrorConcealmentIntfcDeMux* self = new (ELeave) CMMFErrorConcealmentIntfcDeMux;
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: CMMFErrorConcealmentIntfcDeMux::CMMFErrorConcealmentIntfcDeMux()
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: 
sl@0: CMMFErrorConcealmentIntfcDeMux::~CMMFErrorConcealmentIntfcDeMux()
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: 
sl@0: TInt CMMFErrorConcealmentIntfcDeMux::DoOpenSlaveL(TUid /*aInterface*/, const TDesC8& /*aPackageBuf*/)
sl@0: 	{
sl@0: 	// fetch the Error Concealment intfc Hw Device custom interface
sl@0: 	iInterfaceErrorConcealmentIntfc = static_cast<MMMFErrorConcealmentIntfc*> (iTarget->CustomInterface(KUidErrorConcealmentIntfc)); 
sl@0: 
sl@0: 	if (!iInterfaceErrorConcealmentIntfc)
sl@0: 		{
sl@0: 		iInterfaceErrorConcealmentIntfc = NULL;
sl@0: 		User::Leave(KErrNotSupported);
sl@0: 		}
sl@0: 
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: void CMMFErrorConcealmentIntfcDeMux::DoCloseSlaveL(TInt /*aHandle*/)
sl@0: 	{
sl@0: 	// nothing to do
sl@0: 	}
sl@0: 
sl@0: 
sl@0: // original RMessage is supplied so that remote demux plugin can extract necessary details
sl@0: // using DeMux utility
sl@0: TInt CMMFErrorConcealmentIntfcDeMux::DoSendSlaveSyncCommandL(const RMmfIpcMessage& aMessage)
sl@0: 	{
sl@0: 	TMMFDevSoundCIMessageData data;
sl@0: 	TInt result = KErrGeneral;
sl@0: 
sl@0: 	// decode message
sl@0: 	iUtility->GetSyncMessageDataL(aMessage, data);
sl@0: 
sl@0: 	switch (data.iCommand)
sl@0: 		{
sl@0: 		case EMMFDevSoundCIErrorConcealmentIntfcConcealErrorForNextBuffer:
sl@0: 			{
sl@0: 			result = DoConcealErrorForNextBufferL();
sl@0: 
sl@0: 			break;
sl@0: 			}
sl@0: 		case EMMFDevSoundCIErrorConcealmentIntfcSetFrameMode:
sl@0: 			{
sl@0: 			TPckgBuf<TBool> frameModeOn; 
sl@0: 			iUtility->ReadFromInputDesL(aMessage, &frameModeOn);
sl@0: 			
sl@0: 			result = DoSetFrameModeL(frameModeOn());
sl@0: 
sl@0: 			break;
sl@0: 			}
sl@0: 		default:
sl@0: 			{
sl@0: 			User::Leave(KErrNotSupported);
sl@0: 			}
sl@0: 		}
sl@0: 
sl@0: 	return result;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: // original RMessage is supplied so that remote demux plugin can extract necessary details
sl@0: // using DeMux utility
sl@0: TInt CMMFErrorConcealmentIntfcDeMux::DoSendSlaveSyncCommandResultL(const RMmfIpcMessage& aMessage)
sl@0: 	{
sl@0: 	TMMFDevSoundCIMessageData data;
sl@0: 	TInt result = KErrGeneral;
sl@0: 
sl@0: 	// decode message
sl@0: 	iUtility->GetSyncMessageDataL(aMessage, data);
sl@0: 
sl@0: 	switch (data.iCommand)
sl@0: 		{
sl@0: 		case EMMFDevSoundCIErrorConcealmentIntfcFrameModeRqrdForEC:
sl@0: 			{
sl@0: 			TPckgBuf<TBool> frameModeRqrd; 
sl@0: 
sl@0: 			iUtility->ReadFromInputDesL(aMessage, &frameModeRqrd);
sl@0: 
sl@0: 			result = DoFrameModeRqrdForECL(frameModeRqrd());
sl@0: 
sl@0: 			TPckgBuf<TBool> des(frameModeRqrd());
sl@0: 			iUtility->WriteToOutputDesL(aMessage, des);
sl@0: 
sl@0: 			break;
sl@0: 			}
sl@0: 		default:
sl@0: 			{
sl@0: 			User::Leave(KErrNotSupported);
sl@0: 			}
sl@0: 		}
sl@0: 
sl@0: 	return result;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: void CMMFErrorConcealmentIntfcDeMux::DoSendSlaveAsyncCommandL(const RMmfIpcMessage& /*aMessage*/)
sl@0: 	{
sl@0: 	// not used in this interface
sl@0: 	}
sl@0: 
sl@0: 
sl@0: void CMMFErrorConcealmentIntfcDeMux::DoSendSlaveAsyncCommandResultL(const RMmfIpcMessage& /*aMessage*/)
sl@0: 	{
sl@0: 	// not used in this interface
sl@0: 	}
sl@0: 
sl@0: 
sl@0: // Error Concealment intfc custom interface implementation
sl@0: TInt CMMFErrorConcealmentIntfcDeMux::DoConcealErrorForNextBufferL()
sl@0: 	{
sl@0: 	TInt result = KErrNotFound;
sl@0: 
sl@0: 	if (iInterfaceErrorConcealmentIntfc)
sl@0: 		{
sl@0: 		result = iInterfaceErrorConcealmentIntfc->ConcealErrorForNextBuffer();
sl@0: 		}
sl@0: 
sl@0: 	return result;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: // Error Concealment intfc custom interface implementation
sl@0: TInt CMMFErrorConcealmentIntfcDeMux::DoSetFrameModeL(TBool aFrameModeRqrd)
sl@0: 	{
sl@0: 	TInt result = KErrNotFound;
sl@0: 
sl@0: 	if (iInterfaceErrorConcealmentIntfc)
sl@0: 		{
sl@0: 		result = iInterfaceErrorConcealmentIntfc->SetFrameMode(aFrameModeRqrd);
sl@0: 		}
sl@0: 		
sl@0: 	return result;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: // Error Concealment intfc custom interface implementation
sl@0: TInt CMMFErrorConcealmentIntfcDeMux::DoFrameModeRqrdForECL(TBool& aFrameModeRqrd)
sl@0: 	{
sl@0: 	TInt result = KErrNotFound;
sl@0: 
sl@0: 	if (iInterfaceErrorConcealmentIntfc)
sl@0: 		{
sl@0: 		result = iInterfaceErrorConcealmentIntfc->FrameModeRqrdForEC(aFrameModeRqrd);
sl@0: 		}
sl@0: 
sl@0: 	return result;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: //
sl@0: // ImplementationTable
sl@0: //
sl@0: const TImplementationProxy ImplementationTable[] = 
sl@0: 	{
sl@0: 	IMPLEMENTATION_PROXY_ENTRY(KMmfUidCustomInterfaceErrorConcealmentIntfcMux,		CMMFErrorConcealmentIntfcMux::NewL),
sl@0: 	IMPLEMENTATION_PROXY_ENTRY(KMmfUidCustomInterfaceErrorConcealmentIntfcDeMux,	CMMFErrorConcealmentIntfcDeMux::NewL),
sl@0: 	};
sl@0: 
sl@0: //
sl@0: // ImplementationGroupProxy
sl@0: //
sl@0: EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
sl@0: 	{
sl@0: 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
sl@0: 
sl@0: 	return ImplementationTable;
sl@0: 	}
sl@0: