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 sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "audiovibracontrolci.h" sl@0: sl@0: sl@0: // MUX // sl@0: sl@0: TInt CMMFAudioVibraControlMux::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 = {KMmfUidCustomInterfaceAudioVibraControlDeMux}; 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 CMMFAudioVibraControlMux::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 CMMFAudioVibraControlMux::PassDestructorKey(TUid aDestructorKey) sl@0: { sl@0: // store the destructor key sl@0: iKey = aDestructorKey; sl@0: } sl@0: sl@0: sl@0: void CMMFAudioVibraControlMux::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* CMMFAudioVibraControlMux::NewL() sl@0: { sl@0: CMMFAudioVibraControlMux* self = new (ELeave) CMMFAudioVibraControlMux; sl@0: return self; sl@0: } sl@0: sl@0: sl@0: TAny* CMMFAudioVibraControlMux::CustomInterface(TUid /*aInterfaceId*/) sl@0: { sl@0: MAudioVibraControl* interface = this; sl@0: return interface; sl@0: } sl@0: sl@0: sl@0: CMMFAudioVibraControlMux::CMMFAudioVibraControlMux() : sl@0: iRemoteHandle(-1) sl@0: { sl@0: } sl@0: sl@0: sl@0: CMMFAudioVibraControlMux::~CMMFAudioVibraControlMux() sl@0: { sl@0: } sl@0: sl@0: sl@0: // from MAudioVibraControl sl@0: TInt CMMFAudioVibraControlMux::StartVibra() 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: EMMFDevSoundCIAudioVibraControlStartVibra, sl@0: KNullDesC8); sl@0: } sl@0: sl@0: return result; sl@0: } sl@0: sl@0: sl@0: // from MAudioVibraControl sl@0: TInt CMMFAudioVibraControlMux::StopVibra() 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: EMMFDevSoundCIAudioVibraControlStopVibra, sl@0: KNullDesC8); sl@0: } sl@0: sl@0: return result; sl@0: } sl@0: sl@0: sl@0: sl@0: // DEMUX // sl@0: sl@0: TInt CMMFAudioVibraControlDeMux::OpenInterface(TUid /*aInterfaceId*/) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: void CMMFAudioVibraControlDeMux::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 CMMFAudioVibraControlDeMux::PassDestructorKey(TUid aDestructorKey) sl@0: { sl@0: // store the destructor key sl@0: iKey = aDestructorKey; sl@0: } sl@0: sl@0: sl@0: void CMMFAudioVibraControlDeMux::SetInterfaceTarget(MMMFDevSoundCustomInterfaceTarget* aTarget) sl@0: { sl@0: iTarget = aTarget; sl@0: } sl@0: sl@0: sl@0: void CMMFAudioVibraControlDeMux::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 CMMFAudioVibraControlDeMux::RefreshL() sl@0: { sl@0: // refetch the Audio vibra control custom interface if we already have a target sl@0: if (iTarget) sl@0: { sl@0: iInterfaceAudioVibraControl = static_cast (iTarget->CustomInterface(KUidAudioVibraControl)); sl@0: sl@0: if (!iInterfaceAudioVibraControl) sl@0: { sl@0: iInterfaceAudioVibraControl = NULL; sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: MMMFDevSoundCustomInterfaceDeMuxPlugin* CMMFAudioVibraControlDeMux::NewL() sl@0: { sl@0: CMMFAudioVibraControlDeMux* self = new (ELeave) CMMFAudioVibraControlDeMux; sl@0: return self; sl@0: } sl@0: sl@0: sl@0: CMMFAudioVibraControlDeMux::CMMFAudioVibraControlDeMux() sl@0: { sl@0: } sl@0: sl@0: sl@0: CMMFAudioVibraControlDeMux::~CMMFAudioVibraControlDeMux() sl@0: { sl@0: } sl@0: sl@0: sl@0: TInt CMMFAudioVibraControlDeMux::DoOpenSlaveL(TUid /*aInterface*/, const TDesC8& /*aPackageBuf*/) sl@0: { sl@0: // fetch the Audio vibra control Hw Device custom interface sl@0: iInterfaceAudioVibraControl = static_cast (iTarget->CustomInterface(KUidAudioVibraControl)); sl@0: sl@0: if (!iInterfaceAudioVibraControl) sl@0: { sl@0: iInterfaceAudioVibraControl = NULL; sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: void CMMFAudioVibraControlDeMux::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 CMMFAudioVibraControlDeMux::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 EMMFDevSoundCIAudioVibraControlStartVibra: sl@0: { sl@0: result = DoStartVibraL(); sl@0: break; sl@0: } sl@0: case EMMFDevSoundCIAudioVibraControlStopVibra: sl@0: { sl@0: result = DoStopVibraL(); 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: TInt CMMFAudioVibraControlDeMux::DoSendSlaveSyncCommandResultL(const RMmfIpcMessage& /*aMessage*/) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: void CMMFAudioVibraControlDeMux::DoSendSlaveAsyncCommandL(const RMmfIpcMessage& /*aMessage*/) sl@0: { sl@0: // not used in this interface sl@0: } sl@0: sl@0: sl@0: void CMMFAudioVibraControlDeMux::DoSendSlaveAsyncCommandResultL(const RMmfIpcMessage& /*aMessage*/) sl@0: { sl@0: // not used in this interface sl@0: } sl@0: sl@0: sl@0: TInt CMMFAudioVibraControlDeMux::DoStartVibraL() sl@0: { sl@0: TInt result = KErrNotFound; sl@0: sl@0: if (iInterfaceAudioVibraControl) sl@0: { sl@0: result = iInterfaceAudioVibraControl->StartVibra(); sl@0: } sl@0: sl@0: return result; sl@0: } sl@0: sl@0: sl@0: TInt CMMFAudioVibraControlDeMux::DoStopVibraL() sl@0: { sl@0: TInt result = KErrNotFound; sl@0: sl@0: if (iInterfaceAudioVibraControl) sl@0: { sl@0: result = iInterfaceAudioVibraControl->StopVibra(); sl@0: } sl@0: sl@0: return result; sl@0: } sl@0: sl@0: // sl@0: // ImplementationTable sl@0: // sl@0: const TImplementationProxy ImplementationTable[] = sl@0: { sl@0: IMPLEMENTATION_PROXY_ENTRY(KMmfUidCustomInterfaceAudioVibraControlMux, CMMFAudioVibraControlMux::NewL), sl@0: IMPLEMENTATION_PROXY_ENTRY(KMmfUidCustomInterfaceAudioVibraControlDeMux, CMMFAudioVibraControlDeMux::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: }