|
1 // Copyright (c) 2007-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 |
|
17 #include "mmrcserversession.h" |
|
18 #include "mmrcerrorcodes.h" |
|
19 #include "mmrcservercontroller.h" |
|
20 #include "mmrcadaptationproxy.h" |
|
21 |
|
22 #include <a3f/maudiocontext.h> |
|
23 |
|
24 #include "mlogicalchain.h" |
|
25 #include "logicalaudiostream.h" |
|
26 #include "audiocontext.h" |
|
27 |
|
28 #include <a3f/a3ffourcclookup.h> |
|
29 |
|
30 |
|
31 //------------------------------------------------------------------------------------ |
|
32 // |
|
33 //------------------------------------------------------------------------------------ |
|
34 /** |
|
35 * By default Symbian 2nd phase constructor is private. |
|
36 * @param CMMRCServerController& A reference on the MMRC Server controller |
|
37 */ |
|
38 CMMRCServerSession::CMMRCServerSession(CMMRCServerController& aServerController, |
|
39 const CFourCCConvertor& aFourCCConvertor) |
|
40 : iMMRCServerController(aServerController), |
|
41 iShutdown(0), |
|
42 iLogicalChainRequested(NULL), |
|
43 iLogicalChainLastCommited(NULL), |
|
44 iLogicalChainRequestResponse(NULL), |
|
45 iLogicalChainPreemptionNotification(NULL) |
|
46 { |
|
47 TRACE_CREATE(); |
|
48 DP_CONTEXT(----> CMMRCServerSession::CMMRCServerSession *CD1*, CtxDevSound, DPLOCAL); |
|
49 DP_IN(); |
|
50 iFourCCConvertor = &aFourCCConvertor; |
|
51 DP_OUT(); |
|
52 } |
|
53 |
|
54 /** |
|
55 * Destructor |
|
56 */ |
|
57 CMMRCServerSession::~CMMRCServerSession() |
|
58 { |
|
59 DP_CONTEXT(----> CMMRCServerSession::~CMMRCServerSession *CD1*, CtxDevSound, DPLOCAL); |
|
60 DP_IN(); |
|
61 //remove any request associated to this session from the controller |
|
62 iMMRCServerController.CloseSessionByContextId(iContextId); |
|
63 |
|
64 if (iMMRCServerSideAdaptationResponseAO) |
|
65 { |
|
66 delete iMMRCServerSideAdaptationResponseAO; |
|
67 iMMRCServerSideAdaptationResponseAO=0; |
|
68 }; |
|
69 |
|
70 if( iLogicalChainLastCommited ) |
|
71 { |
|
72 iLogicalChainLastCommited->Release(); |
|
73 iLogicalChainLastCommited = NULL; |
|
74 }; |
|
75 |
|
76 if( iLogicalChainRequested ) |
|
77 { |
|
78 iLogicalChainRequested->Release(); |
|
79 iLogicalChainRequested = NULL; |
|
80 } |
|
81 if( iLogicalChainRequestResponse ) |
|
82 { |
|
83 iLogicalChainRequestResponse->Release(); |
|
84 iLogicalChainRequestResponse = NULL; |
|
85 }; |
|
86 |
|
87 if( iLogicalChainPreemptionNotification ) |
|
88 { |
|
89 iLogicalChainPreemptionNotification->Release(); |
|
90 iLogicalChainPreemptionNotification = NULL; |
|
91 }; |
|
92 |
|
93 iMsgQueue.Close(); |
|
94 |
|
95 DP_OUT(); |
|
96 } |
|
97 |
|
98 /** |
|
99 * Constructs, and returns a pointer to, a new CMMRCServerSession object. |
|
100 * Leaves on failure. |
|
101 * @param CMMRCServerController& A reference on the MMRC Server controller |
|
102 * @param CFourCCConvertor& A reference to the Fourcc to format converter |
|
103 * @return CMMRCServerSession* A pointer to newly created utlitly object. |
|
104 */ |
|
105 CMMRCServerSession* CMMRCServerSession::NewL(CMMRCServerController& aServerController, |
|
106 const CFourCCConvertor& aFourCCConvertor) |
|
107 { |
|
108 DP_STATIC_CONTEXT(----> CMMRCServerSession::NewL *CD1*, CtxDevSound, DPLOCAL); |
|
109 DP_IN(); |
|
110 |
|
111 CMMRCServerSession* self = NewLC(aServerController, aFourCCConvertor); |
|
112 CleanupStack::Pop(self); |
|
113 |
|
114 DP0_RET(self, "self=0x%x"); |
|
115 } |
|
116 |
|
117 /** |
|
118 * Constructs, leaves object on the cleanup stack, and returns a pointer |
|
119 * to, a new CMMRCServerSession object. |
|
120 * Leaves on failure. |
|
121 * @param CMMRCServerController& A reference on the MMRC Server controller |
|
122 * @param CFourCCConvertor& A reference to the Fourcc to format converter |
|
123 * @return CMMRCServerSession* A pointer to newly created utlitly object. |
|
124 */ |
|
125 CMMRCServerSession* CMMRCServerSession::NewLC(CMMRCServerController& aServerController, |
|
126 const CFourCCConvertor& aFourCCConvertor) |
|
127 { |
|
128 DP_STATIC_CONTEXT(----> CMMRCServerSession::NewLC *CD1*, CtxDevSound, DPLOCAL); |
|
129 DP_IN(); |
|
130 |
|
131 CMMRCServerSession* self = new(ELeave) CMMRCServerSession(aServerController, aFourCCConvertor); |
|
132 CleanupStack::PushL( self ); |
|
133 self->ConstructL(); |
|
134 |
|
135 DP0_RET(self, "self=0x%x"); |
|
136 } |
|
137 |
|
138 /** |
|
139 CMMRCServerSession::ConstructL |
|
140 Symbian 2nd phase constructor can leave. |
|
141 */ |
|
142 void CMMRCServerSession::ConstructL() |
|
143 { |
|
144 DP_CONTEXT(----> CMMRCServerSession::ConstructL *CD1*, CtxDevSound, DPLOCAL); |
|
145 DP_IN(); |
|
146 |
|
147 iContextId = reinterpret_cast<TUint32>(this); |
|
148 iMMRCServerSideAdaptationResponseAO = CMMRCServerSideAdaptationResponseAO::NewL(); |
|
149 iMMRCServerSideAdaptationResponseAO->Initialize(this, &iServerThread); |
|
150 |
|
151 DP_OUT(); |
|
152 } |
|
153 |
|
154 /** |
|
155 * from CSession2 |
|
156 * @param aMessage - Function and data for the session |
|
157 */ |
|
158 void CMMRCServerSession::ServiceL(const RMessage2& aMessage) |
|
159 { |
|
160 DP_CONTEXT(----> CMMRCServerSession::ServiceL *CD1*, CtxDevSound, DPLOCAL); |
|
161 DP_IN(); |
|
162 |
|
163 TRAPD( errL, DispatchMessageL(aMessage) ); |
|
164 |
|
165 if( errL != KErrNone ) |
|
166 { |
|
167 #ifdef SYMBIAN_MULTIMEDIA_ENABLE_LOGGING |
|
168 RDebug::Print(_L("CMMRCServerSession::ServiceL - err %d"), errL); |
|
169 #endif |
|
170 } |
|
171 |
|
172 DP_OUT(); |
|
173 } |
|
174 |
|
175 /** |
|
176 * Dispatch the message received from ServeL |
|
177 * EMMRCClientToServerSetMsgQueueHandle - Initialise the queue handler |
|
178 * EMMRCClientToServerMessage - Process a message from the client |
|
179 * EMMRCClientToServerMessageUpdate - Process a message update from the client |
|
180 * EMMRCClientToServerMessageAcknowledgement - Process the acknowldgement from the client |
|
181 * @param aMessage - Function and data for the session |
|
182 * @return error code |
|
183 * @leave in case of writeL leave or request leave |
|
184 */ |
|
185 TInt CMMRCServerSession::DispatchMessageL(const RMessage2& aMessage) |
|
186 { |
|
187 DP_CONTEXT(----> CMMRCServerSession::DispatchMessageL *CD1*, CtxDevSound, DPLOCAL); |
|
188 DP_IN(); |
|
189 |
|
190 TInt error(KErrNone); |
|
191 |
|
192 TMMRCClientToServerMessages messageFunction = static_cast<TMMRCClientToServerMessages>(aMessage.Function()); |
|
193 switch(messageFunction) |
|
194 { |
|
195 |
|
196 case EMMRCClientToServerSetClientThreadId: |
|
197 { |
|
198 TThreadId* id = static_cast<TThreadId*>(const_cast<TAny *>(aMessage.Ptr0())); |
|
199 iClientThread.Open(*id); |
|
200 RThread me; |
|
201 iServerThread.Open(me.Id()); |
|
202 aMessage.Complete(error); |
|
203 } |
|
204 break; |
|
205 |
|
206 case EMMRCClientToServerSetAdaptationProxy: |
|
207 { |
|
208 iMMRCClientSideServerRequestToAdaptationAO = static_cast<CMMRCClientSideServerRequestToAdaptationAO*>(const_cast<TAny *>(aMessage.Ptr0())); |
|
209 |
|
210 if(iMMRCClientSideServerRequestToAdaptationAO) |
|
211 { |
|
212 iMMRCClientSideServerRequestToAdaptationAO->Initialize(this, |
|
213 iMMRCServerSideAdaptationResponseAO, |
|
214 &iClientThread, |
|
215 *iFourCCConvertor); |
|
216 } |
|
217 aMessage.Complete(error); |
|
218 } |
|
219 break; |
|
220 |
|
221 case EMMRCClientToServerSetMsgQueueHandle: |
|
222 { |
|
223 error = iMsgQueue.Open( aMessage, 0 ); |
|
224 aMessage.Complete(error); |
|
225 } |
|
226 break; |
|
227 |
|
228 case EMMRCClientToServerCloseSession: |
|
229 { |
|
230 //set a flag so that any subsequent acknowledgment will be ignored... |
|
231 iShutdown=ETrue; |
|
232 aMessage.Complete(error); |
|
233 } |
|
234 break; |
|
235 |
|
236 case EMMRCClientToServerRequestResource: |
|
237 { |
|
238 error = EnqueueRequestL(aMessage); |
|
239 // AM this is needed since the request is not asynchronous. |
|
240 // It is processed asynchronously which is different |
|
241 aMessage.Complete(error); |
|
242 } |
|
243 break; |
|
244 |
|
245 case EMMRCClientToServerRequestContextId: |
|
246 { |
|
247 // CDS This code does not appear to be handling PlatSec functionality well |
|
248 |
|
249 TProcessId PID; |
|
250 TPckg<TProcessId> processIdPckg(PID); |
|
251 TPckgBuf<TUint64> contextIdPckg; |
|
252 |
|
253 aMessage.ReadL( 0, processIdPckg ); |
|
254 |
|
255 RProcess client; |
|
256 TInt err = client.Open(PID); |
|
257 if(err == KErrNone) |
|
258 { |
|
259 iClientHasMMCapability = client.HasCapability(ECapabilityMultimediaDD, KSuppressPlatSecDiagnostic); |
|
260 iClientHasUECapability = client.HasCapability(ECapabilityUserEnvironment, KSuppressPlatSecDiagnostic); |
|
261 client.Close(); |
|
262 } |
|
263 aMessage.WriteL( 1, contextIdPckg ); |
|
264 aMessage.Complete(error); |
|
265 } |
|
266 break; |
|
267 |
|
268 |
|
269 case EMMRCClientToServerRegisterAsClient: |
|
270 { |
|
271 // ignoring arguments |
|
272 error = iMMRCServerController.EnqueueRequestForAPRL(*this); |
|
273 aMessage.Complete(error); |
|
274 } |
|
275 break; |
|
276 |
|
277 case EMMRCClientToServerCancelRegisterAsClient: |
|
278 { |
|
279 // ignoring arguments |
|
280 error = iMMRCServerController.RemoveRequestForAPR(*this); |
|
281 aMessage.Complete(error); |
|
282 } |
|
283 break; |
|
284 |
|
285 case EMMRCClientToServerWillResumePlay: |
|
286 { |
|
287 error = iMMRCServerController.WillResumePlay(); |
|
288 aMessage.Complete(error); |
|
289 } |
|
290 break; |
|
291 |
|
292 default: |
|
293 { |
|
294 #ifdef SYMBIAN_MULTIMEDIA_ENABLE_LOGGING |
|
295 RDebug::Print(_L("!!!!CMMRCServerSession::DispatchMessageL - unknown message")); |
|
296 #endif |
|
297 // Unknown Message |
|
298 error = KErrNotSupported; |
|
299 } |
|
300 break; |
|
301 } |
|
302 |
|
303 DP0_RET(error, "err=%d"); |
|
304 } |
|
305 |
|
306 /** |
|
307 * Process a message that can be |
|
308 * EMMRCMessageStateAffecting a state-effecting message |
|
309 * EMMRCMessageCommit a resource request |
|
310 * @param const RMessage2& aMessage |
|
311 */ |
|
312 void CMMRCServerSession::PreProcessRequestL(const RMessage2& aMessage) |
|
313 { |
|
314 DP_CONTEXT(----> CMMRCServerSession::PreprocessMessageL *CD1*, CtxDevSound, DPLOCAL); |
|
315 DP_IN(); |
|
316 |
|
317 MLogicalChain* logicalChainRequested = static_cast<MLogicalChain*>(const_cast<TAny *>(aMessage.Ptr1())); |
|
318 if( logicalChainRequested == NULL ) |
|
319 { |
|
320 #ifdef _DEBUG |
|
321 RDebug::Print(_L("!!!!CMMRCServerSession::PreProcessRequestL - logicalChainRequested NULL")); |
|
322 ASSERT(0); |
|
323 #endif |
|
324 User::Leave(KErrArgument); |
|
325 } |
|
326 |
|
327 TInt err1 = KErrNone, err2 = KErrNone; |
|
328 iAudioContext = static_cast<CAudioContext*>(const_cast<TAny *>(aMessage.Ptr2())); |
|
329 MLogicalChain* logicalChainLastCommited = static_cast<MLogicalChain*>(const_cast<TAny *>(aMessage.Ptr0())); |
|
330 |
|
331 if(iLogicalChainLastCommitedStack) |
|
332 { |
|
333 iLogicalChainLastCommitedStack->Release(); |
|
334 iLogicalChainLastCommitedStack = NULL; |
|
335 } |
|
336 if(iLogicalChainRequestedStack) |
|
337 { |
|
338 iLogicalChainRequestedStack->Release(); |
|
339 iLogicalChainRequestedStack = NULL; |
|
340 } |
|
341 |
|
342 iAudioContext->CriticalSection().Wait(); |
|
343 TInt msgVersion = iAudioContext->MsgVersion(); |
|
344 if(msgVersion == aMessage.Int3()) |
|
345 { |
|
346 if(logicalChainLastCommited) |
|
347 { |
|
348 TRAP(err1, iLogicalChainLastCommitedStack = logicalChainLastCommited->CloneL()); |
|
349 } |
|
350 |
|
351 if(logicalChainRequested) |
|
352 { |
|
353 TRAP(err2, iLogicalChainRequestedStack = logicalChainRequested->CloneL()); |
|
354 } |
|
355 } |
|
356 iAudioContext->CriticalSection().Signal(); |
|
357 |
|
358 if(msgVersion != aMessage.Int3()) |
|
359 { |
|
360 User::Leave(KErrCompletion); |
|
361 } |
|
362 |
|
363 if(err1!=KErrNone) |
|
364 { |
|
365 #ifdef SYMBIAN_MULTIMEDIA_ENABLE_LOGGING |
|
366 RDebug::Print(_L("!!!!CMMRCServerSession::PreProcessRequestL - logicalChainLastCommited->CloneL - error = %d"), err1); |
|
367 #endif |
|
368 ASSERT(0); |
|
369 User::Leave(err1); |
|
370 } |
|
371 |
|
372 if(err2!=KErrNone) |
|
373 { |
|
374 #ifdef SYMBIAN_MULTIMEDIA_ENABLE_LOGGING |
|
375 RDebug::Print(_L("!!!!CMMRCServerSession::PreProcessRequestL - logicalChainRequested->CloneL - error = %d"), err2); |
|
376 #endif |
|
377 if(iLogicalChainLastCommitedStack) |
|
378 { |
|
379 iLogicalChainRequestedStack->Release(); |
|
380 iLogicalChainRequestedStack = NULL; |
|
381 } |
|
382 ASSERT(0); |
|
383 User::Leave(err2); |
|
384 } |
|
385 |
|
386 DP_OUT(); |
|
387 } |
|
388 |
|
389 /** |
|
390 * Process a message that can be |
|
391 * EMMRCMessageStateAffecting a state-effecting message |
|
392 * EMMRCMessageCommit a resource request |
|
393 * @param const RMessage2& aMessage |
|
394 */ |
|
395 TInt CMMRCServerSession::EnqueueRequestL(const RMessage2& aMessage) |
|
396 { |
|
397 DP_CONTEXT(----####> CMMRCServerSession::ProcessRequestL *CD1*, CtxDevSound, DPLOCAL); |
|
398 DP_IN(); |
|
399 |
|
400 TInt err = KErrNone; |
|
401 TRAP(err, PreProcessRequestL(aMessage)); |
|
402 if( err == KErrNone ) |
|
403 { |
|
404 err = iMMRCServerController.EnqueueRequestL(*this); |
|
405 } |
|
406 |
|
407 DP0_RET(err, "err = %d"); |
|
408 } |
|
409 |
|
410 /* |
|
411 * |
|
412 */ |
|
413 void CMMRCServerSession::StartProcessL() |
|
414 { |
|
415 DP_CONTEXT(----> CMMRCServerSession::StartProcessL *CD1*, CtxDevSound, DPLOCAL); |
|
416 DP_IN(); |
|
417 |
|
418 if( iLogicalChainLastCommited ) |
|
419 { |
|
420 //jjpy TODO should compare with iLogicalChainRequestedStack |
|
421 iLogicalChainLastCommited->Release(); |
|
422 } |
|
423 |
|
424 if(iLogicalChainRequested) |
|
425 { |
|
426 #ifdef _DEBUG |
|
427 RDebug::Print(_L("!!!!CMMRCServerSession::StartProcessL - iLogicalChainRequested not NULL")); |
|
428 ASSERT(0); |
|
429 #endif |
|
430 iLogicalChainRequested->Release(); |
|
431 } |
|
432 |
|
433 iLogicalChainLastCommited = iLogicalChainLastCommitedStack; |
|
434 iLogicalChainRequested = iLogicalChainRequestedStack; |
|
435 |
|
436 iLogicalChainLastCommitedStack = 0; |
|
437 iLogicalChainRequestedStack = 0; |
|
438 |
|
439 //Send the CommitUpdate to the client |
|
440 TMMRCQueueItem messageItem; |
|
441 messageItem.iRequestType = EMMRCRequestCommitUpdate; |
|
442 messageItem.iResult = EMMRCServerToClientCommitUpdate; |
|
443 messageItem.iErrorCode = KErrNone; |
|
444 TInt errSend = iMsgQueue.Send(messageItem); |
|
445 #ifdef _DEBUG |
|
446 if(errSend!=KErrNone) |
|
447 { |
|
448 RDebug::Print(_L("!!!!CMMRCServerSession::PreProcessRequestL - error = %d"), errSend); |
|
449 ASSERT(0); |
|
450 } |
|
451 #endif |
|
452 User::LeaveIfError(errSend); |
|
453 |
|
454 DP_OUT(); |
|
455 } |
|
456 |
|
457 /* |
|
458 * |
|
459 */ |
|
460 void CMMRCServerSession::StartPreemptionL() |
|
461 { |
|
462 DP_CONTEXT(----> CMMRCServerSession::StartPreemptionL *CD1*, CtxDevSound, DPLOCAL); |
|
463 DP_IN(); |
|
464 |
|
465 //Should be NULL |
|
466 if(iLogicalChainRequested) |
|
467 { |
|
468 #ifdef _DEBUG |
|
469 RDebug::Print(_L("!!!!CMMRCServerSession::StartPreemptionL - iLogicalChainRequested not NULL")); |
|
470 ASSERT(0); |
|
471 #endif |
|
472 iLogicalChainRequested->Release(); |
|
473 } |
|
474 |
|
475 //Should NOT be NULL. |
|
476 if( iLogicalChainLastCommited ) |
|
477 { |
|
478 iLogicalChainRequested = iLogicalChainLastCommited->CloneL(); |
|
479 CLogicalAudioStream* audiostream = static_cast<CLogicalAudioStream*>(iLogicalChainRequested); |
|
480 TAudioState state = audiostream->StreamState(); |
|
481 |
|
482 // MMRC wont't support demote to EIdle anymore |
|
483 // All stream are demote to EInitialised |
|
484 switch(state) |
|
485 { |
|
486 case EIdle: |
|
487 { |
|
488 audiostream->Unload(); |
|
489 } |
|
490 break; |
|
491 |
|
492 case EPrimed: |
|
493 case EActive: |
|
494 { |
|
495 User::LeaveIfError(audiostream->Stop()); |
|
496 audiostream->Unload(); |
|
497 } |
|
498 break; |
|
499 default: |
|
500 #ifdef _DEBUG |
|
501 RDebug::Print(_L("!!!!CMMRCServerSession::StartPreemptionL - wrong state ")); |
|
502 ASSERT(0); |
|
503 #endif |
|
504 break; |
|
505 } |
|
506 } |
|
507 |
|
508 DP_OUT(); |
|
509 } |
|
510 |
|
511 /** |
|
512 * Callback on a resource request |
|
513 * @param TMMRCServerToClientMessageResults aResult the result on the request |
|
514 * @leave |
|
515 */ |
|
516 void CMMRCServerSession::AdaptationRequestAcknowledgment(TMMRCAdaptationToServerRequestResults aResult, TInt aError) |
|
517 { |
|
518 DP_CONTEXT(----@@@@> CMMRCServerSession::AdaptationRequestAcknowledgment *CD1*, CtxDevSound, DPLOCAL); |
|
519 DP_IN(); |
|
520 |
|
521 TMMRCQueueItem messageItem; |
|
522 messageItem.iRequestType = EMMRCRequestCommitResponse; |
|
523 |
|
524 switch(aResult) |
|
525 { |
|
526 case EMMRCAdaptationToServerResourceComplete: |
|
527 { |
|
528 TUint64 contextId; |
|
529 TMMRCServerState serverState; |
|
530 iMMRCServerController.ServerState(serverState, contextId); |
|
531 switch(serverState) |
|
532 { |
|
533 case EMMRCServerStateWaitResourceResponseFromAdaptation: // here we process the response |
|
534 { |
|
535 messageItem.iResult = EMMRCServerToClientResourceAgreed; |
|
536 messageItem.iErrorCode = aError; |
|
537 iMMRCServerController.AdaptationRequestAcknowledgment(*this, aResult, aError); |
|
538 SendRequestResponseToClient(messageItem); |
|
539 } //end case EMMRCServerStateWaitResourceResponseFromAdaptation |
|
540 break; |
|
541 case EMMRCServerStateWaitPreemptionResponse: // here we process the response |
|
542 { |
|
543 messageItem.iResult = EMMRCServerToClientResourcePreempt; |
|
544 messageItem.iErrorCode = KErrCompletion; |
|
545 iMMRCServerController.AdaptationRequestAcknowledgment(*this, aResult, KErrCompletion); |
|
546 SendPreemptionNotificationToClient(messageItem); |
|
547 } |
|
548 break; |
|
549 default: |
|
550 { |
|
551 #ifdef _DEBUG |
|
552 RDebug::Print(_L("!!!!CMMRCServerSession::AdaptationRequestAcknowledgment - Unknown message")); |
|
553 ASSERT(0); |
|
554 #endif |
|
555 } |
|
556 break; |
|
557 } //end case EMMRCServerStateWaitPreemptionRespons |
|
558 } |
|
559 break; |
|
560 |
|
561 case EMMRCAdaptationToServerResourceIncomplete: |
|
562 { |
|
563 messageItem.iResult = EMMRCServerToClientResourceDenied; |
|
564 messageItem.iErrorCode = aError; |
|
565 iMMRCServerController.AdaptationRequestAcknowledgment(*this, aResult, aError); |
|
566 SendRequestResponseToClient(messageItem); |
|
567 } |
|
568 break; |
|
569 |
|
570 case EMMRCAdaptationToServerResourceTimeout: |
|
571 { |
|
572 messageItem.iResult = EMMRCServerToClientRequestError; |
|
573 messageItem.iErrorCode = KErrCompletion; |
|
574 iMMRCServerController.AdaptationRequestAcknowledgment(*this, EMMRCAdaptationToServerResourceTimeout, KErrCompletion); |
|
575 SendRequestResponseToClient(messageItem); |
|
576 } |
|
577 break; |
|
578 |
|
579 default: |
|
580 break; |
|
581 } |
|
582 |
|
583 DP_OUT(); |
|
584 } |
|
585 |
|
586 /** |
|
587 * |
|
588 * |
|
589 */ |
|
590 void CMMRCServerSession::SendRequestResponseToClient(TMMRCQueueItem& messageItem) |
|
591 { |
|
592 DP_CONTEXT(----====> CMMRCServerSession::SendRequestResponseToClient *CD1*, CtxDevSound, DPLOCAL); |
|
593 DP_IN(); |
|
594 if(messageItem.iErrorCode == KErrNone) |
|
595 { |
|
596 //1) Set the iLogicalChainRequestResponse |
|
597 if(iLogicalChainRequestResponse) |
|
598 { |
|
599 iLogicalChainRequestResponse->Release(); |
|
600 iLogicalChainRequestResponse = NULL; |
|
601 } |
|
602 if(iLogicalChainRequested) |
|
603 { |
|
604 TInt errT; |
|
605 TRAP(errT, iLogicalChainRequestResponse = iLogicalChainRequested->CloneL()); |
|
606 DP1(DLERR,"ECloneLeftWhenSendingResponseToClient %d", errT); |
|
607 __ASSERT_DEBUG(errT == KErrNone, Panic(ECloneLeftWhenSendingResponseToClient)); |
|
608 } |
|
609 //2) Set the last commited chain et set the desired one to NULL |
|
610 if( iLogicalChainLastCommited ) |
|
611 { |
|
612 iLogicalChainLastCommited->Release(); |
|
613 iLogicalChainLastCommited = NULL; |
|
614 } |
|
615 iLogicalChainLastCommited = iLogicalChainRequested; |
|
616 iLogicalChainRequested = NULL; |
|
617 } |
|
618 else //In case of ERROR |
|
619 { |
|
620 //1) Set the iLogicalChainRequestResponse |
|
621 if(iLogicalChainRequestResponse) |
|
622 { |
|
623 iLogicalChainRequestResponse->Release(); |
|
624 iLogicalChainRequestResponse = NULL; |
|
625 } |
|
626 if(iLogicalChainRequested) |
|
627 { |
|
628 TInt errT; |
|
629 TRAP(errT, iLogicalChainRequestResponse = iLogicalChainLastCommited->CloneL()); |
|
630 DP1(DLERR,"ECloneLeftWhenSendingResponseToClient %d", errT); |
|
631 __ASSERT_DEBUG(errT == KErrNone, Panic(ECloneLeftWhenSendingResponseToClient)); |
|
632 } |
|
633 //2) Set the last commited chain et set the desired one to NULL |
|
634 if( iLogicalChainRequested ) |
|
635 { |
|
636 iLogicalChainRequested->Release(); |
|
637 iLogicalChainRequested = NULL; |
|
638 } |
|
639 |
|
640 if(iLogicalChainRequestedStack) |
|
641 { |
|
642 CLogicalAudioStream* lChain = static_cast <CLogicalAudioStream*>(iLogicalChainLastCommited); |
|
643 TAudioTypeSettings settings; |
|
644 settings.iPriority = iLogicalChainRequestedStack->Priority(); |
|
645 settings.iPref = 0; |
|
646 lChain->SetAudioType(settings); |
|
647 } |
|
648 } |
|
649 // Set the data for the client |
|
650 messageItem.iData = iLogicalChainRequestResponse; |
|
651 |
|
652 //send the response to the client |
|
653 TInt errSend = iMsgQueue.Send(messageItem); |
|
654 DP1(DLERR,"EMsgQueueFailedToSendMsg %d", errSend); |
|
655 __ASSERT_DEBUG(errSend == KErrNone, Panic(EMsgQueueFailedToSendMsg)); |
|
656 |
|
657 DP_OUT(); |
|
658 } |
|
659 |
|
660 /** |
|
661 * |
|
662 * |
|
663 */ |
|
664 void CMMRCServerSession::SendPreemptionNotificationToClient(TMMRCQueueItem& messageItem) |
|
665 { |
|
666 DP_CONTEXT(----~~~~> CMMRCServerSession::SendRequestResponseToClient *CD1*, CtxDevSound, DPLOCAL); |
|
667 DP_IN(); |
|
668 //1) Set the iLogicalChainPreemptionNotification |
|
669 if(iLogicalChainPreemptionNotification) |
|
670 { |
|
671 iLogicalChainPreemptionNotification->Release(); |
|
672 iLogicalChainPreemptionNotification = NULL; |
|
673 } |
|
674 if(iLogicalChainRequested) |
|
675 { |
|
676 TInt errT; |
|
677 TRAP(errT, iLogicalChainPreemptionNotification = iLogicalChainRequested->CloneL()); |
|
678 DP1(DLERR,"ECloneLeftWhenSendingResponseToClient %d", errT); |
|
679 __ASSERT_DEBUG(errT == KErrNone, Panic(ECloneLeftWhenSendingResponseToClient)); |
|
680 |
|
681 iLogicalChainRequested->Release(); |
|
682 iLogicalChainRequested = NULL; |
|
683 } |
|
684 |
|
685 messageItem.iData = iLogicalChainPreemptionNotification; |
|
686 |
|
687 //send the response to the client |
|
688 TInt errSend = iMsgQueue.Send(messageItem); |
|
689 DP1(DLERR,"EMsgQueueFailedToSendMsg %d", errSend); |
|
690 __ASSERT_DEBUG(errSend == KErrNone, Panic(EMsgQueueFailedToSendMsg)); |
|
691 |
|
692 DP_OUT(); |
|
693 } |
|
694 |
|
695 /** |
|
696 * Notify all the paused client that a resource has been unallocated |
|
697 */ |
|
698 void CMMRCServerSession::NotifyClientResourceUnallocated() |
|
699 { |
|
700 DP_CONTEXT(----****> CMMRCServerSession::NotifyClientsResourceUnallocated *CD1*, CtxDevSound, DPLOCAL); |
|
701 DP_IN(); |
|
702 |
|
703 TMMRCQueueItem messageItem; |
|
704 messageItem.iRequestType = EMMRCRequestResourceUnallocated; |
|
705 TInt errSend = iMsgQueue.Send(messageItem); |
|
706 DP1(DLERR,"EMsgQueueFailedToSendMsg %d", errSend); |
|
707 __ASSERT_DEBUG(errSend == KErrNone, Panic(EMsgQueueFailedToSendMsg)); |
|
708 |
|
709 DP_OUT(); |
|
710 } |
|
711 |
|
712 |
|
713 /** |
|
714 * return the current committed chain (const) |
|
715 * @return the current committed chain |
|
716 */ |
|
717 const MLogicalChain* CMMRCServerSession::LogicalChainRequested() const |
|
718 { |
|
719 DP_CONTEXT(----> CMMRCServerSession::LogicalChainRequested const *CD1*, CtxDevSound, DPLOCAL); |
|
720 DP_IN(); |
|
721 |
|
722 DP0_RET(iLogicalChainRequested, "iLogicalChainRequested=0x%x"); |
|
723 } |
|
724 |
|
725 /** |
|
726 * return the current committed chain (const) |
|
727 * @return the current committed chain |
|
728 */ |
|
729 const MLogicalChain* CMMRCServerSession::LogicalChainRequestedStack() const |
|
730 { |
|
731 DP_CONTEXT(----> CMMRCServerSession::LogicalChainRequestedStack const *CD1*, CtxDevSound, DPLOCAL); |
|
732 DP_IN(); |
|
733 |
|
734 DP0_RET(iLogicalChainRequestedStack, "iLogicalChainRequestedStack=0x%x"); |
|
735 } |
|
736 |
|
737 |
|
738 /** |
|
739 * return the last committed chain (const) |
|
740 * @return the last committed chain |
|
741 */ |
|
742 const MLogicalChain* CMMRCServerSession::LogicalChainLastCommited() const |
|
743 { |
|
744 DP_CONTEXT(----> CMMRCServerSession::LogicalChainLastCommited const *CD1*, CtxDevSound, DPLOCAL); |
|
745 DP_IN(); |
|
746 |
|
747 DP0_RET(iLogicalChainLastCommited, "iLogicalChainLastCommited=0x%x"); |
|
748 } |
|
749 |
|
750 /** |
|
751 * return the Audio Context (const) |
|
752 * @return the Audio Context |
|
753 */ |
|
754 const MAudioContext* CMMRCServerSession::AudioContext() const |
|
755 { |
|
756 DP_CONTEXT(----> CMMRCServerSession::AudioContext *CD1*, CtxDevSound, DPLOCAL); |
|
757 DP_IN(); |
|
758 |
|
759 DP0_RET(iAudioContext, "iAudioContext=0x%x"); |
|
760 } |
|
761 |
|
762 /** |
|
763 * return the current committed chain |
|
764 * @return the current committed chain |
|
765 */ |
|
766 MLogicalChain* CMMRCServerSession::LogicalChainRequested() |
|
767 { |
|
768 DP_CONTEXT(----> CMMRCServerSession::LogicalChainRequested *CD1*, CtxDevSound, DPLOCAL); |
|
769 DP_IN(); |
|
770 |
|
771 DP0_RET(iLogicalChainRequested, "iLogicalChainRequested=0x%x"); |
|
772 } |
|
773 |
|
774 /** |
|
775 * return the current committed chain |
|
776 * @return the current committed chain |
|
777 */ |
|
778 MLogicalChain* CMMRCServerSession::LogicalChainRequestedStack() |
|
779 { |
|
780 DP_CONTEXT(----> CMMRCServerSession::LogicalChainRequestedStack *CD1*, CtxDevSound, DPLOCAL); |
|
781 DP_IN(); |
|
782 |
|
783 DP0_RET(iLogicalChainRequestedStack, "iLogicalChainRequestedStack=0x%x"); |
|
784 } |
|
785 |
|
786 /** |
|
787 * return the last committed chain |
|
788 * @return the last committed chain |
|
789 */ |
|
790 MLogicalChain* CMMRCServerSession::LogicalChainLastCommited() |
|
791 { |
|
792 DP_CONTEXT(----> CMMRCServerSession::LogicalChainLastCommited *CD1*, CtxDevSound, DPLOCAL); |
|
793 DP_IN(); |
|
794 |
|
795 DP0_RET(iLogicalChainLastCommited, "iLogicalChainLastCommited=0x%x"); |
|
796 } |
|
797 |
|
798 /** |
|
799 * |
|
800 * @param |
|
801 * @return |
|
802 */ |
|
803 CMMRCClientSideServerRequestToAdaptationAO* CMMRCServerSession::AdaptationProxy() |
|
804 { |
|
805 DP_CONTEXT(----> CMMRCServerSession::AdaptationProxy *CD1*, CtxDevSound, DPLOCAL); |
|
806 DP_IN(); |
|
807 |
|
808 DP0_RET(iMMRCClientSideServerRequestToAdaptationAO, "iMMRCServerAdaptationProxy=0x%x"); |
|
809 } |
|
810 |
|
811 /** |
|
812 * |
|
813 * @param |
|
814 * @return |
|
815 */ |
|
816 TUint64 CMMRCServerSession::ContextId() |
|
817 { |
|
818 DP_CONTEXT(----> CMMRCServerSession::ContextId *CD1*, CtxDevSound, DPLOCAL); |
|
819 DP_IN(); |
|
820 |
|
821 DP0_RET(iContextId, "iContextId=%d"); |
|
822 } |
|
823 |
|
824 /** |
|
825 * |
|
826 */ |
|
827 TBool CMMRCServerSession::HasMultimediaCapability() const |
|
828 { |
|
829 return iClientHasMMCapability; |
|
830 } |
|
831 |
|
832 |
|
833 /** |
|
834 * |
|
835 */ |
|
836 void CMMRCServerSession::Clean() |
|
837 { |
|
838 DP_CONTEXT(----> CMMRCServerSession::Clean *CD1*, CtxDevSound, DPLOCAL); |
|
839 DP_IN(); |
|
840 DP_OUT(); |
|
841 } |
|
842 |
|
843 /** |
|
844 * |
|
845 * @param |
|
846 */ |
|
847 void CMMRCServerSession::Disconnect(const RMessage2& aMessage) |
|
848 { |
|
849 DP_CONTEXT(----> CMMRCServerSession::Disconnect *CD1*, CtxDevSound, DPLOCAL); |
|
850 DP_IN(); |
|
851 |
|
852 CSession2::Disconnect(aMessage); |
|
853 |
|
854 DP_OUT(); |
|
855 } |
|
856 |
|
857 /** |
|
858 * |
|
859 * @return |
|
860 */ |
|
861 TBool CMMRCServerSession::IsServerShuttingDown() |
|
862 { |
|
863 DP_CONTEXT(----> CMMRCServerSession::IsServerShuttingDown *CD1*, CtxDevSound, DPLOCAL); |
|
864 DP_IN(); |
|
865 |
|
866 DP0_RET(iShutdown, "state(bool) = %d"); |
|
867 } |
|
868 |
|
869 TInt CMMRCServerSession::RequestsSent() |
|
870 { |
|
871 return iRequestsSent; |
|
872 }; |
|
873 |
|
874 void CMMRCServerSession::IncrementRequestsSent() |
|
875 { |
|
876 iRequestsSent++; |
|
877 }; |
|
878 |
|
879 CMMRCServerSideAdaptationResponseAO* CMMRCServerSession::ServerProxy() |
|
880 { |
|
881 return iMMRCServerSideAdaptationResponseAO; |
|
882 }; |
|
883 |
|
884 TInt CMMRCServerSession::SendRequestToAdaptation(TMMRCServerSessionRequestType aRequestType) |
|
885 { |
|
886 TInt err=KErrNone; |
|
887 if (!IsServerShuttingDown()) |
|
888 { |
|
889 IncrementRequestsSent(); |
|
890 ServerProxy()->StartAdaptationListening(); |
|
891 AdaptationProxy()->Service(aRequestType); |
|
892 } |
|
893 else |
|
894 { |
|
895 // send some server shutting down error code. |
|
896 } |
|
897 return err; |
|
898 }; |
|
899 |
|
900 TInt CMMRCServerSession::GetPriority() const |
|
901 { |
|
902 DP_CONTEXT(----> CMMRCServerSession::GetPriority *CD1*, CtxDevSound, DPLOCAL); |
|
903 DP_IN(); |
|
904 TInt priority = 0; |
|
905 if(LogicalChainLastCommited() != NULL) |
|
906 { |
|
907 priority = const_cast<MLogicalChain*>( LogicalChainLastCommited() )->Priority(); |
|
908 } |
|
909 DP0_RET(priority, "priority = %d"); |
|
910 } |
|
911 |
|
912 void CMMRCServerSession::Panic(TMMRCServerSessionPanicCodes aCode) |
|
913 { |
|
914 User::Panic(KMMRCServerSessionPanicCategory, aCode); |
|
915 } |
|
916 |
|
917 /** |
|
918 * @ return Boolean value specifying whether Client has UserEnvironment Capability. |
|
919 */ |
|
920 TBool CMMRCServerSession::HasUserEnvironmentCapability() |
|
921 { |
|
922 return iClientHasUECapability; |
|
923 } |
|
924 |
|
925 /** |
|
926 * @ param Error Value to send |
|
927 * @ return Error Value specifying any error in adding the message to the message queue. |
|
928 */ |
|
929 |
|
930 TInt CMMRCServerSession::NotifyClientOfError(TInt aError) |
|
931 { |
|
932 // Create message and send to Client |
|
933 TMMRCQueueItem messageItem; |
|
934 messageItem.iRequestType = EMMRCRequestCommitUpdate; |
|
935 messageItem.iResult = EMMRCServerToClientCommitUpdate; |
|
936 messageItem.iErrorCode = KErrNone; |
|
937 TInt errSend = iMsgQueue.Send(messageItem); |
|
938 |
|
939 // Create a message with the Error and send to Client |
|
940 messageItem.iRequestType = EMMRCRequestCommitResponse; |
|
941 messageItem.iResult = EMMRCServerToClientResourceAgreed; |
|
942 messageItem.iErrorCode = aError; |
|
943 TInt errSend2 = iMsgQueue.Send(messageItem); |
|
944 if (errSend!=KErrNone) |
|
945 { |
|
946 return errSend; |
|
947 } |
|
948 else |
|
949 { |
|
950 return errSend2; |
|
951 } |
|
952 } |
|
953 //EOF |