mmappcomponents/mmmtpdataprovider/mmmtpdpplugins/abstractmediamtpdataprovider/src/cabstractmediamtpdataproviderenumerator.cpp
branchRCL_3
changeset 9 bee149131e4b
parent 0 a2952bb97e68
child 14 05b0d2323768
equal deleted inserted replaced
4:d45095c2f4f3 9:bee149131e4b
    32 #include "mmmtpdputility.h"
    32 #include "mmmtpdputility.h"
    33 #include "cmmmtpdpmetadataaccesswrapper.h"
    33 #include "cmmmtpdpmetadataaccesswrapper.h"
    34 #include "cmmmtpdpmetadatampxaccess.h"
    34 #include "cmmmtpdpmetadatampxaccess.h"
    35 
    35 
    36 
    36 
    37 /** Number of objects to insert into the object manager in one go*/
       
    38 const TInt KMTPDriveGranularity = 5;
    37 const TInt KMTPDriveGranularity = 5;
       
    38 const TInt KAbstractMediaDpArrayGranularity = 2;
    39 
    39 
    40 _LIT( KPlaylistFilePath, "Playlists\\" );
    40 _LIT( KPlaylistFilePath, "Playlists\\" );
       
    41 
       
    42 #if defined(_DEBUG) || defined(MMMTPDP_PERFLOG)
       
    43 _LIT( KMpxGetAllAbstractMedia, "MpxGetAllAbstractMedia" );
       
    44 _LIT( KMpxQueryAbstractMediaReference, "MpxQueryAbstractMediaReference" );
       
    45 _LIT( KObjectManagerObjectUid, "ObjectManagerObjectUid" );
       
    46 _LIT( KObjectManagerInsert, "ObjectManagerInsert" );
       
    47 _LIT( KObjectManagerHandle, "ObjectManagerHandle" );
       
    48 _LIT( KReferenceManagerSetReference, "ReferenceManagerSetReference" );
       
    49 #endif
    41 
    50 
    42 // -----------------------------------------------------------------------------
    51 // -----------------------------------------------------------------------------
    43 // CAbstractMediaMtpDataProviderEnumerator::NewL
    52 // CAbstractMediaMtpDataProviderEnumerator::NewL
    44 // Two phase constructor
    53 // Two phase constructor
    45 // -----------------------------------------------------------------------------
    54 // -----------------------------------------------------------------------------
    67     CActive( EPriorityLow ),
    76     CActive( EPriorityLow ),
    68     iFramework( aFramework ),
    77     iFramework( aFramework ),
    69     iObjectMgr( aFramework.ObjectMgr() ),
    78     iObjectMgr( aFramework.ObjectMgr() ),
    70     iDataProviderId( aFramework.DataProviderId() ),
    79     iDataProviderId( aFramework.DataProviderId() ),
    71     iDataProvider( aDataProvider ),
    80     iDataProvider( aDataProvider ),
    72     iStorages( 2 ),
    81     iStorages( KAbstractMediaDpArrayGranularity ),
    73     iAbstractMedias( NULL ),
    82     iAbstractMedias( NULL ),
    74     iCount( 0 ),
    83     iCount( 0 ),
    75     iCurrentIndex( 0 )
    84     iCurrentIndex( 0 )
    76     {
    85     {
    77     PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::CAbstractMediaMtpDataProviderEnumerator, iDataProviderId = %d" ), iDataProviderId );
    86     PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::CAbstractMediaMtpDataProviderEnumerator, iDataProviderId = %d" ), iDataProviderId );
   103     Cancel();
   112     Cancel();
   104     iStorages.Close();
   113     iStorages.Close();
   105 
   114 
   106     delete iAbstractMedias;
   115     delete iAbstractMedias;
   107     iAbstractMedias = NULL;
   116     iAbstractMedias = NULL;
       
   117 
   108 #if defined(_DEBUG) || defined(MMMTPDP_PERFLOG)
   118 #if defined(_DEBUG) || defined(MMMTPDP_PERFLOG)
   109     delete iPerfLog;
   119     delete iPerfLog;
   110 #endif // _DEBUG
   120 #endif // _DEBUG
   111     PRINT( _L( "MM MTP <= CAbstractMediaMtpDataProviderEnumerator::~CAbstractMediaMtpDataProviderEnumerator" ) );
   121     PRINT( _L( "MM MTP <= CAbstractMediaMtpDataProviderEnumerator::~CAbstractMediaMtpDataProviderEnumerator" ) );
   112     }
   122     }
   200 
   210 
   201     TFileName root( storage.DesC( CMTPStorageMetaData::EStorageSuid ) );
   211     TFileName root( storage.DesC( CMTPStorageMetaData::EStorageSuid ) );
   202     PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::ScanStorageL StorageSuid = %S" ), &root );
   212     PRINT1( _L( "MM MTP <> CAbstractMediaMtpDataProviderEnumerator::ScanStorageL StorageSuid = %S" ), &root );
   203 
   213 
   204     // created by windows media player, or else return responsecode is Access denied
   214     // created by windows media player, or else return responsecode is Access denied
   205     // Create abstract media directory if it does not exist
   215     // Create playlist directory if it does not exist
       
   216     // NOTE: Only playlist need to create directory here, for the dummy files
   206     HBufC* tempBuf = HBufC::NewLC( KMaxFileName );  // + tempBuf
   217     HBufC* tempBuf = HBufC::NewLC( KMaxFileName );  // + tempBuf
   207     TPtr folder = tempBuf->Des();
   218     TPtr folder = tempBuf->Des();
   208     folder.Zero();
   219     folder.Zero();
   209     folder.Append( root );
   220     folder.Append( root );
   210     folder.Append( KPlaylistFilePath );
   221     folder.Append( KPlaylistFilePath );
   230     CleanupStack::PopAndDestroy( tempBuf ); // - tempBuf
   241     CleanupStack::PopAndDestroy( tempBuf ); // - tempBuf
   231 
   242 
   232     // find all abstract medias stored in MPX
   243     // find all abstract medias stored in MPX
   233     delete iAbstractMedias;
   244     delete iAbstractMedias;
   234     iAbstractMedias = NULL;
   245     iAbstractMedias = NULL;
   235     PERFLOGSTART( KMpxGetAllPlaylist );
   246     PERFLOGSTART( KMpxGetAllAbstractMedia );
   236     TRAPD( err, iDataProvider.GetWrapperL().GetAllPlaylistL( root, &iAbstractMedias ) );
   247     TRAPD( err, iDataProvider.GetWrapperL().GetAllAbstractMediaL( root, &iAbstractMedias, EMPXPlaylist  ) );
   237     PERFLOGSTOP( KMpxGetAllPlaylist );
   248     PERFLOGSTOP( KMpxGetAllAbstractMedia );
   238 
   249 
   239     if ( iAbstractMedias != NULL && err == KErrNone )
   250     if ( iAbstractMedias != NULL && err == KErrNone )
   240         {
   251         {
   241         iCount = iAbstractMedias->Count();
   252         iCount = iAbstractMedias->Count();
   242         iCurrentIndex = 0;
   253         iCurrentIndex = 0;
   260 //
   271 //
   261 // -----------------------------------------------------------------------------
   272 // -----------------------------------------------------------------------------
   262 //
   273 //
   263 void CAbstractMediaMtpDataProviderEnumerator::ScanNextL()
   274 void CAbstractMediaMtpDataProviderEnumerator::ScanNextL()
   264     {
   275     {
   265     PRINT1( _L( "MM MTP = > CAbstractMediaMtpDataProviderEnumerator::ScanNextStorageL iStorages.Count = %d" ), iStorages.Count() );
   276     PRINT1( _L( "MM MTP => CAbstractMediaMtpDataProviderEnumerator::ScanNextL iStorages.Count = %d" ), iStorages.Count() );
   266     if ( iCurrentIndex < iCount )
   277     if ( iCurrentIndex < iCount )
   267         {
   278         {
   268         TRequestStatus* status = &iStatus;
   279         TRequestStatus* status = &iStatus;
   269         User::RequestComplete( status, iStatus.Int() );
   280         User::RequestComplete( status, iStatus.Int() );
   270         SetActive();
   281         SetActive();
   294 // NOTE: preserve for performance improvement
   305 // NOTE: preserve for performance improvement
   295 // -----------------------------------------------------------------------------
   306 // -----------------------------------------------------------------------------
   296 //
   307 //
   297 void CAbstractMediaMtpDataProviderEnumerator::RunL()
   308 void CAbstractMediaMtpDataProviderEnumerator::RunL()
   298     {
   309     {
   299     TBuf<KMaxFileName> playlist;
   310     PRINT( _L( "MM MTP => CAbstractMediaMtpDataProviderEnumerator::RunL" ) );
   300 
   311 
   301     // insert all playlists into handle db of framework
   312     // insert all abstract medias into handle db of framework
   302     CMPXMedia* media = ( *iAbstractMedias )[iCurrentIndex];
   313     CMPXMedia* media = ( *iAbstractMedias )[iCurrentIndex];
   303     PERFLOGSTART( KMpxGetPlaylistName );
   314     
   304     iDataProvider.GetWrapperL().GetPlaylistNameL( media, playlist );
   315     // Increase the index first in case of leave
   305     PERFLOGSTOP( KMpxGetPlaylistName );
   316     iCurrentIndex++;
   306     AddEntryL( playlist );
   317     
   307 
   318     HBufC* abstractMedia = iDataProvider.GetWrapperL().GetAbstractMediaNameL( media, EMPXPlaylist );
   308     // find all reference of each playlist and create dummy files for each playlist
   319     CleanupStack::PushL( abstractMedia ); // + abstractMedia
       
   320     AddEntryL( *abstractMedia );
       
   321 
       
   322     // find all reference of each abstract media
   309     CDesCArray* references = new ( ELeave ) CDesCArrayFlat( KMTPDriveGranularity );
   323     CDesCArray* references = new ( ELeave ) CDesCArrayFlat( KMTPDriveGranularity );
   310     CleanupStack::PushL( references ); // + references
   324     CleanupStack::PushL( references ); // + references
   311 
   325 
   312     PERFLOGSTART( KMpxQueryPlaylistReference );
   326     PERFLOGSTART( KMpxQueryAbstractMediaReference );
   313     iDataProvider.GetWrapperL().GetAllReferenceL( media, *references );
   327     iDataProvider.GetWrapperL().GetAllReferenceL( media, *references );
   314     PERFLOGSTOP( KMpxQueryPlaylistReference );
   328     PERFLOGSTOP( KMpxQueryAbstractMediaReference );
   315 
   329 
   316     // insert references into reference db
   330     // insert references into reference db
   317     AddReferencesL( playlist, *references );
   331     AddReferencesL( *abstractMedia, *references );
   318 
   332 
   319     CleanupStack::PopAndDestroy( references ); // - references
   333     CleanupStack::PopAndDestroy( references ); // - references
   320     iCurrentIndex++;
   334     CleanupStack::PopAndDestroy( abstractMedia ); // - abstractMedia
   321 
   335 
   322     ScanNextL();
   336     ScanNextL();
   323     }
   337     }
   324 
   338 
   325 // -----------------------------------------------------------------------------
   339 // -----------------------------------------------------------------------------
   341 // NOTE: preserve for performance improvement
   355 // NOTE: preserve for performance improvement
   342 // -----------------------------------------------------------------------------
   356 // -----------------------------------------------------------------------------
   343 //
   357 //
   344 void CAbstractMediaMtpDataProviderEnumerator::DoCancel()
   358 void CAbstractMediaMtpDataProviderEnumerator::DoCancel()
   345     {
   359     {
   346 
   360     // Do nothing
   347     }
   361     }
   348 
   362 
   349 // -----------------------------------------------------------------------------
   363 // -----------------------------------------------------------------------------
   350 // CAbstractMediaMtpDataProviderEnumerator::SignalCompleteL
   364 // CAbstractMediaMtpDataProviderEnumerator::SignalCompleteL
   351 // Called when the enumeration is completed
   365 // Called when the enumeration is completed
   378     PERFLOGSTART( KObjectManagerObjectUid );
   392     PERFLOGSTART( KObjectManagerObjectUid );
   379     TUint32 parentHandle = iFramework.ObjectMgr().HandleL( parser.DriveAndPath() );
   393     TUint32 parentHandle = iFramework.ObjectMgr().HandleL( parser.DriveAndPath() );
   380     PERFLOGSTOP( KObjectManagerObjectUid );
   394     PERFLOGSTOP( KObjectManagerObjectUid );
   381     object->SetUint( CMTPObjectMetaData::EParentHandle, parentHandle );
   395     object->SetUint( CMTPObjectMetaData::EParentHandle, parentHandle );
   382 
   396 
   383     PERFLOGSTART(KObjectManagerInsert);
   397     PERFLOGSTART( KObjectManagerInsert );
   384     iObjectMgr.InsertObjectL( *object );
   398     iObjectMgr.InsertObjectL( *object );
   385     PERFLOGSTOP(KObjectManagerInsert);
   399     PERFLOGSTOP( KObjectManagerInsert );
   386 
   400 
   387     CleanupStack::PopAndDestroy( object );// - object
   401     CleanupStack::PopAndDestroy( object );// - object
   388 
   402 
   389     iDataProvider.GetWrapperL().CreateDummyFile( aSuid );
   403     iDataProvider.GetWrapperL().CreateDummyFile( aSuid );
   390 
   404