First public contribution.
1 // Copyright (c) 2000-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 "MmfBtAudioPolicySession.h"
17 #include "MmfBtPolicyClientServer.h"
18 #include "MmfBtAudioPolicyServer.h"
19 #include "MmfBtDevSoundInfo.h"
23 CMMFAudioPolicySession* CMMFAudioPolicySession::NewL()
25 CMMFAudioPolicySession* self = new(ELeave) CMMFAudioPolicySession();
26 CleanupStack::PushL(self);
32 void CMMFAudioPolicySession::ConstructL()
34 iAudioPolicyRequest = new (ELeave) CMMFAudioPolicyRequest();
37 CMMFAudioPolicySession::CMMFAudioPolicySession() : iEventsQue(_FOFF(TMMFAudioPolicyEventHolder,iLink))
41 void CMMFAudioPolicySession::CreateL(const CMmfIpcServer& aServer)
43 iServer = STATIC_CAST(CMMFAudioPolicyServer*, (CONST_CAST(CMmfIpcServer*, &aServer)));
44 iServer->IncrementSessionCount();
45 CMmfIpcSession::CreateL(aServer);
46 iServer->IncrementSessionId();
47 iPolicySessionId = iServer->PolicySessionId();
48 // Get ptr to AudioPolicy from the server
49 iAudioPolicy = iServer->AudioPolicy();
50 (iAudioPolicy->AudioPolicyRequestArray())->SetReserveL(iServer->PolicySessionCount());
53 CMMFAudioPolicyServer* CMMFAudioPolicySession::Server()
55 return STATIC_CAST(CMMFAudioPolicyServer*, iServer);
58 CMMFAudioPolicySession::~CMMFAudioPolicySession()
60 delete iEventReceiver;
61 delete iAudioPolicyRequest;
63 if (!iEventsQue.IsEmpty())
65 TMMFAudioPolicyEventHolder* heldEvent = iEventsQue.First();
66 iEventsQue.Remove(*heldEvent);
69 iAudioPolicyPrioritySettings.iState = EMMFStateClosed;
70 // Have session's CMMFAudioPolicyRequest object removed from list
71 iAudioPolicy->RemoveFromList(iPolicySessionId);
72 iServer->DecrementSessionCount();
73 iServer->StopNotificationTimer();
76 void CMMFAudioPolicySession::ServiceL(const RMmfIpcMessage& aMessage)
78 TBool complete = EFalse;
79 switch(aMessage.Function())
81 case EMMFPolicyMakeRequest:
82 MakeRequestL(aMessage);
83 aMessage.Complete(KErrNone);
85 case EMMFPolicySetDevSoundInfo:
86 complete = SetDevSoundInfoL(aMessage);
88 case EMMFPolicyUpdateState:
89 complete = UpdateStateL(aMessage);
91 case EMMFPolicyReceiveEvents:
92 complete = ReceiveEventsL(aMessage);
94 case EMMFPolicyCancelReceiveEvents:
95 complete = CancelReceiveEvents();
97 case EMMFPolicyGetPlayFormatsSupported:
98 complete = GetPlayFormatsSupportedL(aMessage);
100 case EMMFPolicyGetRecordFormatsSupported:
101 complete = GetRecordFormatsSupportedL(aMessage);
103 case EMMFPolicyGetPlayFormat:
104 complete = GetPlayFormatL(aMessage);
106 case EMMFPolicyGetRecordFormat:
107 complete = GetRecordFormatL(aMessage);
109 case EMMFPolicyLaunchRequests:
110 complete = LaunchRequest();
112 case EMMFPolicyRequestResourceNotification:
113 complete = RequestResourceNotificationL(aMessage);
115 case EMMFPolicyCancelRequestResourceNotification:
116 complete = CancelRequestResourceNotificationL(aMessage);
118 case EMMFPolicyStopNotification:
119 complete = StopNotificationL(aMessage);
121 case EMMFPolicyGetResourceNotificationEvent:
122 complete = GetResourceNotificationEventL(aMessage);
125 User::Leave(KErrNotSupported);
130 aMessage.Complete(KErrNone);
134 void CMMFAudioPolicySession::MakeRequestL(const RMmfIpcMessage& aMessage)
136 TMMFAudioPolicyPrioritySettingsPckg settingsPckg;
137 MmfMessageUtil::ReadL(aMessage, 0, settingsPckg);
139 iAudioPolicyRequest->SetPriority(settingsPckg().iPriority);
140 iAudioPolicyRequest->SetPref(settingsPckg().iPref);
141 iAudioPolicyRequest->SetState(settingsPckg().iState);
143 iAudioPolicyRequest->SetCapabilities(settingsPckg().iCapabilities);
145 // Set session Id in Request
146 iAudioPolicyRequest->SetPolicySessionId(iPolicySessionId);
147 iAudioPolicy->MakeRequest(iAudioPolicyRequest);
150 TBool CMMFAudioPolicySession::UpdateStateL(const RMmfIpcMessage& aMessage)
152 TMMFAudioPolicyPrioritySettingsPckg settingsPckg;
153 MmfMessageUtil::ReadL(aMessage, 0, settingsPckg);
155 iAudioPolicyRequest->SetState(settingsPckg().iState);
156 iAudioPolicy->ModifyEntry(iPolicySessionId, iAudioPolicyRequest);
160 void CMMFAudioPolicySession::SendEventToClient(TMMFAudioPolicyEvent& aEvent)
164 iEventReceiver->SendEvent(aEvent);
165 delete iEventReceiver;
170 TMMFAudioPolicyEventHolder* heldEvent = new TMMFAudioPolicyEventHolder(aEvent);
171 iEventsQue.AddLast(*heldEvent);
175 TBool CMMFAudioPolicySession::SetDevSoundInfoL(const RMmfIpcMessage& aMessage)
177 TMMFDevSoundInfoPckg devSoundInfoPckg;
178 MmfMessageUtil::ReadL(aMessage, 0, devSoundInfoPckg);
179 iDevSoundId = devSoundInfoPckg().iDevSoundId;
183 TBool CMMFAudioPolicySession::ReceiveEventsL(const RMmfIpcMessage& aMessage)
186 User::Leave(KErrAlreadyExists);
187 iEventReceiver = CMMFAudioPolicyEventReceiver::NewL(aMessage);
188 //send the next cached event (if any) to the client
189 if (!iEventsQue.IsEmpty())
191 TMMFAudioPolicyEventHolder* heldEvent = iEventsQue.First();
192 iEventReceiver->SendEvent(heldEvent->iEvent);
193 iEventsQue.Remove(*heldEvent);
194 delete iEventReceiver;
200 TBool CMMFAudioPolicySession::CancelReceiveEvents()
202 delete iEventReceiver;
203 iEventReceiver = NULL;
207 TBool CMMFAudioPolicySession::GetPlayFormatsSupportedL(const RMmfIpcMessage& aMessage)
209 RMdaDevSound::TSoundFormatsSupportedBuf aPlayFormatsSupported;
210 aPlayFormatsSupported = iAudioPolicy->MdaHwInfo()->GetPlayFormatsSupported();
211 MmfMessageUtil::WriteL(aMessage, 0, aPlayFormatsSupported);
215 TBool CMMFAudioPolicySession::GetRecordFormatsSupportedL(const RMmfIpcMessage& aMessage)
217 RMdaDevSound::TSoundFormatsSupportedBuf aRecordFormatsSupported;
218 aRecordFormatsSupported = iAudioPolicy->MdaHwInfo()->GetRecordFormatsSupported();
219 MmfMessageUtil::WriteL(aMessage, 0, aRecordFormatsSupported);
223 TBool CMMFAudioPolicySession::GetPlayFormatL(const RMmfIpcMessage& aMessage)
225 RMdaDevSound::TCurrentSoundFormatBuf aPlayFormat;
226 aPlayFormat = iAudioPolicy->MdaHwInfo()->GetPlayFormat();
227 MmfMessageUtil::WriteL(aMessage, 0, aPlayFormat);
231 TBool CMMFAudioPolicySession::GetRecordFormatL(const RMmfIpcMessage& aMessage)
233 RMdaDevSound::TCurrentSoundFormatBuf aRecordFormat;
234 aRecordFormat = iAudioPolicy->MdaHwInfo()->GetRecordFormat();
235 MmfMessageUtil::WriteL(aMessage, 0, aRecordFormat);
239 TBool CMMFAudioPolicySession::LaunchRequest()
241 iAudioPolicy->LaunchRequest();
245 TBool CMMFAudioPolicySession::RequestResourceNotificationL(const RMmfIpcMessage& aMessage)
247 TMMFAudioPolicyResourceNotificationSettingsPckg notificationPckg;
248 MmfMessageUtil::ReadL(aMessage, 0, notificationPckg);
249 iAudioPolicyRequest->SetNotificationEvent(notificationPckg().iNotificationUid);
250 iAudioPolicy->SetNotification(iPolicySessionId,notificationPckg().iNotificationUid);
254 TBool CMMFAudioPolicySession::CancelRequestResourceNotificationL(const RMmfIpcMessage& aMessage)
256 if(iServer->IsTimerActive() == EFalse)
258 iServer->StartNotificationTimer();
260 TMMFAudioPolicyResourceNotificationSettingsPckg notificationPckg;
261 MmfMessageUtil::ReadL(aMessage, 0, notificationPckg);
262 iAudioPolicyRequest->ResetNotificationEvent(notificationPckg().iNotificationUid);
263 iAudioPolicy->SetNotification(iPolicySessionId,KNullUid);
267 TBool CMMFAudioPolicySession::StopNotificationL(const RMmfIpcMessage& /*aMessage*/)
269 iServer->StopNotificationTimer();
273 TBool CMMFAudioPolicySession::GetResourceNotificationEventL(const RMmfIpcMessage& aMessage)
275 TMMFAudioPolicyResourceNotificationSettingsPckg notificationPckg;
276 notificationPckg().iNotificationUid = iAudioPolicyRequest->NotificationEvent();
277 MmfMessageUtil::WriteL(aMessage, 0, notificationPckg);
281 CMMFAudioPolicyEventReceiver* CMMFAudioPolicyEventReceiver::NewL(const RMmfIpcMessage& aMessage)
283 return new(ELeave) CMMFAudioPolicyEventReceiver(aMessage);
286 CMMFAudioPolicyEventReceiver::~CMMFAudioPolicyEventReceiver()
288 if (iNeedToCompleteMessage)
289 iMessage.Complete(KErrDied);
292 void CMMFAudioPolicyEventReceiver::SendEvent(const TMMFAudioPolicyEvent& aEvent)
294 TMMFAudioPolicyEventPckg eventpckg(aEvent);
295 TInt err = MmfMessageUtil::Write(iMessage, 0, eventpckg);
296 iMessage.Complete(err);
297 iNeedToCompleteMessage = EFalse;
300 void CMMFAudioPolicyEventReceiver::SendEvent(const TMMFEvent& aEvent)
302 TMMFEventPckg eventpckg(aEvent);
303 TInt err = MmfMessageUtil::Write(iMessage, 0, eventpckg);
304 iMessage.Complete(err);
305 iNeedToCompleteMessage = EFalse;
308 CMMFAudioPolicyEventReceiver::CMMFAudioPolicyEventReceiver(const RMmfIpcMessage& aMessage) :
309 iMessage(aMessage), iNeedToCompleteMessage(ETrue)