40 // --------------------------------------------------------------------------- |
40 // --------------------------------------------------------------------------- |
41 // |
41 // |
42 CThumbnailServerSession::CThumbnailServerSession(): CSession2() |
42 CThumbnailServerSession::CThumbnailServerSession(): CSession2() |
43 { |
43 { |
44 iBitmapHandle = 0; |
44 iBitmapHandle = 0; |
|
45 iBitmap = NULL; |
|
46 iBuffer = NULL; |
45 } |
47 } |
46 |
48 |
47 |
49 |
48 // --------------------------------------------------------------------------- |
50 // --------------------------------------------------------------------------- |
49 // CThumbnailServerSession::~CThumbnailServerSession() |
51 // CThumbnailServerSession::~CThumbnailServerSession() |
158 // Handles service request messages from clients. |
160 // Handles service request messages from clients. |
159 // ----------------------------------------------------------------------------- |
161 // ----------------------------------------------------------------------------- |
160 // |
162 // |
161 void CThumbnailServerSession::ServiceL( const RMessage2& aMessage ) |
163 void CThumbnailServerSession::ServiceL( const RMessage2& aMessage ) |
162 { |
164 { |
163 __ASSERT_DEBUG( !iMessage.Handle(), ThumbnailPanic( |
165 TN_DEBUG1( "CThumbnailServerSession::ServiceL() - begin" ); |
164 EThumbnailMessageNotCompleted )); |
166 |
|
167 __ASSERT_DEBUG( !iMessage.Handle(), ThumbnailPanic(EThumbnailMessageNotCompleted)); |
165 if ( iMessage.Handle()) |
168 if ( iMessage.Handle()) |
166 { |
169 { |
167 iMessage.Complete( KErrUnknown ); |
170 iMessage.Complete( KErrUnknown ); |
168 iMessage = RMessage2(); |
171 iMessage = RMessage2(); |
169 } |
172 } |
|
173 |
170 iMessage = aMessage; |
174 iMessage = aMessage; |
171 |
175 |
|
176 if ( iMessage.Handle()) |
|
177 { |
|
178 // get client thread |
|
179 TInt err = iMessage.Client( iClientThread ); |
|
180 if (err != KErrNone) |
|
181 { |
|
182 TN_DEBUG1( "CThumbnailServerSession::ServiceL() - client thread not found"); |
|
183 |
|
184 iMessage = RMessage2(); |
|
185 } |
|
186 } |
|
187 else |
|
188 { |
|
189 TN_DEBUG1( "CThumbnailServerSession::ServiceL() - message null"); |
|
190 } |
|
191 |
172 // clean up possible trash |
192 // clean up possible trash |
173 if (iBitmapHandle) |
193 if (iBitmapHandle) |
174 { |
194 { |
175 Server()->DeleteBitmapFromPool( iBitmapHandle ); |
195 Server()->DeleteBitmapFromPool( iBitmapHandle ); |
176 iBitmapHandle = 0; |
196 iBitmapHandle = 0; |
181 iBuffer = NULL; |
201 iBuffer = NULL; |
182 iOriginalSize = TSize(); |
202 iOriginalSize = TSize(); |
183 |
203 |
184 TInt ret = KErrNone; |
204 TInt ret = KErrNone; |
185 |
205 |
186 TRAPD( err, |
206 TRAPD( err, ret = DispatchMessageL( aMessage ) ); |
187 { |
207 |
188 ret = DispatchMessageL( aMessage ); |
208 // if message was not completed, or Leave occurred |
189 } |
|
190 ); |
|
191 if ( iMessage.Handle()) |
209 if ( iMessage.Handle()) |
192 { |
210 { |
193 iMessage.Complete( ConvertSqlErrToE32Err( err != KErrNone ? err : ret )); |
211 if ( ClientThreadAlive() ) |
|
212 { |
|
213 iMessage.Complete( ConvertSqlErrToE32Err( err != KErrNone ? err : ret )); |
|
214 } |
|
215 |
194 iMessage = RMessage2(); |
216 iMessage = RMessage2(); |
195 } |
217 } |
196 else |
218 |
197 { |
219 // close thread handle |
198 return; |
220 iClientThread.Close(); |
199 } |
221 |
|
222 TN_DEBUG1( "CThumbnailServerSession::ServiceL() - end" ); |
200 } |
223 } |
201 |
224 |
202 |
225 |
203 // ----------------------------------------------------------------------------- |
226 // ----------------------------------------------------------------------------- |
204 // CThumbnailServerSession::Server() |
227 // CThumbnailServerSession::Server() |
342 CThumbnailMDSQueryTask* task = new( ELeave )CThumbnailMDSQueryTask( |
365 CThumbnailMDSQueryTask* task = new( ELeave )CThumbnailMDSQueryTask( |
343 Server()->Processor(), params.iPriority + 1, Server()->GetMdESession(), *Server()); |
366 Server()->Processor(), params.iPriority + 1, Server()->GetMdESession(), *Server()); |
344 |
367 |
345 CleanupStack::PushL( task ); |
368 CleanupStack::PushL( task ); |
346 task->QueryPathByIdL(params.iThumbnailId, EFalse); |
369 task->QueryPathByIdL(params.iThumbnailId, EFalse); |
347 task->SetMessageData( TThumbnailServerRequestId( this, params.iRequestId ), iMessage ); |
370 task->SetMessageData( TThumbnailServerRequestId( this, params.iRequestId ), iMessage, iClientThread ); |
348 Server()->QueueTaskL( task ); |
371 Server()->QueueTaskL( task ); |
349 CleanupStack::Pop( task ); // owned by processor now |
372 CleanupStack::Pop( task ); // owned by processor now |
350 |
373 |
351 // query task is now responsible for completing the message |
374 // query task is now responsible for completing the message |
352 iMessage = RMessage2(); |
375 iMessage = RMessage2(); |
439 |
462 |
440 CThumbnailDecodeTask* task = new( ELeave )CThumbnailDecodeTask( Server() |
463 CThumbnailDecodeTask* task = new( ELeave )CThumbnailDecodeTask( Server() |
441 ->Processor(), * Server(), iBuffer, params.iPriority, params.iDisplayMode ); |
464 ->Processor(), * Server(), iBuffer, params.iPriority, params.iDisplayMode ); |
442 |
465 |
443 CleanupStack::PushL( task ); |
466 CleanupStack::PushL( task ); |
444 task->SetMessageData( TThumbnailServerRequestId( this, params.iRequestId ), iMessage ); |
467 task->SetMessageData( TThumbnailServerRequestId( this, params.iRequestId ), iMessage, iClientThread ); |
445 Server()->QueueTaskL( task ); |
468 Server()->QueueTaskL( task ); |
446 CleanupStack::Pop( task ); // owned by processor now |
469 CleanupStack::Pop( task ); // owned by processor now |
447 |
470 |
448 // Decode task is now responsible for completing the message |
471 // Decode task is now responsible for completing the message |
449 iMessage = RMessage2(); |
472 iMessage = RMessage2(); |
516 |
539 |
517 CThumbnailDecodeTask* task = new( ELeave )CThumbnailDecodeTask( Server() |
540 CThumbnailDecodeTask* task = new( ELeave )CThumbnailDecodeTask( Server() |
518 ->Processor(), * Server(), iBuffer, params.iPriority, params.iDisplayMode ); |
541 ->Processor(), * Server(), iBuffer, params.iPriority, params.iDisplayMode ); |
519 |
542 |
520 CleanupStack::PushL( task ); |
543 CleanupStack::PushL( task ); |
521 task->SetMessageData( TThumbnailServerRequestId( this, params.iRequestId ), iMessage ); |
544 task->SetMessageData( TThumbnailServerRequestId( this, params.iRequestId ), iMessage, iClientThread ); |
522 Server()->QueueTaskL( task ); |
545 Server()->QueueTaskL( task ); |
523 CleanupStack::Pop( task ); // owned by processor now |
546 CleanupStack::Pop( task ); // owned by processor now |
524 |
547 |
525 // Decode task is now responsible for completing the message |
548 // Decode task is now responsible for completing the message |
526 iMessage = RMessage2(); |
549 iMessage = RMessage2(); |
624 |
647 |
625 // get bitmap |
648 // get bitmap |
626 CFbsBitmap* bitmap = new( ELeave )CFbsBitmap(); |
649 CFbsBitmap* bitmap = new( ELeave )CFbsBitmap(); |
627 CleanupStack::PushL( bitmap ); |
650 CleanupStack::PushL( bitmap ); |
628 User::LeaveIfError( bitmap->Duplicate( bitmapHandle ) ); |
651 User::LeaveIfError( bitmap->Duplicate( bitmapHandle ) ); |
|
652 |
|
653 // use pool to prevent bitmap leak |
|
654 // this bitmap is shared to several scale tasks, one of which can Leave |
629 Server()->AddBitmapToPoolL( reqId.iSession, bitmap, reqId ); |
655 Server()->AddBitmapToPoolL( reqId.iSession, bitmap, reqId ); |
|
656 |
630 CleanupStack::Pop( bitmap ); |
657 CleanupStack::Pop( bitmap ); |
631 iBitmapHandle = bitmap->Handle(); |
658 iBitmapHandle = bitmap->Handle(); |
632 |
659 |
633 RArray < TThumbnailPersistentSize >* missingSizes = NULL; |
660 RArray < TThumbnailPersistentSize >* missingSizes = NULL; |
634 |
661 |
685 |
712 |
686 // completion to first task, because task processor works like stack |
713 // completion to first task, because task processor works like stack |
687 if( i == 0 ) |
714 if( i == 0 ) |
688 { |
715 { |
689 // scaleTask is now responsible for completing the RMessage |
716 // scaleTask is now responsible for completing the RMessage |
690 scaleTask->SetMessageData( reqId, iMessage ); |
717 scaleTask->SetMessageData( reqId, iMessage, iClientThread ); |
691 iMessage = RMessage2(); |
718 iMessage = RMessage2(); |
692 } |
719 } |
693 } |
720 } |
694 } |
721 } |
695 else |
722 else |
788 } |
816 } |
789 |
817 |
790 CleanupStack::Pop( aFile ); |
818 CleanupStack::Pop( aFile ); |
791 |
819 |
792 CleanupStack::PushL( task ); |
820 CleanupStack::PushL( task ); |
793 task->SetMessageData( TThumbnailServerRequestId( this, params.iRequestId ), |
821 task->SetMessageData( TThumbnailServerRequestId( this, params.iRequestId ),iMessage, iClientThread ); |
794 iMessage ); |
|
795 Server()->QueueTaskL( task ); |
822 Server()->QueueTaskL( task ); |
796 CleanupStack::Pop( task ); // owned by processor now |
823 CleanupStack::Pop( task ); // owned by processor now |
797 |
824 |
798 if ( missingSizes ) |
825 if ( missingSizes ) |
799 { |
826 { |
896 { |
923 { |
897 task->ScaledBitmapToPool( EFalse ); |
924 task->ScaledBitmapToPool( EFalse ); |
898 } |
925 } |
899 |
926 |
900 CleanupStack::PushL( task ); |
927 CleanupStack::PushL( task ); |
901 task->SetMessageData( TThumbnailServerRequestId( this, params.iRequestId ), |
928 task->SetMessageData( TThumbnailServerRequestId( this, params.iRequestId ),iMessage, iClientThread ); |
902 iMessage ); |
|
903 Server()->QueueTaskL( task ); |
929 Server()->QueueTaskL( task ); |
904 CleanupStack::Pop( task ); // owned by processor now |
930 CleanupStack::Pop( task ); // owned by processor now |
905 |
931 |
906 if ( missingSizes ) |
932 if ( missingSizes ) |
907 { |
933 { |
918 // |
944 // |
919 void CThumbnailServerSession::FetchThumbnailL() |
945 void CThumbnailServerSession::FetchThumbnailL() |
920 { |
946 { |
921 TN_DEBUG1("CThumbnailServerSession::FetchThumbnailL()"); |
947 TN_DEBUG1("CThumbnailServerSession::FetchThumbnailL()"); |
922 __ASSERT_DEBUG( !iBitmap, ThumbnailPanic( EThumbnailBitmapNotReleased )); |
948 __ASSERT_DEBUG( !iBitmap, ThumbnailPanic( EThumbnailBitmapNotReleased )); |
|
949 __ASSERT_DEBUG( !iBuffer, ThumbnailPanic( EThumbnailBitmapNotReleased )); |
923 |
950 |
924 delete iBitmap; |
951 delete iBitmap; |
925 iBitmap = NULL; |
952 iBitmap = NULL; |
|
953 delete iBuffer; |
|
954 iBuffer = NULL; |
926 |
955 |
927 TThumbnailRequestParams& params = iRequestParams(); |
956 TThumbnailRequestParams& params = iRequestParams(); |
928 |
957 |
929 if ( params.iThumbnailSize != EUnknownThumbnailSize && |
958 if ( params.iThumbnailSize != EUnknownThumbnailSize && |
930 params.iThumbnailSize != ECustomThumbnailSize ) |
959 params.iThumbnailSize != ECustomThumbnailSize ) |
969 params.iFlags& CThumbnailManager::ECropToAspectRatio, |
998 params.iFlags& CThumbnailManager::ECropToAspectRatio, |
970 params.iThumbnailSize, params.iModified, |
999 params.iThumbnailSize, params.iModified, |
971 EFalse, EFalse); |
1000 EFalse, EFalse); |
972 } |
1001 } |
973 |
1002 |
974 if ( ClientThreadAlive(iMessage) ) |
1003 if ( ClientThreadAlive() ) |
975 { |
1004 { |
976 // No need to scale, return iBitmap directly |
1005 TN_DEBUG2("CThumbnailServerSession::ProcessBitmapL(), iBitmap handle= 0x%08x", iBitmap->Handle()); |
977 |
1006 |
978 TThumbnailServerRequestId &reqId = (TThumbnailServerRequestId&)params.iRequestId; |
1007 params.iBitmapHandle = iBitmap->Handle(); |
979 // No need to scale, return iBitmap directly |
1008 const TSize bitmapSize = iBitmap->SizeInPixels(); |
980 Server()->AddBitmapToPoolL( this, iBitmap, reqId ); |
|
981 |
|
982 CFbsBitmap* bitmap = iBitmap; |
|
983 |
|
984 TN_DEBUG2("CThumbnailServerSession::ProcessBitmapL(), iBitmap handle= 0x%08x", bitmap->Handle()); |
|
985 |
|
986 iBitmap = NULL; // owned by server now |
|
987 |
|
988 params.iBitmapHandle = bitmap->Handle(); |
|
989 const TSize bitmapSize = bitmap->SizeInPixels(); |
|
990 |
1009 |
991 if ( params.iQualityPreference == CThumbnailManager |
1010 if ( params.iQualityPreference == CThumbnailManager |
992 ::EOptimizeForQualityWithPreview && bitmapSize.iWidth < |
1011 ::EOptimizeForQualityWithPreview && bitmapSize.iWidth < |
993 params.iSize.iWidth && bitmapSize.iHeight < params.iSize.iHeight && |
1012 params.iSize.iWidth && bitmapSize.iHeight < params.iSize.iHeight && |
994 bitmapSize.iWidth < iOriginalSize.iWidth && bitmapSize.iHeight < |
1013 bitmapSize.iWidth < iOriginalSize.iWidth && bitmapSize.iHeight < |
998 params.iControlFlags = EThumbnailPreviewThumbnail; |
1017 params.iControlFlags = EThumbnailPreviewThumbnail; |
999 } |
1018 } |
1000 |
1019 |
1001 iMessage.WriteL( 0, iRequestParams ); |
1020 iMessage.WriteL( 0, iRequestParams ); |
1002 |
1021 |
|
1022 TN_DEBUG1("CThumbnailServerSession()::ProcessBitmapL() bitmap to pool"); |
|
1023 |
|
1024 TThumbnailServerRequestId &reqId = (TThumbnailServerRequestId&)params.iRequestId; |
|
1025 Server()->AddBitmapToPoolL( this, iBitmap, reqId ); |
|
1026 |
1003 iMessage.Complete( KErrNone ); |
1027 iMessage.Complete( KErrNone ); |
1004 iMessage = RMessage2(); |
1028 iMessage = RMessage2(); |
|
1029 |
|
1030 iBitmap = NULL; // owned by server now |
1005 } |
1031 } |
1006 else |
1032 else |
1007 { |
1033 { |
1008 delete iBitmap; |
1034 delete iBitmap; |
1009 iBitmap = NULL; |
1035 iBitmap = NULL; |
1027 // Cancel pending request. |
1053 // Cancel pending request. |
1028 // ----------------------------------------------------------------------------- |
1054 // ----------------------------------------------------------------------------- |
1029 // |
1055 // |
1030 TInt CThumbnailServerSession::CancelRequest( const RMessage2& aMessage ) |
1056 TInt CThumbnailServerSession::CancelRequest( const RMessage2& aMessage ) |
1031 { |
1057 { |
|
1058 TN_DEBUG1( "CThumbnailServerSession::CancelRequest()" ); |
|
1059 |
1032 const TThumbnailServerRequestId requestId( this, aMessage.Int0()); |
1060 const TThumbnailServerRequestId requestId( this, aMessage.Int0()); |
1033 const TInt err = Server()->DequeTask( requestId ); |
1061 const TInt err = Server()->DequeTask( requestId ); |
1034 TN_DEBUG4( |
1062 TN_DEBUG4( |
1035 "CThumbnailServerSession::CancelRequest(0x%08x/%d) - returning %d", |
1063 "CThumbnailServerSession::CancelRequest(0x%08x/%d) - returning %d", |
1036 requestId.iSession, requestId.iRequestId, err ); |
1064 requestId.iSession, requestId.iRequestId, err ); |
1042 // Change priority of pending request. |
1070 // Change priority of pending request. |
1043 // ----------------------------------------------------------------------------- |
1071 // ----------------------------------------------------------------------------- |
1044 // |
1072 // |
1045 TInt CThumbnailServerSession::ChangePriority( const RMessage2& aMessage ) |
1073 TInt CThumbnailServerSession::ChangePriority( const RMessage2& aMessage ) |
1046 { |
1074 { |
|
1075 TN_DEBUG1( "CThumbnailServerSession::ChangePriority()" ); |
|
1076 |
1047 const TThumbnailServerRequestId requestId( this, aMessage.Int0()); |
1077 const TThumbnailServerRequestId requestId( this, aMessage.Int0()); |
1048 const TInt newPriority = aMessage.Int1(); |
1078 const TInt newPriority = aMessage.Int1(); |
1049 |
1079 |
1050 const TInt err = Server()->ChangeTaskPriority( requestId, newPriority ); |
1080 const TInt err = Server()->ChangeTaskPriority( requestId, newPriority ); |
1051 TN_DEBUG5( |
1081 TN_DEBUG5( |
1127 // allocated by the client. |
1157 // allocated by the client. |
1128 // ----------------------------------------------------------------------------- |
1158 // ----------------------------------------------------------------------------- |
1129 // |
1159 // |
1130 void CThumbnailServerSession::GetMimeTypeListL( const RMessage2& aMessage ) |
1160 void CThumbnailServerSession::GetMimeTypeListL( const RMessage2& aMessage ) |
1131 { |
1161 { |
|
1162 TN_DEBUG1( "CThumbnailServerSession::GetMimeTypeListL()" ); |
|
1163 |
1132 TInt len = aMessage.GetDesMaxLengthL( 0 ); |
1164 TInt len = aMessage.GetDesMaxLengthL( 0 ); |
1133 HBufC* buf = HBufC::NewLC( len ); |
1165 HBufC* buf = HBufC::NewLC( len ); |
1134 TPtr ptr = buf->Des(); |
1166 TPtr ptr = buf->Des(); |
1135 Server()->GetMimeTypeList( ptr ); |
1167 Server()->GetMimeTypeList( ptr ); |
1136 aMessage.WriteL( 0, * buf ); |
1168 aMessage.WriteL( 0, * buf ); |
1330 // --------------------------------------------------------------------------- |
1362 // --------------------------------------------------------------------------- |
1331 // CThumbnailServerSession::ClientThreadAlive() |
1363 // CThumbnailServerSession::ClientThreadAlive() |
1332 // Checks if client thread is still alive and RMessage2 handle valid. |
1364 // Checks if client thread is still alive and RMessage2 handle valid. |
1333 // --------------------------------------------------------------------------- |
1365 // --------------------------------------------------------------------------- |
1334 // |
1366 // |
1335 TBool CThumbnailServerSession::ClientThreadAlive(RMessage2& aMessage) |
1367 TBool CThumbnailServerSession::ClientThreadAlive() |
1336 { |
1368 { |
1337 if ( aMessage.Handle()) |
1369 TN_DEBUG1( "CThumbnailServerSession::ClientThreadAlive()"); |
1338 { |
1370 |
1339 RThread clientThread; |
1371 if ( iMessage.Handle()) |
1340 |
1372 { |
1341 // get client thread |
1373 // check if client thread alive |
1342 TInt err = aMessage.Client( clientThread ); |
1374 TExitType exitType = iClientThread.ExitType(); |
1343 if (err != KErrNone) |
1375 |
1344 { |
1376 if( exitType != EExitPending ) |
1345 TN_DEBUG1( "CThumbnailServerSession::ClientThreadAlive() - client thread not found"); |
1377 { |
1346 |
1378 TN_DEBUG1( "CThumbnailServerSession::ClientThreadAlive() - client thread died"); |
1347 aMessage = RMessage2(); |
1379 |
|
1380 iMessage = RMessage2(); |
1348 |
1381 |
1349 return EFalse; |
1382 return EFalse; |
1350 } |
1383 } |
1351 |
|
1352 // check if client thread alive |
|
1353 TExitType exitType = clientThread.ExitType(); |
|
1354 |
|
1355 clientThread.Close(); |
|
1356 |
|
1357 if( exitType != EExitPending ) |
|
1358 { |
|
1359 TN_DEBUG1( "CThumbnailServerSession::ClientThreadAlive() - client thread died"); |
|
1360 |
|
1361 aMessage = RMessage2(); |
|
1362 |
|
1363 return EFalse; |
|
1364 } |
|
1365 else |
1384 else |
1366 { |
1385 { |
1367 // all OK |
1386 // all OK |
1368 return ETrue; |
1387 return ETrue; |
1369 } |
1388 } |
1370 } |
1389 } |
1371 else |
1390 else |
1372 { |
1391 { |
|
1392 TN_DEBUG1( "CThumbnailServerSession::ClientThreadAlive() - message null"); |
1373 return EFalse; |
1393 return EFalse; |
1374 } |
1394 } |
1375 } |
1395 } |
1376 |
1396 |
1377 // End of file |
1397 // End of file |