imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailserver.cpp
branchRCL_3
changeset 5 82749d516180
parent 1 235a7fc86938
child 7 2eb74cf6572e
equal deleted inserted replaced
1:235a7fc86938 5:82749d516180
    33 #include "thumbnailstore.h"
    33 #include "thumbnailstore.h"
    34 #include "thumbnaildiskunmountobserver.h"
    34 #include "thumbnaildiskunmountobserver.h"
    35 #include "thumbnailpanic.h"
    35 #include "thumbnailpanic.h"
    36 #include "thumbnailcenrep.h"
    36 #include "thumbnailcenrep.h"
    37 #include "thumbnailmemorycardobserver.h"
    37 #include "thumbnailmemorycardobserver.h"
    38 #include "tnmgetimei.h"
    38 #include "tmgetimei.h"
    39 #include "thumbnailformatobserver.h"
       
    40 
    39 
    41 
    40 
    42 _LIT8( KThumbnailMimeWildCard, "*" );
    41 _LIT8( KThumbnailMimeWildCard, "*" );
    43 _LIT8( KThumbnailMimeImage, "image" );
    42 _LIT8( KThumbnailMimeImage, "image" );
    44 _LIT8( KThumbnailMimeVideo, "video" );
    43 _LIT8( KThumbnailMimeVideo, "video" );
   232     iProcessor = CThumbnailTaskProcessor::NewL();
   231     iProcessor = CThumbnailTaskProcessor::NewL();
   233     REComSession::FinalClose();
   232     REComSession::FinalClose();
   234     REComSession::ListImplementationsL( TUid::Uid( THUMBNAIL_PROVIDER_IF_UID ),
   233     REComSession::ListImplementationsL( TUid::Uid( THUMBNAIL_PROVIDER_IF_UID ),
   235         iPluginInfoArray );
   234         iPluginInfoArray );
   236     
   235     
   237     CTnmgetimei * imeigetter = CTnmgetimei::NewLC();
   236     CTMGetImei * imeiGetter = CTMGetImei::NewLC();
   238    
   237    
   239     iImei = imeigetter->GetIMEI();
   238     iImei = imeiGetter->GetIMEI();
   240     CleanupStack::PopAndDestroy(imeigetter);
   239     CleanupStack::PopAndDestroy(imeiGetter);
   241     
   240     
   242     iFs.CreatePrivatePath(EDriveC);
   241     iFs.CreatePrivatePath(EDriveC);
   243     iFs.SetSessionToPrivate(EDriveC);
   242     iFs.SetSessionToPrivate(EDriveC);
   244     
   243     
   245     iCenrep = CThumbnailCenRep::NewL();
   244     iCenrep = CThumbnailCenRep::NewL();
   246                
   245                
   247     iPersistentSizes = iCenrep->GetPersistentSizes();
   246     iPersistentSizes = iCenrep->GetPersistentSizes();
   248             
   247             
   249     iMMCObserver = CThumbnailMemoryCardObserver::NewL( this, iFs );
   248     iMMCObserver = CThumbnailMemoryCardObserver::NewL( this, iFs );
   250     
   249     
   251     iFormatObserver = CThumbnailFormatObserver::NewL( this );
   250     iFormatObserver = CTMFormatObserver::NewL( *this );
   252     
   251     
   253     iFormatting = EFalse;
   252     iFormatting = EFalse;
   254     
   253     
   255     OpenStoresL();
   254     OpenStoresL();
   256     
   255     
   396     TN_DEBUG2( "CThumbnailServer::DropSession() iSessionCount was %d",
   395     TN_DEBUG2( "CThumbnailServer::DropSession() iSessionCount was %d",
   397         iSessionCount );
   396         iSessionCount );
   398     iSessionCount--;
   397     iSessionCount--;
   399     
   398     
   400     iProcessor->RemoveTasks(aSession);
   399     iProcessor->RemoveTasks(aSession);
       
   400     
       
   401     TN_DEBUG2( "CThumbnailServer::DropSession() aSession = 0x%08x", aSession );        
       
   402     
       
   403     // clean-up bitmap pool
       
   404     
       
   405     THashMapIter < TInt, TThumbnailBitmapRef > bpiter( iBitmapPool );
       
   406 
       
   407     // const pointer to a non-const object
       
   408     const TThumbnailBitmapRef* ref = bpiter.NextValue();
       
   409 
       
   410     while ( ref )
       
   411         {
       
   412         
       
   413         TN_DEBUG2( "CThumbnailServer::DropSession() - ref->iSession = 0x%08x", ref->iSession );
       
   414         
       
   415         if ( ref->iSession == aSession )
       
   416             {            
       
   417             delete ref->iBitmap;            
       
   418             bpiter.RemoveCurrent();
       
   419                         
       
   420             TN_DEBUG2( "CThumbnailServer::DropSession() - deleted bitmap, left=%d", 
       
   421                                 iBitmapPool.Count());
       
   422             }
       
   423         ref = bpiter.NextValue();
       
   424         
       
   425         }
       
   426 
   401     if ( iSessionCount <= 0 )
   427     if ( iSessionCount <= 0 )
   402         {
   428         {
   403         // rename thread
   429         // rename thread
   404         User::RenameThread( KThumbnailServerShutdown );
   430         User::RenameThread( KThumbnailServerShutdown );
   405         
   431         
   430 // CThumbnailServer::AddBitmapToPoolL()
   456 // CThumbnailServer::AddBitmapToPoolL()
   431 // Add bitmap to bitmap pool.
   457 // Add bitmap to bitmap pool.
   432 // -----------------------------------------------------------------------------
   458 // -----------------------------------------------------------------------------
   433 //
   459 //
   434 void CThumbnailServer::AddBitmapToPoolL( CThumbnailServerSession* aSession,
   460 void CThumbnailServer::AddBitmapToPoolL( CThumbnailServerSession* aSession,
   435     CFbsBitmap* aBitmap )
   461     CFbsBitmap* aBitmap, TThumbnailServerRequestId aRequestId )
   436     {
   462     {
   437     if( !aBitmap )
   463     if( !aBitmap )
   438         {
   464         {
   439         TN_DEBUG1( "CThumbnailServer::AddBitmapToPoolL() - KErrArgument");
   465         TN_DEBUG1( "CThumbnailServer::AddBitmapToPoolL() - KErrArgument");
   440         User::Leave( KErrArgument );
   466         User::Leave( KErrArgument );
   442     TN_DEBUG4( 
   468     TN_DEBUG4( 
   443         "CThumbnailServer::AddBitmapToPoolL(aSession=0x%08x, aBitmap=0x%08x), handle=%d", aSession, aBitmap, aBitmap->Handle());
   469         "CThumbnailServer::AddBitmapToPoolL(aSession=0x%08x, aBitmap=0x%08x), handle=%d", aSession, aBitmap, aBitmap->Handle());
   444 
   470 
   445     TThumbnailBitmapRef* ptr = iBitmapPool.Find( aBitmap->Handle());
   471     TThumbnailBitmapRef* ptr = iBitmapPool.Find( aBitmap->Handle());
   446 
   472 
       
   473     TN_DEBUG2( "CThumbnailServer::AddBitmapToPoolL() - id = %d", aRequestId.iRequestId );
       
   474     
   447     if ( ptr )
   475     if ( ptr )
   448         {
   476         {
   449         ptr->iRefCount++;
   477         ptr->iRefCount++;
   450         }
   478         }
   451     else
   479     else
   452         {
   480         {
   453         TThumbnailBitmapRef ref;
   481         TThumbnailBitmapRef ref;
   454         ref.iBitmap = aBitmap;
   482         ref.iBitmap = aBitmap;
   455         ref.iSession = aSession;
   483         ref.iSession = aSession;
   456         ref.iRefCount = 1; // magic: first reference
   484         ref.iRefCount = 1; // magic: first reference        
       
   485         ref.iRequestId = aRequestId.iRequestId;               
       
   486         
   457         iBitmapPool.InsertL( aBitmap->Handle(), ref );
   487         iBitmapPool.InsertL( aBitmap->Handle(), ref );
   458         }
   488         }
   459     
   489     
   460 #ifdef _DEBUG
   490 #ifdef _DEBUG
   461     TN_DEBUG2( "CThumbnailServer::BITMAP-POOL-COUNTER----------, Bitmaps = %d", iBitmapPool.Count() );
   491     TN_DEBUG2( "CThumbnailServer::BITMAP-POOL-COUNTER----------, Bitmaps = %d", iBitmapPool.Count() );
   526             TN_DEBUG3( 
   556             TN_DEBUG3( 
   527                 "CThumbnailServer::DeleteBitmapFromPool(%d) -- deleting 0x%08x)", aHandle, ptr );
   557                 "CThumbnailServer::DeleteBitmapFromPool(%d) -- deleting 0x%08x)", aHandle, ptr );
   528             delete ptr->iBitmap;
   558             delete ptr->iBitmap;
   529             ptr->iBitmap = NULL;
   559             ptr->iBitmap = NULL;
   530             iBitmapPool.Remove( aHandle );
   560             iBitmapPool.Remove( aHandle );
       
   561             TN_DEBUG2( "CThumbnailServer::DeleteBitmapFromPool -- items left %d", iBitmapPool.Count() );
   531             }
   562             }
   532         else
   563         else
   533             {
   564             {
   534             TN_DEBUG3( 
   565             TN_DEBUG3( 
   535                 "CThumbnailServer::DeleteBitmapFromPool(%d) -- refcount now %d",
   566                 "CThumbnailServer::DeleteBitmapFromPool(%d) -- refcount now %d",
   536                 aHandle, ptr->iRefCount );
   567                 aHandle, ptr->iRefCount );
   537             }
   568             }
   538         }
   569         }
   539     else
   570     else
   540         {
   571         {
       
   572         __ASSERT_DEBUG(( EFalse ), ThumbnailPanic( EThumbnailBitmapNotReleased ));
   541         TN_DEBUG2( "CThumbnailServer::DeleteBitmapFromPool(%d) -- not found!",
   573         TN_DEBUG2( "CThumbnailServer::DeleteBitmapFromPool(%d) -- not found!",
   542             aHandle );
   574             aHandle );
   543         }
   575         }
   544     }
   576     }
   545 
   577 
   739 // Removes thumbnailtask from processor queue.
   771 // Removes thumbnailtask from processor queue.
   740 // -----------------------------------------------------------------------------
   772 // -----------------------------------------------------------------------------
   741 //
   773 //
   742 TInt CThumbnailServer::DequeTask( const TThumbnailServerRequestId& aRequestId )
   774 TInt CThumbnailServer::DequeTask( const TThumbnailServerRequestId& aRequestId )
   743     {
   775     {
   744     return iProcessor->RemoveTask( aRequestId );
   776     
       
   777     TInt error = iProcessor->RemoveTask( aRequestId );
       
   778         
       
   779     // clean-up bitmap pool        
       
   780         
       
   781     THashMapIter < TInt, TThumbnailBitmapRef > bpiter( iBitmapPool );
       
   782 
       
   783     // const pointer to a non-const object
       
   784     const TThumbnailBitmapRef* ref = bpiter.NextValue();
       
   785 
       
   786     while ( ref )
       
   787         {
       
   788         
       
   789         TN_DEBUG2( "CThumbnailServer::DequeTask() - ref->iRequestId = %d", ref->iRequestId );
       
   790 
       
   791         if ( ref->iSession == aRequestId.iSession && 
       
   792              ref->iRequestId == aRequestId.iRequestId )
       
   793             {            
       
   794             delete ref->iBitmap;            
       
   795             bpiter.RemoveCurrent();                        
       
   796                         
       
   797             TN_DEBUG2( "CThumbnailServer::DequeTask() - deleted bitmap, left=%d", 
       
   798                                 iBitmapPool.Count());
       
   799             }
       
   800         ref = bpiter.NextValue();
       
   801         
       
   802         }
       
   803 
       
   804     return error;
   745     }
   805     }
   746 
   806 
   747 
   807 
   748 // -----------------------------------------------------------------------------
   808 // -----------------------------------------------------------------------------
   749 // CThumbnailServer::ChangeTaskPriority()
   809 // CThumbnailServer::ChangeTaskPriority()
   873         pStore = storeIter.NextValue())
   933         pStore = storeIter.NextValue())
   874         {
   934         {
   875         TN_DEBUG2( "CThumbnailServer::FetchThumbnailL() store iteration - round == %d ", roundCount++);
   935         TN_DEBUG2( "CThumbnailServer::FetchThumbnailL() store iteration - round == %d ", roundCount++);
   876         CThumbnailStore* const store = (CThumbnailStore*)(*pStore);
   936         CThumbnailStore* const store = (CThumbnailStore*)(*pStore);
   877         
   937         
   878         TRAP_IGNORE( store->FetchThumbnailL( aThumbnailId, aThumbnail, aData, aThumbnailSize, aOriginalSize ));
   938         TRAPD(err, store->FetchThumbnailL( aThumbnailId, aThumbnail, aData, aThumbnailSize, aOriginalSize ));
   879         
   939         
   880         if ( aThumbnail || aData)
   940         if( err == KErrCompletion )
       
   941             {
       
   942             // If thumbnail of requested size is blacklisted, fetching is left with KErrCompletion
       
   943             TN_DEBUG1( 
       
   944                 "CThumbnailServer::FetchThumbnailL() - thumbnail blacklisted" );
       
   945             User::Leave( err );
       
   946             }
       
   947         else if ( aThumbnail || aData)
   881             { // thumbnail found from DB
   948             { // thumbnail found from DB
   882             TN_DEBUG1( "CThumbnailServer::FetchThumbnailL() found" );
   949             TN_DEBUG1( "CThumbnailServer::FetchThumbnailL() found" );
   883             break;
   950             break;
   884             }
   951             }
   885 /*
   952 /*
  1527 
  1594 
  1528 // -----------------------------------------------------------------------------
  1595 // -----------------------------------------------------------------------------
  1529 // Closes stores for removable drives
  1596 // Closes stores for removable drives
  1530 // -----------------------------------------------------------------------------
  1597 // -----------------------------------------------------------------------------
  1531 //
  1598 //
  1532 
       
  1533 void CThumbnailServer::CloseRemovableDrivesL()
  1599 void CThumbnailServer::CloseRemovableDrivesL()
  1534     {
  1600     {
  1535     TDriveList driveList;
  1601     TDriveList driveList;
  1536     TInt drive; 
  1602     TInt drive; 
  1537     TDriveInfo driveInfo;
  1603     TDriveInfo driveInfo;
  1562 
  1628 
  1563 // -----------------------------------------------------------------------------
  1629 // -----------------------------------------------------------------------------
  1564 // Open Stores for removable drives
  1630 // Open Stores for removable drives
  1565 // -----------------------------------------------------------------------------
  1631 // -----------------------------------------------------------------------------
  1566 //
  1632 //
  1567 
       
  1568 void CThumbnailServer::OpenRemovableDrivesL()
  1633 void CThumbnailServer::OpenRemovableDrivesL()
  1569     {
  1634     {
  1570     TDriveList driveList;
  1635     TDriveList driveList;
  1571     TInt drive; 
  1636     TInt drive; 
  1572     TDriveInfo driveInfo;
  1637     TDriveInfo driveInfo;
  1596 
  1661 
  1597 // -----------------------------------------------------------------------------
  1662 // -----------------------------------------------------------------------------
  1598 // Is formatting ongoing
  1663 // Is formatting ongoing
  1599 // -----------------------------------------------------------------------------
  1664 // -----------------------------------------------------------------------------
  1600 //
  1665 //
  1601 
       
  1602 TBool CThumbnailServer::IsFormatting()
  1666 TBool CThumbnailServer::IsFormatting()
  1603     {
  1667     {
  1604     return iFormatting;
  1668     return iFormatting;
  1605     }
  1669     }
  1606 
  1670 
       
  1671 // ---------------------------------------------------------------------------
       
  1672 // CThumbnailServer::FormatNotification
       
  1673 // Handles a format operation
       
  1674 // ---------------------------------------------------------------------------
       
  1675 //
       
  1676 void CThumbnailServer::FormatNotification( TBool aFormat )
       
  1677     {
       
  1678     TN_DEBUG2( "CThumbnailServer::FormatNotification(%d)", aFormat );
       
  1679     
       
  1680     if(aFormat)
       
  1681         {
       
  1682         TRAP_IGNORE( CloseRemovableDrivesL() );
       
  1683         }
       
  1684     else 
       
  1685         {
       
  1686         TRAP_IGNORE( OpenRemovableDrivesL() );
       
  1687         }
       
  1688     }
       
  1689