mmappcomponents/mmmtpdataprovider/mmmtpdpplugins/mediamtpdataprovider/src/cmediamtpdataproviderenumerator.cpp
branchRCL_3
changeset 28 f56ec6ce2732
parent 14 05b0d2323768
child 34 e257e2b6459d
--- a/mmappcomponents/mmmtpdataprovider/mmmtpdpplugins/mediamtpdataprovider/src/cmediamtpdataproviderenumerator.cpp	Tue Apr 27 17:09:22 2010 +0300
+++ b/mmappcomponents/mmmtpdataprovider/mmmtpdpplugins/mediamtpdataprovider/src/cmediamtpdataproviderenumerator.cpp	Tue May 11 16:40:32 2010 +0300
@@ -20,27 +20,12 @@
 #include <mtp/mmtpobjectmgr.h>
 #include <mtp/mmtpstoragemgr.h>
 #include <mtp/cmtpobjectmetadata.h>
-#include <hal.h>
 
-#include "mediamtpdataproviderconst.h"
 #include "cmediamtpdataproviderenumerator.h"
 #include "cmediamtpdataprovider.h"
 #include "mmmtpdplogger.h"
-#include "mmmtpdputility.h"
-#include "cmmmtpdpaccesssingleton.h"
 #include "cmmmtpdpmetadataaccesswrapper.h"
 
-
-#if defined(_DEBUG) || defined(MMMTPDP_PERFLOG)
-_LIT( KDirectoryScan, "DirectoryScan" );
-_LIT( KFormatFilter, "FormatFilter" );
-_LIT( KObjectManagerObjectUid, "ObjectManagerObjectUid" );
-_LIT( KObjectManagerInsert, "ObjectManagerInsert" );
-#endif
-
-// Unit: microsecond
-const TInt KThresholdOfEnumerationLoopDuration = 1000 * 1000; // microsecond
-
 const TInt KMTPDriveGranularity = 5;
 const TInt KMediaDpArrayGranularity = 2;
 
@@ -73,14 +58,10 @@
     CMediaMtpDataProvider& aDataProvider ) :
         CActive( EPriorityLow ), // EPriorityStandard ? sure?
         iFramework( aFramework ),
-        iObjectMgr( aFramework.ObjectMgr() ),
-        iDataProviderId( aFramework.DataProviderId() ),
         iDataProvider( aDataProvider ),
-        iDirStack( KMediaDpArrayGranularity ),
-        iStorages( KMediaDpArrayGranularity ),
-        iScanningDir( EFalse )
+        iStorages( KMediaDpArrayGranularity )
     {
-    PRINT1( _L( "MM MTP <> CMediaMtpDataProviderEnumerator::CMediaMtpDataProviderEnumerator, iDataProviderId = %d" ), iDataProviderId );
+    PRINT1( _L( "MM MTP <> CMediaMtpDataProviderEnumerator::CMediaMtpDataProviderEnumerator, DataProviderId = %d" ), iFramework.DataProviderId() );
     }
 
 // -----------------------------------------------------------------------------
@@ -92,8 +73,6 @@
     {
     PRINT( _L( "MM MTP => CMediaMtpDataProviderEnumerator::~CMediaMtpDataProviderEnumerator" ) );
     Cancel();
-    iDir.Close();
-    iDirStack.Close();
     iStorages.Close();
 
 #if defined(_DEBUG) || defined(MMMTPDP_PERFLOG)
@@ -129,10 +108,9 @@
             }
         CleanupStack::PopAndDestroy( &storages ); // - storages
         }
-    else if ( aStorageId != KMTPNotSpecified32 )
+    else if ( aStorageId != KMTPNotSpecified32 
+            && storageMgr.ValidStorageId( aStorageId ) )
         {
-        __ASSERT_DEBUG( storageMgr.ValidStorageId( aStorageId ), User::Invariant() );
-
         const CMTPStorageMetaData& storage( storageMgr.StorageL( aStorageId ) );
 
         if ( storage.Uint( CMTPStorageMetaData::EStorageSystemType )
@@ -157,15 +135,9 @@
         }
 
     iStorageId = aStorageId;
-
-    if ( iStorages.Count() > 0 )
-        {
-        ScanStorageL( iStorages[0] );
-        }
-    else
-        {
-        SignalCompleteL( iDataProvider );
-        }
+    TRequestStatus* status = &iStatus;
+    User::RequestComplete( status, iStatus.Int() );
+    SetActive();
 
     PRINT( _L( "MM MTP <= CMediaMtpDataProviderEnumerator::StartL" ) );
     }
@@ -177,243 +149,38 @@
 //
 void CMediaMtpDataProviderEnumerator::DoCancel()
     {
-    iDir.Close();
-    }
-
-// -----------------------------------------------------------------------------
-// CMediaMtpDataProviderEnumerator::ScanStorageL
-//
-// -----------------------------------------------------------------------------
-//
-void CMediaMtpDataProviderEnumerator::ScanStorageL( TUint32 aStorageId )
-    {
-    const CMTPStorageMetaData& storage( iFramework.StorageMgr().StorageL( aStorageId ) );
-
-    __ASSERT_DEBUG( ( storage.Uint( CMTPStorageMetaData::EStorageSystemType ) == CMTPStorageMetaData::ESystemTypeDefaultFileSystem ),
-        User::Invariant() );
-
-    TFileName root( storage.DesC( CMTPStorageMetaData::EStorageSuid ) );
-    PRINT2( _L("MM MTP <> CMediaMtpDataProviderEnumerator::ScanStorageL aStorageId = 0x%x, StorageSuid = %S"), aStorageId, &root );
-
-    iParentHandle = KMTPHandleNoParent;
-    iPath.Set( root, NULL, NULL);
-    iDir.Close();
-    User::LeaveIfError( iDir.Open( iFramework.Fs(),
-        iPath.DriveAndPath(),
-        KEntryAttNormal | KEntryAttDir ) );
-    ScanDirL();
-    }
-
-// -----------------------------------------------------------------------------
-// CMediaMtpDataProviderEnumerator::ScanNextStorageL
-//
-// -----------------------------------------------------------------------------
-//
-void CMediaMtpDataProviderEnumerator::ScanNextStorageL()
-    {
-    // If there are one or more unscanned storages left
-    // (the currently scanned one is still on the list)
-    if ( iStorages.Count() > 1 )
-        {
-        // Round trip suppport
-        const CMTPStorageMetaData& storage( iFramework.StorageMgr().StorageL( iStorages[0] ) );
-        TFileName root( storage.DesC( CMTPStorageMetaData::EStorageSuid ) );
-        GetModifiedContentL( root );
-        TRAPD( err, iDataProvider.GetWrapperL().UpdateMusicCollectionL() );
-        if ( err != KErrNone )
-            {
-            PRINT1( _L("MM MTP <> ScanNextStorageL, UpdateMusicCollectionL err =%d "), err );            
-            }
-
-        iStorages.Remove( 0 );
-        ScanStorageL( iStorages[0] );
-        }
-    else
-        {
-        // Round trip suppport
-        const CMTPStorageMetaData& storage( iFramework.StorageMgr().StorageL( iStorages[0] ) );
-        TFileName root( storage.DesC( CMTPStorageMetaData::EStorageSuid ) );
-        GetModifiedContentL( root );
-
-        // We are done
-        iStorages.Reset();
-
-        SignalCompleteL( iDataProvider );
-        }
-    }
-
-// -----------------------------------------------------------------------------
-// CMediaMtpDataProviderEnumerator::ScanDirL
-//
-// -----------------------------------------------------------------------------
-//
-void CMediaMtpDataProviderEnumerator::ScanDirL()
-    {
-    PRINT( _L( "MM MTP => CMediaMtpDataProviderEnumerator::ScanDirL" ) );
-
-    StartEnumerationCount();
-
-    iFirstUnprocessed = 0;
-
-    iScanningDir = ETrue;
-    PERFLOGSTART( KDirectoryScan );
-    iDir.Read( iEntries, iStatus );
-    SetActive();
-
-    PRINT( _L( "MM MTP <= CMediaMtpDataProviderEnumerator::ScanDirL" ) );
-    }
-
-// -----------------------------------------------------------------------------
-// CMediaMtpDataProviderEnumerator::ScanNextDirL
-// Recurse into the next directory on the stack
-// and scan it for entries.
-// -----------------------------------------------------------------------------
-//
-void CMediaMtpDataProviderEnumerator::ScanNextDirL()
-    {
-    TInt count = iDirStack.Count();
-
-    if ( count == 0 )
-        {
-        // No more directories on the stack, try the next storage
-        ScanNextStorageL();
-        }
-    else
-        {
-        TEntry* entry = iDirStack[count - 1];
-        if ( entry != NULL )
-            {
-
-            // Empty TEntry, no more subdirectories in
-            // the current path
-            if ( entry->iName == KNullDesC )
-                {
-                // Remove current dir from path
-                iPath.PopDir();
-                iDirStack.Remove( count - 1 );
-                delete entry;
-                entry = NULL;
-                iDir.Close();
-
-                // Scan the next directory of the parent
-                ScanNextDirL();
-                }
-            // Going into a subdirectory of current
-            else
-                {
-                // Add directory to path
-                iPath.AddDir( entry->iName );
-                // Remove directory so we don't think it's a subdirectory
-                iDirStack.Remove( count - 1 );
-                delete entry;
-                entry = NULL;
-                ScanNextSubdirL();
-                }
-            }
-        }
-    }
-
-// -----------------------------------------------------------------------------
-// CMediaMtpDataProviderEnumerator::ScanNextSubdirL
-// Scan next sub dir
-// -----------------------------------------------------------------------------
-//
-void CMediaMtpDataProviderEnumerator::ScanNextSubdirL()
-    {
-    PRINT( _L( "MM MTP => CMediaMtpDataProviderEnumerator::ScanNextSubdirL" ) );
-
-    // A empty (non-constructed) TEntry is our marker telling us to pop a directory
-    // from iPath when we see this
-    TEntry* entry = new TEntry( TEntry() );
-
-    User::LeaveIfNull( entry );
-
-    iDirStack.AppendL( entry );
-
-    // Leave with KErrNotFound if we don't find the object handle since it shouldn't be on the
-    // dirstack if the entry wasn't added
-    TPtrC suid = iPath.DriveAndPath().Left( iPath.DriveAndPath().Length() );
-    // Update the current parenthandle with object of the directory
-    PERFLOGSTART( KObjectManagerObjectUid );
-    iParentHandle = iFramework.ObjectMgr().HandleL( suid );
-    PERFLOGSTOP( KObjectManagerObjectUid );
-    PRINT1( _L( "MM MTP <> iParentHandle = 0x%x" ), iParentHandle );
-
-    // Kick-off a scan of the next directory
-    iDir.Close();
-
-    TInt err = iDir.Open( iFramework.Fs(),
-        iPath.DriveAndPath(),
-        KEntryAttNormal | KEntryAttDir );
-
-    PRINT1( _L( "MM MTP <> CMediaMtpDataProviderEnumerator::ScanNextSubdirL, RDir::Open err = %d" ), err );
-
-    if ( err == KErrNone )
-        ScanDirL();
-    else
-        {
-        iEntries = TEntryArray();
-
-        TRequestStatus* status = &iStatus;
-        User::RequestComplete( status, iStatus.Int() );
-        SetActive();
-        }
-
-
-    PRINT( _L( "MM MTP <= CMediaMtpDataProviderEnumerator::ScanNextSubdirL" ) );
     }
 
 // -----------------------------------------------------------------------------
 // CMediaMtpDataProviderEnumerator::RunL
-//
+// Update the mpx db flag for round trip
 // -----------------------------------------------------------------------------
 //
 void CMediaMtpDataProviderEnumerator::RunL()
     {
-    if ( iScanningDir )
-        {
-        PERFLOGSTOP( KDirectoryScan );
-        }
+    PRINT1( _L( "MM MTP => CMediaMtpDataProviderEnumerator::RunL iStorages.Count() = %d" ), iStorages.Count() );
 
-    iScanningDir = EFalse;
-    if ( iEntries.Count() == 0 )
+    if ( iStorages.Count() > 0 )
         {
-        // No entries to process, scan next dir or storage
-        ScanNextDirL();
-        }
-    else if ( iFirstUnprocessed < iEntries.Count() )
-        {
-        PRINT1( _L( "MM MTP <> CMediaMtpDataProviderEnumerator::RunL iFirstUnprocessed = %d" ), iFirstUnprocessed);
-        TRAPD( err, ProcessEntriesL(););
+        const CMTPStorageMetaData& storage( iFramework.StorageMgr().StorageL( iStorages[0] ) );
+        const TDesC& root( storage.DesC( CMTPStorageMetaData::EStorageSuid ) );
+        GetModifiedContentL( root );
+        TRAPD( err, iDataProvider.GetWrapperL().UpdateMusicCollectionL( root ) );
         if ( err != KErrNone )
             {
-            iFirstUnprocessed++;
+            PRINT1( _L("MM MTP <> CMediaMtpDataProviderEnumerator::RunL, UpdateMusicCollectionL err =%d "), err );            
             }
-
-        // Complete ourselves with current TRequestStatus
-        // since we need to run again to either scan a new dir or drive
-        // or process more entries
+        iStorages.Remove( 0 );
         TRequestStatus* status = &iStatus;
         User::RequestComplete( status, iStatus.Int() );
         SetActive();
         }
     else
         {
-        switch ( iStatus.Int() )
-            {
-            case KErrNone:
-                // There are still entries left to be read
-                ScanDirL();
-                break;
-
-            case KErrEof:
-                // There are no more entries
-            default:
-                // Error, ignore and continue with next dir
-                ScanNextDirL();
-                break;
-            }
+        iStorages.Reset();
+        SignalCompleteL( iDataProvider );
         }
+    PRINT( _L( "MM MTP <= CMediaMtpDataProviderEnumerator::RunL" ) );
     }
 
 // -----------------------------------------------------------------------------
@@ -440,13 +207,6 @@
     {
     CActiveScheduler::Add( this );
 
-    TTimeIntervalMicroSeconds32 tickPeriod = 0;
-    TInt err = UserHal::TickPeriod(tickPeriod);
-
-    PRINT1( _L( "MM MTP <> CMediaMtpDataProviderEnumerator::ConstructL, UserHal::TickPeriod err = %d" ), err);
-    User::LeaveIfError( err );
-    iTickPeriod = tickPeriod.Int();
-
 #if defined(_DEBUG) || defined(MMMTPDP_PERFLOG)
     iPerfLog = CMmMtpDpPerfLog::NewL( _L( "MediaMtpDataProviderEnumerator" ) );
 #endif
@@ -465,159 +225,6 @@
     }
 
 // -----------------------------------------------------------------------------
-// CMediaMtpDataProviderEnumerator::ProcessEntriesL
-// Iterates iEntries adding entries as needed to object manager and iDirStack.
-// -----------------------------------------------------------------------------
-//
-void CMediaMtpDataProviderEnumerator::ProcessEntriesL()
-    {
-    PRINT( _L( "MM MTP => CMediaMtpDataProviderEnumerator::ProcessEntriesL" ) );
-
-    TFileName path = iPath.DriveAndPath();
-
-    while ( !IsOverThreshold() && iFirstUnprocessed < iEntries.Count() )
-        {
-        const TEntry& entry = iEntries[iFirstUnprocessed];
-
-        TInt len = entry.iName.Length();
-
-        // Skip object with too long name
-        if ( KMaxFileName >= path.Length() + len )
-            {
-            path.Append( entry.iName );
-            PRINT1( _L( "MM MTP <> path = %S" ), &path );
-
-            if ( entry.IsDir() )
-                {
-                path.Append( '\\' );
-                ++len;
-
-                // we don't need to process folder, just remember
-                // the folder
-                TEntry* dirEntry = new TEntry( entry );
-                User::LeaveIfNull( dirEntry );
-                iDirStack.AppendL( dirEntry );
-                }
-            else if ( IsFileAccepted( path ) )
-                {
-                AddEntryL( path );
-                }
-
-            // Remove filename part
-            path.SetLength( path.Length() - len );
-            }
-
-        iFirstUnprocessed++;
-        }
-
-    StartEnumerationCount();
-    PRINT( _L( "MM MTP <= CMediaMtpDataProviderEnumerator::ProcessEntriesL" ) );
-    }
-
-// -----------------------------------------------------------------------------
-// CMediaMtpDataProviderEnumerator::AddEntryL
-// Add a file entry to the object store
-// -----------------------------------------------------------------------------
-//
-void CMediaMtpDataProviderEnumerator::AddEntryL( const TDesC& aFullFileName )
-    {
-    PRINT1( _L( "MM MTP => CMediaDataProviderEnumerator::AddEntryL aFullFileName = %S" ), &aFullFileName );
-
-    CMTPObjectMetaData* object( CMTPObjectMetaData::NewLC( iDataProviderId,
-        iFormatCode,
-        iStorages[0],
-        aFullFileName ) );    // + object
-
-    object->SetUint( CMTPObjectMetaData::EParentHandle, iParentHandle );
-
-    if ( ( iFormatCode == EMTPFormatCodeMP4Container )
-        || ( iFormatCode == EMTPFormatCode3GPContainer )
-        || ( iFormatCode == EMTPFormatCodeASF ) )
-        {
-        TMmMtpSubFormatCode subFormatCode;
-
-        // Note: Delay the file parsing until external enumeration phase to avoid time-out
-        subFormatCode = EMTPSubFormatCodeUnknown;
-
-        object->SetUint( CMTPObjectMetaData::EFormatSubCode, (TUint)subFormatCode );
-        }
-
-    PERFLOGSTART( KObjectManagerInsert );
-    iObjectMgr.InsertObjectL( *object );
-    PERFLOGSTOP( KObjectManagerInsert );
-
-    CleanupStack::PopAndDestroy( object );  // - object
-
-    PRINT1( _L( "MM MTP <= CMediaMtpDataProviderEnumerator::AddEntryL, entry inserted, iFormatCode = 0x%x" ), iFormatCode);
-    }
-
-// -----------------------------------------------------------------------------
-// CMediaMtpDataProviderEnumerator::GetObjectFormatCode
-// Returns a TMTPFormatCode for the requested object
-// -----------------------------------------------------------------------------
-//
-TMTPFormatCode CMediaMtpDataProviderEnumerator::GetObjectFormatCode( const TDesC& aFullFileName )
-    {
-    PRINT1( _L("MM MTP <> CMediaMtpDataProviderEnumerator::GetObjectFormatCodeL aFullFileName = %S"), &aFullFileName );
-    TMTPFormatCode formatCode = MmMtpDpUtility::FormatFromFilename( aFullFileName );
-    return formatCode;
-    }
-
-// -----------------------------------------------------------------------------
-// CMediaMtpDataProviderEnumerator::IsFileAccepted
-// Is the file format is supported by this Dp
-// -----------------------------------------------------------------------------
-//
-TBool CMediaMtpDataProviderEnumerator::IsFileAccepted( const TDesC& aFullFileName )
-    {
-    PERFLOGSTART( KFormatFilter );
-    iFormatCode = GetObjectFormatCode( aFullFileName );
-    PRINT1( _L( "MM MTP <> CMediaMtpDataProviderEnumerator::IsFileAcceptedL formatCode = 0x%x" ), iFormatCode );
-    TBool accepted = EFalse;
-    TInt count = sizeof( KMediaMtpDataProviderSupportedFormats ) / sizeof( TUint16 );
-    for ( TInt i = 0; i < count; i++ )
-        {
-        if ( iFormatCode == KMediaMtpDataProviderSupportedFormats[i] )
-            {
-            accepted = ETrue;
-            break;
-            }
-        }
-
-    PERFLOGSTOP( KFormatFilter );
-    return accepted;
-    }
-
-// -----------------------------------------------------------------------------
-// CMediaDpMtpEnumerator::StartEnumerationCount
-// start record system tick
-// -----------------------------------------------------------------------------
-//
-void CMediaMtpDataProviderEnumerator::StartEnumerationCount()
-    {
-    iTickCountBegin = User::TickCount();
-    }
-
-// -----------------------------------------------------------------------------
-// CMediaDpMtpEnumerator::IsOverThreshold
-// Is system tick more than the predefined value?
-// -----------------------------------------------------------------------------
-//
-TBool CMediaMtpDataProviderEnumerator::IsOverThreshold()
-    {
-    TUint tcNow = User::TickCount();
-
-    if ( ( tcNow - iTickCountBegin ) * iTickPeriod >= KThresholdOfEnumerationLoopDuration )
-        {
-        return ETrue;
-        }
-    else
-        {
-        return EFalse;
-        }
-    }
-
-// -----------------------------------------------------------------------------
 // CMediaDpMtpEnumerator::GetModifiedContentL()
 // Get Modified Content and report to Framework
 // -----------------------------------------------------------------------------
@@ -638,7 +245,6 @@
         CMTPObjectMetaData* object = CMTPObjectMetaData::NewLC();   // + object
         for ( TInt i = 0; i < arrayCount; i++ )
             {
-
             if ( iFramework.ObjectMgr().ObjectL( ( *modifiedContents )[i], *object ) )
                 {
                 object->SetUint( CMTPObjectMetaData::EObjectMetaDataUpdate , 1 );
@@ -661,7 +267,6 @@
 //
 void CMediaMtpDataProviderEnumerator::SessionClosedL()
     {
-    iDataProvider.GetWrapperL().UpdateMusicCollectionL();
     iDataProvider.GetWrapperL().CleanupDatabaseL();
     }