mmappcomponents/mmmtpdataprovider/mmmtpdpplugins/abstractmediamtpdataprovider/src/cabstractmediamtpdataproviderenumerator.cpp
changeset 32 edd273b3192a
parent 27 cbb1bfb7ebfb
child 35 2ee890d2f7e7
equal deleted inserted replaced
27:cbb1bfb7ebfb 32:edd273b3192a
    23 #include <mtp/mmtpstoragemgr.h>
    23 #include <mtp/mmtpstoragemgr.h>
    24 #include <mtp/mmtpreferencemgr.h>
    24 #include <mtp/mmtpreferencemgr.h>
    25 #include <mpxmediaarray.h>
    25 #include <mpxmediaarray.h>
    26 #include <mpxmedia.h>
    26 #include <mpxmedia.h>
    27 
    27 
    28 #include "abstractmediamtpdataproviderconst.h"
       
    29 #include "cabstractmediamtpdataproviderenumerator.h"
    28 #include "cabstractmediamtpdataproviderenumerator.h"
    30 #include "cabstractmediamtpdataprovider.h"
    29 #include "cabstractmediamtpdataprovider.h"
    31 #include "mmmtpdplogger.h"
    30 #include "mmmtpdplogger.h"
    32 #include "mmmtpdputility.h"
    31 #include "mmmtpdputility.h"
    33 #include "cmmmtpdpmetadataaccesswrapper.h"
    32 #include "cmmmtpdpmetadataaccesswrapper.h"
    34 #include "cmmmtpdpmetadatampxaccess.h"
       
    35 
    33 
    36 
    34 
    37 const TInt KMTPDriveGranularity = 5;
    35 const TInt KMTPDriveGranularity = 5;
    38 const TInt KAbstractMediaDpArrayGranularity = 2;
    36 const TInt KAbstractMediaDpArrayGranularity = 2;
    39 
    37 
    80     iDataProvider( aDataProvider ),
    78     iDataProvider( aDataProvider ),
    81     iStorages( KAbstractMediaDpArrayGranularity ),
    79     iStorages( KAbstractMediaDpArrayGranularity ),
    82     iAbstractMedias( NULL ),
    80     iAbstractMedias( NULL ),
    83     iCount( 0 ),
    81     iCount( 0 ),
    84     iCurrentIndex( 0 ),
    82     iCurrentIndex( 0 ),
    85     iEnumState ( EEnumPlaylist )
    83     iEnumState ( EEnumNone )
    86     {
    84     {
    87     PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::CAbstractMediaMtpDataProviderEnumerator, iDataProviderId = %d" ), iDataProviderId );
    85     PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::CAbstractMediaMtpDataProviderEnumerator, iDataProviderId = %d" ), iDataProviderId );
    88     }
    86     }
    89 
    87 
    90 // -----------------------------------------------------------------------------
    88 // -----------------------------------------------------------------------------
   148             iStorages.AppendL( storages[i]->Uint(
   146             iStorages.AppendL( storages[i]->Uint(
   149                 CMTPStorageMetaData::EStorageId ) );
   147                 CMTPStorageMetaData::EStorageId ) );
   150             }
   148             }
   151         CleanupStack::PopAndDestroy( &storages );   // - storages
   149         CleanupStack::PopAndDestroy( &storages );   // - storages
   152         }
   150         }
   153     else if ( aStorageId != KMTPNotSpecified32 )
   151     else if ( aStorageId != KMTPNotSpecified32
   154         {
   152             && storageMgr.ValidStorageId( aStorageId ) )
   155         __ASSERT_DEBUG( storageMgr.ValidStorageId( aStorageId ), User::Invariant() );
   153         {
   156         const CMTPStorageMetaData& storage(
   154         const CMTPStorageMetaData& storage(
   157              storageMgr.StorageL( aStorageId ) );
   155              storageMgr.StorageL( aStorageId ) );
   158         if ( storage.Uint( CMTPStorageMetaData::EStorageSystemType ) ==
   156         if ( storage.Uint( CMTPStorageMetaData::EStorageSystemType ) ==
   159                 CMTPStorageMetaData::ESystemTypeDefaultFileSystem )
   157                 CMTPStorageMetaData::ESystemTypeDefaultFileSystem )
   160             {
   158             {
   179             }
   177             }
   180         }
   178         }
   181 
   179 
   182     // keep in mind for notification when enumeration complete
   180     // keep in mind for notification when enumeration complete
   183     iStorageId = aStorageId;
   181     iStorageId = aStorageId;
   184     iEnumState = EEnumPlaylist;
   182     iEnumState = EEnumNone;
   185     if ( iStorages.Count() > 0 )
       
   186         {
       
   187         InitStorageL();
       
   188         }
       
   189     ScanNextL();
   183     ScanNextL();
   190 
   184 
   191     PRINT( _L( "MM MTP <= CAbstractMediaMtpDataProviderEnumerator::StartL" ) );
   185     PRINT( _L( "MM MTP <= CAbstractMediaMtpDataProviderEnumerator::StartL" ) );
   192     }
   186     }
   193 
   187 
   267 // Proceed to next abstract media item
   261 // Proceed to next abstract media item
   268 // -----------------------------------------------------------------------------
   262 // -----------------------------------------------------------------------------
   269 //
   263 //
   270 void CAbstractMediaMtpDataProviderEnumerator::ScanNextL()
   264 void CAbstractMediaMtpDataProviderEnumerator::ScanNextL()
   271     {
   265     {
   272     while ( iStorages.Count() > 0 )
   266     PRINT( _L( "MM MTP => CAbstractMediaMtpDataProviderEnumerator::ScanNextL" ) );
   273         {
   267 
   274         while ( iEnumState < EEnumCount )
   268     if ( iCurrentIndex >= iCount )
   275             {
   269         {
   276             if ( iCurrentIndex < iCount )
   270         iEnumState++;
   277                 {
   271         }
   278                 TRequestStatus* status = &iStatus;
   272 
   279                 User::RequestComplete( status, iStatus.Int() );
   273     if ( iEnumState >= EEnumCount )
   280                 SetActive();
   274         {
   281                 PRINT2( _L( "MM MTP <> Current storage is still being scanned, current index = %d, total AbstractMedia count = %d" ),
   275         iEnumState = EEnumPlaylist;
   282                     iCurrentIndex,
   276         iStorages.Remove( 0 );
   283                     iCount );
   277         }
   284                 return;
   278 
   285                 }
   279     if ( iStorages.Count() > 0 )
   286             ++iEnumState;
   280         {
   287             if ( iEnumState == EEnumCount )
   281         if( iCurrentIndex >= iCount )
   288                 {
   282             {
   289                 break;
       
   290                 }
       
   291             InitStorageL();
   283             InitStorageL();
   292             }
   284             }
   293 
   285 
   294         iStorages.Remove( 0 );
   286         TRequestStatus* status = &iStatus;
   295         if ( iStorages.Count() == 0 )
   287         User::RequestComplete( status, iStatus.Int() );
   296             {
   288         SetActive();
   297             break;
   289         }
   298             }
   290     else
   299         iEnumState = EEnumPlaylist;
   291         {
   300         InitStorageL();
   292         // We are done
   301         }
   293         PRINT( _L( "MM MTP <> Objects enumeration completed" ) );
   302     // We are done
   294         delete iAbstractMedias;
   303     PRINT( _L( "MM MTP <> Objects enumeration completed" ) );
   295         iAbstractMedias = NULL;
   304     delete iAbstractMedias;
   296         iStorages.Reset();
   305     iAbstractMedias = NULL;
   297         SignalCompleteL( iDataProvider );
   306     iStorages.Reset();
   298         }
   307     SignalCompleteL( iDataProvider );
   299 
       
   300     PRINT( _L( "MM MTP <= CAbstractMediaMtpDataProviderEnumerator::ScanNextL" ) );   
   308     }
   301     }
   309 
   302 
   310 // -----------------------------------------------------------------------------
   303 // -----------------------------------------------------------------------------
   311 // CAbstractMediaMtpDataProviderEnumerator::RunL
   304 // CAbstractMediaMtpDataProviderEnumerator::RunL
   312 // NOTE: preserve for performance improvement
   305 // NOTE: preserve for performance improvement
   313 // -----------------------------------------------------------------------------
   306 // -----------------------------------------------------------------------------
   314 //
   307 //
   315 void CAbstractMediaMtpDataProviderEnumerator::RunL()
   308 void CAbstractMediaMtpDataProviderEnumerator::RunL()
   316     {
   309     {
   317     // insert all abstract medias into handle db of framework
   310     PRINT( _L( "MM MTP => CAbstractMediaMtpDataProviderEnumerator::RunL" ) );
   318     CMPXMedia* media = ( *iAbstractMedias )[iCurrentIndex];
   311     if ( iCurrentIndex < iCount )
   319     
   312         {
   320     // Increase the index first in case of leave
   313         PRINT2( _L( "MM MTP <> Current storage is still being scanned, current index = %d, total AbstractMedia count = %d" ),
   321     iCurrentIndex++;
   314             iCurrentIndex,
   322     TMPXGeneralCategory category = ( iEnumState == EEnumPlaylist ) ? EMPXPlaylist : EMPXAbstractAlbum;
   315             iCount );
   323     HBufC* abstractMedia = iDataProvider.GetWrapperL().GetAbstractMediaNameL( media, category );
   316         // insert all abstract medias into handle db of framework
   324     CleanupStack::PushL( abstractMedia ); // + abstractMedia
   317         CMPXMedia* media = ( *iAbstractMedias )[iCurrentIndex];
   325     TBool ret = ETrue;
   318 
   326     if ( iEnumState == EEnumAbstractAlbum )
   319         // Increase the index first in case of leave
   327         {
   320         iCurrentIndex++;
   328         //The abstract album may be removed, check it first
   321         TMPXGeneralCategory category = ( iEnumState == EEnumPlaylist ) ? EMPXPlaylist : EMPXAbstractAlbum;
   329         ret = BaflUtils::FileExists( iFramework.Fs(), *abstractMedia );
   322         HBufC* abstractMedia = iDataProvider.GetWrapperL().GetAbstractMediaNameL( media, category );
   330         PRINT2( _L( "MM MTP <> BaflUtils::FileExists( RFs,%S ) ret = %d" ), abstractMedia, ret );
   323         CleanupStack::PushL( abstractMedia ); // + abstractMedia
   331         }
   324 
   332 
   325         TBool ret = ETrue;
   333     if ( ret )
   326         if ( iEnumState == EEnumAbstractAlbum )
   334         {
   327             {
   335         PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::RunL abstractMedia=%S" ), abstractMedia );
   328             // The abstract album may be removed, check it first
   336         AddEntryL( *abstractMedia );
   329             ret = BaflUtils::FileExists( iFramework.Fs(), *abstractMedia );
   337 
   330             PRINT2( _L( "MM MTP <> BaflUtils::FileExists( RFs,%S ) ret = %d" ), abstractMedia, ret );
   338         // find all reference of each abstract media
   331             }
   339         CDesCArray* references = new ( ELeave ) CDesCArrayFlat( KMTPDriveGranularity );
   332         else // EEnumPlaylist
   340         CleanupStack::PushL( references ); // + references
   333             {
   341     
   334             // Add an object to the object store for DB based playlist
   342         PERFLOGSTART( KMpxQueryAbstractMediaReference );
   335             AddEntryL( *abstractMedia );
   343         iDataProvider.GetWrapperL().GetAllReferenceL( media, *references );
   336             }
   344         PERFLOGSTOP( KMpxQueryAbstractMediaReference );
   337 
   345     
   338         if ( ret )
   346         // insert references into reference db
   339             {
   347         AddReferencesL( *abstractMedia, *references );
   340             PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::RunL abstractMedia=%S" ), abstractMedia );
   348     
   341 
   349         CleanupStack::PopAndDestroy( references ); // - references
   342             // find all reference of each abstract media
   350         }     
   343             CDesCArray* references = new ( ELeave ) CDesCArrayFlat( KMTPDriveGranularity );
   351     CleanupStack::PopAndDestroy( abstractMedia ); // - abstractMedia
   344             CleanupStack::PushL( references ); // + references
       
   345 
       
   346             PERFLOGSTART( KMpxQueryAbstractMediaReference );
       
   347             iDataProvider.GetWrapperL().GetAllReferenceL( media, *references );
       
   348             PERFLOGSTOP( KMpxQueryAbstractMediaReference );
       
   349 
       
   350             // insert references into reference db
       
   351             AddReferencesL( *abstractMedia, *references );
       
   352 
       
   353             CleanupStack::PopAndDestroy( references ); // - references
       
   354             }
       
   355         CleanupStack::PopAndDestroy( abstractMedia ); // - abstractMedia
       
   356         }
   352 
   357 
   353     ScanNextL();
   358     ScanNextL();
       
   359     PRINT( _L( "MM MTP <= CAbstractMediaMtpDataProviderEnumerator::RunL" ) );
   354     }
   360     }
   355 
   361 
   356 // -----------------------------------------------------------------------------
   362 // -----------------------------------------------------------------------------
   357 // CAbstractMediaMtpDataProviderEnumerator::RunError
   363 // CAbstractMediaMtpDataProviderEnumerator::RunError
   358 // NOTE: preserve for performance improvement
   364 // NOTE: preserve for performance improvement
   361 TInt CAbstractMediaMtpDataProviderEnumerator::RunError( TInt aError )
   367 TInt CAbstractMediaMtpDataProviderEnumerator::RunError( TInt aError )
   362     {
   368     {
   363     if ( aError != KErrNone )
   369     if ( aError != KErrNone )
   364         PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::RunError with error %d" ), aError );
   370         PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::RunError with error %d" ), aError );
   365 
   371 
       
   372     TRAP_IGNORE( SignalCompleteL( iDataProvider ) );
   366     return KErrNone;
   373     return KErrNone;
   367     }
   374     }
   368 
   375 
   369 // -----------------------------------------------------------------------------
   376 // -----------------------------------------------------------------------------
   370 // CAbstractMediaMtpDataProviderEnumerator::DoCancel()
   377 // CAbstractMediaMtpDataProviderEnumerator::DoCancel()
   425             }
   432             }
   426         }
   433         }
   427 
   434 
   428     if ( parentHandle != KMTPHandleNone )
   435     if ( parentHandle != KMTPHandleNone )
   429         {
   436         {
   430         object->SetUint( CMTPObjectMetaData::EParentHandle, parentHandle );
   437         // Handle .m3u playlist like abstract playlist in two situations:
   431 
   438         // 1. The .m3u file is not on the file system.
   432         PERFLOGSTART( KObjectManagerInsert );
   439         // 2. The .m3u file is hidden and 0 size
   433         iObjectMgr.InsertObjectL( *object );
   440         TBool add = ETrue;
   434         PERFLOGSTOP( KObjectManagerInsert );
   441         if ( format == EMTPFormatCodeM3UPlaylist )
   435 
   442             {
   436         CleanupStack::PopAndDestroy( object );// - object
   443             TEntry entry;
   437 
   444             TInt err = iFramework.Fs().Entry( aSuid, entry );
   438         //Only remember the playlist file for clean up
   445             add = ( err != KErrNone) || ( entry.iSize == 0 && entry.IsHidden() );
   439         if( iEnumState == EEnumPlaylist )
   446             }
   440             {
   447 
       
   448         if ( add )
       
   449             {
       
   450             object->SetUint( CMTPObjectMetaData::EParentHandle, parentHandle );
       
   451 
       
   452             PERFLOGSTART( KObjectManagerInsert );
       
   453             iObjectMgr.InsertObjectL( *object );
       
   454             PERFLOGSTOP( KObjectManagerInsert );
       
   455 
       
   456             //Create the dummy file on file system
   441             iDataProvider.GetWrapperL().CreateDummyFile( aSuid );
   457             iDataProvider.GetWrapperL().CreateDummyFile( aSuid );
   442 
       
   443             // remember the abstract media file for clean up
   458             // remember the abstract media file for clean up
   444             iDataProvider.GetWrapperL().AddDummyFileL( aSuid );
   459             iDataProvider.GetWrapperL().AddDummyFileL( aSuid );
   445             }
   460             }
   446         }
   461         }
       
   462 
       
   463     CleanupStack::PopAndDestroy( object );// - object
   447 
   464 
   448     PRINT( _L( "MM MTP <= CAbstractMediaMtpDataProviderEnumerator::AddEntryL" ) );
   465     PRINT( _L( "MM MTP <= CAbstractMediaMtpDataProviderEnumerator::AddEntryL" ) );
   449     }
   466     }
   450 
   467 
   451 // -----------------------------------------------------------------------------
   468 // -----------------------------------------------------------------------------