sl@0
|
1 |
// Copyright (c) 2001-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 "MmfAudioPolicy.h"
|
sl@0
|
17 |
#include "MmfAudioPolicySession.h"
|
sl@0
|
18 |
#include "MmfAudioPolicyServer.h"
|
sl@0
|
19 |
#include "MdaHwInfo.h"
|
sl@0
|
20 |
#include "MmfAudioPolicyRequest.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
/**
|
sl@0
|
23 |
*@internalTechnology
|
sl@0
|
24 |
*@return if a client owns or wish to own audio resource
|
sl@0
|
25 |
*/
|
sl@0
|
26 |
inline TBool IsActiveState(TMMFAudioPolicyState aState)
|
sl@0
|
27 |
{
|
sl@0
|
28 |
return (aState < EMMFStateStopped || aState==EMMFStateNotified || aState==EMMFStatePlayDualTone);
|
sl@0
|
29 |
}
|
sl@0
|
30 |
|
sl@0
|
31 |
CAudioPolicy::~CAudioPolicy()
|
sl@0
|
32 |
{
|
sl@0
|
33 |
delete iMdaHwInfo;
|
sl@0
|
34 |
delete iAudioPolicyRequestArray;
|
sl@0
|
35 |
}
|
sl@0
|
36 |
|
sl@0
|
37 |
void CAudioPolicy::ConstructL()
|
sl@0
|
38 |
{
|
sl@0
|
39 |
// Create dynamic array for sessions list
|
sl@0
|
40 |
iAudioPolicyRequestArray = new(ELeave) CPolicyReqPtrArray(CAudioPolicy::EGranularity);
|
sl@0
|
41 |
iMdaHwInfo = CMdaHwInfo::NewL();
|
sl@0
|
42 |
}
|
sl@0
|
43 |
|
sl@0
|
44 |
EXPORT_C CAudioPolicy* CAudioPolicy::NewL(CMMFAudioPolicyServer* aAudioPolicyServer)
|
sl@0
|
45 |
{
|
sl@0
|
46 |
|
sl@0
|
47 |
CAudioPolicy* self = new(ELeave)CAudioPolicy(aAudioPolicyServer);
|
sl@0
|
48 |
CleanupStack::PushL(self);
|
sl@0
|
49 |
self->ConstructL();
|
sl@0
|
50 |
CleanupStack::Pop();
|
sl@0
|
51 |
return(self);
|
sl@0
|
52 |
}
|
sl@0
|
53 |
|
sl@0
|
54 |
CAudioPolicy::CAudioPolicy(CMMFAudioPolicyServer* aAudioPolicyServer) :
|
sl@0
|
55 |
iAudioPolicyServer(aAudioPolicyServer),
|
sl@0
|
56 |
iNotifiedSessionId(KErrNotFound),
|
sl@0
|
57 |
iSessionIdAwaitingForDevsound(KErrNotFound),
|
sl@0
|
58 |
iStopHandledFromSessId(KErrNotFound)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
void CAudioPolicy::MakeRequest(CMMFAudioPolicyRequest* aAudioPolicyRequest)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
// since we have a FIFO q, then remove request and re-add it.
|
sl@0
|
65 |
RemoveFromList(aAudioPolicyRequest->PolicySessionId(), EFalse);
|
sl@0
|
66 |
if (iStopHandledFromSessId==aAudioPolicyRequest->PolicySessionId())
|
sl@0
|
67 |
{
|
sl@0
|
68 |
iStopHandledFromSessId=KErrNotFound;
|
sl@0
|
69 |
}
|
sl@0
|
70 |
// Process Request by looking at priorities, preferences, special states...
|
sl@0
|
71 |
TPolicyResponse responseValue = ProcessRequest(aAudioPolicyRequest);
|
sl@0
|
72 |
#if defined(ALLOW_POLICY_DEBUG)
|
sl@0
|
73 |
RDebug::Print(_L("Sess ID=%d, Priority=%d"),aAudioPolicyRequest->PolicySessionId(),aAudioPolicyRequest->Priority());
|
sl@0
|
74 |
#endif
|
sl@0
|
75 |
switch (responseValue)
|
sl@0
|
76 |
{
|
sl@0
|
77 |
case EDenied:
|
sl@0
|
78 |
{
|
sl@0
|
79 |
TMMFAudioPolicyEvent responseEvent(TMMFAudioPolicyEvent::EMMFAudioPolicyPriorityTooLow, KErrInUse,EMMFStateWaitingForResource);
|
sl@0
|
80 |
// the client won't be notified until he has request so, so we can set its state anyway
|
sl@0
|
81 |
aAudioPolicyRequest->SetState( EMMFStateWaitingForResource );
|
sl@0
|
82 |
iAudioPolicyServer->SendEventToClient(aAudioPolicyRequest->PolicySessionId(), responseEvent);
|
sl@0
|
83 |
}
|
sl@0
|
84 |
break;
|
sl@0
|
85 |
case EProceed:
|
sl@0
|
86 |
{
|
sl@0
|
87 |
iAudioPolicyServer->StopNotificationTimer();
|
sl@0
|
88 |
TMMFAudioPolicyEvent responseEvent(TMMFAudioPolicyEvent::EMMFAudioPolicyNoEvent, KErrNone, aAudioPolicyRequest->State());
|
sl@0
|
89 |
iAudioPolicyServer->SendEventToClient(aAudioPolicyRequest->PolicySessionId(), responseEvent);
|
sl@0
|
90 |
}
|
sl@0
|
91 |
break;
|
sl@0
|
92 |
case EStopThenProceed:
|
sl@0
|
93 |
{
|
sl@0
|
94 |
iAudioPolicyServer->StopNotificationTimer();
|
sl@0
|
95 |
iSessionIdAwaitingForDevsound=aAudioPolicyRequest->PolicySessionId();
|
sl@0
|
96 |
// we have to wait for devsound to stop client(s), then notify that one
|
sl@0
|
97 |
}
|
sl@0
|
98 |
break;
|
sl@0
|
99 |
case EResume:
|
sl@0
|
100 |
case EMix:
|
sl@0
|
101 |
default:
|
sl@0
|
102 |
ASSERT(EFalse);
|
sl@0
|
103 |
}
|
sl@0
|
104 |
TRAPD(err, iAudioPolicyRequestArray->AppendL(aAudioPolicyRequest) );
|
sl@0
|
105 |
__ASSERT_ALWAYS(err==KErrNone, Panic(EMMFAudioPolicyRequestArrayOverflow) ); // we reserved space, so shouldn't hit this
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
TPolicyResponse CAudioPolicy::ProcessRequest(CMMFAudioPolicyRequest* aAudioPolicyRequest)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
// If there is no other item on list, return with proceed
|
sl@0
|
111 |
if (iAudioPolicyRequestArray->Count()==0)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
return EProceed;
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
TPolicyResponse responseValue(EProceed);
|
sl@0
|
117 |
TInt requestPriority = aAudioPolicyRequest->Priority();
|
sl@0
|
118 |
|
sl@0
|
119 |
TBool requestCaps = aAudioPolicyRequest->Capabilities();
|
sl@0
|
120 |
|
sl@0
|
121 |
// Iterate through list and compare priorities:
|
sl@0
|
122 |
// QUEST: state checking shall be done as well?
|
sl@0
|
123 |
for (TInt index = 0; index < iAudioPolicyRequestArray->Count(); index++)
|
sl@0
|
124 |
{
|
sl@0
|
125 |
CMMFAudioPolicyRequest& currentReq=*(*iAudioPolicyRequestArray)[index];
|
sl@0
|
126 |
if (!IsActiveState(currentReq.State()) ) // this request is inactive
|
sl@0
|
127 |
{
|
sl@0
|
128 |
continue;
|
sl@0
|
129 |
}
|
sl@0
|
130 |
// If there's even one on the list w/ a higher priority deny request and leave:
|
sl@0
|
131 |
|
sl@0
|
132 |
if (currentReq.Capabilities() > requestCaps)
|
sl@0
|
133 |
{
|
sl@0
|
134 |
responseValue = EDenied;
|
sl@0
|
135 |
break;
|
sl@0
|
136 |
}
|
sl@0
|
137 |
else if(currentReq.Capabilities() == requestCaps)
|
sl@0
|
138 |
{
|
sl@0
|
139 |
if(currentReq.Priority() >= requestPriority)
|
sl@0
|
140 |
{
|
sl@0
|
141 |
responseValue = EDenied;
|
sl@0
|
142 |
break;
|
sl@0
|
143 |
}
|
sl@0
|
144 |
}
|
sl@0
|
145 |
if (currentReq.State()==EMMFStateWaitingForResource || currentReq.State()==EMMFStatePreempted)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
continue;
|
sl@0
|
148 |
}
|
sl@0
|
149 |
// we need to stop active client since new request is of higher priority
|
sl@0
|
150 |
TMMFAudioPolicyEvent freezeEvent(TMMFAudioPolicyEvent::EMMFAudioPolicyPriorityTooLow, KErrInUse, EMMFStatePaused);
|
sl@0
|
151 |
#if defined(ALLOW_POLICY_DEBUG)
|
sl@0
|
152 |
RDebug::Print(_L("Sess ID=%d, State=%d Has been preempted"),currentReq.PolicySessionId(),currentReq.State());
|
sl@0
|
153 |
#endif
|
sl@0
|
154 |
currentReq.SetState( EMMFStatePreempted );
|
sl@0
|
155 |
currentReq.SetEventFlag(EFalse);
|
sl@0
|
156 |
iAudioPolicyServer->SendEventToClient(currentReq.PolicySessionId(), freezeEvent);
|
sl@0
|
157 |
responseValue = EStopThenProceed;
|
sl@0
|
158 |
}
|
sl@0
|
159 |
|
sl@0
|
160 |
return responseValue;
|
sl@0
|
161 |
}
|
sl@0
|
162 |
|
sl@0
|
163 |
void CAudioPolicy::ModifyEntry(TInt aPolicySessionId,const TMMFAudioPolicyState aNewState)
|
sl@0
|
164 |
{
|
sl@0
|
165 |
CMMFAudioPolicyRequest* sessionEntry=FindPolicyRequestById(aPolicySessionId);
|
sl@0
|
166 |
#if defined(ALLOW_POLICY_DEBUG)
|
sl@0
|
167 |
RDebug::Print(_L("Sess ID=%d, Old State=%d New State=%d"),aPolicySessionId,sessionEntry?sessionEntry->State():-1, aNewState);
|
sl@0
|
168 |
#endif
|
sl@0
|
169 |
// some client took over resource, so update its state and cancel timer
|
sl@0
|
170 |
if (IsActiveState(aNewState))
|
sl@0
|
171 |
{
|
sl@0
|
172 |
if (sessionEntry)
|
sl@0
|
173 |
{
|
sl@0
|
174 |
sessionEntry->SetState(aNewState);
|
sl@0
|
175 |
sessionEntry->SetEventFlag(EFalse);
|
sl@0
|
176 |
}
|
sl@0
|
177 |
iAudioPolicyServer->StopNotificationTimer();
|
sl@0
|
178 |
iNotifiedSessionId =KErrNotFound;
|
sl@0
|
179 |
ASSERT(iSessionIdAwaitingForDevsound==KErrNotFound); // we shouldn't have a client waiting to be notified
|
sl@0
|
180 |
if (iStopHandledFromSessId==aPolicySessionId)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
iStopHandledFromSessId=KErrNotFound;
|
sl@0
|
183 |
}
|
sl@0
|
184 |
return;
|
sl@0
|
185 |
}
|
sl@0
|
186 |
if (iNotifiedSessionId==aPolicySessionId) // if client that was notified, then stop timer.
|
sl@0
|
187 |
{
|
sl@0
|
188 |
iAudioPolicyServer->StopNotificationTimer();
|
sl@0
|
189 |
}
|
sl@0
|
190 |
if (sessionEntry==NULL) // to cope with erroneous behaviour of devsound
|
sl@0
|
191 |
{
|
sl@0
|
192 |
return;
|
sl@0
|
193 |
}
|
sl@0
|
194 |
// we have update from the client, if we have other clients waiting we should notify them
|
sl@0
|
195 |
if ( (aNewState == EMMFStatePaused || (aNewState == EMMFStateStopped && iStopHandledFromSessId!=aPolicySessionId) )
|
sl@0
|
196 |
&& sessionEntry->State()!=EMMFStateStopped && sessionEntry->State()!=EMMFStateWaitingForResource)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
if (aNewState == EMMFStateStopped) // to eliminate duplicate stop events
|
sl@0
|
199 |
{
|
sl@0
|
200 |
iStopHandledFromSessId=aPolicySessionId;
|
sl@0
|
201 |
}
|
sl@0
|
202 |
if (sessionEntry->State()==EMMFStatePreempted)
|
sl@0
|
203 |
{
|
sl@0
|
204 |
sessionEntry->SetState(EMMFStateWaitingForResource);
|
sl@0
|
205 |
}
|
sl@0
|
206 |
|
sl@0
|
207 |
if (iSessionIdAwaitingForDevsound==aPolicySessionId)
|
sl@0
|
208 |
{
|
sl@0
|
209 |
iSessionIdAwaitingForDevsound=KErrNotFound;
|
sl@0
|
210 |
}
|
sl@0
|
211 |
|
sl@0
|
212 |
if (aNewState == EMMFStatePaused || aNewState == EMMFStateStopped) // devsound should free, so notify waiting client
|
sl@0
|
213 |
{
|
sl@0
|
214 |
if (iSessionIdAwaitingForDevsound!=KErrNotFound) // we have a client waiting for Devsound, so notify it
|
sl@0
|
215 |
{
|
sl@0
|
216 |
NotifySessionWithTimeout(iSessionIdAwaitingForDevsound, TMMFAudioPolicyEvent::EMMFAudioPolicyNoEvent);
|
sl@0
|
217 |
iSessionIdAwaitingForDevsound=KErrNotFound;
|
sl@0
|
218 |
}
|
sl@0
|
219 |
else if (!iAudioPolicyServer->IsTimerActive()) // do not try to notify if we're still waiting for response
|
sl@0
|
220 |
{
|
sl@0
|
221 |
const TInt sessionIdToNotify = CheckSessionToNotify();
|
sl@0
|
222 |
if(sessionIdToNotify != KErrNotFound)
|
sl@0
|
223 |
{
|
sl@0
|
224 |
// set the state as notified
|
sl@0
|
225 |
NotifySessionWithTimeout(sessionIdToNotify, TMMFAudioPolicyEvent::EMMFAudioPolicyResourceNotification);
|
sl@0
|
226 |
}
|
sl@0
|
227 |
}
|
sl@0
|
228 |
}
|
sl@0
|
229 |
}
|
sl@0
|
230 |
// we update state to passive only if the client hasn't been stopped by us, so as not loose its waiting indication
|
sl@0
|
231 |
if (sessionEntry->State()!=EMMFStateWaitingForResource)
|
sl@0
|
232 |
{
|
sl@0
|
233 |
sessionEntry->SetState(aNewState);
|
sl@0
|
234 |
}
|
sl@0
|
235 |
}
|
sl@0
|
236 |
|
sl@0
|
237 |
void CAudioPolicy::NotifySessionWithTimeout(TInt aPolicySessionId, TMMFAudioPolicyEvent::TAudioPolicyEventType aEvent)
|
sl@0
|
238 |
{
|
sl@0
|
239 |
CMMFAudioPolicyRequest* sessionEntry=FindPolicyRequestById(aPolicySessionId);
|
sl@0
|
240 |
ASSERT(sessionEntry);
|
sl@0
|
241 |
#if defined(ALLOW_POLICY_DEBUG)
|
sl@0
|
242 |
RDebug::Print(_L("Sending timed not. ID=%d, State=%d Event=%d"),aPolicySessionId,sessionEntry->State(), aEvent);
|
sl@0
|
243 |
#endif
|
sl@0
|
244 |
const TMMFAudioPolicyEvent eventToSend(aEvent, KErrNone, sessionEntry->State());
|
sl@0
|
245 |
sessionEntry->SetEventFlag(ETrue);
|
sl@0
|
246 |
iAudioPolicyServer->StartNotificationTimer();
|
sl@0
|
247 |
iNotifiedSessionId = aPolicySessionId;
|
sl@0
|
248 |
iAudioPolicyServer->SendEventToClient(aPolicySessionId, eventToSend);
|
sl@0
|
249 |
}
|
sl@0
|
250 |
|
sl@0
|
251 |
void CAudioPolicy::RemoveFromList(TInt aPolicySessionId, TBool aAllowTimerRestart)
|
sl@0
|
252 |
{
|
sl@0
|
253 |
if (aPolicySessionId==KErrNotFound)
|
sl@0
|
254 |
{
|
sl@0
|
255 |
return;
|
sl@0
|
256 |
}
|
sl@0
|
257 |
for (TInt index = iAudioPolicyRequestArray->Count(); index-- ;)
|
sl@0
|
258 |
{
|
sl@0
|
259 |
// Find correct entry to remove
|
sl@0
|
260 |
if ( (*iAudioPolicyRequestArray)[index]->PolicySessionId() == aPolicySessionId)
|
sl@0
|
261 |
{
|
sl@0
|
262 |
if (iSessionIdAwaitingForDevsound==aPolicySessionId)
|
sl@0
|
263 |
{
|
sl@0
|
264 |
iSessionIdAwaitingForDevsound=KErrNotFound;
|
sl@0
|
265 |
}
|
sl@0
|
266 |
if (iNotifiedSessionId==aPolicySessionId && iAudioPolicyServer->IsTimerActive())
|
sl@0
|
267 |
{
|
sl@0
|
268 |
iNotifiedSessionId=KErrNotFound;
|
sl@0
|
269 |
// the session we were waiting for disconnected so try to immediately notify another one
|
sl@0
|
270 |
iAudioPolicyServer->StopNotificationTimer();
|
sl@0
|
271 |
if (iAudioPolicyRequestArray->Count() > 1 && aAllowTimerRestart)
|
sl@0
|
272 |
{
|
sl@0
|
273 |
iAudioPolicyServer->StartNotificationTimer(ETrue);
|
sl@0
|
274 |
}
|
sl@0
|
275 |
}
|
sl@0
|
276 |
else if(!iAudioPolicyServer->IsTimerActive())
|
sl@0
|
277 |
{
|
sl@0
|
278 |
if (iAudioPolicyRequestArray->Count() > 1 && aAllowTimerRestart)
|
sl@0
|
279 |
{
|
sl@0
|
280 |
iAudioPolicyServer->StartNotificationTimer(ETrue);
|
sl@0
|
281 |
}
|
sl@0
|
282 |
}
|
sl@0
|
283 |
iAudioPolicyRequestArray->Delete(index);
|
sl@0
|
284 |
return;
|
sl@0
|
285 |
}
|
sl@0
|
286 |
}
|
sl@0
|
287 |
}
|
sl@0
|
288 |
|
sl@0
|
289 |
void CAudioPolicy::HandlePreferences(CMMFAudioPolicyRequest* /*aAudioPolicyRequest*/, TInt /*aPref*/, TPolicyResponse& /*aResponse*/)
|
sl@0
|
290 |
{
|
sl@0
|
291 |
}
|
sl@0
|
292 |
|
sl@0
|
293 |
// this is weird, but devsound
|
sl@0
|
294 |
// does Stop() if a client is denied access to resource
|
sl@0
|
295 |
// then calls this routine to indicate that resource became available
|
sl@0
|
296 |
void CAudioPolicy::LaunchRequest(TInt aSessionId)
|
sl@0
|
297 |
{
|
sl@0
|
298 |
ASSERT(iSessionIdAwaitingForDevsound!=aSessionId);
|
sl@0
|
299 |
ModifyEntry(aSessionId, EMMFStateStopped);
|
sl@0
|
300 |
}
|
sl@0
|
301 |
|
sl@0
|
302 |
void CAudioPolicy::ReserveClientNumL(TInt aNum)
|
sl@0
|
303 |
{
|
sl@0
|
304 |
iAudioPolicyRequestArray->SetReserveL(aNum);
|
sl@0
|
305 |
}
|
sl@0
|
306 |
|
sl@0
|
307 |
/**
|
sl@0
|
308 |
@internalTechnology
|
sl@0
|
309 |
|
sl@0
|
310 |
This function raises a panic
|
sl@0
|
311 |
|
sl@0
|
312 |
@param aError
|
sl@0
|
313 |
one of the several panics codes that may be raised by this dll
|
sl@0
|
314 |
|
sl@0
|
315 |
@panic EMMFAudioPolicyRequestArrayOverflow is raised when policyrequest array is full
|
sl@0
|
316 |
*/
|
sl@0
|
317 |
GLDEF_C void Panic(TMMFAudioPolicyPanicCodes aPanicCode)
|
sl@0
|
318 |
{
|
sl@0
|
319 |
User::Panic(KMMFAudioPolicyPanicCategory, aPanicCode);
|
sl@0
|
320 |
}
|
sl@0
|
321 |
|
sl@0
|
322 |
// checks based on the session ,Is the session is registered for Notification
|
sl@0
|
323 |
TBool CAudioPolicy::IsRegisteredNotification(TInt aSessionId) const
|
sl@0
|
324 |
{
|
sl@0
|
325 |
TUid event;
|
sl@0
|
326 |
for (TInt index = 0; index < iAudioPolicyRequestArray->Count(); index++)
|
sl@0
|
327 |
{
|
sl@0
|
328 |
if((*iAudioPolicyRequestArray)[index]->PolicySessionId() == aSessionId)
|
sl@0
|
329 |
{
|
sl@0
|
330 |
event = (*iAudioPolicyRequestArray)[index]->NotificationEvent();
|
sl@0
|
331 |
if (event == KMMFEventCategoryAudioResourceAvailable)
|
sl@0
|
332 |
{
|
sl@0
|
333 |
// only when the client is registered for KMMFEventCategoryAudioResourceAvailable event
|
sl@0
|
334 |
return ETrue;
|
sl@0
|
335 |
}
|
sl@0
|
336 |
break;
|
sl@0
|
337 |
}
|
sl@0
|
338 |
}
|
sl@0
|
339 |
return EFalse;
|
sl@0
|
340 |
}
|
sl@0
|
341 |
|
sl@0
|
342 |
// get the next highest priority of the client to notify
|
sl@0
|
343 |
TInt CAudioPolicy::CheckSessionToNotify()
|
sl@0
|
344 |
{
|
sl@0
|
345 |
TInt nextHighestPriority= -100;
|
sl@0
|
346 |
TInt sessionToNotify = KErrNotFound;
|
sl@0
|
347 |
|
sl@0
|
348 |
// get the max priority and set the Index
|
sl@0
|
349 |
for (TInt attempt=2; attempt-- && sessionToNotify==KErrNotFound;)
|
sl@0
|
350 |
{
|
sl@0
|
351 |
|
sl@0
|
352 |
for (TInt index = 0; index < iAudioPolicyRequestArray->Count(); ++index)
|
sl@0
|
353 |
{
|
sl@0
|
354 |
CMMFAudioPolicyRequest& currentReq=*(*iAudioPolicyRequestArray)[index];
|
sl@0
|
355 |
if((nextHighestPriority <= currentReq.Priority())
|
sl@0
|
356 |
&& (currentReq.NotificationEvent() == KMMFEventCategoryAudioResourceAvailable)
|
sl@0
|
357 |
&& (!currentReq.IsEventNotified())
|
sl@0
|
358 |
&& currentReq.State()==EMMFStateWaitingForResource)
|
sl@0
|
359 |
{
|
sl@0
|
360 |
nextHighestPriority = currentReq.Priority();
|
sl@0
|
361 |
sessionToNotify = currentReq.PolicySessionId();
|
sl@0
|
362 |
}
|
sl@0
|
363 |
}
|
sl@0
|
364 |
// we tried to notify every session once, so reset flag and try again.
|
sl@0
|
365 |
if (sessionToNotify==KErrNotFound)
|
sl@0
|
366 |
{
|
sl@0
|
367 |
for (TInt i=iAudioPolicyRequestArray->Count(); i--;)
|
sl@0
|
368 |
{
|
sl@0
|
369 |
(*iAudioPolicyRequestArray)[i]->SetEventFlag(EFalse);
|
sl@0
|
370 |
}
|
sl@0
|
371 |
}
|
sl@0
|
372 |
}
|
sl@0
|
373 |
return sessionToNotify;
|
sl@0
|
374 |
}
|
sl@0
|
375 |
|
sl@0
|
376 |
// send the message to the server
|
sl@0
|
377 |
void CAudioPolicy::NotifyNextClient()
|
sl@0
|
378 |
{
|
sl@0
|
379 |
const TInt sessionIdToNotify = CheckSessionToNotify();
|
sl@0
|
380 |
#if defined(ALLOW_POLICY_DEBUG)
|
sl@0
|
381 |
RDebug::Print(_L("Sess ID %d didn't continue within timeout, Next ID=%d"), iNotifiedSessionId, sessionIdToNotify);
|
sl@0
|
382 |
#endif
|
sl@0
|
383 |
iNotifiedSessionId = KErrNotFound;
|
sl@0
|
384 |
if(sessionIdToNotify != KErrNotFound)
|
sl@0
|
385 |
{
|
sl@0
|
386 |
NotifySessionWithTimeout(sessionIdToNotify, TMMFAudioPolicyEvent::EMMFAudioPolicyResourceNotification);
|
sl@0
|
387 |
}
|
sl@0
|
388 |
}
|
sl@0
|
389 |
|
sl@0
|
390 |
// Set in the AudiopolicyRequestArray the uid registered
|
sl@0
|
391 |
TInt CAudioPolicy::SetNotification(TInt aSessionId, TUid aEventType)
|
sl@0
|
392 |
{
|
sl@0
|
393 |
if (KMMFEventCategoryAudioResourceAvailable!=aEventType)
|
sl@0
|
394 |
{
|
sl@0
|
395 |
return EFalse;
|
sl@0
|
396 |
}
|
sl@0
|
397 |
for (TInt index = iAudioPolicyRequestArray->Count(); index-- ; )
|
sl@0
|
398 |
{
|
sl@0
|
399 |
CMMFAudioPolicyRequest& currentReq=*(*iAudioPolicyRequestArray)[index];
|
sl@0
|
400 |
if(currentReq.PolicySessionId() == aSessionId)
|
sl@0
|
401 |
{
|
sl@0
|
402 |
currentReq.SetNotificationEvent(aEventType);
|
sl@0
|
403 |
#if defined(ALLOW_POLICY_DEBUG)
|
sl@0
|
404 |
RDebug::Print(_L("Sess ID %d state=%d requested resource notification"), aSessionId, currentReq.State());
|
sl@0
|
405 |
#endif
|
sl@0
|
406 |
if (!IsActiveState(currentReq.State()))
|
sl@0
|
407 |
{
|
sl@0
|
408 |
currentReq.SetState(EMMFStateWaitingForResource);
|
sl@0
|
409 |
}
|
sl@0
|
410 |
return ETrue;
|
sl@0
|
411 |
}
|
sl@0
|
412 |
}
|
sl@0
|
413 |
return EFalse;
|
sl@0
|
414 |
}
|
sl@0
|
415 |
|
sl@0
|
416 |
CMMFAudioPolicyRequest* CAudioPolicy::FindPolicyRequestById(TInt aSessionId) const
|
sl@0
|
417 |
{
|
sl@0
|
418 |
for (TInt index = iAudioPolicyRequestArray->Count(); index-- ; )
|
sl@0
|
419 |
{
|
sl@0
|
420 |
if((*iAudioPolicyRequestArray)[index]->PolicySessionId() == aSessionId)
|
sl@0
|
421 |
{
|
sl@0
|
422 |
return (*iAudioPolicyRequestArray)[index];
|
sl@0
|
423 |
}
|
sl@0
|
424 |
}
|
sl@0
|
425 |
return NULL;
|
sl@0
|
426 |
}
|
sl@0
|
427 |
|
sl@0
|
428 |
|
sl@0
|
429 |
|