imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailserver.cpp
changeset 0 2014ca87e772
child 1 235a7fc86938
equal deleted inserted replaced
-1:000000000000 0:2014ca87e772
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  Thumbnail server
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32svr.h>
       
    20 #include <mihlscaler.h>
       
    21 #include <driveinfo.h>
       
    22 #include <caf/data.h>
       
    23 #include <oma2agent.h>
       
    24 #include <bautils.h>  
       
    25 #include <mdesession.h>
       
    26 
       
    27 #include "thumbnailserver.h"
       
    28 #include "thumbnailtaskprocessor.h"
       
    29 #include "thumbnailserversession.h"
       
    30 #include "thumbnailmanagerconstants.h"
       
    31 #include "thumbnailmanageruids.hrh"
       
    32 #include "thumbnaillog.h"
       
    33 #include "thumbnailstore.h"
       
    34 #include "thumbnaildiskunmountobserver.h"
       
    35 #include "thumbnailpanic.h"
       
    36 #include "thumbnailcenrep.h"
       
    37 #include "thumbnailmemorycardobserver.h"
       
    38 #include "tnmgetimei.h"
       
    39 #include "thumbnailformatobserver.h"
       
    40 
       
    41 
       
    42 _LIT8( KThumbnailMimeWildCard, "*" );
       
    43 _LIT8( KThumbnailMimeImage, "image" );
       
    44 _LIT8( KThumbnailMimeVideo, "video" );
       
    45 _LIT8( KThumbnailMimeAudio, "audio" );
       
    46 
       
    47 const TChar KThumbnailMimeSeparatorChar = '/';
       
    48 const TChar KThumbnailMimeWildCardChar = '*';
       
    49 const TChar KThumbnailMimeTypeSeparatorChar = ' ';
       
    50 
       
    51 // ----------------------------------------------------------------------------------------
       
    52 // Server's policy here
       
    53 // ----------------------------------------------------------------------------------------
       
    54 
       
    55 // ----------------------------------------------------------------------------------------
       
    56 // Total number of ranges
       
    57 // ----------------------------------------------------------------------------------------
       
    58 const TUint KThumbnailServerRangeCount = 17;
       
    59  
       
    60 // ----------------------------------------------------------------------------------------
       
    61 // Definition of the ranges
       
    62 // ----------------------------------------------------------------------------------------
       
    63 const TInt KThumbnailServerRanges[KThumbnailServerRangeCount] = 
       
    64 {
       
    65     ERequestThumbByPathAsync,      
       
    66     ERequestThumbByFileHandleAsync,          
       
    67     EReleaseBitmap,
       
    68     ECancelRequest,
       
    69     EChangePriority,
       
    70     ECreateThumbnails,
       
    71     EDeleteThumbnails,
       
    72     EGetMimeTypeBufferSize,
       
    73     EGetMimeTypeList,
       
    74     ERequestThumbByIdAsync,
       
    75     ERequestThumbByBufferAsync,
       
    76     ERequestSetThumbnailByBuffer,
       
    77     EDeleteThumbnailsById,
       
    78     EReserved1,
       
    79     EUpdateThumbnails,
       
    80     ERequestSetThumbnailByBitmap,
       
    81     EThumbnailServerRequestCount,
       
    82 };
       
    83 
       
    84 // ----------------------------------------------------------------------------------------
       
    85 // Policy to implement for each of the above ranges 
       
    86 // ----------------------------------------------------------------------------------------      
       
    87 const TUint8 KThumbnailServerElementsIndex[KThumbnailServerRangeCount] = 
       
    88     {
       
    89     CPolicyServer::ECustomCheck,    // ERequestThumbByPathAsync
       
    90     CPolicyServer::ECustomCheck,    // ERequestThumbByFileHandleAsync
       
    91     CPolicyServer::ECustomCheck,    // EReleaseBitmap
       
    92     CPolicyServer::ECustomCheck,    // ECancelRequest
       
    93     CPolicyServer::ECustomCheck,    // EChangePriority
       
    94     CPolicyServer::ECustomCheck,    // ECreateThumbnails
       
    95     CPolicyServer::ECustomCheck,    // EDeleteThumbnails
       
    96     CPolicyServer::ECustomCheck,    // EGetMimeTypeBufferSize
       
    97     CPolicyServer::ECustomCheck,    // EGetMimeTypeList
       
    98     CPolicyServer::ECustomCheck,    // ERequestThumbByIdAsync
       
    99     CPolicyServer::ECustomCheck,    // ERequestThumbByBufferAsync
       
   100     CPolicyServer::ECustomCheck,    // ERequestSetThumbnailByBuffer
       
   101     CPolicyServer::ECustomCheck,    // EDeleteThumbnailsById
       
   102     CPolicyServer::ECustomCheck,    
       
   103     CPolicyServer::ECustomCheck,    // EUpdateThumbnails
       
   104     CPolicyServer::ECustomCheck,    // ERequestSetThumbnailByBitmap
       
   105     CPolicyServer::ECustomCheck,    // EThumbnailServerRequestCount
       
   106     };
       
   107 
       
   108 // ----------------------------------------------------------------------------------------
       
   109 // Package all the above together into a policy 
       
   110 // ---------------------------------------------------------------------------------------- 
       
   111 const CPolicyServer::TPolicy KThumbnailServerPolicy =
       
   112     {
       
   113     CPolicyServer::EAlwaysPass,
       
   114     KThumbnailServerRangeCount,      // number of ranges
       
   115     KThumbnailServerRanges,          // ranges array
       
   116     KThumbnailServerElementsIndex,   // elements<->ranges index
       
   117     NULL 
       
   118                                // array of elements
       
   119     };
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // CustomSecurityCheckL
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 CPolicyServer::TCustomResult CThumbnailServer::CustomSecurityCheckL(
       
   126         const RMessage2& aMsg, TInt& /*aAction*/, TSecurityInfo& /*aMissing*/ )
       
   127     {
       
   128     CPolicyServer::TCustomResult securityCheckResult = EFail;
       
   129     
       
   130     switch ( aMsg.Function() )
       
   131         {
       
   132         case ERequestThumbByPathAsync:
       
   133         case ERequestThumbByFileHandleAsync:
       
   134         case ERequestThumbByIdAsync:
       
   135         case ERequestThumbByBufferAsync:
       
   136             {
       
   137             securityCheckResult = EPass;
       
   138             break;
       
   139             }
       
   140         case EReleaseBitmap:
       
   141         case ECancelRequest:
       
   142         case EChangePriority:
       
   143         case ECreateThumbnails:
       
   144         case EDeleteThumbnails:
       
   145         case EGetMimeTypeBufferSize:
       
   146         case EGetMimeTypeList:
       
   147         case ERequestSetThumbnailByBuffer:
       
   148         case EDeleteThumbnailsById:
       
   149         case EUpdateThumbnails:   
       
   150         case ERequestSetThumbnailByBitmap:
       
   151             {
       
   152             if( aMsg.HasCapability( ECapabilityReadDeviceData ) && 
       
   153                 aMsg.HasCapability( ECapabilityWriteDeviceData ) )
       
   154                 {
       
   155                 securityCheckResult = EPass;
       
   156                 }
       
   157             break;
       
   158             }
       
   159 
       
   160         case EReserved1:
       
   161         case EThumbnailServerRequestCount:
       
   162         default:
       
   163             {
       
   164             securityCheckResult = EFail;
       
   165             }
       
   166         }
       
   167     
       
   168     return securityCheckResult;
       
   169     }
       
   170 // ---------------------------------------------------------------------------
       
   171 // CustomFailureActionL
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 CPolicyServer::TCustomResult CThumbnailServer::CustomFailureActionL(
       
   175         const RMessage2& /*aMsg*/, TInt /*aAction*/, const TSecurityInfo& /*aMissing*/ )
       
   176     {
       
   177     // Not used
       
   178     return EFail;
       
   179     }
       
   180 
       
   181 // ======== MEMBER FUNCTIONS ========
       
   182 
       
   183 // ---------------------------------------------------------------------------
       
   184 // CThumbnailServer::CThumbnailServer()
       
   185 // C++ default constructor can NOT contain any code, that might leave.
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 CThumbnailServer::CThumbnailServer(): CPolicyServer( CActive::EPriorityStandard,
       
   189     KThumbnailServerPolicy, EUnsharableSessions )
       
   190     {
       
   191     // No implementation required
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CThumbnailServer::NewL()
       
   196 // Two-phased constructor.
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 CThumbnailServer* CThumbnailServer::NewL()
       
   200     {
       
   201     CThumbnailServer* self = new( ELeave )CThumbnailServer();
       
   202     CleanupStack::PushL( self );
       
   203     self->ConstructL();
       
   204     CleanupStack::Pop( self );
       
   205     return self;
       
   206     }
       
   207 
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // CThumbnailServer::ConstructL()
       
   211 // Symbian 2nd phase constructor can leave.
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 void CThumbnailServer::ConstructL()
       
   215     {
       
   216     TN_DEBUG1( "CThumbnailServer::ConstructL()" );
       
   217     
       
   218 #ifdef _DEBUG
       
   219     iPlaceholderCounter = 0;
       
   220 #endif
       
   221     
       
   222     // create shutdown observer
       
   223     iShutdownObserver = CTMShutdownObserver::NewL( *this, KTMPSNotification, KShutdown, ETrue );  
       
   224     iShutdown = EFalse;
       
   225     
       
   226     // connect to MDS
       
   227     iMdESession = CMdESession::NewL( *this );
       
   228     
       
   229     User::LeaveIfError( iFbsSession.Connect());
       
   230     User::LeaveIfError( Start( KThumbnailServerName ));
       
   231     User::LeaveIfError( iFs.Connect());
       
   232     iProcessor = CThumbnailTaskProcessor::NewL();
       
   233     REComSession::FinalClose();
       
   234     REComSession::ListImplementationsL( TUid::Uid( THUMBNAIL_PROVIDER_IF_UID ),
       
   235         iPluginInfoArray );
       
   236     
       
   237     CTnmgetimei * imeigetter = CTnmgetimei::NewLC();
       
   238    
       
   239     iImei = imeigetter->GetIMEI();
       
   240     CleanupStack::PopAndDestroy(imeigetter);
       
   241     
       
   242     iFs.CreatePrivatePath(EDriveC);
       
   243     iFs.SetSessionToPrivate(EDriveC);
       
   244     
       
   245     iCenrep = CThumbnailCenRep::NewL();
       
   246                
       
   247     iPersistentSizes = iCenrep->GetPersistentSizes();
       
   248             
       
   249     iMMCObserver = CThumbnailMemoryCardObserver::NewL( this, iFs );
       
   250     
       
   251     iFormatObserver = CThumbnailFormatObserver::NewL( this );
       
   252     
       
   253     iFormatting = EFalse;
       
   254     
       
   255     OpenStoresL();
       
   256     
       
   257     AddUnmountObserversL();
       
   258     }
       
   259 
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // Destructor.
       
   263 // ---------------------------------------------------------------------------
       
   264 //
       
   265 CThumbnailServer::~CThumbnailServer()
       
   266     {
       
   267     TN_DEBUG1( "CThumbnailServer::~CThumbnailServer()" );
       
   268 
       
   269     iShutdown = ETrue;
       
   270     
       
   271     delete iShutdownObserver;
       
   272     delete iProcessor;
       
   273     
       
   274     if (iMdESession)
       
   275         {
       
   276         delete iMdESession;
       
   277         }
       
   278 
       
   279     ResetAndDestroyHashMap < TInt, CThumbnailStore > ( iStores );
       
   280     ResetAndDestroyHashMap < TInt32, CThumbnailProvider > ( iProviders );
       
   281     
       
   282     iUnmountObservers.ResetAndDestroy();
       
   283     delete iMMCObserver;
       
   284     delete iFormatObserver;
       
   285     
       
   286     THashMapIter < TInt, TThumbnailBitmapRef > bpiter( iBitmapPool );
       
   287 
       
   288     // const pointer to a non-const object
       
   289     const TThumbnailBitmapRef* ref = bpiter.NextValue();
       
   290 
       
   291     while ( ref )
       
   292         {
       
   293         delete ref->iBitmap;
       
   294         ref = bpiter.NextValue();
       
   295         }
       
   296     
       
   297     delete iScaler;
       
   298     iBitmapPool.Close();
       
   299     iFbsSession.Disconnect();
       
   300     iRecognizer.Close();
       
   301     iPluginInfoArray.ResetAndDestroy();
       
   302     delete iCenrep;
       
   303     iFs.Close();
       
   304     REComSession::FinalClose();
       
   305     }
       
   306 
       
   307 // -----------------------------------------------------------------------------
       
   308 // CThumbnailServer::HandleSessionOpened
       
   309 // -----------------------------------------------------------------------------
       
   310 //
       
   311 void CThumbnailServer::HandleSessionOpened( CMdESession& /* aSession */, TInt /*aError*/ )
       
   312     {
       
   313     TN_DEBUG1( "CThumbnailServer::HandleSessionOpened");
       
   314     }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // CThumbnailServer::HandleSessionError
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 void CThumbnailServer::HandleSessionError( CMdESession& /*aSession*/, TInt aError )
       
   321     {
       
   322     if (aError != KErrNone)
       
   323         {
       
   324         TN_DEBUG2( "CThumbnailServer::HandleSessionError == %d", aError );
       
   325         }   
       
   326     }
       
   327 
       
   328 // -----------------------------------------------------------------------------
       
   329 // CThumbnailServer::NewSessionL()
       
   330 // Creates new server session.
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 CSession2* CThumbnailServer::NewSessionL( const TVersion& aVersion, const
       
   334     RMessage2&  /*aMessage*/ )const
       
   335     {
       
   336     const TVersion v( KThumbnailServerMajorVersionNumber,
       
   337         KThumbnailServerMinorVersionNumber, KThumbnailServerBuildVersionNumber )
       
   338         ;
       
   339     if ( !User::QueryVersionSupported( v, aVersion ))
       
   340         {
       
   341         User::Leave( KErrNotSupported );
       
   342         }
       
   343     return new( ELeave )CThumbnailServerSession();
       
   344     }
       
   345 
       
   346 
       
   347 // -----------------------------------------------------------------------------
       
   348 // CThumbnailServer::ThreadFunctionL()
       
   349 // -----------------------------------------------------------------------------
       
   350 //
       
   351 void CThumbnailServer::ThreadFunctionL()
       
   352     {
       
   353     // Rename own thread
       
   354     User::LeaveIfError( User::RenameThread( KThumbnailServerName ));
       
   355 
       
   356     CThumbnailServer* server = NULL;
       
   357     CActiveScheduler* scheduler = new( ELeave )CActiveScheduler();
       
   358 
       
   359     if ( scheduler )
       
   360         {
       
   361         CActiveScheduler::Install( scheduler );
       
   362         CleanupStack::PushL( scheduler );
       
   363         server = CThumbnailServer::NewL(); // Adds server in scheduler
       
   364         // No need to CleanupStack::PushL(server) since no leaves can happen
       
   365         RProcess::Rendezvous( KErrNone );
       
   366         TN_DEBUG1( 
       
   367             "CThumbnailServer::ThreadFunctionL() -- CActiveScheduler::Start() in" );
       
   368         CActiveScheduler::Start();
       
   369         TN_DEBUG1( 
       
   370             "CThumbnailServer::ThreadFunctionL() -- CActiveScheduler::Start() out" );
       
   371         // Comes here if server gets shut down
       
   372         delete server;
       
   373         CleanupStack::PopAndDestroy( scheduler );
       
   374         }
       
   375     }
       
   376 
       
   377 
       
   378 // -----------------------------------------------------------------------------
       
   379 // CThumbnailServer::AddSession()
       
   380 // -----------------------------------------------------------------------------
       
   381 //
       
   382 void CThumbnailServer::AddSession()
       
   383     {
       
   384     TN_DEBUG2( "CThumbnailServer::AddSession() iSessionCount was %d",
       
   385         iSessionCount );
       
   386     iSessionCount++;
       
   387     }
       
   388 
       
   389 
       
   390 // -----------------------------------------------------------------------------
       
   391 // CThumbnailServer::DropSession()
       
   392 // -----------------------------------------------------------------------------
       
   393 //
       
   394 void CThumbnailServer::DropSession(CThumbnailServerSession* aSession)
       
   395     {
       
   396     TN_DEBUG2( "CThumbnailServer::DropSession() iSessionCount was %d",
       
   397         iSessionCount );
       
   398     iSessionCount--;
       
   399     
       
   400     iProcessor->RemoveTasks(aSession);
       
   401     if ( iSessionCount <= 0 )
       
   402         {
       
   403         // rename thread
       
   404         User::RenameThread( KThumbnailServerShutdown );
       
   405         
       
   406         // server shutdown
       
   407         if (!iShutdown)
       
   408             {
       
   409             CActiveScheduler::Stop();
       
   410             iShutdown = ETrue;
       
   411             }
       
   412         }
       
   413     }
       
   414 
       
   415 // -----------------------------------------------------------------------------
       
   416 // CThumbnailServer::ShutdownNotification
       
   417 // -----------------------------------------------------------------------------
       
   418 //
       
   419 void CThumbnailServer::ShutdownNotification()
       
   420     {
       
   421     if (!iShutdown)
       
   422         {
       
   423         CActiveScheduler::Stop();
       
   424         iShutdown = ETrue;
       
   425         }
       
   426     }
       
   427 
       
   428 
       
   429 // -----------------------------------------------------------------------------
       
   430 // CThumbnailServer::AddBitmapToPoolL()
       
   431 // Add bitmap to bitmap pool.
       
   432 // -----------------------------------------------------------------------------
       
   433 //
       
   434 void CThumbnailServer::AddBitmapToPoolL( CThumbnailServerSession* aSession,
       
   435     CFbsBitmap* aBitmap )
       
   436     {
       
   437     if( !aBitmap )
       
   438         {
       
   439         User::Leave( KErrArgument );
       
   440         }
       
   441     TN_DEBUG4( 
       
   442         "CThumbnailServer::AddBitmapToPoolL(aSession=0x%08x, aBitmap=0x%08x), handle=%d", aSession, aBitmap, aBitmap->Handle());
       
   443 
       
   444     TThumbnailBitmapRef* ptr = iBitmapPool.Find( aBitmap->Handle());
       
   445 
       
   446     if ( ptr )
       
   447         {
       
   448         ptr->iRefCount++;
       
   449         }
       
   450     else
       
   451         {
       
   452         TThumbnailBitmapRef ref;
       
   453         ref.iBitmap = aBitmap;
       
   454         ref.iSession = aSession;
       
   455         ref.iRefCount = 1; // magic: first reference
       
   456         iBitmapPool.InsertL( aBitmap->Handle(), ref );
       
   457         }
       
   458     
       
   459 #ifdef _DEBUG
       
   460     TN_DEBUG2( "CThumbnailServer::BITMAP-POOL-COUNTER----------, Bitmaps = %d", iBitmapPool.Count() );
       
   461 #endif
       
   462     }
       
   463 
       
   464 
       
   465 // -----------------------------------------------------------------------------
       
   466 // CThumbnailServer::StoreThumbnailL()
       
   467 // -----------------------------------------------------------------------------
       
   468 //
       
   469 void CThumbnailServer::StoreThumbnailL( const TDesC& aPath, CFbsBitmap* aBitmap,
       
   470     const TSize& aOriginalSize, const TBool aCropped, const TThumbnailSize aThumbnailSize,
       
   471     const TThumbnailId aThumbnailId, const TBool aThumbFromPath, const TBool aCheckExist )
       
   472     {
       
   473     TN_DEBUG6( 
       
   474         "CThumbnailServer::StoreBitmapL(aPath=%S, aBitmap=0x%08x, aOriginalSize=%dx%d, aCropped=%d)", &aPath, aBitmap, aOriginalSize.iWidth, aOriginalSize.iHeight, aCropped );
       
   475 #ifdef _DEBUG
       
   476     TN_DEBUG2( "CThumbnailServer::StoreThumbnailL() - iScaledBitmap displaymode is %d", aBitmap->DisplayMode());
       
   477 #endif
       
   478     
       
   479     if (!aCheckExist)
       
   480         {
       
   481         StoreForPathL( aPath )->StoreThumbnailL( aPath, aBitmap, aOriginalSize,
       
   482                        aCropped, aThumbnailSize, aThumbnailId, aThumbFromPath );
       
   483         }    
       
   484     else if(BaflUtils::FileExists( iFs, aPath))
       
   485         {
       
   486         StoreForPathL( aPath )->StoreThumbnailL( aPath, aBitmap, aOriginalSize,
       
   487                        aCropped, aThumbnailSize, aThumbnailId, aThumbFromPath );
       
   488         }
       
   489     else
       
   490         {
       
   491         TN_DEBUG1( "CThumbnailServer::StoreThumbnailL() - file doesn't exists anymore, skip store!");
       
   492         }
       
   493     }
       
   494 
       
   495 
       
   496 // -----------------------------------------------------------------------------
       
   497 // CThumbnailServer::FetchThumbnailL()
       
   498 // -----------------------------------------------------------------------------
       
   499 //
       
   500 void CThumbnailServer::FetchThumbnailL( const TDesC& aPath, CFbsBitmap* &
       
   501     aThumbnail, TDesC8* & aData, const TThumbnailSize aThumbnailSize, TSize &aOriginalSize )
       
   502     {
       
   503     TN_DEBUG3( "CThumbnailServer::FetchThumbnailL(aPath=%S aThumbnailSize=%d)", &aPath, aThumbnailSize );
       
   504 
       
   505     StoreForPathL( aPath )->FetchThumbnailL( aPath, aThumbnail, aData, aThumbnailSize, aOriginalSize);
       
   506     }
       
   507 
       
   508 
       
   509 
       
   510 // -----------------------------------------------------------------------------
       
   511 // CThumbnailServer::DeleteBitmapFromPool()
       
   512 // Removes bitmap from bitmap pool
       
   513 // -----------------------------------------------------------------------------
       
   514 //
       
   515 void CThumbnailServer::DeleteBitmapFromPool( TInt aHandle )
       
   516     {
       
   517     TN_DEBUG2( "CThumbnailServer::DeleteBitmapFromPool(%d)", aHandle );
       
   518 
       
   519     TThumbnailBitmapRef* ptr = iBitmapPool.Find( aHandle );
       
   520     if ( ptr )
       
   521         {
       
   522         ptr->iRefCount--;
       
   523         if ( !ptr->iRefCount )
       
   524             {
       
   525             TN_DEBUG3( 
       
   526                 "CThumbnailServer::DeleteBitmapFromPool(%d) -- deleting 0x%08x)", aHandle, ptr );
       
   527             delete ptr->iBitmap;
       
   528             ptr->iBitmap = NULL;
       
   529             iBitmapPool.Remove( aHandle );
       
   530             }
       
   531         else
       
   532             {
       
   533             TN_DEBUG3( 
       
   534                 "CThumbnailServer::DeleteBitmapFromPool(%d) -- refcount now %d",
       
   535                 aHandle, ptr->iRefCount );
       
   536             }
       
   537         }
       
   538     else
       
   539         {
       
   540         TN_DEBUG2( "CThumbnailServer::DeleteBitmapFromPool(%d) -- not found!",
       
   541             aHandle );
       
   542         }
       
   543     }
       
   544 
       
   545 
       
   546 // -----------------------------------------------------------------------------
       
   547 // Delete thumbnails for given object file
       
   548 // -----------------------------------------------------------------------------
       
   549 //
       
   550 void CThumbnailServer::DeleteThumbnailsL( const TDesC& aPath )
       
   551     {
       
   552     TN_DEBUG2( "CThumbnailServer::DeleteThumbnailsL(%S)", &aPath);
       
   553     
       
   554     StoreForPathL( aPath )->DeleteThumbnailsL( aPath );
       
   555     }
       
   556 
       
   557 
       
   558 // -----------------------------------------------------------------------------
       
   559 // Delete thumbnails by Id
       
   560 // -----------------------------------------------------------------------------
       
   561 //
       
   562 void CThumbnailServer::DeleteThumbnailsByIdL( const TThumbnailId aItemId )
       
   563     {
       
   564     TN_DEBUG2( "CThumbnailServer::DeleteThumbnailsByIdL(%d)", aItemId);
       
   565     
       
   566 #ifdef _DEBUG
       
   567     TTime aStart, aStop;
       
   568     aStart.UniversalTime();
       
   569 #endif
       
   570     
       
   571     // no path available, can be any store    
       
   572     THashMapIter<TInt, CThumbnailStore*> iter( iStores );
       
   573     CThumbnailStore* const *store = iter.NextValue();
       
   574 
       
   575     while ( store )
       
   576         {
       
   577         TInt err = KErrNone;   
       
   578         TRAP(err, ((CThumbnailStore*)(*store))->DeleteThumbnailsL(aItemId) );
       
   579         if (err == KErrNone)
       
   580             {
       
   581 #ifdef _DEBUG
       
   582     aStop.UniversalTime();
       
   583     TN_DEBUG2( "CThumbnailStore::DeleteThumbnailsByIdL() took %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000);
       
   584 #endif
       
   585             return;
       
   586             }
       
   587         store = iter.NextValue();
       
   588         }    
       
   589     }
       
   590 
       
   591 
       
   592 // -----------------------------------------------------------------------------
       
   593 // CThumbnailServer::ResolveMimeTypeL()
       
   594 // -----------------------------------------------------------------------------
       
   595 //
       
   596 TDataType CThumbnailServer::ResolveMimeTypeL( RFile& aFile )
       
   597     {
       
   598     TN_DEBUG1( "CThumbnailStore::ResolveMimeTypeL()");
       
   599     RFile tmp = aFile;
       
   600     
       
   601     // check if DRM
       
   602     ContentAccess::CData* data = ContentAccess::CData::NewLC( 
       
   603             tmp, ContentAccess::KDefaultContentObject, ContentAccess::EPeek );
       
   604 
       
   605     TInt filetype( 0 );
       
   606     TInt drm( 0 );
       
   607     User::LeaveIfError( data->GetAttribute( ContentAccess::EIsProtected, drm ) );
       
   608     data->GetAttribute( ContentAccess::EFileType, filetype );
       
   609     CleanupStack::PopAndDestroy();    
       
   610 
       
   611 	//close aFile on leave	
       
   612     CleanupClosePushL( aFile );    
       
   613     
       
   614     if ( drm && filetype != ContentAccess::EOma1Dcf )
       
   615         {
       
   616         // cannot handle other than Oma DRM 1.x files
       
   617         TN_DEBUG1( "CThumbnailStore::ResolveMimeTypeL()- only OMA DRM 1.0 supported");
       
   618         User::Leave(KErrNotSupported);
       
   619         }    
       
   620     
       
   621     TDataRecognitionResult res;
       
   622     if ( iRecognizer.Handle() == KNullHandle )
       
   623         {
       
   624         // error using recognizer, (re)connect
       
   625         User::LeaveIfError( iRecognizer.Connect());
       
   626         }
       
   627     
       
   628     User::LeaveIfError( iRecognizer.RecognizeData( aFile, res ));
       
   629     
       
   630     if ( res.iConfidence == CApaDataRecognizerType::ENotRecognized )
       
   631         {
       
   632         // file type not supported
       
   633         User::Leave( KErrNotSupported );
       
   634         }
       
   635 
       
   636     CleanupStack::Pop( &aFile );
       
   637     return res.iDataType;
       
   638     }
       
   639 
       
   640 // -----------------------------------------------------------------------------
       
   641 // CThumbnailServer::ResolveProviderL()
       
   642 // Resolves plugin to be used in thumbnail creation.
       
   643 // -----------------------------------------------------------------------------
       
   644 //
       
   645 CThumbnailProvider* CThumbnailServer::ResolveProviderL( const TDesC8& aMimeType
       
   646     )
       
   647     {
       
   648 #ifdef _DEBUG
       
   649     TBuf < KMaxDataTypeLength > buf; // 16-bit descriptor for debug prints
       
   650     buf.Copy( aMimeType );
       
   651     TN_DEBUG2( "CThumbnailServer::ResolveProviderL(%S)", &buf );
       
   652 #endif 
       
   653 
       
   654     CThumbnailProvider* ret = NULL;
       
   655 
       
   656     TInt separatorPos = aMimeType.Locate( KThumbnailMimeSeparatorChar );
       
   657     TPtrC8 mediaType( aMimeType.Left( separatorPos ));
       
   658     TPtrC8 subType( aMimeType.Mid( separatorPos + 1 )); // skip slash
       
   659 
       
   660     const TInt count = iPluginInfoArray.Count();
       
   661     for ( TInt i( 0 ); i < count && !ret; i++ )
       
   662         {
       
   663         const TDesC8& opaqueData = iPluginInfoArray[i]->OpaqueData();
       
   664         TInt pSeparatorPos = opaqueData.Locate( KThumbnailMimeSeparatorChar );
       
   665         TPtrC8 pMediaType( opaqueData.Left( pSeparatorPos ));
       
   666         TPtrC8 pSubType( opaqueData.Mid( pSeparatorPos + 1 )); // skip slash
       
   667         
       
   668         if ( !pMediaType.CompareF( mediaType ))
       
   669             {
       
   670             if ( !pSubType.CompareF( KThumbnailMimeWildCard ) ||
       
   671                 !pSubType.CompareF( subType ))
       
   672                 {
       
   673 #ifdef _DEBUG
       
   674                 TN_DEBUG3( 
       
   675                     "CThumbnailServer::ResolveProviderL(%S) -- using provider 0x%08x", &buf, iPluginInfoArray[i]->ImplementationUid().iUid );
       
   676 #endif 
       
   677                 ret = GetProviderL( iPluginInfoArray[i]->ImplementationUid());
       
   678                 }
       
   679             }
       
   680         }
       
   681     if ( !ret )
       
   682         {
       
   683 #ifdef _DEBUG
       
   684         TN_DEBUG2( 
       
   685             "CThumbnailServer::ResolveProviderL(%S) -- provider not found",
       
   686             &buf );
       
   687 #endif 
       
   688         User::Leave( KErrNotSupported );
       
   689         }
       
   690     return ret;
       
   691     }
       
   692 
       
   693 
       
   694 // -----------------------------------------------------------------------------
       
   695 // CThumbnailServer::GetProviderL()
       
   696 // -----------------------------------------------------------------------------
       
   697 //
       
   698 CThumbnailProvider* CThumbnailServer::GetProviderL( const TUid& aImplUid )
       
   699     {
       
   700     CThumbnailProvider** resPtr = iProviders.Find( aImplUid.iUid );
       
   701     CThumbnailProvider* res = NULL;
       
   702     if ( resPtr )
       
   703         {
       
   704         // Use existing instance
       
   705         res = * resPtr;
       
   706         }
       
   707     else
       
   708         {
       
   709         // Plug-in needs to be loaded
       
   710         TN_DEBUG2( 
       
   711             "CThumbnailServer::GetProviderL() -- loading plug-in, UID 0x%08x",
       
   712             aImplUid );
       
   713         res = CThumbnailProvider::NewL( aImplUid );
       
   714         TN_DEBUG1( "CThumbnailServer::GetProviderL() -- loading complete" );
       
   715         CleanupStack::PushL( res );
       
   716         iProviders.InsertL( aImplUid.iUid, res );
       
   717         CleanupStack::Pop( res );
       
   718         }
       
   719 
       
   720     return res;
       
   721     }
       
   722 
       
   723 
       
   724 // -----------------------------------------------------------------------------
       
   725 // CThumbnailServer::QueueTaskL()
       
   726 // Adds thumbnailtask to processor queue.
       
   727 // -----------------------------------------------------------------------------
       
   728 //
       
   729 void CThumbnailServer::QueueTaskL( CThumbnailTask* aTask )
       
   730     {
       
   731     __ASSERT_DEBUG(( aTask ), ThumbnailPanic( EThumbnailNullPointer ));
       
   732     iProcessor->AddTaskL( aTask );
       
   733     }
       
   734 
       
   735 
       
   736 // -----------------------------------------------------------------------------
       
   737 // CThumbnailServer::DequeTask()
       
   738 // Removes thumbnailtask from processor queue.
       
   739 // -----------------------------------------------------------------------------
       
   740 //
       
   741 TInt CThumbnailServer::DequeTask( const TThumbnailServerRequestId& aRequestId )
       
   742     {
       
   743     return iProcessor->RemoveTask( aRequestId );
       
   744     }
       
   745 
       
   746 
       
   747 // -----------------------------------------------------------------------------
       
   748 // CThumbnailServer::ChangeTaskPriority()
       
   749 // Changes priority of specific task.
       
   750 // -----------------------------------------------------------------------------
       
   751 //
       
   752 TInt CThumbnailServer::ChangeTaskPriority( const TThumbnailServerRequestId&
       
   753     aRequestId, TInt aNewPriority )
       
   754     {
       
   755     return iProcessor->ChangeTaskPriority( aRequestId, aNewPriority );
       
   756     }
       
   757 
       
   758 
       
   759 // -----------------------------------------------------------------------------
       
   760 // CThumbnailServer::ScaleBitmapL()
       
   761 // Used to scale image.
       
   762 // -----------------------------------------------------------------------------
       
   763 //
       
   764 void CThumbnailServer::ScaleBitmapL( TRequestStatus& aStatus, const CFbsBitmap&
       
   765     aSource, CFbsBitmap& aDest, const TRect& aSourceRect )
       
   766     {
       
   767     if ( !iScaler )
       
   768         {
       
   769         iScaler = IHLScaler::CreateL();
       
   770         }
       
   771     TRect destRect( TPoint(), aDest.SizeInPixels());
       
   772     User::LeaveIfError( iScaler->Scale( aStatus, aSource, aSourceRect, aDest,
       
   773         destRect ));
       
   774     }
       
   775 
       
   776 
       
   777 // -----------------------------------------------------------------------------
       
   778 // CThumbnailServer::CancelScale()
       
   779 // Cancels scaling task.
       
   780 // -----------------------------------------------------------------------------
       
   781 //
       
   782 void CThumbnailServer::CancelScale()
       
   783     {
       
   784     if ( iScaler )
       
   785         {
       
   786         iScaler->CancelProcess();
       
   787         }
       
   788     }
       
   789 
       
   790 
       
   791 // -----------------------------------------------------------------------------
       
   792 // CThumbnailServer::Processor()
       
   793 // Returns processor.
       
   794 // -----------------------------------------------------------------------------
       
   795 //
       
   796 CThumbnailTaskProcessor& CThumbnailServer::Processor()
       
   797     {
       
   798     __ASSERT_DEBUG(( iProcessor ), ThumbnailPanic( EThumbnailNullPointer ));
       
   799     return * iProcessor;
       
   800     }
       
   801 
       
   802 // -----------------------------------------------------------------------------
       
   803 // Get the thumbnail store instance, which is responsible for this drive
       
   804 // -----------------------------------------------------------------------------
       
   805 //
       
   806 CThumbnailStore* CThumbnailServer::StoreForDriveL( const TInt aDrive )
       
   807     {
       
   808     TN_DEBUG2( "CThumbnailServer::StoreForDriveL() drive=%d", aDrive );
       
   809     CThumbnailStore** resPtr = iStores.Find( aDrive );
       
   810     CThumbnailStore* res = NULL;
       
   811 
       
   812 
       
   813     if ( resPtr )
       
   814         {
       
   815         res = * resPtr;
       
   816         }
       
   817     else
       
   818         {
       
   819         if(iFormatting)
       
   820            {
       
   821            TN_DEBUG1( "CThumbnailServer::StoreForDriveL() - FORMATTING! - ABORT");
       
   822            User::Leave( KErrNotSupported );
       
   823            } 
       
   824         TVolumeInfo volumeInfo;
       
   825         TInt err = iFs.Volume( volumeInfo, aDrive );
       
   826         if ( err || volumeInfo.iDrive.iDriveAtt& KDriveAttRom ||
       
   827             volumeInfo.iDrive.iDriveAtt& KDriveAttRemote ||
       
   828             volumeInfo.iDrive.iMediaAtt& KMediaAttWriteProtected ||
       
   829             volumeInfo.iDrive.iMediaAtt& KMediaAttLocked )
       
   830             {
       
   831             // We don't support ROM disks or remote mounts. Media
       
   832             // must be read-write and not locked.
       
   833             User::Leave( KErrAccessDenied);
       
   834             }
       
   835 
       
   836         res = CThumbnailStore::NewL( iFs, aDrive, iImei, this );
       
   837         CleanupStack::PushL( res );
       
   838         iStores.InsertL( aDrive, res );
       
   839         res->SetPersistentSizes(iPersistentSizes);
       
   840         CleanupStack::Pop( res );
       
   841         
       
   842         for(TInt i = 0; i<iUnmountObservers.Count(); i++)
       
   843             {
       
   844             iUnmountObservers[i]->StartNotify();
       
   845             }
       
   846         }
       
   847 
       
   848     return res;
       
   849     }
       
   850 
       
   851 
       
   852 // -----------------------------------------------------------------------------
       
   853 // CThumbnailServer::FetchThumbnailL()
       
   854 // -----------------------------------------------------------------------------
       
   855 //
       
   856 void CThumbnailServer::FetchThumbnailL( TThumbnailId aThumbnailId, CFbsBitmap* &
       
   857     aThumbnail, TDesC8* & aData, TThumbnailSize aThumbnailSize, TSize &aOriginalSize )
       
   858     {
       
   859     TN_DEBUG3( "CThumbnailServer::FetchThumbnailL(aThumbnailId=%d aThumbnailSize=%d)", aThumbnailId, aThumbnailSize );
       
   860 
       
   861 #ifdef _DEBUG
       
   862     TTime aStart, aStop;
       
   863     aStart.UniversalTime();
       
   864     TInt roundCount = 1;
       
   865 #endif
       
   866     
       
   867     THashMapIter<TInt, CThumbnailStore*> storeIter(iStores);
       
   868     
       
   869     TN_DEBUG1( "CThumbnailServer::FetchThumbnailL() store iteration - begin");
       
   870     for (CThumbnailStore* const* pStore = storeIter.NextValue();
       
   871         pStore && aThumbnail == NULL ;
       
   872         pStore = storeIter.NextValue())
       
   873         {
       
   874         TN_DEBUG2( "CThumbnailServer::FetchThumbnailL() store iteration - round == %d ", roundCount++);
       
   875         CThumbnailStore* const store = (CThumbnailStore*)(*pStore);
       
   876         
       
   877         TRAP_IGNORE( store->FetchThumbnailL( aThumbnailId, aThumbnail, aData, aThumbnailSize, aOriginalSize ));
       
   878         
       
   879         if ( aThumbnail || aData)
       
   880             { // thumbnail found from DB
       
   881             TN_DEBUG1( "CThumbnailServer::FetchThumbnailL() found" );
       
   882             break;
       
   883             }
       
   884 /*
       
   885 #ifdef _DEBUG
       
   886     aStop.UniversalTime();
       
   887     TN_DEBUG3( "CThumbnailServer::FetchThumbnailL() iteration round %d took %d ms", roundCount, (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000);
       
   888 #endif 
       
   889 */
       
   890         }
       
   891 
       
   892 #ifdef _DEBUG
       
   893     aStop.UniversalTime();
       
   894     TN_DEBUG2( "CThumbnailServer::FetchThumbnailL() took %d ms", (TInt)aStop.MicroSecondsFrom(aStart).Int64()/1000);
       
   895 #endif 
       
   896     
       
   897     if ( !aThumbnail && !aData)
       
   898         { // thumbnail not found from DB
       
   899         TN_DEBUG1( "CThumbnailServer::FetchThumbnailL() not found" );
       
   900         User::Leave( KErrNotFound );
       
   901         }  
       
   902     }
       
   903 
       
   904 
       
   905 // -----------------------------------------------------------------------------
       
   906 // Get the thumbnail store instance, which is responsible for the drive
       
   907 // identified by given path
       
   908 // -----------------------------------------------------------------------------
       
   909 //
       
   910 CThumbnailStore* CThumbnailServer::StoreForPathL( const TDesC& aPath )
       
   911     {
       
   912     if(aPath.Length() < 3 || aPath.Length() > KMaxPath)
       
   913         {
       
   914         User::Leave(KErrArgument);
       
   915         }
       
   916     TInt drive = 0;
       
   917     User::LeaveIfError( RFs::CharToDrive( aPath[0], drive ));
       
   918     return StoreForDriveL( drive );
       
   919     }
       
   920 
       
   921 
       
   922 // ---------------------------------------------------------------------------
       
   923 // CThumbnailStore::PersistentSizeL()
       
   924 // ---------------------------------------------------------------------------
       
   925 //
       
   926 TThumbnailPersistentSize & CThumbnailServer::PersistentSizeL( TThumbnailSize
       
   927         aThumbnailSize )
       
   928     {
       
   929     if ( !iCenrep )
       
   930            {
       
   931            iCenrep = CThumbnailCenRep::NewL();
       
   932            }
       
   933     
       
   934     return iCenrep->PersistentSizeL( aThumbnailSize );
       
   935     
       
   936     }
       
   937 
       
   938 // -----------------------------------------------------------------------------
       
   939 // Open store for each mounted drive
       
   940 // -----------------------------------------------------------------------------
       
   941 //
       
   942 void CThumbnailServer::OpenStoresL()
       
   943     {      
       
   944     // get list of mounted drives and open stores
       
   945     TDriveList driveListInt;
       
   946     TInt driveCountInt(0);
       
   947     User::LeaveIfError(DriveInfo::GetUserVisibleDrives(
       
   948            iFs, driveListInt, driveCountInt, KDriveAttInternal | KDriveAttRemovable ));
       
   949 
       
   950     for( TInt i = EDriveA; i <= EDriveZ && driveCountInt; i++ )
       
   951         {
       
   952         if (driveListInt[i])
       
   953             {
       
   954             TVolumeInfo volumeInfo;
       
   955             TInt err = iFs.Volume( volumeInfo, i );
       
   956             
       
   957             if (!err)
       
   958                 {
       
   959                 TN_DEBUG2( "CThumbnailServer::OpenStoresL() StoreForDriveL %d", i);
       
   960                 
       
   961                 // ignore errors
       
   962                 TRAP_IGNORE( StoreForDriveL( i ));
       
   963                 
       
   964                 // start also placeholder task
       
   965                 //AddPlaceholderTaskL(i);
       
   966                 
       
   967                 driveCountInt--;
       
   968                 }
       
   969             }            
       
   970         }
       
   971     
       
   972     }
       
   973 
       
   974 // -----------------------------------------------------------------------------
       
   975 // Close the thumbnail store instance, which is responsible for this drive
       
   976 // -----------------------------------------------------------------------------
       
   977 //
       
   978 void CThumbnailServer::CloseStoreForDriveL( const TInt aDrive )
       
   979     {
       
   980     TN_DEBUG2( "CThumbnailServer::CloseStoreForDriveL drive=%d", aDrive);
       
   981     CThumbnailStore** store = iStores.Find( aDrive );
       
   982     
       
   983     if (store)
       
   984         {
       
   985         delete *store;
       
   986         iStores.Remove( aDrive );
       
   987         }
       
   988     }
       
   989 
       
   990 
       
   991 // ---------------------------------------------------------------------------
       
   992 // CThumbnailStore::PersistentSizes()
       
   993 // ---------------------------------------------------------------------------
       
   994 //
       
   995 RArray < TThumbnailPersistentSize > CThumbnailServer::PersistentSizesL()
       
   996     {
       
   997     return iPersistentSizes;
       
   998     }
       
   999 
       
  1000 void CThumbnailServer::GetMissingSizesAndIDsL( const TDesC& aPath, TInt aSourceType, RArray <
       
  1001     TThumbnailPersistentSize > & aMissingSizes, TBool& aMissingIDs )
       
  1002     {
       
  1003     StoreForPathL( aPath )->GetMissingSizesAndIDsL( aPath, aSourceType, aMissingSizes, aMissingIDs );
       
  1004     }
       
  1005 
       
  1006 // ---------------------------------------------------------------------------
       
  1007 // CThumbnailServer::Fs()
       
  1008 // ---------------------------------------------------------------------------
       
  1009 //
       
  1010 RFs& CThumbnailServer::Fs()
       
  1011     {
       
  1012     return iFs;
       
  1013     }
       
  1014 
       
  1015 // ---------------------------------------------------------------------------
       
  1016 // CThumbnailServer::AddUnmountObserversL()
       
  1017 // ---------------------------------------------------------------------------
       
  1018 //
       
  1019 void CThumbnailServer::AddUnmountObserversL()
       
  1020     {
       
  1021     TDriveList driveList;
       
  1022     TInt drive; 
       
  1023     TDriveInfo driveInfo;
       
  1024     
       
  1025     iUnmountObservers.ResetAndDestroy();
       
  1026     
       
  1027     User::LeaveIfError( iFs.DriveList(driveList) );
       
  1028    
       
  1029     // search all drives
       
  1030     for( drive = EDriveA; drive <= EDriveZ; drive++ )
       
  1031         {
       
  1032         if( !driveList[drive] ) 
       
  1033             {
       
  1034             // If drive-list entry is zero, drive is not available
       
  1035             continue;
       
  1036             }
       
  1037         
       
  1038         TInt err = iFs.Drive(driveInfo, drive);
       
  1039         
       
  1040         // if removable drive, add observer
       
  1041         if (!err && driveInfo.iDriveAtt& KDriveAttRemovable)
       
  1042             {
       
  1043             TN_DEBUG2( "CThumbnailServer::AddOnMountObserver drive=%d", drive);
       
  1044             CThumbnailDiskUnmountObserver* obs = CThumbnailDiskUnmountObserver::NewL( iFs, drive, this );
       
  1045             CleanupStack::PushL( obs );
       
  1046             iUnmountObservers.AppendL( obs );
       
  1047             CleanupStack::Pop( obs );
       
  1048             }
       
  1049         }
       
  1050     }
       
  1051 
       
  1052 // ---------------------------------------------------------------------------
       
  1053 // CThumbnailServer::MemoryCardStatusChangedL()
       
  1054 // ---------------------------------------------------------------------------
       
  1055 //
       
  1056 void CThumbnailServer::MemoryCardStatusChangedL()
       
  1057     {
       
  1058     TN_DEBUG1( "CThumbnailServer::MemoryCardStatusChangedL in()" );
       
  1059     TDriveList driveList;
       
  1060     TInt drive; 
       
  1061     TVolumeInfo volumeInfo;
       
  1062     TDriveInfo driveInfo;
       
  1063         
       
  1064     User::LeaveIfError( iFs.DriveList(driveList) );
       
  1065        
       
  1066     // search all drives
       
  1067     for( drive = EDriveA; drive <= EDriveZ; drive++ )
       
  1068         {
       
  1069         if( !driveList[drive] ) 
       
  1070            {
       
  1071           // If drive-list entry is zero, drive is not available
       
  1072             continue;
       
  1073            }
       
  1074             
       
  1075         TInt err = iFs.Volume(volumeInfo, drive);
       
  1076         TInt err_drive = iFs.Drive(driveInfo, drive);    
       
  1077         
       
  1078         // mount -- if removable drive, add new store
       
  1079         if (!err && !err_drive && driveInfo.iDriveAtt& KDriveAttRemovable)
       
  1080             {
       
  1081             // ignore errors
       
  1082             TRAP_IGNORE( StoreForDriveL( drive ));
       
  1083                     
       
  1084             }
       
  1085         
       
  1086         //dismount -- if removable drive, close store
       
  1087         else if(err && !err_drive && driveInfo.iDriveAtt& KDriveAttRemovable)
       
  1088             {
       
  1089             CloseStoreForDriveL( drive);
       
  1090             }
       
  1091         }
       
  1092 
       
  1093     TN_DEBUG1( "CThumbnailServer::MemoryCardStatusChangedL out()" );
       
  1094     }
       
  1095 
       
  1096 
       
  1097 // -----------------------------------------------------------------------------
       
  1098 // Get the required size (in characters) for a buffer that contains the
       
  1099 // list of supported MIME types
       
  1100 // -----------------------------------------------------------------------------
       
  1101 //
       
  1102 TInt CThumbnailServer::GetMimeTypeBufferSize()const
       
  1103     {
       
  1104     TInt size = 0;
       
  1105     for ( TInt i = iPluginInfoArray.Count(); --i >= 0; )
       
  1106         {
       
  1107         const TDesC8& opaqueData = iPluginInfoArray[i]->OpaqueData();
       
  1108         size += opaqueData.Length();
       
  1109         size++; // space for separator character
       
  1110         }
       
  1111     if ( size )
       
  1112         {
       
  1113         size--; // no need for a separator character at the end
       
  1114         }
       
  1115 
       
  1116     return size;
       
  1117     }
       
  1118 
       
  1119 // -----------------------------------------------------------------------------
       
  1120 // Get the list of supported MIME types and store them in the buffer
       
  1121 // allocated by the client.
       
  1122 // -----------------------------------------------------------------------------
       
  1123 //
       
  1124 void CThumbnailServer::GetMimeTypeList( TDes& aBuffer )const
       
  1125     {
       
  1126     TBuf < KMaxDataTypeLength > buf; // needed for convert from TBuf8 to TBuf
       
  1127     aBuffer.Zero();
       
  1128     const TInt count = iPluginInfoArray.Count();
       
  1129     for ( TInt i = 0; i < count; i++ )
       
  1130         {
       
  1131         const TDesC8& opaqueData = iPluginInfoArray[i]->OpaqueData();
       
  1132         buf.Copy( opaqueData );
       
  1133         aBuffer.Append( buf );
       
  1134         aBuffer.Append( KThumbnailMimeTypeSeparatorChar );
       
  1135         }
       
  1136     if ( count )
       
  1137         {
       
  1138         // remove last separator char
       
  1139         aBuffer.SetLength( aBuffer.Length() - 1 );
       
  1140         }
       
  1141     }
       
  1142 
       
  1143 
       
  1144 // -----------------------------------------------------------------------------
       
  1145 // Updates thumbnails by given Id.
       
  1146 // -----------------------------------------------------------------------------
       
  1147 //
       
  1148 TBool CThumbnailServer::UpdateThumbnailsL( const TThumbnailId aItemId, const TDesC& aPath,
       
  1149                                            const TInt /*aOrientation*/, const TInt64 aModified )
       
  1150     {
       
  1151     TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL()");
       
  1152     
       
  1153     // 1. check path change
       
  1154     // 2. check orientation change
       
  1155     // 3. check timestamp change
       
  1156     TBool pathChanged = EFalse;
       
  1157     TBool orientationChanged = EFalse;
       
  1158     TBool modifiedChanged = EFalse;
       
  1159     
       
  1160     CThumbnailStore* newstore = StoreForPathL( aPath );
       
  1161     TInt err(KErrNone);
       
  1162 
       
  1163     // no path available, can be any store    
       
  1164     THashMapIter<TInt, CThumbnailStore*> iter( iStores );
       
  1165     CThumbnailStore* const *store = iter.NextValue();
       
  1166 
       
  1167     while ( store )
       
  1168          {     
       
  1169         err = KErrNone;   
       
  1170         
       
  1171         TRAP(err, ((CThumbnailStore*)(*store))->FindStoreL( aItemId ) );
       
  1172          
       
  1173          // no need to move thumbs to different store
       
  1174          if (err == KErrNone && *store == newstore)
       
  1175             {
       
  1176             pathChanged = ((CThumbnailStore*)(*store))->UpdateStoreL(aItemId, aPath);
       
  1177             
       
  1178             if (pathChanged)
       
  1179                 {
       
  1180                 TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - path updated");
       
  1181                 
       
  1182                 // path updated, no need to check further
       
  1183                 return ETrue;
       
  1184                 }
       
  1185             else
       
  1186                 {
       
  1187                 // placeholder for orientation check
       
  1188                 orientationChanged = EFalse;
       
  1189                 
       
  1190                 if (orientationChanged)
       
  1191                     {
       
  1192                     TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - orientation updated");
       
  1193                     
       
  1194                     // orientation updated, no need to check further
       
  1195                     return ETrue;
       
  1196                     }
       
  1197                 else
       
  1198                     {
       
  1199                     TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - modified ?");
       
  1200                     modifiedChanged = ((CThumbnailStore*)(*store))->CheckModifiedL(aItemId, aModified);
       
  1201                     
       
  1202                     if (modifiedChanged)
       
  1203                         {
       
  1204                         TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - modified YES");
       
  1205                         
       
  1206                         // delete old thumbs
       
  1207                         ((CThumbnailStore*)(*store))->DeleteThumbnailsL(aItemId);
       
  1208                         
       
  1209                         // need to create new thumbs
       
  1210                         return EFalse;
       
  1211                         }
       
  1212                     else
       
  1213                         {
       
  1214                         TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - modified NO");
       
  1215                         
       
  1216                         // not modified
       
  1217                         return ETrue;
       
  1218                         }
       
  1219                     }
       
  1220                 }
       
  1221             
       
  1222             }                 
       
  1223          // move to new store
       
  1224          else if (err == KErrNone && *store != newstore)
       
  1225             {
       
  1226             RArray < TThumbnailDatabaseData* >* thumbnails = NULL;
       
  1227             thumbnails = new (ELeave) RArray < TThumbnailDatabaseData* >;
       
  1228             CleanupClosePushL( *thumbnails );
       
  1229             ((CThumbnailStore*)(*store))->FetchThumbnailsL(aItemId, *thumbnails);
       
  1230             newstore->StoreThumbnailsL(aPath, *thumbnails);
       
  1231             ((CThumbnailStore*)(*store))->DeleteThumbnailsL(aItemId);
       
  1232             CleanupStack::PopAndDestroy( thumbnails);
       
  1233             delete thumbnails;
       
  1234             thumbnails = NULL;
       
  1235             
       
  1236             TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - moved to different store");
       
  1237             
       
  1238             // no need to check further
       
  1239             return ETrue;
       
  1240             }
       
  1241          
       
  1242          store = iter.NextValue();
       
  1243          } 
       
  1244     
       
  1245     TN_DEBUG1( "CThumbnailServer::UpdateThumbnailsL() - no thumbs found, create new");
       
  1246     
       
  1247     return EFalse;
       
  1248     }
       
  1249 
       
  1250 // -----------------------------------------------------------------------------
       
  1251 // CThumbnailServer::MimeTypeFromFileExt()
       
  1252 // -----------------------------------------------------------------------------
       
  1253 //
       
  1254 TInt CThumbnailServer::MimeTypeFromFileExt( const TDesC& aFileName, TDataType& aMimeType )
       
  1255     {
       
  1256     TBool found = ETrue;
       
  1257     TParsePtrC parse( aFileName );
       
  1258     TPtrC ext( parse.Ext() );
       
  1259     
       
  1260     if ( ext.CompareF( KJpegExt ) == 0 || ext.CompareF( KJpgExt ) == 0)
       
  1261         {
       
  1262         aMimeType = TDataType( KJpegMime );
       
  1263         }
       
  1264     else if ( ext.CompareF( KJpeg2000Ext ) == 0 )
       
  1265         {
       
  1266         aMimeType = TDataType( KJpeg2000Mime );
       
  1267         }
       
  1268     else if ( ext.CompareF( KSvgExt ) == 0 )
       
  1269         {
       
  1270         aMimeType = TDataType( KSvgMime );
       
  1271         }    
       
  1272     else if ( ext.CompareF( KGifExt ) == 0 )
       
  1273         {
       
  1274         aMimeType = TDataType( KGifMime );
       
  1275         } 
       
  1276     else if ( ext.CompareF( KPngExt ) == 0 )
       
  1277         {
       
  1278         aMimeType = TDataType( KPngMime );
       
  1279         }
       
  1280     else if ( ext.CompareF( KMpgExt1 ) == 0 )
       
  1281         {
       
  1282         aMimeType = TDataType( KMpgMime1 );
       
  1283         } 
       
  1284     else if ( ext.CompareF( KMpeg4Ext ) == 0 )
       
  1285         {
       
  1286         aMimeType = TDataType( KMpeg4Mime );
       
  1287         } 
       
  1288     else if ( ext.CompareF( KMp4Ext ) == 0 )
       
  1289         {
       
  1290         aMimeType = TDataType( KMp4Mime );
       
  1291         } 
       
  1292     else if ( ext.CompareF( KAviExt ) == 0 )
       
  1293         {
       
  1294         aMimeType = TDataType( KAviMime );
       
  1295         }
       
  1296     else if ( ext.CompareF( KMp3Ext ) == 0 )
       
  1297         {
       
  1298         aMimeType = TDataType( KMp3Mime );
       
  1299         } 
       
  1300     else if ( ext.CompareF( KNonEmbeddArtExt ) == 0 )
       
  1301         {
       
  1302         aMimeType = TDataType( KNonEmbeddArtMime );
       
  1303         }
       
  1304     else if ( ext.CompareF( KAacExt ) == 0 )
       
  1305         {
       
  1306         aMimeType = TDataType( KAacMime );
       
  1307         }   
       
  1308     else if ( ext.CompareF( KWmaExt ) == 0 )
       
  1309         {
       
  1310         aMimeType = TDataType( KWmaMime );
       
  1311         } 
       
  1312     else if ( ext.CompareF( KBmpExt ) == 0 )
       
  1313         {
       
  1314         aMimeType = TDataType( KBmpMime );
       
  1315         }
       
  1316     else if ( ext.CompareF( K3gpExt ) == 0 )
       
  1317         {
       
  1318         aMimeType = TDataType( KVideo3gppMime );
       
  1319         } 
       
  1320     else if ( ext.CompareF( KAmrExt ) == 0 )
       
  1321         {
       
  1322         aMimeType = TDataType( KAudioAmrMime );
       
  1323         }
       
  1324     else if ( ext.CompareF( KWmvExt ) == 0 )
       
  1325         {
       
  1326         aMimeType = TDataType( KVideoWmvMime );
       
  1327         } 
       
  1328     else if ( ext.CompareF( KRealAudioExt ) == 0 )
       
  1329         {
       
  1330         aMimeType = TDataType( KRealAudioMime );
       
  1331         }
       
  1332     else if ( ext.CompareF( KPmRealAudioPluginExt ) == 0 )
       
  1333         {
       
  1334         aMimeType = TDataType( KPmRealAudioPluginMime );
       
  1335         } 
       
  1336     else if ( ext.CompareF( KRealVideoExt ) == 0 )
       
  1337         {
       
  1338         aMimeType = TDataType( KRealVideoMime );
       
  1339         }
       
  1340     else if ( ext.CompareF( KM4aExt ) == 0 )
       
  1341         {
       
  1342         aMimeType = TDataType( KM4aMime);
       
  1343         }
       
  1344     else if ( ext.CompareF( KM4vExt ) == 0 )
       
  1345         {
       
  1346         aMimeType = TDataType( KMp4Mime);
       
  1347         }
       
  1348     else if ( ext.CompareF( KPmRealVideoPluginExt ) == 0 )
       
  1349         {
       
  1350         aMimeType = TDataType( KPmRealVideoPluginMime );
       
  1351         }
       
  1352     else if ( ext.CompareF( KPmRealVbVideoPluginExt ) == 0 )
       
  1353         {
       
  1354         aMimeType = TDataType( KPmRealVbVideoPluginMime );
       
  1355         }
       
  1356     else if ( ext.CompareF( KFlashVideoExt ) == 0 )
       
  1357         {
       
  1358         aMimeType = TDataType( KFlashVideoMime );
       
  1359         } 
       
  1360     else if ( ext.CompareF( KMatroskaVideoExt ) == 0 )
       
  1361         {
       
  1362         aMimeType = TDataType( KMatroskaVideoMime );
       
  1363         } 
       
  1364     else
       
  1365         {
       
  1366         aMimeType = TDataType( KNullDesC8 );
       
  1367         found = EFalse;
       
  1368         }
       
  1369     
       
  1370     if (found)
       
  1371         {
       
  1372         return KErrNone;
       
  1373         }
       
  1374     
       
  1375     return KErrNotFound;
       
  1376     }
       
  1377 
       
  1378 // -----------------------------------------------------------------------------
       
  1379 // CThumbnailServer::SourceTypeFromMimeType()
       
  1380 // -----------------------------------------------------------------------------
       
  1381 //
       
  1382 TInt CThumbnailServer::SourceTypeFromMimeType( const TDataType& aMimeType )
       
  1383     {
       
  1384     const TPtrC8 mimeType = aMimeType.Des8();
       
  1385   
       
  1386     TInt separatorPos = mimeType.Locate( KThumbnailMimeSeparatorChar );
       
  1387     TPtrC8 mediaType( mimeType.Left( separatorPos ));
       
  1388 
       
  1389     if (mediaType.Compare(KThumbnailMimeImage) == 0)
       
  1390         {
       
  1391         return TThumbnailPersistentSize::EImage;
       
  1392         }
       
  1393     else if (mediaType.Compare(KThumbnailMimeVideo) == 0)
       
  1394         {
       
  1395         return TThumbnailPersistentSize::EVideo;
       
  1396         }
       
  1397     else if (mediaType.Compare(KThumbnailMimeAudio) == 0)
       
  1398         {
       
  1399         return TThumbnailPersistentSize::EAudio;
       
  1400         }
       
  1401 
       
  1402     return TThumbnailPersistentSize::EUnknownSourceType;        
       
  1403     }
       
  1404 
       
  1405 // -----------------------------------------------------------------------------
       
  1406 // CThumbnailServer::SourceTypeFromSizeType()
       
  1407 // -----------------------------------------------------------------------------
       
  1408 //
       
  1409 TInt CThumbnailServer::SourceTypeFromSizeType( const TInt aSizeType )
       
  1410     {
       
  1411     TInt sourceType = 0;
       
  1412     
       
  1413     switch (aSizeType)
       
  1414         {
       
  1415         case EImageGridThumbnailSize:
       
  1416         case EImageListThumbnailSize:
       
  1417         case EImageFullScreenThumbnailSize:
       
  1418             sourceType = TThumbnailPersistentSize::EImage;
       
  1419             break;
       
  1420         case EVideoGridThumbnailSize:
       
  1421         case EVideoListThumbnailSize:
       
  1422         case EVideoFullScreenThumbnailSize:  
       
  1423             sourceType = TThumbnailPersistentSize::EVideo;
       
  1424             break;
       
  1425         case EAudioGridThumbnailSize:
       
  1426         case EAudioListThumbnailSize:
       
  1427         case EAudioFullScreenThumbnailSize:
       
  1428             sourceType = TThumbnailPersistentSize::EAudio;
       
  1429             break;
       
  1430         default:
       
  1431             sourceType = TThumbnailPersistentSize::EUnknownSourceType;  
       
  1432         }
       
  1433     
       
  1434     return sourceType;
       
  1435     }
       
  1436 
       
  1437 // -----------------------------------------------------------------------------
       
  1438 // CThumbnailServer::SupportedMimeType()
       
  1439 // -----------------------------------------------------------------------------
       
  1440 //
       
  1441 TBool CThumbnailServer::SupportedMimeType( const TDataType& aMimeType )
       
  1442     {
       
  1443     const TPtrC8 mimeType = aMimeType.Des8();
       
  1444     
       
  1445     if ( mimeType.CompareF( KJpegMime ) == 0 || 
       
  1446          mimeType.CompareF( KJpeg2000Mime ) == 0 ||
       
  1447          mimeType.CompareF( KGifMime ) == 0 ||
       
  1448          mimeType.CompareF( KPngMime ) == 0 ||
       
  1449          mimeType.CompareF( KBmpMime ) == 0 ||
       
  1450          mimeType.CompareF( KMpgMime1 ) == 0 ||
       
  1451          mimeType.CompareF( KMpeg4Mime ) == 0 ||
       
  1452          mimeType.CompareF( KMp4Mime ) == 0 ||
       
  1453          mimeType.CompareF( KAviMime ) == 0 ||
       
  1454          mimeType.CompareF( KVideo3gppMime ) == 0 ||
       
  1455          mimeType.CompareF( KVideoWmvMime ) == 0 ||
       
  1456          mimeType.CompareF( KRealVideoMime ) == 0 ||
       
  1457          mimeType.CompareF( KMp3Mime ) == 0 ||
       
  1458          mimeType.CompareF( KAacMime ) == 0 ||
       
  1459          mimeType.CompareF( KWmaMime ) == 0 ||
       
  1460          mimeType.CompareF( KAudioAmrMime ) == 0 ||
       
  1461          mimeType.CompareF( KRealAudioMime ) == 0 ||
       
  1462          mimeType.CompareF( KM4aMime ) == 0  ||
       
  1463          mimeType.CompareF( KFlashVideoMime ) == 0 ||
       
  1464          mimeType.CompareF( KPmRealVideoPluginMime ) == 0 ||
       
  1465          mimeType.CompareF( KPmRealVbVideoPluginMime ) == 0 ||
       
  1466          mimeType.CompareF( KPmRealAudioPluginMime ) == 0 )
       
  1467         {
       
  1468         return ETrue;
       
  1469         }
       
  1470     
       
  1471     return EFalse;
       
  1472     }
       
  1473 
       
  1474 // -----------------------------------------------------------------------------
       
  1475 // CThumbnailServer::GetMdESession()
       
  1476 // -----------------------------------------------------------------------------
       
  1477 //
       
  1478 CMdESession* CThumbnailServer::GetMdESession()
       
  1479     {
       
  1480     return iMdESession;
       
  1481     }
       
  1482 
       
  1483 
       
  1484 // -----------------------------------------------------------------------------
       
  1485 // E32Main()
       
  1486 // -----------------------------------------------------------------------------
       
  1487 //
       
  1488 TInt E32Main()
       
  1489     {
       
  1490     __UHEAP_MARK;
       
  1491     CTrapCleanup* cleanup = CTrapCleanup::New();
       
  1492     TInt result = KErrNoMemory;
       
  1493     if ( cleanup )
       
  1494         {
       
  1495         TRAP( result, CThumbnailServer::ThreadFunctionL());
       
  1496         TN_DEBUG2( 
       
  1497             "CThumbnailServer::E32Main() -- thread function out, result=%d",
       
  1498             result );
       
  1499         delete cleanup;
       
  1500         }
       
  1501     if ( result != KErrNone )
       
  1502         {
       
  1503         // Signal the client that server creation failed
       
  1504         TN_DEBUG1( "CThumbnailServer::E32Main() -- Rendezvous() in" );
       
  1505         RProcess::Rendezvous( result );
       
  1506         TN_DEBUG1( "CThumbnailServer::E32Main() -- Rendezvous() out" );
       
  1507         }
       
  1508 
       
  1509     __UHEAP_MARKEND;
       
  1510     return result;
       
  1511     }
       
  1512 
       
  1513 // -----------------------------------------------------------------------------
       
  1514 // Updates ID for thumbnails with given Path
       
  1515 // -----------------------------------------------------------------------------
       
  1516 //
       
  1517 void CThumbnailServer::UpdateIDL( const TDesC& aPath, const TThumbnailId aNewId )
       
  1518     {
       
  1519     TN_DEBUG3( "CThumbnailServer::UpdateIDL() aPath = %S aId = %d", &aPath, aNewId);
       
  1520     
       
  1521     CThumbnailStore* store = StoreForPathL( aPath );
       
  1522     User::LeaveIfNull( store );
       
  1523     store->UpdateStoreL( aPath, aNewId );
       
  1524     }
       
  1525 
       
  1526 // -----------------------------------------------------------------------------
       
  1527 // Closes stores for removable drives
       
  1528 // -----------------------------------------------------------------------------
       
  1529 //
       
  1530 
       
  1531 void CThumbnailServer::CloseRemovableDrivesL()
       
  1532     {
       
  1533     TDriveList driveList;
       
  1534     TInt drive; 
       
  1535     TDriveInfo driveInfo;
       
  1536     iFormatting = ETrue;    
       
  1537         
       
  1538     User::LeaveIfError( iFs.DriveList(driveList) );
       
  1539        
       
  1540     // search all drives
       
  1541     for( drive = EDriveA; drive <= EDriveZ; drive++ )
       
  1542         {
       
  1543         if( !driveList[drive] ) 
       
  1544            {
       
  1545            // If drive-list entry is zero, drive is not available
       
  1546            continue;
       
  1547            }
       
  1548             
       
  1549         TInt err = iFs.Drive(driveInfo, drive);
       
  1550             
       
  1551         // if removable drive, close store
       
  1552         if (!err && driveInfo.iDriveAtt& KDriveAttRemovable)
       
  1553             {
       
  1554             TN_DEBUG2( "CThumbnailServer::CloseRemovableDrive drive=%d", drive);
       
  1555             CloseStoreForDriveL(drive);
       
  1556             }
       
  1557         }
       
  1558     iProcessor->RemoveAllTasks();
       
  1559     }
       
  1560 
       
  1561 // -----------------------------------------------------------------------------
       
  1562 // Open Stores for removable drives
       
  1563 // -----------------------------------------------------------------------------
       
  1564 //
       
  1565 
       
  1566 void CThumbnailServer::OpenRemovableDrivesL()
       
  1567     {
       
  1568     TDriveList driveList;
       
  1569     TInt drive; 
       
  1570     TDriveInfo driveInfo;
       
  1571     iFormatting = EFalse;    
       
  1572         
       
  1573     User::LeaveIfError( iFs.DriveList(driveList) );
       
  1574        
       
  1575     // search all drives
       
  1576     for( drive = EDriveA; drive <= EDriveZ; drive++ )
       
  1577         {
       
  1578         if( !driveList[drive] ) 
       
  1579            {
       
  1580            // If drive-list entry is zero, drive is not available
       
  1581            continue;
       
  1582            }
       
  1583             
       
  1584         TInt err = iFs.Drive(driveInfo, drive);
       
  1585             
       
  1586         // if removable drive, open store
       
  1587         if (!err && driveInfo.iDriveAtt& KDriveAttRemovable)
       
  1588             {
       
  1589             TN_DEBUG2( "CThumbnailServer::OpenRemovableDrive drive=%d", drive);
       
  1590             StoreForDriveL(drive);
       
  1591             }
       
  1592         }
       
  1593     }
       
  1594 
       
  1595 // -----------------------------------------------------------------------------
       
  1596 // Is formatting ongoing
       
  1597 // -----------------------------------------------------------------------------
       
  1598 //
       
  1599 
       
  1600 TBool CThumbnailServer::IsFormatting()
       
  1601     {
       
  1602     return iFormatting;
       
  1603     }
       
  1604