sl@0: // Copyright (c) 2005-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 "MmfBtDevSoundEventHandler.h" sl@0: #include "MmfBtAudioPolicyProxy.h" sl@0: sl@0: #include "MmfBtDevSoundSessionXtnd.h" sl@0: sl@0: CMMFDevSoundEventHandler* CMMFDevSoundEventHandler::NewL(RMMFAudioPolicyProxy* aAudioPolicyProxy) sl@0: { sl@0: CMMFDevSoundEventHandler* self = new(ELeave) CMMFDevSoundEventHandler(aAudioPolicyProxy); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: CMMFDevSoundEventHandler::CMMFDevSoundEventHandler(RMMFAudioPolicyProxy* aAudioPolicyProxy) : sl@0: CActive(EPriorityLow), iAudioPolicyProxy(aAudioPolicyProxy) sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: void CMMFDevSoundEventHandler::ConstructL() sl@0: { sl@0: } sl@0: sl@0: void CMMFDevSoundEventHandler::SetDevSoundInfo(CMMFDevSoundSessionXtnd* aDevSound) sl@0: { sl@0: iDevSound = aDevSound; sl@0: iDevSoundId++; sl@0: aDevSound->SetDevSoundId(iDevSoundId); sl@0: } sl@0: sl@0: CMMFDevSoundEventHandler::~CMMFDevSoundEventHandler() sl@0: { sl@0: Cancel(); sl@0: } sl@0: sl@0: void CMMFDevSoundEventHandler::ReceiveEvents() sl@0: { sl@0: iAudioPolicyProxy->ReceiveEvents(iAudioPolicyEventPckg, iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CMMFDevSoundEventHandler::CancelReceiveEvents() sl@0: { sl@0: Cancel(); sl@0: } sl@0: sl@0: void CMMFDevSoundEventHandler::RunL() sl@0: { sl@0: TMMFAudioPolicyEvent aEvent; sl@0: aEvent.iEventType = iAudioPolicyEventPckg().iEventType; sl@0: aEvent.iErrorCode = iAudioPolicyEventPckg().iErrorCode; sl@0: aEvent.iState = iAudioPolicyEventPckg().iState; sl@0: sl@0: // Determine whether or not to call on client to send event or call on other sl@0: // SoundDevice's to start play/record functions: sl@0: if ( (aEvent.iEventType == TMMFAudioPolicyEvent::EMMFAudioPolicySwitchToIdle) sl@0: || (aEvent.iEventType == TMMFAudioPolicyEvent::EMMFAudioPolicyNoEvent) ) sl@0: { sl@0: // Determine what to do, based on state: sl@0: switch (aEvent.iState) sl@0: { sl@0: case EMMFStatePlayData: sl@0: iDevSound->StartPlayDataL(); sl@0: break; sl@0: case EMMFStateRecordData: sl@0: iDevSound->StartRecordDataL(); sl@0: break; sl@0: case EMMFStatePlayTone: sl@0: iDevSound->StartPlayToneL(); sl@0: break; sl@0: case EMMFStatePlayDualTone: sl@0: iDevSound->StartPlayDualToneL(); sl@0: break; sl@0: case EMMFStatePlayDTMFString: sl@0: iDevSound->StartPlayDTMFStringL(); sl@0: break; sl@0: case EMMFStatePlayToneSequence: sl@0: iDevSound->StartPlayToneSequenceL(); sl@0: break; sl@0: default: sl@0: break; sl@0: } // End switch sl@0: // Set self up to receive more events: sl@0: iAudioPolicyProxy->ReceiveEvents(iAudioPolicyEventPckg, iStatus); sl@0: SetActive(); sl@0: } sl@0: else if(aEvent.iEventType == TMMFAudioPolicyEvent::EMMFAudioPolicyResourceNotification) sl@0: { sl@0: TMMFEvent event; sl@0: event.iErrorCode = aEvent.iErrorCode; sl@0: event.iEventType = KMMFEventCategoryAudioResourceAvailable; sl@0: iDevSound->SendEvent(event); sl@0: } sl@0: else sl@0: { sl@0: //Create a TMMFEvent element for client: sl@0: //NB KErrInUse, KErrDied OR KErrAccessDenied may be returned by the sl@0: //policy server to indicate that the sound device is in use by another sl@0: //higher priority client. sl@0: TMMFEvent event; sl@0: event.iErrorCode = aEvent.iErrorCode; sl@0: iDevSound->SendEvent(event); sl@0: if(!iAudioPolicyProxy->IsRegisteredResourceNotification(KMMFEventCategoryAudioResourceAvailable)) sl@0: { sl@0: iAudioPolicyEventPckg().iEventType = TMMFAudioPolicyEvent::EMMFAudioPolicyResourceNotification; sl@0: iAudioPolicyEventPckg().iErrorCode = 0; sl@0: iAudioPolicyEventPckg().iState = EMMFStateNotified; sl@0: iAudioPolicyProxy->ReceiveEvents(iAudioPolicyEventPckg, iStatus); sl@0: SetActive(); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CMMFDevSoundEventHandler::DoCancel() sl@0: { sl@0: iAudioPolicyProxy->CancelReceiveEvents(); sl@0: } sl@0: sl@0: TInt CMMFDevSoundEventHandler::RunError(TInt aError) sl@0: { sl@0: TMMFEvent event; sl@0: event.iErrorCode = aError;//should probably have an appropriate event type here too? sl@0: iDevSound->SendEventToClient(event); sl@0: return KErrNone; sl@0: }