|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "MmfAudioPolicySession.h" |
|
17 #include "MmfPolicyClientServer.h" |
|
18 #include "MmfAudioPolicyServer.h" |
|
19 #include "MmfDevSoundInfo.h" |
|
20 |
|
21 |
|
22 const TInt KEventQLimit=16; // maximum number of pending events per session |
|
23 |
|
24 CMMFAudioPolicySession* CMMFAudioPolicySession::NewL() |
|
25 { |
|
26 CMMFAudioPolicySession* self = new(ELeave) CMMFAudioPolicySession(); |
|
27 CleanupStack::PushL(self); |
|
28 self->ConstructL(); |
|
29 CleanupStack::Pop(); |
|
30 return self; |
|
31 } |
|
32 |
|
33 void CMMFAudioPolicySession::ConstructL() |
|
34 { |
|
35 iAudioPolicyRequest = new (ELeave) CMMFAudioPolicyRequest(); |
|
36 } |
|
37 |
|
38 CMMFAudioPolicySession::CMMFAudioPolicySession() : iEventsQue(_FOFF(TMMFAudioPolicyEventHolder,iLink)), |
|
39 iNoMemoryEventHolder(TMMFAudioPolicyEvent(TMMFAudioPolicyEvent::EMMFAudioPolicyResourceNotification, KErrNoMemory, EMMFStateCompleted), EFalse) |
|
40 { |
|
41 } |
|
42 |
|
43 void CMMFAudioPolicySession::CreateL(const CMmfIpcServer& aServer) |
|
44 { |
|
45 iServer = STATIC_CAST(CMMFAudioPolicyServer*, (CONST_CAST(CMmfIpcServer*, &aServer))); |
|
46 iServer->IncrementSessionCount(); |
|
47 CMmfIpcSession::CreateL(aServer); |
|
48 iServer->IncrementSessionId(); |
|
49 iPolicySessionId = iServer->PolicySessionId(); |
|
50 // Get ptr to AudioPolicy from the server |
|
51 iAudioPolicy = iServer->AudioPolicy(); |
|
52 iAudioPolicy->ReserveClientNumL(iServer->PolicySessionCount()); |
|
53 } |
|
54 |
|
55 CMMFAudioPolicyServer* CMMFAudioPolicySession::Server() |
|
56 { |
|
57 return STATIC_CAST(CMMFAudioPolicyServer*, iServer); |
|
58 } |
|
59 |
|
60 CMMFAudioPolicySession::~CMMFAudioPolicySession() |
|
61 { |
|
62 delete iEventReceiver; |
|
63 iEventReceiver=NULL; |
|
64 ClearEventQ(); |
|
65 iAudioPolicyPrioritySettings.iState = EMMFStateClosed; |
|
66 // Have session's CMMFAudioPolicyRequest object removed from list |
|
67 if (iAudioPolicy != NULL) |
|
68 { |
|
69 iAudioPolicy->RemoveFromList(iPolicySessionId); |
|
70 } |
|
71 delete iAudioPolicyRequest; |
|
72 if (iServer != NULL) |
|
73 { |
|
74 iServer->DecrementSessionCount(); |
|
75 iServer->StopNotificationTimer(); |
|
76 } |
|
77 } |
|
78 |
|
79 void CMMFAudioPolicySession::ClearEventQ() |
|
80 { |
|
81 while (!iEventsQue.IsEmpty()) |
|
82 { |
|
83 TMMFAudioPolicyEventHolder* heldEvent = iEventsQue.First(); |
|
84 iEventsQue.Remove(*heldEvent); |
|
85 if (heldEvent == &iNoMemoryEventHolder) |
|
86 { |
|
87 iNoMemoryEventUsed = EFalse; |
|
88 } |
|
89 if (heldEvent->iShallBeDeleted) |
|
90 { |
|
91 delete heldEvent; |
|
92 } |
|
93 --iEventQSize; |
|
94 } |
|
95 } |
|
96 |
|
97 void CMMFAudioPolicySession::ServiceL(const RMmfIpcMessage& aMessage) |
|
98 { |
|
99 if (iEventQSize > KEventQLimit) |
|
100 { |
|
101 aMessage.Panic(KMMFAudioPolicyPanicCategory, EMMFAudioPolicySessionEventQueueOverflow); |
|
102 return; |
|
103 } |
|
104 |
|
105 TBool complete = EFalse; |
|
106 switch(aMessage.Function()) |
|
107 { |
|
108 case EMMFPolicyMakeRequest: |
|
109 MakeRequestL(aMessage); |
|
110 aMessage.Complete(KErrNone); |
|
111 break; |
|
112 case EMMFPolicySetDevSoundInfo: |
|
113 complete = SetDevSoundInfoL(aMessage); |
|
114 break; |
|
115 case EMMFPolicyUpdateState: |
|
116 complete = UpdateStateL(aMessage); |
|
117 break; |
|
118 case EMMFPolicyReceiveEvents: |
|
119 complete = ReceiveEventsL(aMessage); |
|
120 break; |
|
121 case EMMFPolicyCancelReceiveEvents: |
|
122 complete = CancelReceiveEvents(); |
|
123 break; |
|
124 case EMMFPolicyGetPlayFormatsSupported: |
|
125 complete = GetPlayFormatsSupportedL(aMessage); |
|
126 break; |
|
127 case EMMFPolicyGetRecordFormatsSupported: |
|
128 complete = GetRecordFormatsSupportedL(aMessage); |
|
129 break; |
|
130 case EMMFPolicyGetPlayFormat: |
|
131 complete = GetPlayFormatL(aMessage); |
|
132 break; |
|
133 case EMMFPolicyGetRecordFormat: |
|
134 complete = GetRecordFormatL(aMessage); |
|
135 break; |
|
136 case EMMFPolicyLaunchRequests: |
|
137 complete = LaunchRequest(); |
|
138 break; |
|
139 case EMMFPolicyRequestResourceNotification: |
|
140 complete = RequestResourceNotificationL(aMessage); |
|
141 break; |
|
142 case EMMFPolicyCancelRequestResourceNotification: |
|
143 complete = CancelRequestResourceNotificationL(aMessage); |
|
144 break; |
|
145 case EMMFPolicyStopNotification: |
|
146 complete = StopNotificationL(aMessage); |
|
147 break; |
|
148 case EMMFPolicyGetResourceNotificationEvent: |
|
149 complete = GetResourceNotificationEventL(aMessage); |
|
150 break; |
|
151 default: |
|
152 User::Leave(KErrNotSupported); |
|
153 break; |
|
154 } |
|
155 if(complete) |
|
156 { |
|
157 aMessage.Complete(KErrNone); |
|
158 } |
|
159 } |
|
160 |
|
161 void CMMFAudioPolicySession::MakeRequestL(const RMmfIpcMessage& aMessage) |
|
162 { |
|
163 TMMFAudioPolicyPrioritySettingsPckg settingsPckg; |
|
164 MmfMessageUtil::ReadL(aMessage, 0, settingsPckg); |
|
165 |
|
166 iAudioPolicyRequest->SetPriority(settingsPckg().iPriority); |
|
167 iAudioPolicyRequest->SetPref(settingsPckg().iPref); |
|
168 iAudioPolicyRequest->SetState(settingsPckg().iState); |
|
169 |
|
170 iAudioPolicyRequest->SetCapabilities(settingsPckg().iCapabilities); |
|
171 |
|
172 // Set session Id in Request |
|
173 iAudioPolicyRequest->SetPolicySessionId(iPolicySessionId); |
|
174 iAudioPolicy->MakeRequest(iAudioPolicyRequest); |
|
175 } |
|
176 |
|
177 TBool CMMFAudioPolicySession::UpdateStateL(const RMmfIpcMessage& aMessage) |
|
178 { |
|
179 TMMFAudioPolicyPrioritySettingsPckg settingsPckg; |
|
180 MmfMessageUtil::ReadL(aMessage, 0, settingsPckg); |
|
181 |
|
182 iAudioPolicy->ModifyEntry(iPolicySessionId, settingsPckg().iState); |
|
183 return ETrue; |
|
184 } |
|
185 |
|
186 void CMMFAudioPolicySession::SendEventToClient(const TMMFAudioPolicyEvent& aEvent) |
|
187 { |
|
188 if (iEventReceiver) |
|
189 { |
|
190 iEventReceiver->SendEvent(aEvent); |
|
191 delete iEventReceiver; |
|
192 iEventReceiver=NULL; |
|
193 } |
|
194 else |
|
195 { |
|
196 if (++iEventQSize > KEventQLimit) // check if Q is not full |
|
197 { |
|
198 return; // we'll panic that bad client later |
|
199 } |
|
200 TMMFAudioPolicyEventHolder* heldEvent = new TMMFAudioPolicyEventHolder(aEvent, ETrue); |
|
201 |
|
202 if (heldEvent==NULL && !iNoMemoryEventUsed) |
|
203 { |
|
204 heldEvent=&iNoMemoryEventHolder; |
|
205 iNoMemoryEventUsed = ETrue; |
|
206 } |
|
207 if (heldEvent) |
|
208 { |
|
209 iEventsQue.AddLast(*heldEvent); |
|
210 } |
|
211 } |
|
212 } |
|
213 |
|
214 TBool CMMFAudioPolicySession::SetDevSoundInfoL(const RMmfIpcMessage& aMessage) |
|
215 { |
|
216 TMMFDevSoundInfoPckg devSoundInfoPckg; |
|
217 MmfMessageUtil::ReadL(aMessage, 0, devSoundInfoPckg); |
|
218 iDevSoundId = devSoundInfoPckg().iDevSoundId; |
|
219 return ETrue; |
|
220 } |
|
221 |
|
222 TBool CMMFAudioPolicySession::ReceiveEventsL(const RMmfIpcMessage& aMessage) |
|
223 { |
|
224 if (iEventReceiver) |
|
225 User::Leave(KErrAlreadyExists); |
|
226 iEventReceiver = CMMFAudioPolicyEventReceiver::NewL(aMessage); |
|
227 #if defined(ALLOW_POLICY_DEBUG) |
|
228 RDebug::Print(_L("Sess. ID=%d listen to events"),iPolicySessionId); |
|
229 #endif |
|
230 //send the next cached event (if any) to the client |
|
231 if (!iEventsQue.IsEmpty()) |
|
232 { |
|
233 TMMFAudioPolicyEventHolder* heldEvent = iEventsQue.First(); |
|
234 iEventReceiver->SendEvent(heldEvent->iEvent); |
|
235 iEventsQue.Remove(*heldEvent); |
|
236 if (heldEvent == &iNoMemoryEventHolder) |
|
237 { |
|
238 iNoMemoryEventUsed = EFalse; |
|
239 } |
|
240 --iEventQSize; |
|
241 if (heldEvent->iShallBeDeleted) |
|
242 { |
|
243 delete heldEvent; |
|
244 } |
|
245 delete iEventReceiver; |
|
246 iEventReceiver=NULL; |
|
247 } |
|
248 return EFalse; |
|
249 } |
|
250 |
|
251 TBool CMMFAudioPolicySession::CancelReceiveEvents() |
|
252 { |
|
253 delete iEventReceiver; |
|
254 iEventReceiver = NULL; |
|
255 return ETrue; |
|
256 } |
|
257 |
|
258 TBool CMMFAudioPolicySession::GetPlayFormatsSupportedL(const RMmfIpcMessage& aMessage) |
|
259 { |
|
260 RMdaDevSound::TSoundFormatsSupportedBuf aPlayFormatsSupported; |
|
261 aPlayFormatsSupported = iAudioPolicy->MdaHwInfo()->GetPlayFormatsSupported(); |
|
262 MmfMessageUtil::WriteL(aMessage, 0, aPlayFormatsSupported); |
|
263 return ETrue; |
|
264 } |
|
265 |
|
266 TBool CMMFAudioPolicySession::GetRecordFormatsSupportedL(const RMmfIpcMessage& aMessage) |
|
267 { |
|
268 RMdaDevSound::TSoundFormatsSupportedBuf aRecordFormatsSupported; |
|
269 aRecordFormatsSupported = iAudioPolicy->MdaHwInfo()->GetRecordFormatsSupported(); |
|
270 MmfMessageUtil::WriteL(aMessage, 0, aRecordFormatsSupported); |
|
271 return ETrue; |
|
272 } |
|
273 |
|
274 TBool CMMFAudioPolicySession::GetPlayFormatL(const RMmfIpcMessage& aMessage) |
|
275 { |
|
276 RMdaDevSound::TCurrentSoundFormatBuf aPlayFormat; |
|
277 aPlayFormat = iAudioPolicy->MdaHwInfo()->GetPlayFormat(); |
|
278 MmfMessageUtil::WriteL(aMessage, 0, aPlayFormat); |
|
279 return ETrue; |
|
280 } |
|
281 |
|
282 TBool CMMFAudioPolicySession::GetRecordFormatL(const RMmfIpcMessage& aMessage) |
|
283 { |
|
284 RMdaDevSound::TCurrentSoundFormatBuf aRecordFormat; |
|
285 aRecordFormat = iAudioPolicy->MdaHwInfo()->GetRecordFormat(); |
|
286 MmfMessageUtil::WriteL(aMessage, 0, aRecordFormat); |
|
287 return ETrue; |
|
288 } |
|
289 |
|
290 TBool CMMFAudioPolicySession::LaunchRequest() |
|
291 { |
|
292 iAudioPolicy->LaunchRequest( iAudioPolicyRequest->PolicySessionId() ); |
|
293 return ETrue; |
|
294 } |
|
295 |
|
296 TBool CMMFAudioPolicySession::RequestResourceNotificationL(const RMmfIpcMessage& aMessage) |
|
297 { |
|
298 TMMFAudioPolicyResourceNotificationSettingsPckg notificationPckg; |
|
299 MmfMessageUtil::ReadL(aMessage, 0, notificationPckg); |
|
300 iAudioPolicyRequest->SetNotificationEvent(notificationPckg().iNotificationUid); |
|
301 iAudioPolicyRequest->SetRequestDataL(notificationPckg().iNotificationDelay); |
|
302 iAudioPolicy->SetNotification(iPolicySessionId,notificationPckg().iNotificationUid); |
|
303 return ETrue; |
|
304 } |
|
305 |
|
306 TBool CMMFAudioPolicySession::CancelRequestResourceNotificationL(const RMmfIpcMessage& aMessage) |
|
307 { |
|
308 TMMFAudioPolicyResourceNotificationSettingsPckg notificationPckg; |
|
309 MmfMessageUtil::ReadL(aMessage, 0, notificationPckg); |
|
310 iAudioPolicyRequest->ResetNotificationEvent(notificationPckg().iNotificationUid); |
|
311 iAudioPolicy->SetNotification(iPolicySessionId,KNullUid); |
|
312 return ETrue; |
|
313 } |
|
314 |
|
315 TBool CMMFAudioPolicySession::StopNotificationL(const RMmfIpcMessage& /*aMessage*/) |
|
316 { |
|
317 iServer->StopNotificationTimer(); |
|
318 return ETrue; |
|
319 } |
|
320 |
|
321 TBool CMMFAudioPolicySession::GetResourceNotificationEventL(const RMmfIpcMessage& aMessage) const |
|
322 { |
|
323 TMMFAudioPolicyResourceNotificationSettingsPckg notificationPckg; |
|
324 notificationPckg().iNotificationUid = iAudioPolicyRequest->NotificationEvent(); |
|
325 MmfMessageUtil::WriteL(aMessage, 0, notificationPckg); |
|
326 return ETrue; |
|
327 } |
|
328 |
|
329 CMMFAudioPolicyEventReceiver* CMMFAudioPolicyEventReceiver::NewL(const RMmfIpcMessage& aMessage) |
|
330 { |
|
331 return new(ELeave) CMMFAudioPolicyEventReceiver(aMessage); |
|
332 } |
|
333 |
|
334 CMMFAudioPolicyEventReceiver::~CMMFAudioPolicyEventReceiver() |
|
335 { |
|
336 if (iNeedToCompleteMessage) |
|
337 { |
|
338 iMessage.Complete(KErrDied); |
|
339 } |
|
340 } |
|
341 |
|
342 void CMMFAudioPolicyEventReceiver::SendEvent(const TMMFAudioPolicyEvent& aEvent) |
|
343 { |
|
344 TMMFAudioPolicyEventPckg eventpckg(aEvent); |
|
345 TInt err = MmfMessageUtil::Write(iMessage, 0, eventpckg); |
|
346 iMessage.Complete(err); |
|
347 iNeedToCompleteMessage = EFalse; |
|
348 } |
|
349 |
|
350 void CMMFAudioPolicyEventReceiver::SendEvent(const TMMFEvent& aEvent) |
|
351 { |
|
352 TMMFEventPckg eventpckg(aEvent); |
|
353 TInt err = MmfMessageUtil::Write(iMessage, 0, eventpckg); |
|
354 iMessage.Complete(err); |
|
355 iNeedToCompleteMessage = EFalse; |
|
356 } |
|
357 |
|
358 CMMFAudioPolicyEventReceiver::CMMFAudioPolicyEventReceiver(const RMmfIpcMessage& aMessage) : |
|
359 iMessage(aMessage), iNeedToCompleteMessage(ETrue) |
|
360 { |
|
361 } |
|
362 |
|
363 CMMFAudioPolicyRequest::CMMFAudioPolicyRequest(): |
|
364 iPolicySessionId(KErrNotFound), |
|
365 iReqDataPtr(KNullDesC8) |
|
366 { |
|
367 iNotificationEventUid = KNullUid; |
|
368 } |
|
369 |
|
370 CMMFAudioPolicyRequest::~CMMFAudioPolicyRequest() |
|
371 { |
|
372 delete iRequestData; |
|
373 } |
|
374 |
|
375 void CMMFAudioPolicyRequest::SetRequestDataL(const TDesC8& aRequestData) |
|
376 { |
|
377 iReqDataPtr.Set(KNullDesC8); |
|
378 if (aRequestData.Length() == 0) |
|
379 { |
|
380 return; |
|
381 } |
|
382 if (iRequestData==NULL || (iRequestData && iRequestData->Des().MaxLength()<aRequestData.Length())) |
|
383 { |
|
384 delete iRequestData; |
|
385 iRequestData = NULL; |
|
386 iRequestData = aRequestData.AllocL(); |
|
387 } |
|
388 else |
|
389 { |
|
390 iRequestData->Des().Copy(aRequestData); |
|
391 } |
|
392 iReqDataPtr.Set(*iRequestData); |
|
393 } |
|
394 |
|
395 |
|
396 |