mmappcomponents/mmmtpdataprovider/mmmtpdpplugins/abstractmediamtpdataprovider/src/cabstractmediamtpdataproviderenumerator.cpp
branchRCL_3
changeset 34 e257e2b6459d
parent 28 f56ec6ce2732
child 52 b034b1c214c2
equal deleted inserted replaced
30:6f9f6e99a23e 34:e257e2b6459d
    20 #include <mtp/cmtpobjectmetadata.h>
    20 #include <mtp/cmtpobjectmetadata.h>
    21 #include <mtp/mmtpdataproviderframework.h>
    21 #include <mtp/mmtpdataproviderframework.h>
    22 #include <mtp/mmtpobjectmgr.h>
    22 #include <mtp/mmtpobjectmgr.h>
    23 #include <mtp/mmtpstoragemgr.h>
    23 #include <mtp/mmtpstoragemgr.h>
    24 #include <mtp/mmtpreferencemgr.h>
    24 #include <mtp/mmtpreferencemgr.h>
       
    25 #include <mtp/tmtptypeuint32.h>
    25 #include <mpxmediaarray.h>
    26 #include <mpxmediaarray.h>
    26 #include <mpxmedia.h>
    27 #include <mpxmedia.h>
    27 
    28 
    28 #include "cabstractmediamtpdataproviderenumerator.h"
    29 #include "cabstractmediamtpdataproviderenumerator.h"
    29 #include "cabstractmediamtpdataprovider.h"
    30 #include "cabstractmediamtpdataprovider.h"
    37 
    38 
    38 _LIT( KPlaylistFilePath, "Playlists\\" );
    39 _LIT( KPlaylistFilePath, "Playlists\\" );
    39 
    40 
    40 #if defined(_DEBUG) || defined(MMMTPDP_PERFLOG)
    41 #if defined(_DEBUG) || defined(MMMTPDP_PERFLOG)
    41 _LIT( KMpxGetAllAbstractMedia, "MpxGetAllAbstractMedia" );
    42 _LIT( KMpxGetAllAbstractMedia, "MpxGetAllAbstractMedia" );
    42 _LIT( KMpxQueryAbstractMediaReference, "MpxQueryAbstractMediaReference" );
       
    43 _LIT( KObjectManagerObjectUid, "ObjectManagerObjectUid" );
    43 _LIT( KObjectManagerObjectUid, "ObjectManagerObjectUid" );
    44 _LIT( KObjectManagerInsert, "ObjectManagerInsert" );
    44 _LIT( KObjectManagerInsert, "ObjectManagerInsert" );
    45 _LIT( KObjectManagerHandle, "ObjectManagerHandle" );
    45 _LIT( KResetObjectFormatSubCode, "ResetObjectFormatSubCode" );
    46 _LIT( KReferenceManagerSetReference, "ReferenceManagerSetReference" );
       
    47 #endif
    46 #endif
    48 
    47 
    49 // -----------------------------------------------------------------------------
    48 // -----------------------------------------------------------------------------
    50 // CAbstractMediaMtpDataProviderEnumerator::NewL
    49 // CAbstractMediaMtpDataProviderEnumerator::NewL
    51 // Two phase constructor
    50 // Two phase constructor
    78     iDataProvider( aDataProvider ),
    77     iDataProvider( aDataProvider ),
    79     iStorages( KAbstractMediaDpArrayGranularity ),
    78     iStorages( KAbstractMediaDpArrayGranularity ),
    80     iAbstractMedias( NULL ),
    79     iAbstractMedias( NULL ),
    81     iCount( 0 ),
    80     iCount( 0 ),
    82     iCurrentIndex( 0 ),
    81     iCurrentIndex( 0 ),
    83     iEnumState ( EEnumNone )
    82     iEnumState ( EEnumNone ),
       
    83     iResetCount( 0 )
    84     {
    84     {
    85     PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::CAbstractMediaMtpDataProviderEnumerator, iDataProviderId = %d" ), iDataProviderId );
    85     PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::CAbstractMediaMtpDataProviderEnumerator, iDataProviderId = %d" ), iDataProviderId );
    86     }
    86     }
    87 
    87 
    88 // -----------------------------------------------------------------------------
    88 // -----------------------------------------------------------------------------
   198         iFramework.StorageMgr().StorageL( iStorages[0] ) );
   198         iFramework.StorageMgr().StorageL( iStorages[0] ) );
   199 
   199 
   200     __ASSERT_DEBUG( ( storage.Uint( CMTPStorageMetaData::EStorageSystemType ) ==
   200     __ASSERT_DEBUG( ( storage.Uint( CMTPStorageMetaData::EStorageSystemType ) ==
   201         CMTPStorageMetaData::ESystemTypeDefaultFileSystem ), User::Invariant() );
   201         CMTPStorageMetaData::ESystemTypeDefaultFileSystem ), User::Invariant() );
   202 
   202 
   203     TFileName root( storage.DesC( CMTPStorageMetaData::EStorageSuid ) );
   203     TPtrC root( storage.DesC( CMTPStorageMetaData::EStorageSuid ) );
   204     PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::InitStorageL StorageSuid = %S" ), &root );
   204     PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::InitStorageL StorageSuid = %S" ), &root );
   205 
   205 
   206     if ( iEnumState == EEnumPlaylist )
   206     if ( iEnumState == EEnumPlaylist )
   207         {
   207         {
   208         // created by windows media player, or else return responsecode is Access denied
   208         // created by windows media player, or else return responsecode is Access denied
   236         }
   236         }
   237 
   237 
   238     // find all abstract medias stored in MPX
   238     // find all abstract medias stored in MPX
   239     delete iAbstractMedias;
   239     delete iAbstractMedias;
   240     iAbstractMedias = NULL;
   240     iAbstractMedias = NULL;
       
   241     iAbstractMedias = new( ELeave ) CDesCArrayFlat( KMTPDriveGranularity );
   241     TMPXGeneralCategory category = ( iEnumState == EEnumPlaylist ) ? EMPXPlaylist : EMPXAbstractAlbum;
   242     TMPXGeneralCategory category = ( iEnumState == EEnumPlaylist ) ? EMPXPlaylist : EMPXAbstractAlbum;
   242     PERFLOGSTART( KMpxGetAllAbstractMedia );
   243     PERFLOGSTART( KMpxGetAllAbstractMedia );
   243     TRAPD( err, iDataProvider.GetWrapperL().GetAllAbstractMediaL( root, &iAbstractMedias, category  ) );
   244     TRAPD( err, iDataProvider.GetWrapperL().GetAllAbstractMediaL( root, *iAbstractMedias, category  ) );
   244     PERFLOGSTOP( KMpxGetAllAbstractMedia );
   245     PERFLOGSTOP( KMpxGetAllAbstractMedia );
   245 
   246 
   246     if ( iAbstractMedias != NULL && err == KErrNone )
   247     if ( iAbstractMedias != NULL && err == KErrNone )
   247         {
   248         {
   248         iCount = iAbstractMedias->Count();
   249         iCount = iAbstractMedias->Count();
   271         }
   272         }
   272 
   273 
   273     if ( iEnumState >= EEnumCount )
   274     if ( iEnumState >= EEnumCount )
   274         {
   275         {
   275         iEnumState = EEnumPlaylist;
   276         iEnumState = EEnumPlaylist;
       
   277         iResetCount = 0;
       
   278         
       
   279         PERFLOGSTART( KResetObjectFormatSubCode );
       
   280         ResetObjectFormatSubCodeL( iStorages[0] );
       
   281         PERFLOGSTOP( KResetObjectFormatSubCode );
       
   282         
       
   283         PRINT2( _L( "MM MTP <> ResetObjectFormatSubCodeL, storage = 0x%x, iResetCount = %d" ), iStorages[0], iResetCount );
   276         iStorages.Remove( 0 );
   284         iStorages.Remove( 0 );
   277         }
   285         }
   278 
   286 
   279     if ( iStorages.Count() > 0 )
   287     if ( iStorages.Count() > 0 )
   280         {
   288         {
   311     if ( iCurrentIndex < iCount )
   319     if ( iCurrentIndex < iCount )
   312         {
   320         {
   313         PRINT2( _L( "MM MTP <> Current storage is still being scanned, current index = %d, total AbstractMedia count = %d" ),
   321         PRINT2( _L( "MM MTP <> Current storage is still being scanned, current index = %d, total AbstractMedia count = %d" ),
   314             iCurrentIndex,
   322             iCurrentIndex,
   315             iCount );
   323             iCount );
   316         // insert all abstract medias into handle db of framework
   324 
   317         CMPXMedia* media = ( *iAbstractMedias )[iCurrentIndex];
   325         // Insert all abstract medias into handle db of framework
   318 
   326         iCurrentIndex++;    // Increase the index first in case of leave
   319         // Increase the index first in case of leave
   327         TPtrC entrySuid( ( *iAbstractMedias )[iCurrentIndex-1] );
   320         iCurrentIndex++;
   328 
   321         TMPXGeneralCategory category = ( iEnumState == EEnumPlaylist ) ? EMPXPlaylist : EMPXAbstractAlbum;
       
   322         HBufC* abstractMedia = iDataProvider.GetWrapperL().GetAbstractMediaNameL( media, category );
       
   323         CleanupStack::PushL( abstractMedia ); // + abstractMedia
       
   324 
       
   325         TBool ret = ETrue;
       
   326         if ( iEnumState == EEnumAbstractAlbum )
   329         if ( iEnumState == EEnumAbstractAlbum )
   327             {
   330             {
   328             // The abstract album may be removed, check it first
   331             // The abstract album may be removed, check it first
   329             ret = BaflUtils::FileExists( iFramework.Fs(), *abstractMedia );
   332             TBool ret = BaflUtils::FileExists( iFramework.Fs(), entrySuid );
   330             PRINT2( _L( "MM MTP <> BaflUtils::FileExists( RFs,%S ) ret = %d" ), abstractMedia, ret );
   333             PRINT2( _L( "MM MTP <> BaflUtils::FileExists( RFs,%S ) ret = %d" ), &entrySuid, ret );
   331             }
   334             }
   332         else // EEnumPlaylist
   335         else // EEnumPlaylist
   333             {
   336             {
   334             // Add an object to the object store for DB based playlist
   337             // Add an object to the object store for DB based playlist
   335             AddEntryL( *abstractMedia );
   338             AddEntryL( entrySuid );
   336             }
   339             }
   337 
   340 
   338         if ( ret )
   341         // Getting all reference during internal enumeration takes too long, query later on demand
   339             {
       
   340             PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::RunL abstractMedia=%S" ), abstractMedia );
       
   341 
       
   342             // find all reference of each abstract media
       
   343             CDesCArray* references = new ( ELeave ) CDesCArrayFlat( KMTPDriveGranularity );
       
   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         }
   342         }
   357 
   343 
   358     ScanNextL();
   344     ScanNextL();
       
   345 
   359     PRINT( _L( "MM MTP <= CAbstractMediaMtpDataProviderEnumerator::RunL" ) );
   346     PRINT( _L( "MM MTP <= CAbstractMediaMtpDataProviderEnumerator::RunL" ) );
   360     }
   347     }
   361 
   348 
   362 // -----------------------------------------------------------------------------
   349 // -----------------------------------------------------------------------------
   363 // CAbstractMediaMtpDataProviderEnumerator::RunError
   350 // CAbstractMediaMtpDataProviderEnumerator::RunError
   463     CleanupStack::PopAndDestroy( object );// - object
   450     CleanupStack::PopAndDestroy( object );// - object
   464 
   451 
   465     PRINT( _L( "MM MTP <= CAbstractMediaMtpDataProviderEnumerator::AddEntryL" ) );
   452     PRINT( _L( "MM MTP <= CAbstractMediaMtpDataProviderEnumerator::AddEntryL" ) );
   466     }
   453     }
   467 
   454 
   468 // -----------------------------------------------------------------------------
   455 void CAbstractMediaMtpDataProviderEnumerator::ResetObjectFormatSubCodeL( TUint32 aStorageId )
   469 // CAbstractMediaMtpDataProviderEnumerator::AddReferencesL
   456     {
   470 // Add references into reference db according to abstract media name
   457     PRINT1( _L( "MM MTP => CAbstractMediaMtpDataProviderEnumerator::ResetObjectFormatSubCodeL, StorageId = 0x%x" ),
   471 // -----------------------------------------------------------------------------
   458         aStorageId );
   472 //
   459     RMTPObjectMgrQueryContext context;
   473 void CAbstractMediaMtpDataProviderEnumerator::AddReferencesL( const TDesC& aAbstractMediaName,
   460     RArray<TUint> handles;
   474     CDesCArray& aReferences )
   461     CleanupClosePushL( context ); // + context
   475     {
   462     CleanupClosePushL( handles ); // + handles
   476     TInt count = aReferences.Count();
   463     
   477     PRINT2( _L("MM MTP => CAbstractMediaMtpDataProviderEnumerator::AddReferencesL AbstractMedia name = %S, ref count = %d"), &aAbstractMediaName, count );
   464     // search all handles in desired storage with desired DP id
   478 
   465     TMTPObjectMgrQueryParams params( aStorageId, KMTPFormatsAll, KMTPHandleNone, iFramework.DataProviderId() );
   479     // check if references are valid
   466 
   480     CMTPObjectMetaData* object = CMTPObjectMetaData::NewLC();   // + object
   467     do
   481     MMTPObjectMgr& objectMgr = iFramework.ObjectMgr();
   468         {
   482 
   469         iObjectMgr.GetObjectHandlesL( params, context, handles );
   483     TInt removeCount = 0;
   470 
   484     for ( TInt i = 0; i < count; i++ )
   471         for ( TInt i = 0; i < handles.Count(); i++ )
   485         {
   472             {
   486         TInt index = i - removeCount;
   473             CMTPObjectMetaData* objectInfo = CMTPObjectMetaData::NewLC(); // + objectInfo
   487         TPtrC temp( aReferences[index] );
   474             
   488         PRINT2( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::AddReferencesL ref[%d]'s name = %S" ), index, &temp );
   475             iResetCount++;
   489         PERFLOGSTART( KObjectManagerHandle );
   476             iObjectMgr.ObjectL( handles[i], *objectInfo );
   490         TUint32 handle = iFramework.ObjectMgr().HandleL( temp );
   477             // EMTPSubFormatCodeUnknown means references of the object haven't been insert into reference db of fw.
   491         PERFLOGSTOP( KObjectManagerHandle );
   478             objectInfo->SetUint( CMTPObjectMetaData::EFormatSubCode, EMTPSubFormatCodeUnknown );
   492         if ( handle == KMTPHandleNone ) // object doesn't exist
   479             iObjectMgr.ModifyObjectL( *objectInfo );
   493             {
   480             CleanupStack::PopAndDestroy( objectInfo ); // - objectInfo
   494             PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::AddReferencesL, [%S] doesn't existed in handle db, remove this from reference array" ), &temp );
   481             }
   495 
   482         }
   496             // if handle is invalid, remove from reference array
   483     while ( !context.QueryComplete() );
   497             aReferences.Delete( index, 1 );
   484 
   498             removeCount++;
   485     CleanupStack::PopAndDestroy( &handles ); // - handles
   499             }
   486     CleanupStack::PopAndDestroy( &context ); // - context
   500         }
   487 
   501     CleanupStack::PopAndDestroy( object );  // - object
   488     PRINT( _L( "MM MTP <= CAbstractMediaMtpDataProviderEnumerator::ResetObjectFormatSubCodeL" ) );
   502 
       
   503     // add all references into references db
       
   504     MMTPReferenceMgr& referenceMgr = iFramework.ReferenceMgr();
       
   505     PERFLOGSTART( KReferenceManagerSetReference );
       
   506     referenceMgr.SetReferencesL( aAbstractMediaName, aReferences );
       
   507     PERFLOGSTOP( KReferenceManagerSetReference );
       
   508 
       
   509     PRINT( _L( "MM MTP <= CAbstractMediaMtpDataProviderEnumerator::AddReferencesL" ) );
       
   510     }
   489     }
   511 
   490 
   512 //end of file
   491 //end of file