First public contribution.
1 // Copyright (c) 2001-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 "MmfDevSoundEventHandler.h"
17 #include "mmfAudioPolicyProxy.h"
19 #include "MmfDevSoundSessionXtnd.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();
101 else if(aEvent.iEventType == TMMFAudioPolicyEvent::EMMFAudioPolicyResourceNotification)
104 event.iErrorCode = aEvent.iErrorCode;
105 event.iEventType = KMMFEventCategoryAudioResourceAvailable;
106 iDevSound->SendEvent(event);
110 ASSERT(aEvent.iEventType == TMMFAudioPolicyEvent::EMMFAudioPolicyPriorityTooLow);
111 //Create a TMMFEvent element for client:
112 //NB KErrInUse, KErrDied OR KErrAccessDenied may be returned by the
113 //policy server to indicate that the sound device is in use by another
114 //higher priority client.
116 event.iErrorCode = aEvent.iErrorCode;
117 iDevSound->SendEvent(event);
119 // Set self up to receive more events:
120 iAudioPolicyProxy->ReceiveEvents(iAudioPolicyEventPckg, iStatus);
124 void CMMFDevSoundEventHandler::DoCancel()
126 iAudioPolicyProxy->CancelReceiveEvents();
129 TInt CMMFDevSoundEventHandler::RunError(TInt aError)
132 event.iErrorCode = aError;//should probably have an appropriate event type here too?
133 iDevSound->SendEventToClient(event);