First public contribution.
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "MmfBtDevSoundEventHandler.h"
17 #include "MmfBtAudioPolicyProxy.h"
19 #include "MmfBtDevSoundSessionXtnd.h"
21 CMMFDevSoundEventHandler* CMMFDevSoundEventHandler::NewL(RMMFAudioPolicyProxy* aAudioPolicyProxy)
23 CMMFDevSoundEventHandler* self = new(ELeave) CMMFDevSoundEventHandler(aAudioPolicyProxy);
24 CleanupStack::PushL(self);
30 CMMFDevSoundEventHandler::CMMFDevSoundEventHandler(RMMFAudioPolicyProxy* aAudioPolicyProxy) :
31 CActive(EPriorityLow), iAudioPolicyProxy(aAudioPolicyProxy)
33 CActiveScheduler::Add(this);
36 void CMMFDevSoundEventHandler::ConstructL()
40 void CMMFDevSoundEventHandler::SetDevSoundInfo(CMMFDevSoundSessionXtnd* aDevSound)
42 iDevSound = aDevSound;
44 aDevSound->SetDevSoundId(iDevSoundId);
47 CMMFDevSoundEventHandler::~CMMFDevSoundEventHandler()
52 void CMMFDevSoundEventHandler::ReceiveEvents()
54 iAudioPolicyProxy->ReceiveEvents(iAudioPolicyEventPckg, iStatus);
58 void CMMFDevSoundEventHandler::CancelReceiveEvents()
63 void CMMFDevSoundEventHandler::RunL()
65 TMMFAudioPolicyEvent aEvent;
66 aEvent.iEventType = iAudioPolicyEventPckg().iEventType;
67 aEvent.iErrorCode = iAudioPolicyEventPckg().iErrorCode;
68 aEvent.iState = iAudioPolicyEventPckg().iState;
70 // Determine whether or not to call on client to send event or call on other
71 // SoundDevice's to start play/record functions:
72 if ( (aEvent.iEventType == TMMFAudioPolicyEvent::EMMFAudioPolicySwitchToIdle)
73 || (aEvent.iEventType == TMMFAudioPolicyEvent::EMMFAudioPolicyNoEvent) )
75 // Determine what to do, based on state:
76 switch (aEvent.iState)
78 case EMMFStatePlayData:
79 iDevSound->StartPlayDataL();
81 case EMMFStateRecordData:
82 iDevSound->StartRecordDataL();
84 case EMMFStatePlayTone:
85 iDevSound->StartPlayToneL();
87 case EMMFStatePlayDualTone:
88 iDevSound->StartPlayDualToneL();
90 case EMMFStatePlayDTMFString:
91 iDevSound->StartPlayDTMFStringL();
93 case EMMFStatePlayToneSequence:
94 iDevSound->StartPlayToneSequenceL();
99 // Set self up to receive more events:
100 iAudioPolicyProxy->ReceiveEvents(iAudioPolicyEventPckg, iStatus);
103 else if(aEvent.iEventType == TMMFAudioPolicyEvent::EMMFAudioPolicyResourceNotification)
106 event.iErrorCode = aEvent.iErrorCode;
107 event.iEventType = KMMFEventCategoryAudioResourceAvailable;
108 iDevSound->SendEvent(event);
112 //Create a TMMFEvent element for client:
113 //NB KErrInUse, KErrDied OR KErrAccessDenied may be returned by the
114 //policy server to indicate that the sound device is in use by another
115 //higher priority client.
117 event.iErrorCode = aEvent.iErrorCode;
118 iDevSound->SendEvent(event);
119 if(!iAudioPolicyProxy->IsRegisteredResourceNotification(KMMFEventCategoryAudioResourceAvailable))
121 iAudioPolicyEventPckg().iEventType = TMMFAudioPolicyEvent::EMMFAudioPolicyResourceNotification;
122 iAudioPolicyEventPckg().iErrorCode = 0;
123 iAudioPolicyEventPckg().iState = EMMFStateNotified;
124 iAudioPolicyProxy->ReceiveEvents(iAudioPolicyEventPckg, iStatus);
130 void CMMFDevSoundEventHandler::DoCancel()
132 iAudioPolicyProxy->CancelReceiveEvents();
135 TInt CMMFDevSoundEventHandler::RunError(TInt aError)
138 event.iErrorCode = aError;//should probably have an appropriate event type here too?
139 iDevSound->SendEventToClient(event);