|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Server implementation fo share files in application private gage |
|
15 * with controlled way |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include <e32std.h> |
|
22 #include <f32file.h> |
|
23 #include <e32math.h> |
|
24 #include "alfstreamerserver.h" |
|
25 #include "alfstreamerconsts.h" |
|
26 #include "alfstreamerbridge.h" |
|
27 #include "alfwindowmanager.h" |
|
28 #include "alfhierarchymodel.h" |
|
29 #include <ecom.h> |
|
30 #include <alf/AlfTransEffectPlugin.h> |
|
31 #include <alf/AlfTransEffectPlugin.hrh> |
|
32 |
|
33 |
|
34 // ================================== |
|
35 // Launcher implementation. |
|
36 // ================================== |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // DoAlfStreamerServerThreadStartFunctionL |
|
40 // Construct the server object |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 LOCAL_C void DoAlfStreamerServerThreadStartFunctionL(CAlfStreamerBridge* aBridge) |
|
44 { |
|
45 CAlfStreamerServer::NewLC(aBridge); |
|
46 |
|
47 RThread().Rendezvous(KErrNone); |
|
48 CActiveScheduler::Start(); |
|
49 CleanupStack::PopAndDestroy(); // server |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // Entry point into the new thread |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 GLDEF_C TInt AlfStreamerServerThreadStartFunction(TAny* aBridge) |
|
57 { |
|
58 __UHEAP_MARK; |
|
59 RThread thread; |
|
60 |
|
61 TInt err = User::RenameThread(KAlfStreamerServerThreadName); |
|
62 if (err == KErrNone) |
|
63 { |
|
64 thread.SetPriority(EPriorityAbsoluteHigh); |
|
65 thread.Close(); |
|
66 |
|
67 // Set up scheduler and cleanup stack for this thread |
|
68 CActiveScheduler* scheduler = new CActiveScheduler; |
|
69 if (!scheduler) |
|
70 { |
|
71 return KErrNoMemory; |
|
72 } |
|
73 CActiveScheduler::Install(scheduler); |
|
74 CTrapCleanup* trapCleanup = CTrapCleanup::New(); |
|
75 if (!trapCleanup) |
|
76 { |
|
77 return KErrNoMemory; |
|
78 } |
|
79 |
|
80 // Set initial trap harness, and construct server object |
|
81 TRAP(err,DoAlfStreamerServerThreadStartFunctionL((CAlfStreamerBridge*)aBridge)); |
|
82 |
|
83 delete CActiveScheduler::Current(); |
|
84 delete trapCleanup; |
|
85 } |
|
86 __UHEAP_MARKEND; |
|
87 return err; |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // LaunchServer |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 TInt CAlfStreamerServer::LaunchServer(TThreadId& aThreadId, CAlfStreamerBridge* aBridge) |
|
95 { |
|
96 // First, check that ther server isn't already running. |
|
97 TFindServer findServer(ALFSTREAMER_SERVER_NAME); |
|
98 TFullName name; |
|
99 if (findServer.Next(name) == KErrNone) |
|
100 { |
|
101 return KErrAlreadyExists; |
|
102 } |
|
103 RThread serverThread; |
|
104 |
|
105 TInt err = serverThread.Create( |
|
106 KAlfStreamerServerThreadName, |
|
107 AlfStreamerServerThreadStartFunction, |
|
108 16384, // magic |
|
109 0, // uses caller thread's heap |
|
110 (TAny*)aBridge, |
|
111 EOwnerThread); |
|
112 |
|
113 aThreadId = serverThread.Id(); |
|
114 TRequestStatus status; |
|
115 serverThread.Rendezvous(status); |
|
116 serverThread.Resume(); |
|
117 serverThread.Close(); |
|
118 User::WaitForRequest(status); |
|
119 return err; |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // NewLC |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CAlfStreamerServer::NewLC(CAlfStreamerBridge* aBridge) |
|
127 { |
|
128 CAlfStreamerServer* pS = new (ELeave) CAlfStreamerServer(aBridge); |
|
129 CleanupStack::PushL(pS); |
|
130 pS->ConstructL(); |
|
131 } |
|
132 |
|
133 TInt DoRendezvous(TAny* aCallBack) |
|
134 { |
|
135 RThread().Rendezvous(KErrNone); |
|
136 CAsyncCallBack* cb = (CAsyncCallBack*) aCallBack; |
|
137 delete cb; |
|
138 return KErrNone; |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // ConstructL |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 void CAlfStreamerServer::ConstructL() |
|
146 { |
|
147 StartL(ALFSTREAMER_SERVER_NAME); |
|
148 |
|
149 iWindowHierarcy = CAlfHierarchyModel::NewL(*this); |
|
150 iWindowMgr = CAlfWindowManager::NewL(iWindowHierarcy); |
|
151 iBridge->SetStreamerServer( *this ); |
|
152 iThemesListener = CThemeRepositoryListener::NewL(); |
|
153 iThemesListener->IssueRequest(); |
|
154 iRendezvous = new (ELeave) CAsyncCallBack(EPriorityHigh*3); |
|
155 iRendezvous->Set(TCallBack(DoRendezvous, iRendezvous)); |
|
156 iRendezvous->CallBack(); |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------------------------- |
|
160 // NewSessionL |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 CSession2* CAlfStreamerServer::NewSessionL(const TVersion& /*aVersion*/,const RMessage2& /*aMessage*/) const |
|
164 { |
|
165 CSession2* newSession = new(ELeave) CAlfStreamerServerSession(); |
|
166 iSessions++; |
|
167 |
|
168 return newSession; |
|
169 } |
|
170 |
|
171 CAlfStreamerServerSession* CAlfStreamerServer::WservSession(TInt aScreenNumber) |
|
172 { |
|
173 CAlfStreamerServerSession* windowServerSession = NULL; |
|
174 for(TInt i = 0; i < iWindowServerSessions.Count(); i++ ) |
|
175 { |
|
176 if(aScreenNumber == iWindowServerSessions[i]->ScreenNumber() ) |
|
177 { |
|
178 windowServerSession = iWindowServerSessions[i]; |
|
179 break; |
|
180 } |
|
181 } |
|
182 return windowServerSession; |
|
183 } |
|
184 |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // HandleClientExit |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 void CAlfStreamerServer::HandleClientExit(const CSession2* /*aClient*/) |
|
191 { |
|
192 iSessions--; |
|
193 if (!iSessions) |
|
194 { |
|
195 // CActiveScheduler::Stop(); // TODO: lets not die, if client dies. |
|
196 } |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // destructor of CAlfStreamerServer |
|
201 // --------------------------------------------------------------------------- |
|
202 // |
|
203 CAlfStreamerServer::~CAlfStreamerServer() |
|
204 { |
|
205 delete iThemesListener; |
|
206 delete iWindowMgr; |
|
207 delete iWindowHierarcy; |
|
208 iCompositionSessions.Close(); |
|
209 iCompositionHostSessions.Close(); |
|
210 iCompositionTokens.Close(); |
|
211 iWindowServerSessions.Close(); |
|
212 } |
|
213 |
|
214 void CAlfStreamerServer::AppendCompositionSessionL(CAlfStreamerServerSession* aSession, TBool aHost) |
|
215 { |
|
216 if(!aHost) |
|
217 { |
|
218 TInt index = iCompositionSessions.Find(aSession); |
|
219 if (index == KErrNotFound) |
|
220 { |
|
221 iCompositionSessions.AppendL(aSession); |
|
222 } |
|
223 } |
|
224 else |
|
225 { |
|
226 TInt index = iCompositionHostSessions.Find(aSession); |
|
227 if (index == KErrNotFound) |
|
228 { |
|
229 iCompositionHostSessions.AppendL(aSession); |
|
230 } |
|
231 } |
|
232 } |
|
233 void CAlfStreamerServer::RemoveCompositionSession(CAlfStreamerServerSession* aSession) |
|
234 { |
|
235 TInt index = iCompositionSessions.Find(aSession); |
|
236 if (index != KErrNotFound) |
|
237 { |
|
238 FreeCompositionSessionExtents(aSession); |
|
239 TPckgC<TInt> id(reinterpret_cast<TInt>(aSession)); |
|
240 for(TInt u = 0; u < iWindowServerSessions.Count(); u++ ) |
|
241 { |
|
242 if( aSession->ScreenNumber() == iWindowServerSessions[u]->ScreenNumber()) |
|
243 { |
|
244 TRAP_IGNORE(QueueRequestForSessionL(iWindowServerSessions[u], id, KAlfCompOpSessionClosed)); |
|
245 } |
|
246 } |
|
247 |
|
248 iCompositionSessions.Remove(index); |
|
249 |
|
250 } |
|
251 TInt hostindex = iCompositionHostSessions.Find(aSession); |
|
252 if (hostindex != KErrNotFound) |
|
253 { |
|
254 HBufC8* message = HBufC8::NewLC(8); |
|
255 TInt session = reinterpret_cast<TInt>(aSession); |
|
256 TPtr8 clientBuf = message->Des(); |
|
257 clientBuf.Insert(0, TPtrC8((TUint8*)&session ,sizeof(TInt))); |
|
258 TInt newtarget = 0; |
|
259 clientBuf.Insert(1 * sizeof(TInt), TPtrC8((TUint8*)&newtarget ,sizeof(TInt))); |
|
260 for(TInt i = 0; i < iWindowServerSessions.Count(); i++ ) |
|
261 { |
|
262 if( aSession->ScreenNumber() == iWindowServerSessions[i]->ScreenNumber()) |
|
263 { |
|
264 TRAP_IGNORE(QueueRequestForSessionL(iWindowServerSessions[i], *message, KAlfCompOpBindSourceToToken)); // bind to 0 -> remove binding |
|
265 } |
|
266 } |
|
267 CleanupStack::PopAndDestroy(); |
|
268 iCompositionHostSessions.Remove(hostindex); |
|
269 } |
|
270 |
|
271 // clean possible tokens for this composition source |
|
272 TInt targetSession = reinterpret_cast<TInt>(aSession); |
|
273 for( TInt i = 0; i < iCompositionTokens.Count() ; i++) |
|
274 { |
|
275 if ( targetSession == iCompositionTokens[i].iTarget ) |
|
276 { |
|
277 iCompositionTokens.Remove(i); |
|
278 i--; |
|
279 } |
|
280 }; |
|
281 } |
|
282 |
|
283 void CAlfStreamerServer::HandleCompositionRequestL(CAlfStreamerServerSession* aSession, TInt aOp, const RMessage2& aMessage) |
|
284 { |
|
285 CAlfStreamerServerSession* wservsession = WservSession( aSession->ScreenNumber() ); |
|
286 |
|
287 TInt length = aMessage.GetDesLength(0); |
|
288 User::LeaveIfError(length); |
|
289 HBufC8* message = HBufC8::NewLC(length+4); |
|
290 TPtr8 clientBuf = message->Des(); |
|
291 aMessage.ReadL(0,clientBuf); |
|
292 |
|
293 if(aOp == KAlfCompOpSetExtent) |
|
294 { |
|
295 TInt* ptr = (TInt*)clientBuf.Ptr(); |
|
296 TInt screennumber = ptr[4]; |
|
297 if(screennumber!=aSession->ScreenNumber()) |
|
298 { |
|
299 aSession->ExtentSurfaceId().iInternal[0] = ptr[5]; |
|
300 aSession->ExtentSurfaceId().iInternal[1] = ptr[6]; |
|
301 aSession->ExtentSurfaceId().iInternal[2] = ptr[7]; |
|
302 aSession->ExtentSurfaceId().iInternal[3] = ptr[8]; |
|
303 wservsession = WservSession( screennumber ); |
|
304 } |
|
305 } |
|
306 else if(aOp == KAlfCompOpSessionClosed) |
|
307 { |
|
308 FreeCompositionSessionExtents(aSession); |
|
309 } |
|
310 |
|
311 TInt session = reinterpret_cast<TInt>(aSession); |
|
312 clientBuf.Insert(0, TPtrC8((TUint8*)&session ,sizeof(TInt))); |
|
313 |
|
314 if( wservsession ) // don't send to any wservsession if composition source does not have a window anywhere and this is not SetExtent operation |
|
315 { |
|
316 QueueRequestForSessionL(wservsession, clientBuf, aOp); |
|
317 } |
|
318 |
|
319 CleanupStack::PopAndDestroy(); // unefficient.. |
|
320 |
|
321 if (!wservsession) |
|
322 { |
|
323 aMessage.Complete(KErrNotReady); |
|
324 return; |
|
325 } |
|
326 |
|
327 if( aOp == KAlfCompOpCreateSource ) |
|
328 { |
|
329 AppendCompositionSessionL(aSession); |
|
330 aMessage.Complete(reinterpret_cast<TInt>(aSession)); |
|
331 } |
|
332 else if ( aOp != KAlfCompOpSetZOrder ) |
|
333 { |
|
334 aMessage.Complete(KErrNone); |
|
335 } |
|
336 } |
|
337 |
|
338 void CAlfStreamerServer::QueueRequestForSessionL(CAlfStreamerServerSession* aSession, const TPtrC8& aPtr, TInt aOp) |
|
339 { |
|
340 aSession->QueueL(aPtr, aOp); |
|
341 } |
|
342 |
|
343 void CAlfStreamerServer::QueueRequestAllSessionsL(const TPtrC8& aPtr, TInt aOp, TBool aAlsoWServ) |
|
344 { |
|
345 if (aAlsoWServ) |
|
346 { |
|
347 for(TInt i = 0; i < iWindowServerSessions.Count(); i++ ) |
|
348 { |
|
349 iWindowServerSessions[i]->QueueL(aPtr, aOp); |
|
350 } |
|
351 } |
|
352 |
|
353 for(TInt i = iCompositionSessions.Count()-1; i >= 0; i-- ) |
|
354 { |
|
355 iCompositionSessions[i]->QueueL(aPtr, aOp); |
|
356 } |
|
357 } |
|
358 |
|
359 TInt CAlfStreamerServer::CreatePermissionToken(const RMessage2& aMessage, TInt aTarget, CAlfStreamerServerSession* aSession) |
|
360 { |
|
361 TInt length = aMessage.GetDesLength(0); |
|
362 User::LeaveIfError(length); |
|
363 HBufC8* message = HBufC8::NewLC(length); |
|
364 TPtr8 clientBuf = message->Des(); |
|
365 aMessage.ReadL(0,clientBuf); |
|
366 |
|
367 TInt* ptr = (TInt*) clientBuf.Ptr(); |
|
368 TInt newkey = Math::Random(); |
|
369 |
|
370 TRAPD( err, iCompositionTokens.AppendL( CCompositionToken( newkey, ptr[0] /* customer specified key */, |
|
371 ptr[1] /*flags*/, aTarget, |
|
372 aSession->ScreenNumber() ) ) ); |
|
373 if (err) |
|
374 { |
|
375 newkey = 0; |
|
376 } |
|
377 RDebug::Print(_L("CAlfStreamerServer::CreatePermissionToken - newkey %d target: %d, err: %d"), newkey, aTarget, err ); |
|
378 |
|
379 CleanupStack::PopAndDestroy(message); |
|
380 return newkey; |
|
381 } |
|
382 |
|
383 void CAlfStreamerServer::ValidateToken( CAlfStreamerServerSession* aSession, const RMessage2& aMessage) |
|
384 { |
|
385 TInt length = aMessage.GetDesLength(0); |
|
386 User::LeaveIfError(length); |
|
387 HBufC8* message = HBufC8::NewLC(length + 12); |
|
388 TPtr8 clientBuf = message->Des(); |
|
389 aMessage.ReadL(0,clientBuf); |
|
390 |
|
391 TInt* ptr = (TInt*) clientBuf.Ptr(); |
|
392 TInt tokenkey = ptr[1]; |
|
393 TInt secret = ptr[2]; |
|
394 // only AlfStreamer server knows the tokens. Thus it will pass the existing target and attribs to the client |
|
395 TInt i = 0; |
|
396 while( i < iCompositionTokens.Count() ) |
|
397 { |
|
398 if ( tokenkey == iCompositionTokens[i].iKey && secret == iCompositionTokens[i].iSecretKey ) |
|
399 { |
|
400 break; |
|
401 } |
|
402 i++; |
|
403 }; |
|
404 |
|
405 if ( i < iCompositionTokens.Count()) |
|
406 { |
|
407 CAlfStreamerServerSession* wservsession = WservSession( iCompositionTokens[i].iScreenNumber ); |
|
408 if( wservsession ) |
|
409 { |
|
410 aSession->SetScreenNumber( wservsession->ScreenNumber() ); |
|
411 // CCompositionToken token(iCompositionTokens[i].iKey, iCompositionTokens[i].iSecretKey, iCompositionTokens[i].iFlags, iCompositionTokens[i].iTarget, iCompositionTokens[i].iScreenNumber); |
|
412 TInt session = reinterpret_cast<TInt>(aSession); |
|
413 clientBuf.Insert(0, TPtrC8((TUint8*)&session ,sizeof(TInt))); |
|
414 |
|
415 if( iCompositionTokens[i].iCombinedTarget ) |
|
416 { |
|
417 clientBuf.Insert(1 * sizeof(TInt), TPtrC8((TUint8*)&iCompositionTokens[i].iKey ,sizeof(TInt))); |
|
418 clientBuf.Insert(2 * sizeof(TInt), TPtrC8((TUint8*)&iCompositionTokens[i].iFlags ,sizeof(TInt))); |
|
419 } |
|
420 else |
|
421 { |
|
422 clientBuf.Insert(1 * sizeof(TInt), TPtrC8((TUint8*)&iCompositionTokens[i].iTarget ,sizeof(TInt))); |
|
423 clientBuf.Insert(2 * sizeof(TInt), TPtrC8((TUint8*)&iCompositionTokens[i].iFlags ,sizeof(TInt))); |
|
424 } |
|
425 |
|
426 AppendCompositionSessionL(aSession, ETrue); |
|
427 // pass the updated buffer to client |
|
428 QueueRequestForSessionL(wservsession, clientBuf, KAlfCompOpBindSourceToToken); |
|
429 CleanupStack::PopAndDestroy(); // unefficient.. |
|
430 aMessage.Complete(KErrNone); |
|
431 } |
|
432 else |
|
433 { |
|
434 CleanupStack::PopAndDestroy(); // unefficient.. |
|
435 aMessage.Complete(KErrNotFound); |
|
436 } |
|
437 } |
|
438 else |
|
439 { |
|
440 CleanupStack::PopAndDestroy(); // unefficient.. |
|
441 aMessage.Complete(KErrNotFound); // client will get User::Leave after this. |
|
442 } |
|
443 } |
|
444 |
|
445 void CAlfStreamerServer::HandleCompositionEventL(CAlfStreamerServerSession* aSession, TInt aOp, const RMessage2& aMessage) |
|
446 { |
|
447 if ( aOp == KAlfCompositionWServReady ) |
|
448 { |
|
449 TInt index = iWindowServerSessions.Find(aSession); |
|
450 if (index == KErrNotFound) |
|
451 { |
|
452 iWindowServerSessions.AppendL(aSession); |
|
453 } |
|
454 aMessage.Complete(KErrNone); |
|
455 return; |
|
456 } |
|
457 |
|
458 if ( aOp == KAlfCompositionLowOnGraphicsMemory || aOp == KAlfCompositionGoodOnGraphicsMemory |
|
459 || aOp == KAlfCompositionTargetHidden ||aOp == KAlfCompositionTargetVisible) |
|
460 { |
|
461 aMessage.Complete(KErrNone); |
|
462 QueueRequestAllSessionsL(KNullDesC8(), aOp, ETrue); |
|
463 return; |
|
464 } |
|
465 |
|
466 TInt length = aMessage.GetDesLength(0); |
|
467 User::LeaveIfError(length); |
|
468 HBufC8* message = HBufC8::NewLC(length); |
|
469 TPtr8 clientBuf = message->Des(); |
|
470 aMessage.ReadL(0,clientBuf); |
|
471 |
|
472 TInt* ptr = (TInt*) clientBuf.Ptr(); |
|
473 CAlfStreamerServerSession* target = reinterpret_cast<CAlfStreamerServerSession*>(*ptr); |
|
474 |
|
475 switch(aOp) |
|
476 { |
|
477 case KAlfCompositionFrameReady: |
|
478 { |
|
479 QueueRequestAllSessionsL(clientBuf.Right(4), aOp); |
|
480 break; |
|
481 } |
|
482 case KAlfCompositionTargetCreated: |
|
483 { |
|
484 if (!target->MessagePtr().IsNull()) |
|
485 { |
|
486 // create a combined target token |
|
487 if(ptr[1] > 0 ) |
|
488 { |
|
489 |
|
490 TRAPD( err, iCompositionTokens.AppendL( |
|
491 CCompositionToken( |
|
492 ptr[1], // new token |
|
493 ptr[2], // secret key |
|
494 0, |
|
495 reinterpret_cast<TInt>(aSession), |
|
496 aSession->ScreenNumber(), |
|
497 ETrue // combined target |
|
498 ) ) ); |
|
499 if (err) |
|
500 { |
|
501 ptr[1] = 0; |
|
502 } |
|
503 |
|
504 } |
|
505 |
|
506 target->MessagePtr().Complete(ptr[1]); |
|
507 } |
|
508 break; |
|
509 } |
|
510 default: |
|
511 break; |
|
512 } |
|
513 CleanupStack::PopAndDestroy(); |
|
514 aMessage.Complete(KErrNone); |
|
515 } |
|
516 |
|
517 |
|
518 void CAlfStreamerServer::FreeCompositionSessionExtents(CAlfStreamerServerSession* aSession) |
|
519 { |
|
520 if( !aSession->ExtentSurfaceId().IsNull()) |
|
521 { |
|
522 for(TInt i = 0; i < iWindowServerSessions.Count(); i++) |
|
523 { |
|
524 if( aSession->ScreenNumber() != iWindowServerSessions[i]->ScreenNumber() ) |
|
525 { |
|
526 TInt session = reinterpret_cast<TInt>(aSession); |
|
527 TInt array[] = {session, 0,0,0,0, // TRect() |
|
528 0, // screennumber does not matter |
|
529 aSession->ExtentSurfaceId().iInternal[0], |
|
530 aSession->ExtentSurfaceId().iInternal[1], |
|
531 aSession->ExtentSurfaceId().iInternal[2], |
|
532 aSession->ExtentSurfaceId().iInternal[3] }; |
|
533 TPtrC8 ptr((TUint8*)&array ,sizeof(array)); |
|
534 QueueRequestForSessionL(iWindowServerSessions[i], ptr, KAlfCompOpSetExtent ); |
|
535 } |
|
536 } |
|
537 aSession->ExtentSurfaceId().CreateNullId(); |
|
538 } |
|
539 } |
|
540 |
|
541 // --------------------------------------------------------------------------- |
|
542 // constructor |
|
543 // --------------------------------------------------------------------------- |
|
544 // |
|
545 CAlfStreamerServerSession::CAlfStreamerServerSession() : iScreenNumber(KErrNotFound) |
|
546 { |
|
547 } |
|
548 |
|
549 // --------------------------------------------------------------------------- |
|
550 // destructor of CAlfStreamerServerSession |
|
551 // --------------------------------------------------------------------------- |
|
552 // |
|
553 CAlfStreamerServerSession::~CAlfStreamerServerSession() |
|
554 { |
|
555 TInt i = 0; |
|
556 RImplInfoPtrArray pluginArray; |
|
557 REComSession::ListImplementationsL( KAlfGfxPluginInterfaceUId, pluginArray ); |
|
558 for ( i = iLoadedPlugins.Count() - 1; i >= 0; i-- ) |
|
559 { |
|
560 TInt j = 0; |
|
561 for ( j= 0; j < pluginArray.Count(); j++ ) |
|
562 { |
|
563 TUid loaded = TUid::Uid(iLoadedPlugins[i]); |
|
564 TUid listed = pluginArray[j]->ImplementationUid(); |
|
565 TPtrC8 listedopaque = pluginArray[j]->OpaqueData(); |
|
566 if ( loaded == listed && ( (listedopaque.CompareF( KAlfDoNotUnloadPlugin )) != 0 ) ) |
|
567 { |
|
568 ((CAlfStreamerServer*)(Server()))->WindowMgr()->DestroyPlugin(TUid::Uid(iLoadedPlugins[i])); |
|
569 } |
|
570 } |
|
571 } |
|
572 // Clear the data in plugin array |
|
573 for (TInt i = pluginArray.Count() - 1; i >= 0; i-- ) |
|
574 { |
|
575 // destroy |
|
576 delete pluginArray[i]; |
|
577 pluginArray.Remove( i ); |
|
578 } |
|
579 pluginArray.Close(); |
|
580 iLoadedPlugins.Close(); |
|
581 |
|
582 CAlfStreamerServer* server = dynamic_cast<CAlfStreamerServer*>((CAlfStreamerServer*)Server()); // nice const cast |
|
583 server->RemoveCompositionSession((CAlfStreamerServerSession*)this); // deja vu |
|
584 server->HandleClientExit(this); |
|
585 } |
|
586 |
|
587 |
|
588 // --------------------------------------------------------------------------- |
|
589 // ServiceL |
|
590 // --------------------------------------------------------------------------- |
|
591 // |
|
592 void CAlfStreamerServerSession::ServiceL(const RMessage2& aMessage) |
|
593 { |
|
594 // RDebug::Print(_L("CAlfStreamerServerSession::ServiceL %d"), aMessage.Function()); |
|
595 CAlfStreamerServer* server = (CAlfStreamerServer*)( Server() ); |
|
596 |
|
597 TInt op = aMessage.Function(); |
|
598 |
|
599 // handle composition control ops in different function |
|
600 if (op >= KAlfCompOpCreateSource) |
|
601 { |
|
602 HandleCompositionOpL(op, aMessage, server); |
|
603 return; |
|
604 } |
|
605 |
|
606 switch(op) |
|
607 { |
|
608 case EAlfBridgerBlindSend: |
|
609 case EAlfBridgerSendChunk: |
|
610 case EAlfBridgerRequestDataBlock: |
|
611 case EAlfBridgerAsyncronousData: |
|
612 case EDsNotifyNativeWindowData: |
|
613 { |
|
614 server->WindowTree()->HandleMessageL( aMessage ); |
|
615 return; |
|
616 } |
|
617 |
|
618 case EAlfDecodSLoadPlugin: |
|
619 { |
|
620 TInt index = iLoadedPlugins.Find(aMessage.Int0()); |
|
621 TRAPD( err, server->WindowMgr()->LoadPluginL(TUid::Uid(aMessage.Int0())) ); |
|
622 // was successfully loaded, add uid to session's array |
|
623 if ( err == KErrNone || err == KErrAlreadyExists ) |
|
624 { |
|
625 if ( index == KErrNotFound ) |
|
626 { |
|
627 iLoadedPlugins.AppendL(aMessage.Int0()); |
|
628 } |
|
629 } |
|
630 else |
|
631 { |
|
632 User::Leave( err ); |
|
633 } |
|
634 break; |
|
635 } |
|
636 case EAlfDecodSUnloadPlugin: |
|
637 { |
|
638 TInt index = iLoadedPlugins.Find(aMessage.Int0()); |
|
639 if (index != KErrNotFound ) |
|
640 { |
|
641 RImplInfoPtrArray pluginArray; |
|
642 REComSession::ListImplementationsL( KAlfGfxPluginInterfaceUId, pluginArray ); |
|
643 TInt i = 0; |
|
644 for ( i = 0; i < pluginArray.Count(); i++ ) |
|
645 { |
|
646 TUid loaded = TUid::Uid(aMessage.Int0()); |
|
647 TUid listed = pluginArray[i]->ImplementationUid(); |
|
648 TPtrC8 listedopaque = pluginArray[i]->OpaqueData(); |
|
649 if ( loaded == listed && (listedopaque.CompareF( KAlfDoNotUnloadPlugin )) != 0 ) |
|
650 { |
|
651 iLoadedPlugins.Remove(index); |
|
652 server->WindowMgr()->DestroyPlugin(TUid::Uid(aMessage.Int0())); |
|
653 } |
|
654 } |
|
655 // Clear the data in plugin array, it is not going to be used any more. |
|
656 for ( i = pluginArray.Count() - 1; i >= 0; i-- ) |
|
657 { |
|
658 // destroy |
|
659 delete pluginArray[i]; |
|
660 pluginArray.Remove( i ); |
|
661 } |
|
662 pluginArray.Close(); |
|
663 } |
|
664 break; |
|
665 } |
|
666 |
|
667 case EAlfDecodSSendSynch: |
|
668 case EAlfDecodSSendAsynch: |
|
669 { |
|
670 server->WindowMgr()->HandlePluginMsgL(aMessage); // will complete synch message immediately |
|
671 return; // so message won't be completed |
|
672 } |
|
673 |
|
674 case EAlfDecodSCancelAsynch: |
|
675 { |
|
676 server->WindowMgr()->CancelPluginMsg(TUid::Uid(aMessage.Int0()), aMessage.Int1()); |
|
677 break; |
|
678 } |
|
679 |
|
680 case EAlfDecodSPrepareFrame: |
|
681 { |
|
682 server->WindowMgr()->PrepareNewFrame(aMessage.Int0()); |
|
683 break; |
|
684 } |
|
685 case EAlfSetScreenRotation: |
|
686 { |
|
687 TInt rotation = aMessage.Int0(); |
|
688 aMessage.Complete(KErrNone); |
|
689 server->Bridge()->AddData( EAlfBridgeSetScreenRotation,rotation); |
|
690 break; |
|
691 } |
|
692 case EAlfGetNativeWindowHandles: |
|
693 { |
|
694 TPckgC<TAlfNativeWindowData> data(server->Bridge()->iAlfWindowData); |
|
695 aMessage.WriteL(0, data); |
|
696 break; |
|
697 } |
|
698 |
|
699 default: |
|
700 { |
|
701 aMessage.Complete(KErrNotSupported); |
|
702 break; |
|
703 } |
|
704 } |
|
705 if (!aMessage.IsNull()) |
|
706 { |
|
707 aMessage.Complete(KErrNone); |
|
708 } |
|
709 // RDebug::Print(_L("CAlfStreamerServerSession::ServiceL exit")); |
|
710 } |
|
711 |
|
712 void CAlfStreamerServerSession::HandleCompositionOpL(TInt aOp, const RMessage2& aMessage, CAlfStreamerServer* aServer) |
|
713 { |
|
714 switch (aOp) |
|
715 { |
|
716 case KAlfCompOpRequestEvent: |
|
717 { |
|
718 iIsListeningCompositionEvents = ETrue; |
|
719 if (!CompletedFromQueue(aMessage)) |
|
720 { |
|
721 iMessagePtr = aMessage; |
|
722 } |
|
723 break; |
|
724 } |
|
725 |
|
726 case KAlfCompOpCancelEventRequest: |
|
727 { |
|
728 if (!iMessagePtr.IsNull()) |
|
729 { |
|
730 iMessagePtr.Complete(KErrCancel); |
|
731 } |
|
732 aMessage.Complete(KErrNone); |
|
733 break; |
|
734 } |
|
735 |
|
736 case KAlfCompositionWServReady: |
|
737 case KAlfCompositionFrameReady: |
|
738 case KAlfCompositionLowOnGraphicsMemory: |
|
739 case KAlfCompositionGoodOnGraphicsMemory: |
|
740 case KAlfCompositionTargetHidden: |
|
741 case KAlfCompositionTargetVisible: |
|
742 case KAlfCompositionTargetCreated: |
|
743 { |
|
744 aServer->HandleCompositionEventL(this, aOp, aMessage); |
|
745 break; |
|
746 } |
|
747 |
|
748 // temp, should go to window server to have more precise control on |
|
749 // operations |
|
750 case KAlfCompOpCreateToken: |
|
751 { |
|
752 TInt token = aServer->CreatePermissionToken( aMessage, reinterpret_cast<TInt>(this), this ); |
|
753 aMessage.Complete(token); |
|
754 break; |
|
755 } |
|
756 case KAlfCompOpBindSourceToToken: |
|
757 { |
|
758 aServer->ValidateToken(this, aMessage); // called method will complete aMessage |
|
759 break; |
|
760 } |
|
761 case KAlfCompOpSetZOrder: |
|
762 iMessagePtr = aMessage; |
|
763 case KAlfCompOpCreateSource: |
|
764 case KAlfCompOpEnableAlpha: |
|
765 case KAlfCompOpSetOpacity: |
|
766 case KAlfCompOpSetRotation: |
|
767 case KAlfCompOpSetExtent: |
|
768 case KAlfCompOpEnableKb: |
|
769 case KAlfComOpSetBackgroundAnim: |
|
770 case KAlfCompOpSessionClosed: |
|
771 { |
|
772 aServer->HandleCompositionRequestL(this, aOp, aMessage); |
|
773 break; |
|
774 } |
|
775 case KAlfCompositionWServScreenNumber: |
|
776 { |
|
777 iScreenNumber = aMessage.Int0(); |
|
778 aMessage.Complete(KErrNone); |
|
779 break; |
|
780 } |
|
781 case KAlfCompositionSourceScreenNumber: |
|
782 { |
|
783 TInt length = aMessage.GetDesLength(0); |
|
784 User::LeaveIfError(length); |
|
785 HBufC8* message = HBufC8::NewLC(length); |
|
786 TPtr8 clientBuf = message->Des(); |
|
787 aMessage.ReadL(0,clientBuf); |
|
788 |
|
789 TInt* ptr = (TInt*) clientBuf.Ptr(); |
|
790 iScreenNumber = ptr[0]; |
|
791 |
|
792 CleanupStack::PopAndDestroy(message); |
|
793 aMessage.Complete(KErrNone); |
|
794 break; |
|
795 } |
|
796 default: |
|
797 // add debug guards or remove |
|
798 RDebug::Print(_L("Oops, unknown composition command: %d "), aOp); |
|
799 User::Invariant(); |
|
800 } |
|
801 } |
|
802 |
|
803 TBool CAlfStreamerServerSession::CompletedFromQueue(const RMessage2& aMessage) |
|
804 { |
|
805 if (iQueue.Count()) |
|
806 { |
|
807 TRAPD(err, aMessage.WriteL(0,*iQueue[0]/*->Des()*/)); |
|
808 TInt cmd = iCmds[0]; |
|
809 if (!err) |
|
810 { |
|
811 delete iQueue[0]; |
|
812 iQueue.Remove(0); |
|
813 iCmds.Remove(0); |
|
814 } |
|
815 else |
|
816 { |
|
817 RDebug::Print(_L("CAlfStreamerServerSession::CompletedFromQueue err: %d"),err); |
|
818 } |
|
819 if( !iMessagePtr.IsNull()) |
|
820 { |
|
821 iMessagePtr.Complete(err?err:cmd); |
|
822 } |
|
823 else |
|
824 { |
|
825 aMessage.Complete(err?err:cmd); |
|
826 } |
|
827 return ETrue; |
|
828 } |
|
829 return EFalse; |
|
830 } |
|
831 |
|
832 void CAlfStreamerServerSession::QueueL(const TPtrC8& aPtr, TInt aCmd) |
|
833 { |
|
834 if (!iIsListeningCompositionEvents) |
|
835 { |
|
836 return; |
|
837 } |
|
838 |
|
839 if (!iMessagePtr.IsNull()) |
|
840 { |
|
841 TRAPD(err, iMessagePtr.WriteL(0,aPtr)); |
|
842 iMessagePtr.Complete(err?err:aCmd); |
|
843 } |
|
844 else |
|
845 { |
|
846 HBufC8* ptr = aPtr.AllocLC(); |
|
847 TInt err = iCmds.Append(aCmd); |
|
848 if (!err) |
|
849 { |
|
850 iQueue.AppendL(ptr); |
|
851 } |
|
852 User::LeaveIfError(err); |
|
853 CleanupStack::Pop(); |
|
854 } |
|
855 } |
|
856 |
|
857 void CAlfStreamerServerSession::SetScreenNumber(TInt aScreennumber) |
|
858 { |
|
859 iScreenNumber = aScreennumber; |
|
860 } |
|
861 |
|
862 TInt CAlfStreamerServerSession::ScreenNumber() const |
|
863 { |
|
864 return iScreenNumber; |
|
865 } |
|
866 |
|
867 TSurfaceId& CAlfStreamerServerSession::ExtentSurfaceId() |
|
868 { |
|
869 return iExtentSurfaceId; |
|
870 } |
|
871 // end of file |