mmappcomponents/mmmtpdataprovider/mmmtpdpplugins/mediamtpdataprovider/src/cmediamtpdataproviderenumerator.cpp
changeset 25 d881023c13eb
parent 0 a2952bb97e68
child 32 edd273b3192a
equal deleted inserted replaced
21:a05c44bc3c61 25:d881023c13eb
    28 #include "mmmtpdplogger.h"
    28 #include "mmmtpdplogger.h"
    29 #include "mmmtpdputility.h"
    29 #include "mmmtpdputility.h"
    30 #include "cmmmtpdpaccesssingleton.h"
    30 #include "cmmmtpdpaccesssingleton.h"
    31 #include "cmmmtpdpmetadataaccesswrapper.h"
    31 #include "cmmmtpdpmetadataaccesswrapper.h"
    32 
    32 
       
    33 
       
    34 #if defined(_DEBUG) || defined(MMMTPDP_PERFLOG)
       
    35 _LIT( KDirectoryScan, "DirectoryScan" );
       
    36 _LIT( KFormatFilter, "FormatFilter" );
       
    37 _LIT( KObjectManagerObjectUid, "ObjectManagerObjectUid" );
       
    38 _LIT( KObjectManagerInsert, "ObjectManagerInsert" );
       
    39 #endif
       
    40 
    33 // Unit: microsecond
    41 // Unit: microsecond
    34 const TInt KThresholdOfEnumerationLoopDuration = 1000 * 1000; // microsecond
    42 const TInt KThresholdOfEnumerationLoopDuration = 1000 * 1000; // microsecond
    35 
    43 
    36 const TInt KMTPDriveGranularity = 5;
    44 const TInt KMTPDriveGranularity = 5;
    37 const TInt KMediaDpArrayGranularity = 2;
    45 const TInt KMediaDpArrayGranularity = 2;
   185         User::Invariant() );
   193         User::Invariant() );
   186 
   194 
   187     TFileName root( storage.DesC( CMTPStorageMetaData::EStorageSuid ) );
   195     TFileName root( storage.DesC( CMTPStorageMetaData::EStorageSuid ) );
   188     PRINT2( _L("MM MTP <> CMediaMtpDataProviderEnumerator::ScanStorageL aStorageId = 0x%x, StorageSuid = %S"), aStorageId, &root );
   196     PRINT2( _L("MM MTP <> CMediaMtpDataProviderEnumerator::ScanStorageL aStorageId = 0x%x, StorageSuid = %S"), aStorageId, &root );
   189 
   197 
   190     iParentHandle = KMTPHandleNone;
   198     iParentHandle = KMTPHandleNoParent;
   191     iPath.Set( root, NULL, NULL);
   199     iPath.Set( root, NULL, NULL);
   192     iDir.Close();
   200     iDir.Close();
   193     User::LeaveIfError( iDir.Open( iFramework.Fs(),
   201     User::LeaveIfError( iDir.Open( iFramework.Fs(),
   194         iPath.DriveAndPath(),
   202         iPath.DriveAndPath(),
   195         KEntryAttNormal | KEntryAttDir ) );
   203         KEntryAttNormal | KEntryAttDir ) );
   209         {
   217         {
   210         // Round trip suppport
   218         // Round trip suppport
   211         const CMTPStorageMetaData& storage( iFramework.StorageMgr().StorageL( iStorages[0] ) );
   219         const CMTPStorageMetaData& storage( iFramework.StorageMgr().StorageL( iStorages[0] ) );
   212         TFileName root( storage.DesC( CMTPStorageMetaData::EStorageSuid ) );
   220         TFileName root( storage.DesC( CMTPStorageMetaData::EStorageSuid ) );
   213         GetModifiedContentL( root );
   221         GetModifiedContentL( root );
   214         iDataProvider.GetWrapperL().UpdateMusicCollectionL();
   222         TRAPD( err, iDataProvider.GetWrapperL().UpdateMusicCollectionL() );
       
   223         if ( err != KErrNone )
       
   224             {
       
   225             PRINT1( _L("MM MTP <> ScanNextStorageL, UpdateMusicCollectionL err =%d "), err );            
       
   226             }
   215 
   227 
   216         iStorages.Remove( 0 );
   228         iStorages.Remove( 0 );
   217         ScanStorageL( iStorages[0] );
   229         ScanStorageL( iStorages[0] );
   218         }
   230         }
   219     else
   231     else
   220         {
   232         {
   221 
       
   222         // Round trip suppport
   233         // Round trip suppport
   223         const CMTPStorageMetaData& storage( iFramework.StorageMgr().StorageL( iStorages[0] ) );
   234         const CMTPStorageMetaData& storage( iFramework.StorageMgr().StorageL( iStorages[0] ) );
   224         TFileName root( storage.DesC( CMTPStorageMetaData::EStorageSuid ) );
   235         TFileName root( storage.DesC( CMTPStorageMetaData::EStorageSuid ) );
   225         GetModifiedContentL( root );
   236         GetModifiedContentL( root );
   226 
   237 
   281                 iPath.PopDir();
   292                 iPath.PopDir();
   282                 iDirStack.Remove( count - 1 );
   293                 iDirStack.Remove( count - 1 );
   283                 delete entry;
   294                 delete entry;
   284                 entry = NULL;
   295                 entry = NULL;
   285                 iDir.Close();
   296                 iDir.Close();
   286     
   297 
   287                 // Scan the next directory of the parent
   298                 // Scan the next directory of the parent
   288                 ScanNextDirL();
   299                 ScanNextDirL();
   289                 }
   300                 }
   290             // Going into a subdirectory of current
   301             // Going into a subdirectory of current
   291             else
   302             else
   312     PRINT( _L( "MM MTP => CMediaMtpDataProviderEnumerator::ScanNextSubdirL" ) );
   323     PRINT( _L( "MM MTP => CMediaMtpDataProviderEnumerator::ScanNextSubdirL" ) );
   313 
   324 
   314     // A empty (non-constructed) TEntry is our marker telling us to pop a directory
   325     // A empty (non-constructed) TEntry is our marker telling us to pop a directory
   315     // from iPath when we see this
   326     // from iPath when we see this
   316     TEntry* entry = new TEntry( TEntry() );
   327     TEntry* entry = new TEntry( TEntry() );
   317     
   328 
   318     User::LeaveIfNull( entry );
   329     User::LeaveIfNull( entry );
   319     
   330 
   320     iDirStack.AppendL( entry );
   331     iDirStack.AppendL( entry );
   321 
   332 
   322     // Leave with KErrNotFound if we don't find the object handle since it shouldn't be on the
   333     // Leave with KErrNotFound if we don't find the object handle since it shouldn't be on the
   323     // dirstack if the entry wasn't added
   334     // dirstack if the entry wasn't added
   324     TPtrC suid = iPath.DriveAndPath().Left( iPath.DriveAndPath().Length() );
   335     TPtrC suid = iPath.DriveAndPath().Left( iPath.DriveAndPath().Length() );
   325     // Update the current parenthandle with object of the directory
   336     // Update the current parenthandle with object of the directory
   326     PERFLOGSTART( KObjectManagerObjectUid );
   337     PERFLOGSTART( KObjectManagerObjectUid );
   327     iParentHandle = iFramework.ObjectMgr().HandleL( suid );
   338     iParentHandle = iFramework.ObjectMgr().HandleL( suid );
   328     PERFLOGSTOP( KObjectManagerObjectUid );
   339     PERFLOGSTOP( KObjectManagerObjectUid );
   329     PRINT1( _L( "MM MTP <> iParentHandle = 0x%Lx" ), iParentHandle );
   340     PRINT1( _L( "MM MTP <> iParentHandle = 0x%x" ), iParentHandle );
   330 
   341 
   331     // Kick-off a scan of the next directory
   342     // Kick-off a scan of the next directory
   332     iDir.Close();
   343     iDir.Close();
   333 
   344 
   334     TInt err = iDir.Open( iFramework.Fs(),
   345     TInt err = iDir.Open( iFramework.Fs(),
   410 //
   421 //
   411 // -----------------------------------------------------------------------------
   422 // -----------------------------------------------------------------------------
   412 //
   423 //
   413 TInt CMediaMtpDataProviderEnumerator::RunError( TInt aError )
   424 TInt CMediaMtpDataProviderEnumerator::RunError( TInt aError )
   414     {
   425     {
   415     PRINT1( _L( "MM MTP <> CMediaMtpDataProviderEnumerator::RunError with error %d" ), aError );
   426     if ( aError != KErrNone )
       
   427         PRINT1( _L( "MM MTP <> CMediaMtpDataProviderEnumerator::RunError with error %d" ), aError );
   416 
   428 
   417     TRAP_IGNORE( SignalCompleteL( iDataProvider ) );
   429     TRAP_IGNORE( SignalCompleteL( iDataProvider ) );
   418 
   430 
   419     return KErrNone;
   431     return KErrNone;
   420     }
   432     }
   459 //
   471 //
   460 void CMediaMtpDataProviderEnumerator::ProcessEntriesL()
   472 void CMediaMtpDataProviderEnumerator::ProcessEntriesL()
   461     {
   473     {
   462     PRINT( _L( "MM MTP => CMediaMtpDataProviderEnumerator::ProcessEntriesL" ) );
   474     PRINT( _L( "MM MTP => CMediaMtpDataProviderEnumerator::ProcessEntriesL" ) );
   463 
   475 
   464     TBuf<KMaxFileName> path = iPath.DriveAndPath();
   476     TFileName path = iPath.DriveAndPath();
   465 
   477 
   466     while ( !IsOverThreshold() && iFirstUnprocessed < iEntries.Count() )
   478     while ( !IsOverThreshold() && iFirstUnprocessed < iEntries.Count() )
   467         {
   479         {
   468         const TEntry& entry = iEntries[iFirstUnprocessed];
   480         const TEntry& entry = iEntries[iFirstUnprocessed];
   469         path.Append( entry.iName );
       
   470         PRINT1( _L( "MM MTP <> path = %S" ), &path );
       
   471 
   481 
   472         TInt len = entry.iName.Length();
   482         TInt len = entry.iName.Length();
   473 
   483 
   474         if ( entry.IsDir() )
   484         // Skip object with too long name
   475             {
   485         if ( KMaxFileName >= path.Length() + len )
   476             path.Append( '\\' );
   486             {
   477             ++len;
   487             path.Append( entry.iName );
   478 
   488             PRINT1( _L( "MM MTP <> path = %S" ), &path );
   479             // we don't need to process folder, just remember
   489 
   480             // the folder
   490             if ( entry.IsDir() )
   481             TEntry* dirEntry = new TEntry( entry );
   491                 {
   482             User::LeaveIfNull( dirEntry );
   492                 path.Append( '\\' );
   483             iDirStack.AppendL( dirEntry );
   493                 ++len;
   484             }
   494 
   485         else if ( IsFileAccepted( path ) )
   495                 // we don't need to process folder, just remember
   486             {
   496                 // the folder
   487             AddEntryL( path );
   497                 TEntry* dirEntry = new TEntry( entry );
   488             }
   498                 User::LeaveIfNull( dirEntry );
   489 
   499                 iDirStack.AppendL( dirEntry );
   490         // Remove filename part
   500                 }
   491         path.SetLength( path.Length() - len );
   501             else if ( IsFileAccepted( path ) )
       
   502                 {
       
   503                 AddEntryL( path );
       
   504                 }
       
   505 
       
   506             // Remove filename part
       
   507             path.SetLength( path.Length() - len );
       
   508             }
   492 
   509 
   493         iFirstUnprocessed++;
   510         iFirstUnprocessed++;
   494         }
   511         }
   495 
   512 
   496     StartEnumerationCount();
   513     StartEnumerationCount();
   551 // Is the file format is supported by this Dp
   568 // Is the file format is supported by this Dp
   552 // -----------------------------------------------------------------------------
   569 // -----------------------------------------------------------------------------
   553 //
   570 //
   554 TBool CMediaMtpDataProviderEnumerator::IsFileAccepted( const TDesC& aFullFileName )
   571 TBool CMediaMtpDataProviderEnumerator::IsFileAccepted( const TDesC& aFullFileName )
   555     {
   572     {
   556     PERFLOGSTART(KFormatFilter);
   573     PERFLOGSTART( KFormatFilter );
   557     iFormatCode = GetObjectFormatCode( aFullFileName );
   574     iFormatCode = GetObjectFormatCode( aFullFileName );
   558     PRINT1( _L( "MM MTP <> CMediaMtpDataProviderEnumerator::IsFileAcceptedL formatCode = 0x%x" ), iFormatCode );
   575     PRINT1( _L( "MM MTP <> CMediaMtpDataProviderEnumerator::IsFileAcceptedL formatCode = 0x%x" ), iFormatCode );
   559     TBool accepted = EFalse;
   576     TBool accepted = EFalse;
   560     TInt count = sizeof( KMediaMtpDataProviderSupportedFormats ) / sizeof( TUint16 );
   577     TInt count = sizeof( KMediaMtpDataProviderSupportedFormats ) / sizeof( TUint16 );
   561     for ( TInt i = 0; i < count; i++ )
   578     for ( TInt i = 0; i < count; i++ )
   565             accepted = ETrue;
   582             accepted = ETrue;
   566             break;
   583             break;
   567             }
   584             }
   568         }
   585         }
   569 
   586 
   570     PERFLOGSTOP(KFormatFilter);
   587     PERFLOGSTOP( KFormatFilter );
   571     return accepted;
   588     return accepted;
   572     }
   589     }
   573 
   590 
   574 // -----------------------------------------------------------------------------
   591 // -----------------------------------------------------------------------------
   575 // CMediaDpMtpEnumerator::StartEnumerationCount
   592 // CMediaDpMtpEnumerator::StartEnumerationCount
   610     PRINT( _L( "MM MTP => CMediaMtpDataProviderEnumerator::GetModifiedContentL" ) );
   627     PRINT( _L( "MM MTP => CMediaMtpDataProviderEnumerator::GetModifiedContentL" ) );
   611     TInt arrayCount = 0;
   628     TInt arrayCount = 0;
   612     CDesCArray* modifiedContents = new ( ELeave ) CDesCArrayFlat( KMTPDriveGranularity );
   629     CDesCArray* modifiedContents = new ( ELeave ) CDesCArrayFlat( KMTPDriveGranularity );
   613     CleanupStack::PushL( modifiedContents ); // + modifiedContents
   630     CleanupStack::PushL( modifiedContents ); // + modifiedContents
   614 
   631 
   615     iDataProvider.GetWrapperL().GetModifiedContentL( aStorageRoot, arrayCount, *modifiedContents );
   632     TRAPD( err, iDataProvider.GetWrapperL().GetModifiedContentL( aStorageRoot, arrayCount, *modifiedContents ) );
       
   633     if ( err != KErrNone )
       
   634         PRINT1( _L("MM MTP <> GetModifiedContentL err =%d "), err );   
   616 
   635 
   617     if ( arrayCount > 0 )
   636     if ( arrayCount > 0 )
   618         {
   637         {
   619         CMTPObjectMetaData* object = CMTPObjectMetaData::NewLC();   // + object
   638         CMTPObjectMetaData* object = CMTPObjectMetaData::NewLC();   // + object
   620         for ( TInt i = 0; i < arrayCount; i++ )
   639         for ( TInt i = 0; i < arrayCount; i++ )