sl@0
|
1 |
// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "MmfBtAudioPolicySession.h"
|
sl@0
|
17 |
#include "MmfBtPolicyClientServer.h"
|
sl@0
|
18 |
#include "MmfBtAudioPolicyServer.h"
|
sl@0
|
19 |
#include "MmfBtDevSoundInfo.h"
|
sl@0
|
20 |
|
sl@0
|
21 |
|
sl@0
|
22 |
|
sl@0
|
23 |
CMMFAudioPolicySession* CMMFAudioPolicySession::NewL()
|
sl@0
|
24 |
{
|
sl@0
|
25 |
CMMFAudioPolicySession* self = new(ELeave) CMMFAudioPolicySession();
|
sl@0
|
26 |
CleanupStack::PushL(self);
|
sl@0
|
27 |
self->ConstructL();
|
sl@0
|
28 |
CleanupStack::Pop();
|
sl@0
|
29 |
return self;
|
sl@0
|
30 |
}
|
sl@0
|
31 |
|
sl@0
|
32 |
void CMMFAudioPolicySession::ConstructL()
|
sl@0
|
33 |
{
|
sl@0
|
34 |
iAudioPolicyRequest = new (ELeave) CMMFAudioPolicyRequest();
|
sl@0
|
35 |
}
|
sl@0
|
36 |
|
sl@0
|
37 |
CMMFAudioPolicySession::CMMFAudioPolicySession() : iEventsQue(_FOFF(TMMFAudioPolicyEventHolder,iLink))
|
sl@0
|
38 |
{
|
sl@0
|
39 |
}
|
sl@0
|
40 |
|
sl@0
|
41 |
void CMMFAudioPolicySession::CreateL(const CMmfIpcServer& aServer)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
iServer = STATIC_CAST(CMMFAudioPolicyServer*, (CONST_CAST(CMmfIpcServer*, &aServer)));
|
sl@0
|
44 |
iServer->IncrementSessionCount();
|
sl@0
|
45 |
CMmfIpcSession::CreateL(aServer);
|
sl@0
|
46 |
iServer->IncrementSessionId();
|
sl@0
|
47 |
iPolicySessionId = iServer->PolicySessionId();
|
sl@0
|
48 |
// Get ptr to AudioPolicy from the server
|
sl@0
|
49 |
iAudioPolicy = iServer->AudioPolicy();
|
sl@0
|
50 |
(iAudioPolicy->AudioPolicyRequestArray())->SetReserveL(iServer->PolicySessionCount());
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
CMMFAudioPolicyServer* CMMFAudioPolicySession::Server()
|
sl@0
|
54 |
{
|
sl@0
|
55 |
return STATIC_CAST(CMMFAudioPolicyServer*, iServer);
|
sl@0
|
56 |
}
|
sl@0
|
57 |
|
sl@0
|
58 |
CMMFAudioPolicySession::~CMMFAudioPolicySession()
|
sl@0
|
59 |
{
|
sl@0
|
60 |
delete iEventReceiver;
|
sl@0
|
61 |
delete iAudioPolicyRequest;
|
sl@0
|
62 |
iEventReceiver=NULL;
|
sl@0
|
63 |
if (!iEventsQue.IsEmpty())
|
sl@0
|
64 |
{
|
sl@0
|
65 |
TMMFAudioPolicyEventHolder* heldEvent = iEventsQue.First();
|
sl@0
|
66 |
iEventsQue.Remove(*heldEvent);
|
sl@0
|
67 |
delete heldEvent;
|
sl@0
|
68 |
}
|
sl@0
|
69 |
iAudioPolicyPrioritySettings.iState = EMMFStateClosed;
|
sl@0
|
70 |
// Have session's CMMFAudioPolicyRequest object removed from list
|
sl@0
|
71 |
iAudioPolicy->RemoveFromList(iPolicySessionId);
|
sl@0
|
72 |
iServer->DecrementSessionCount();
|
sl@0
|
73 |
iServer->StopNotificationTimer();
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
void CMMFAudioPolicySession::ServiceL(const RMmfIpcMessage& aMessage)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
TBool complete = EFalse;
|
sl@0
|
79 |
switch(aMessage.Function())
|
sl@0
|
80 |
{
|
sl@0
|
81 |
case EMMFPolicyMakeRequest:
|
sl@0
|
82 |
MakeRequestL(aMessage);
|
sl@0
|
83 |
aMessage.Complete(KErrNone);
|
sl@0
|
84 |
break;
|
sl@0
|
85 |
case EMMFPolicySetDevSoundInfo:
|
sl@0
|
86 |
complete = SetDevSoundInfoL(aMessage);
|
sl@0
|
87 |
break;
|
sl@0
|
88 |
case EMMFPolicyUpdateState:
|
sl@0
|
89 |
complete = UpdateStateL(aMessage);
|
sl@0
|
90 |
break;
|
sl@0
|
91 |
case EMMFPolicyReceiveEvents:
|
sl@0
|
92 |
complete = ReceiveEventsL(aMessage);
|
sl@0
|
93 |
break;
|
sl@0
|
94 |
case EMMFPolicyCancelReceiveEvents:
|
sl@0
|
95 |
complete = CancelReceiveEvents();
|
sl@0
|
96 |
break;
|
sl@0
|
97 |
case EMMFPolicyGetPlayFormatsSupported:
|
sl@0
|
98 |
complete = GetPlayFormatsSupportedL(aMessage);
|
sl@0
|
99 |
break;
|
sl@0
|
100 |
case EMMFPolicyGetRecordFormatsSupported:
|
sl@0
|
101 |
complete = GetRecordFormatsSupportedL(aMessage);
|
sl@0
|
102 |
break;
|
sl@0
|
103 |
case EMMFPolicyGetPlayFormat:
|
sl@0
|
104 |
complete = GetPlayFormatL(aMessage);
|
sl@0
|
105 |
break;
|
sl@0
|
106 |
case EMMFPolicyGetRecordFormat:
|
sl@0
|
107 |
complete = GetRecordFormatL(aMessage);
|
sl@0
|
108 |
break;
|
sl@0
|
109 |
case EMMFPolicyLaunchRequests:
|
sl@0
|
110 |
complete = LaunchRequest();
|
sl@0
|
111 |
break;
|
sl@0
|
112 |
case EMMFPolicyRequestResourceNotification:
|
sl@0
|
113 |
complete = RequestResourceNotificationL(aMessage);
|
sl@0
|
114 |
break;
|
sl@0
|
115 |
case EMMFPolicyCancelRequestResourceNotification:
|
sl@0
|
116 |
complete = CancelRequestResourceNotificationL(aMessage);
|
sl@0
|
117 |
break;
|
sl@0
|
118 |
case EMMFPolicyStopNotification:
|
sl@0
|
119 |
complete = StopNotificationL(aMessage);
|
sl@0
|
120 |
break;
|
sl@0
|
121 |
case EMMFPolicyGetResourceNotificationEvent:
|
sl@0
|
122 |
complete = GetResourceNotificationEventL(aMessage);
|
sl@0
|
123 |
break;
|
sl@0
|
124 |
default:
|
sl@0
|
125 |
User::Leave(KErrNotSupported);
|
sl@0
|
126 |
break;
|
sl@0
|
127 |
}
|
sl@0
|
128 |
if(complete)
|
sl@0
|
129 |
{
|
sl@0
|
130 |
aMessage.Complete(KErrNone);
|
sl@0
|
131 |
}
|
sl@0
|
132 |
}
|
sl@0
|
133 |
|
sl@0
|
134 |
void CMMFAudioPolicySession::MakeRequestL(const RMmfIpcMessage& aMessage)
|
sl@0
|
135 |
{
|
sl@0
|
136 |
TMMFAudioPolicyPrioritySettingsPckg settingsPckg;
|
sl@0
|
137 |
MmfMessageUtil::ReadL(aMessage, 0, settingsPckg);
|
sl@0
|
138 |
|
sl@0
|
139 |
iAudioPolicyRequest->SetPriority(settingsPckg().iPriority);
|
sl@0
|
140 |
iAudioPolicyRequest->SetPref(settingsPckg().iPref);
|
sl@0
|
141 |
iAudioPolicyRequest->SetState(settingsPckg().iState);
|
sl@0
|
142 |
|
sl@0
|
143 |
iAudioPolicyRequest->SetCapabilities(settingsPckg().iCapabilities);
|
sl@0
|
144 |
|
sl@0
|
145 |
// Set session Id in Request
|
sl@0
|
146 |
iAudioPolicyRequest->SetPolicySessionId(iPolicySessionId);
|
sl@0
|
147 |
iAudioPolicy->MakeRequest(iAudioPolicyRequest);
|
sl@0
|
148 |
}
|
sl@0
|
149 |
|
sl@0
|
150 |
TBool CMMFAudioPolicySession::UpdateStateL(const RMmfIpcMessage& aMessage)
|
sl@0
|
151 |
{
|
sl@0
|
152 |
TMMFAudioPolicyPrioritySettingsPckg settingsPckg;
|
sl@0
|
153 |
MmfMessageUtil::ReadL(aMessage, 0, settingsPckg);
|
sl@0
|
154 |
|
sl@0
|
155 |
iAudioPolicyRequest->SetState(settingsPckg().iState);
|
sl@0
|
156 |
iAudioPolicy->ModifyEntry(iPolicySessionId, iAudioPolicyRequest);
|
sl@0
|
157 |
return ETrue;
|
sl@0
|
158 |
}
|
sl@0
|
159 |
|
sl@0
|
160 |
void CMMFAudioPolicySession::SendEventToClient(TMMFAudioPolicyEvent& aEvent)
|
sl@0
|
161 |
{
|
sl@0
|
162 |
if (iEventReceiver)
|
sl@0
|
163 |
{
|
sl@0
|
164 |
iEventReceiver->SendEvent(aEvent);
|
sl@0
|
165 |
delete iEventReceiver;
|
sl@0
|
166 |
iEventReceiver=NULL;
|
sl@0
|
167 |
}
|
sl@0
|
168 |
else
|
sl@0
|
169 |
{
|
sl@0
|
170 |
TMMFAudioPolicyEventHolder* heldEvent = new TMMFAudioPolicyEventHolder(aEvent);
|
sl@0
|
171 |
iEventsQue.AddLast(*heldEvent);
|
sl@0
|
172 |
}
|
sl@0
|
173 |
}
|
sl@0
|
174 |
|
sl@0
|
175 |
TBool CMMFAudioPolicySession::SetDevSoundInfoL(const RMmfIpcMessage& aMessage)
|
sl@0
|
176 |
{
|
sl@0
|
177 |
TMMFDevSoundInfoPckg devSoundInfoPckg;
|
sl@0
|
178 |
MmfMessageUtil::ReadL(aMessage, 0, devSoundInfoPckg);
|
sl@0
|
179 |
iDevSoundId = devSoundInfoPckg().iDevSoundId;
|
sl@0
|
180 |
return ETrue;
|
sl@0
|
181 |
}
|
sl@0
|
182 |
|
sl@0
|
183 |
TBool CMMFAudioPolicySession::ReceiveEventsL(const RMmfIpcMessage& aMessage)
|
sl@0
|
184 |
{
|
sl@0
|
185 |
if (iEventReceiver)
|
sl@0
|
186 |
User::Leave(KErrAlreadyExists);
|
sl@0
|
187 |
iEventReceiver = CMMFAudioPolicyEventReceiver::NewL(aMessage);
|
sl@0
|
188 |
//send the next cached event (if any) to the client
|
sl@0
|
189 |
if (!iEventsQue.IsEmpty())
|
sl@0
|
190 |
{
|
sl@0
|
191 |
TMMFAudioPolicyEventHolder* heldEvent = iEventsQue.First();
|
sl@0
|
192 |
iEventReceiver->SendEvent(heldEvent->iEvent);
|
sl@0
|
193 |
iEventsQue.Remove(*heldEvent);
|
sl@0
|
194 |
delete iEventReceiver;
|
sl@0
|
195 |
iEventReceiver=NULL;
|
sl@0
|
196 |
}
|
sl@0
|
197 |
return EFalse;
|
sl@0
|
198 |
}
|
sl@0
|
199 |
|
sl@0
|
200 |
TBool CMMFAudioPolicySession::CancelReceiveEvents()
|
sl@0
|
201 |
{
|
sl@0
|
202 |
delete iEventReceiver;
|
sl@0
|
203 |
iEventReceiver = NULL;
|
sl@0
|
204 |
return ETrue;
|
sl@0
|
205 |
}
|
sl@0
|
206 |
|
sl@0
|
207 |
TBool CMMFAudioPolicySession::GetPlayFormatsSupportedL(const RMmfIpcMessage& aMessage)
|
sl@0
|
208 |
{
|
sl@0
|
209 |
RMdaDevSound::TSoundFormatsSupportedBuf aPlayFormatsSupported;
|
sl@0
|
210 |
aPlayFormatsSupported = iAudioPolicy->MdaHwInfo()->GetPlayFormatsSupported();
|
sl@0
|
211 |
MmfMessageUtil::WriteL(aMessage, 0, aPlayFormatsSupported);
|
sl@0
|
212 |
return ETrue;
|
sl@0
|
213 |
}
|
sl@0
|
214 |
|
sl@0
|
215 |
TBool CMMFAudioPolicySession::GetRecordFormatsSupportedL(const RMmfIpcMessage& aMessage)
|
sl@0
|
216 |
{
|
sl@0
|
217 |
RMdaDevSound::TSoundFormatsSupportedBuf aRecordFormatsSupported;
|
sl@0
|
218 |
aRecordFormatsSupported = iAudioPolicy->MdaHwInfo()->GetRecordFormatsSupported();
|
sl@0
|
219 |
MmfMessageUtil::WriteL(aMessage, 0, aRecordFormatsSupported);
|
sl@0
|
220 |
return ETrue;
|
sl@0
|
221 |
}
|
sl@0
|
222 |
|
sl@0
|
223 |
TBool CMMFAudioPolicySession::GetPlayFormatL(const RMmfIpcMessage& aMessage)
|
sl@0
|
224 |
{
|
sl@0
|
225 |
RMdaDevSound::TCurrentSoundFormatBuf aPlayFormat;
|
sl@0
|
226 |
aPlayFormat = iAudioPolicy->MdaHwInfo()->GetPlayFormat();
|
sl@0
|
227 |
MmfMessageUtil::WriteL(aMessage, 0, aPlayFormat);
|
sl@0
|
228 |
return ETrue;
|
sl@0
|
229 |
}
|
sl@0
|
230 |
|
sl@0
|
231 |
TBool CMMFAudioPolicySession::GetRecordFormatL(const RMmfIpcMessage& aMessage)
|
sl@0
|
232 |
{
|
sl@0
|
233 |
RMdaDevSound::TCurrentSoundFormatBuf aRecordFormat;
|
sl@0
|
234 |
aRecordFormat = iAudioPolicy->MdaHwInfo()->GetRecordFormat();
|
sl@0
|
235 |
MmfMessageUtil::WriteL(aMessage, 0, aRecordFormat);
|
sl@0
|
236 |
return ETrue;
|
sl@0
|
237 |
}
|
sl@0
|
238 |
|
sl@0
|
239 |
TBool CMMFAudioPolicySession::LaunchRequest()
|
sl@0
|
240 |
{
|
sl@0
|
241 |
iAudioPolicy->LaunchRequest();
|
sl@0
|
242 |
return ETrue;
|
sl@0
|
243 |
}
|
sl@0
|
244 |
|
sl@0
|
245 |
TBool CMMFAudioPolicySession::RequestResourceNotificationL(const RMmfIpcMessage& aMessage)
|
sl@0
|
246 |
{
|
sl@0
|
247 |
TMMFAudioPolicyResourceNotificationSettingsPckg notificationPckg;
|
sl@0
|
248 |
MmfMessageUtil::ReadL(aMessage, 0, notificationPckg);
|
sl@0
|
249 |
iAudioPolicyRequest->SetNotificationEvent(notificationPckg().iNotificationUid);
|
sl@0
|
250 |
iAudioPolicy->SetNotification(iPolicySessionId,notificationPckg().iNotificationUid);
|
sl@0
|
251 |
return ETrue;
|
sl@0
|
252 |
}
|
sl@0
|
253 |
|
sl@0
|
254 |
TBool CMMFAudioPolicySession::CancelRequestResourceNotificationL(const RMmfIpcMessage& aMessage)
|
sl@0
|
255 |
{
|
sl@0
|
256 |
if(iServer->IsTimerActive() == EFalse)
|
sl@0
|
257 |
{
|
sl@0
|
258 |
iServer->StartNotificationTimer();
|
sl@0
|
259 |
}
|
sl@0
|
260 |
TMMFAudioPolicyResourceNotificationSettingsPckg notificationPckg;
|
sl@0
|
261 |
MmfMessageUtil::ReadL(aMessage, 0, notificationPckg);
|
sl@0
|
262 |
iAudioPolicyRequest->ResetNotificationEvent(notificationPckg().iNotificationUid);
|
sl@0
|
263 |
iAudioPolicy->SetNotification(iPolicySessionId,KNullUid);
|
sl@0
|
264 |
return ETrue;
|
sl@0
|
265 |
}
|
sl@0
|
266 |
|
sl@0
|
267 |
TBool CMMFAudioPolicySession::StopNotificationL(const RMmfIpcMessage& /*aMessage*/)
|
sl@0
|
268 |
{
|
sl@0
|
269 |
iServer->StopNotificationTimer();
|
sl@0
|
270 |
return ETrue;
|
sl@0
|
271 |
}
|
sl@0
|
272 |
|
sl@0
|
273 |
TBool CMMFAudioPolicySession::GetResourceNotificationEventL(const RMmfIpcMessage& aMessage)
|
sl@0
|
274 |
{
|
sl@0
|
275 |
TMMFAudioPolicyResourceNotificationSettingsPckg notificationPckg;
|
sl@0
|
276 |
notificationPckg().iNotificationUid = iAudioPolicyRequest->NotificationEvent();
|
sl@0
|
277 |
MmfMessageUtil::WriteL(aMessage, 0, notificationPckg);
|
sl@0
|
278 |
return ETrue;
|
sl@0
|
279 |
}
|
sl@0
|
280 |
|
sl@0
|
281 |
CMMFAudioPolicyEventReceiver* CMMFAudioPolicyEventReceiver::NewL(const RMmfIpcMessage& aMessage)
|
sl@0
|
282 |
{
|
sl@0
|
283 |
return new(ELeave) CMMFAudioPolicyEventReceiver(aMessage);
|
sl@0
|
284 |
}
|
sl@0
|
285 |
|
sl@0
|
286 |
CMMFAudioPolicyEventReceiver::~CMMFAudioPolicyEventReceiver()
|
sl@0
|
287 |
{
|
sl@0
|
288 |
if (iNeedToCompleteMessage)
|
sl@0
|
289 |
iMessage.Complete(KErrDied);
|
sl@0
|
290 |
}
|
sl@0
|
291 |
|
sl@0
|
292 |
void CMMFAudioPolicyEventReceiver::SendEvent(const TMMFAudioPolicyEvent& aEvent)
|
sl@0
|
293 |
{
|
sl@0
|
294 |
TMMFAudioPolicyEventPckg eventpckg(aEvent);
|
sl@0
|
295 |
TInt err = MmfMessageUtil::Write(iMessage, 0, eventpckg);
|
sl@0
|
296 |
iMessage.Complete(err);
|
sl@0
|
297 |
iNeedToCompleteMessage = EFalse;
|
sl@0
|
298 |
}
|
sl@0
|
299 |
|
sl@0
|
300 |
void CMMFAudioPolicyEventReceiver::SendEvent(const TMMFEvent& aEvent)
|
sl@0
|
301 |
{
|
sl@0
|
302 |
TMMFEventPckg eventpckg(aEvent);
|
sl@0
|
303 |
TInt err = MmfMessageUtil::Write(iMessage, 0, eventpckg);
|
sl@0
|
304 |
iMessage.Complete(err);
|
sl@0
|
305 |
iNeedToCompleteMessage = EFalse;
|
sl@0
|
306 |
}
|
sl@0
|
307 |
|
sl@0
|
308 |
CMMFAudioPolicyEventReceiver::CMMFAudioPolicyEventReceiver(const RMmfIpcMessage& aMessage) :
|
sl@0
|
309 |
iMessage(aMessage), iNeedToCompleteMessage(ETrue)
|
sl@0
|
310 |
{
|
sl@0
|
311 |
}
|