mmappcomponents/harvester/filehandler/src/mpxharvesterfilehandlerimp.cpp
branchRCL_3
changeset 8 bee149131e4b
parent 0 a2952bb97e68
child 12 51035f0751c2
equal deleted inserted replaced
4:d45095c2f4f3 8:bee149131e4b
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Handles all file related activities
    14 * Description:  Handles all file related activities
    15 *  Version     : %version: da1mmcf#72.1.14.2.4.1.4.1.2 % << Don't touch! Updated by Synergy at check-out.
    15 *  Version     : %version: e003sa33#72.1.14.2.4.1.4.1.2.1.3 % << Don't touch! Updated by Synergy at check-out.
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 
    19 
    20 #include <e32base.h>
    20 #include <e32base.h>
   222 #endif
   222 #endif
   223 
   223 
   224     // Create DRM Notifier and register for AddRemove event
   224     // Create DRM Notifier and register for AddRemove event
   225     iDrmNotifier = CDRMNotifier::NewL();
   225     iDrmNotifier = CDRMNotifier::NewL();
   226     iDrmNotifier->RegisterEventObserverL( *this, KEventAddRemove );
   226     iDrmNotifier->RegisterEventObserverL( *this, KEventAddRemove );
       
   227     iCurUSBEvent = KErrNotFound;
   227     }
   228     }
   228 
   229 
   229 // ---------------------------------------------------------------------------
   230 // ---------------------------------------------------------------------------
   230 // Two-Phased Constructor
   231 // Two-Phased Constructor
   231 // ---------------------------------------------------------------------------
   232 // ---------------------------------------------------------------------------
   426 // ---------------------------------------------------------------------------
   427 // ---------------------------------------------------------------------------
   427 //
   428 //
   428 void CMPXHarvesterFileHandlerImp::HandleSystemEventL( TSystemEvent aEvent,
   429 void CMPXHarvesterFileHandlerImp::HandleSystemEventL( TSystemEvent aEvent,
   429                                                       TInt aData )
   430                                                       TInt aData )
   430     {
   431     {
   431     MPX_DEBUG2("CMPXHarvesterFileHandlerImp::HandleSystemEventL %i", aEvent);
   432     MPX_DEBUG3("CMPXHarvesterFileHandlerImp::HandleSystemEventL %i, drive %d", aEvent, aData);
   432     // How to handle each event
   433     // How to handle each event
   433     //
   434     //
   434     // 1: Format and eject, we stop scanning and close only the mmc db
   435     // 1: Format and eject, we stop scanning and close only the mmc db
   435     // 2: Format end and disk insert we reopen db and scan for new files
   436     // 2: Format end and disk insert we reopen db and scan for new files
   436     // 3: USB start we stop scan and close all db
   437     // 3: USB start we stop scan and close all db
   463             MPX_DEBUG3 ("CMPXHarvesterFileHandlerImp::HandleSystemEventL - drive %d status=0x%x", driveNum, driveStatus);
   464             MPX_DEBUG3 ("CMPXHarvesterFileHandlerImp::HandleSystemEventL - drive %d status=0x%x", driveNum, driveStatus);
   464             TChar driveChar;
   465             TChar driveChar;
   465             User::LeaveIfError(
   466             User::LeaveIfError(
   466                 iFs.DriveToChar( driveNum, driveChar ) );
   467                 iFs.DriveToChar( driveNum, driveChar ) );
   467             MPX_DEBUG5 ("CMPXHarvesterFileHandlerImp::HandleSystemEventL - drive %c: is %S, %S and %S",
   468             MPX_DEBUG5 ("CMPXHarvesterFileHandlerImp::HandleSystemEventL - drive %c: is %S, %S and %S",
   468                 driveChar,
   469                 (TUint)driveChar,
   469                 (driveStatus&DriveInfo::EDrivePresent)?&drivePresent:&driveNotPresent,
   470                 (driveStatus&DriveInfo::EDrivePresent)?&drivePresent:&driveNotPresent,
   470                 (driveStatus&DriveInfo::EDriveInUse)?&driveInUse:&driveAvailable,
   471                 (driveStatus&DriveInfo::EDriveInUse)?&driveInUse:&driveAvailable,
   471                 (driveStatus&DriveInfo::EDriveFormatted)?&driveFormatted:&driveNotFormatted);
   472                 (driveStatus&DriveInfo::EDriveFormatted)?&driveFormatted:&driveNotFormatted);
   472             }
   473             }
   473         }
   474         }
   485             {
   486             {
   486             MPX_DEBUG1("Disk Removed event");
   487             MPX_DEBUG1("Disk Removed event");
   487             iIdle->Cancel();
   488             iIdle->Cancel();
   488             CancelScan();
   489             CancelScan();
   489 #ifdef RD_MULTIPLE_DRIVE
   490 #ifdef RD_MULTIPLE_DRIVE
       
   491             TBool dbClosed( EFalse );
   490             for( TInt driveNum = EDriveA; driveNum <= EDriveZ; driveNum++ )
   492             for( TInt driveNum = EDriveA; driveNum <= EDriveZ; driveNum++ )
   491                 {
   493                 {
   492                 if (driveList[driveNum] && (!iDBManager->IsRemoteDrive(static_cast<TDriveNumber>(driveNum))))
   494                 if (driveList[driveNum] && (!iDBManager->IsRemoteDrive(static_cast<TDriveNumber>(driveNum))))
   493                     {
   495                     {
   494                     TUint driveStatus(0);
   496                     TUint driveStatus(0);
   498                         {
   500                         {
   499                         // Close database for non-present drive
   501                         // Close database for non-present drive
   500                         iDBManager->CloseDatabase( (TDriveNumber) driveNum );
   502                         iDBManager->CloseDatabase( (TDriveNumber) driveNum );
   501                         // Save the drive
   503                         // Save the drive
   502                         iRemovedDrive = driveNum;
   504                         iRemovedDrive = driveNum;
       
   505                         dbClosed = ETrue;
   503                         break;
   506                         break;
   504                         }
   507                         }
       
   508                     }
       
   509                 }
       
   510             
       
   511             if( !dbClosed )
       
   512                 {
       
   513                 // GetUserVisibleDrives / RFs::DriveList does not return drive at all
       
   514                 // if it is dismounted using file server methods. This occurs at least
       
   515                 // when removing card using power menu eject. 
       
   516                 // If the drive reported as removed is not ready, close db on that drive.
       
   517                 TUint driveStatus(0);
       
   518                 TInt err( DriveInfo::GetDriveStatus( iFs, aData, driveStatus ) );
       
   519                 MPX_DEBUG4("Drive %d status 0x%x, err %d", aData, driveStatus, err);
       
   520                 if( err == KErrNotReady )
       
   521                     {
       
   522                     iDBManager->CloseDatabase( (TDriveNumber) aData );
       
   523                     iRemovedDrive = aData;
   505                     }
   524                     }
   506                 }
   525                 }
   507 #else
   526 #else
   508             iDBManager->CloseDatabase( (TDriveNumber) aData );
   527             iDBManager->CloseDatabase( (TDriveNumber) aData );
   509 #endif // RD_MULTIPLE_DRIVE
   528 #endif // RD_MULTIPLE_DRIVE
   527 #endif // RD_MULTIPLE_DRIVE
   546 #endif // RD_MULTIPLE_DRIVE
   528             break;
   547             break;
   529             }
   548             }
   530         case EUSBMassStorageStartEvent:
   549         case EUSBMassStorageStartEvent:
   531             {
   550             {
       
   551             if (iCurUSBEvent == EUSBMassStorageStartEvent)
       
   552             	{
       
   553             	break;
       
   554             	}            
   532             iIdle->Cancel();
   555             iIdle->Cancel();
   533             CancelScan();
   556             CancelScan();
   534 #ifdef RD_MULTIPLE_DRIVE
   557 #ifdef RD_MULTIPLE_DRIVE
   535             // Close all databases other than the phone memory database
   558             // Close all databases other than the phone memory database
   536             for( TInt driveNum = EDriveA; driveNum <= EDriveZ; driveNum++ )
   559             for( TInt driveNum = EDriveA; driveNum <= EDriveZ; driveNum++ )
   544                     }
   567                     }
   545                 }
   568                 }
   546 #else
   569 #else
   547             iDBManager->CloseDatabase( (TDriveNumber) aData );
   570             iDBManager->CloseDatabase( (TDriveNumber) aData );
   548 #endif // RD_MULTIPLE_DRIVE
   571 #endif // RD_MULTIPLE_DRIVE
       
   572             iCurUSBEvent = EUSBMassStorageStartEvent;
   549             break;
   573             break;
   550             }
   574             }
   551         case EUSBMassStorageEndEvent:
   575         case EUSBMassStorageEndEvent:
   552             {
   576             {
   553 #ifdef RD_MULTIPLE_DRIVE
   577 #ifdef RD_MULTIPLE_DRIVE
   563                     }
   587                     }
   564                 }
   588                 }
   565 #else
   589 #else
   566             iDBManager->OpenDatabaseL( (TDriveNumber) aData );
   590             iDBManager->OpenDatabaseL( (TDriveNumber) aData );
   567 #endif // RD_MULTIPLE_DRIVE
   591 #endif // RD_MULTIPLE_DRIVE
       
   592             iCurUSBEvent = EUSBMassStorageEndEvent;
   568             break;
   593             break;
   569             }
   594             }
   570         case EUSBMTPNotActiveEvent: // deliberate fall through
   595         case EUSBMTPNotActiveEvent: // deliberate fall through
   571             {
   596             {
       
   597             if (iCurUSBEvent == EUSBMTPNotActiveEvent)
       
   598             	{
       
   599             	break;
       
   600             	}
   572             if ( iRefreshing )
   601             if ( iRefreshing )
   573                 {
   602                 {
   574                 // Notify clients that refresh is cancelled.
   603                 // Notify clients that refresh is cancelled.
   575                 iCollectionUtil->Collection().NotifyL( EMcMsgRefreshEnd, KErrLocked );
   604                 iCollectionUtil->Collection().NotifyL( EMcMsgRefreshEnd, KErrLocked );
   576                 }
   605                 }
       
   606             CancelScan();
       
   607             iCurUSBEvent = EUSBMTPNotActiveEvent;
       
   608             break;
   577             }
   609             }
   578         case EUSBMTPStartEvent:
   610         case EUSBMTPStartEvent:
   579             {
   611             {
   580             CancelScan();
   612             CancelScan();
       
   613             iCurUSBEvent = EUSBMTPStartEvent;
   581             // nothing to do, db is needed for MTP
   614             // nothing to do, db is needed for MTP
       
   615 #ifdef __RAMDISK_PERF_ENABLE
       
   616             // if statement needed because of fall through above.
       
   617             if ( aEvent == EUSBMTPStartEvent )
       
   618                 {
       
   619                 // copy dbs to ram drive
       
   620                 iDBManager->CopyDBsToRamL(ETrue);
       
   621                 }
       
   622 #endif //__RAMDISK_PERF_ENABLE
   582             break;
   623             break;
   583             }
   624             }
   584         case EUSBMTPEndEvent:
   625         case EUSBMTPEndEvent:
   585             {
   626             {
       
   627             iCurUSBEvent = EUSBMTPEndEvent;
   586             // nothing to do, db is updated by MTP
   628             // nothing to do, db is updated by MTP
       
   629 #ifdef __RAMDISK_PERF_ENABLE
       
   630             // copy dbs from ram drive
       
   631             iDBManager->CopyDBsFromRamL();
       
   632 #endif //__RAMDISK_PERF_ENABLE
   587             break;
   633             break;
   588             }
   634             }
   589         case EPowerKeyEjectEvent:
   635         case EPowerKeyEjectEvent:
   590             {
   636             {
   591             CancelScan();
   637             CancelScan();
   703                 MPX_DEBUG1("CMPXHarvesterFileHandlerImp::AddFiles -- db flags drm invalid");
   749                 MPX_DEBUG1("CMPXHarvesterFileHandlerImp::AddFiles -- db flags drm invalid");
   704                 drm = ETrue;
   750                 drm = ETrue;
   705                 }
   751                 }
   706             }
   752             }
   707         // Add to database
   753         // Add to database
       
   754 #ifdef __RAMDISK_PERF_ENABLE
       
   755         // EnsureRamSpaceL will copy dbs from ram if ram space is low or dbs exceeded max space.
       
   756         iDBManager->EnsureRamSpaceL();
       
   757 #endif // __RAMDISK_PERF_ENABLE
   708         CMPXHarvesterDB& db = iDBManager->GetDatabaseL( ::ExtractDrive( path ) );
   758         CMPXHarvesterDB& db = iDBManager->GetDatabaseL( ::ExtractDrive( path ) );
   709         CMPXHarvesterDatabaseTable* table = db.OpenFileL( path );
   759         CMPXHarvesterDatabaseTable* table = db.OpenFileL( path );
   710         CleanupStack::PushL( table );
   760         CleanupStack::PushL( table );
   711 
   761 
   712         // Don't add something we already have
   762         // Don't add something we already have
   719             }
   769             }
   720         CleanupStack::PopAndDestroy( table );
   770         CleanupStack::PopAndDestroy( table );
   721 
   771 
   722         // Return the collection that it should belong to.
   772         // Return the collection that it should belong to.
   723         r = col.iUid;
   773         r = col.iUid;
       
   774 #ifdef __RAMDISK_PERF_ENABLE
       
   775         // This feature will be turned on in the second phase.
       
   776         //TRAP_IGNORE( iDBManager->UpdateDBsFromRamL(0) );
       
   777 #endif // __RAMDISK_PERF_ENABLE
   724         }
   778         }
   725     else
   779     else
   726         {
   780         {
   727         // No file path, leave KErrArgument!
   781         // No file path, leave KErrArgument!
   728         User::Leave( KErrArgument );
   782         User::Leave( KErrArgument );
   740     {
   794     {
   741     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::RemoveFileL <---");
   795     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::RemoveFileL <---");
   742     TInt r(0);
   796     TInt r(0);
   743 
   797 
   744     // Open the db
   798     // Open the db
       
   799 #ifdef __RAMDISK_PERF_ENABLE
       
   800     // EnsureRamSpaceL will copy dbs from ram if ram space is low or dbs exceeded max space.
       
   801     iDBManager->EnsureRamSpaceL();
       
   802 #endif // __RAMDISK_PERF_ENABLE
   745     CMPXHarvesterDB& db = iDBManager->GetDatabaseL( ::ExtractDrive(aPath) );
   803     CMPXHarvesterDB& db = iDBManager->GetDatabaseL( ::ExtractDrive(aPath) );
   746 	MPX_PERF_START( MPX_PERF_HARV_DB_DELETE_SUB1 );
   804 	MPX_PERF_START( MPX_PERF_HARV_DB_DELETE_SUB1 );
   747     CMPXHarvesterDatabaseTable* table = db.OpenFileL( aPath );
   805     CMPXHarvesterDatabaseTable* table = db.OpenFileL( aPath );
   748     MPX_PERF_END( MPX_PERF_HARV_DB_DELETE_SUB1 );
   806     MPX_PERF_END( MPX_PERF_HARV_DB_DELETE_SUB1 );
   749 
   807 
  1022                 iBrokenLink->Start();
  1080                 iBrokenLink->Start();
  1023                 break;
  1081                 break;
  1024                 }
  1082                 }
  1025             case ECleanupBrokenLink:
  1083             case ECleanupBrokenLink:
  1026                 {
  1084                 {
       
  1085 #ifdef __RAMDISK_PERF_ENABLE
       
  1086                 // copy dbs to ram drive
       
  1087                 iDBManager->CopyDBsToRamL();
       
  1088 #endif //__RAMDISK_PERF_ENABLE
       
  1089     
  1027                 MPX_DEBUG1("Start Metadata Scan");
  1090                 MPX_DEBUG1("Start Metadata Scan");
  1028                 iMetadataScanner->Start();
  1091                 iMetadataScanner->Start();
  1029                 break;
  1092                 break;
  1030                 }
  1093                 }
  1031             case EScanMetadata:
  1094             case EScanMetadata:
  1222     // Look for broken files
  1285     // Look for broken files
  1223     HandleBrokenItemsL();
  1286     HandleBrokenItemsL();
  1224 
  1287 
  1225     // Delete previous table and open the next one
  1288     // Delete previous table and open the next one
  1226     Reset();
  1289     Reset();
       
  1290 #ifdef __RAMDISK_PERF_ENABLE
       
  1291     // EnsureRamSpaceL will copy dbs from ram if ram space is low or dbs exceeded max space.
       
  1292     iDBManager->EnsureRamSpaceL();
       
  1293 #endif // __RAMDISK_PERF_ENABLE
  1227     MPX_TRAPD( err, iCurDB = &iDBManager->GetDatabaseL( aDrive ) );
  1294     MPX_TRAPD( err, iCurDB = &iDBManager->GetDatabaseL( aDrive ) );
  1228     if ( err != KErrNone )
  1295     if ( err != KErrNone )
  1229         {
  1296         {
  1230         iDBManager->OpenAllDatabasesL();
  1297         iDBManager->OpenAllDatabasesL();
  1231         iCurDB = &iDBManager->GetDatabaseL( aDrive );
  1298         iCurDB = &iDBManager->GetDatabaseL( aDrive );
  1372                                  parse.NameAndExt(),
  1439                                  parse.NameAndExt(),
  1373                                  lastModTime, collection.iUid, drm );
  1440                                  lastModTime, collection.iUid, drm );
  1374 
  1441 
  1375             iAddedCount++;
  1442             iAddedCount++;
  1376             }
  1443             }
       
  1444 #ifdef __RAMDISK_PERF_ENABLE
       
  1445         // This feature will be turned on in the second phase.
       
  1446         //TRAP_IGNORE( iDBManager->UpdateDBsFromRamL(iAddedCount) );
       
  1447 #endif // __RAMDISK_PERF_ENABLE
  1377         }
  1448         }
  1378     else if ( addErr == KErrDiskFull )
  1449     else if ( addErr == KErrDiskFull )
  1379         {
  1450         {
  1380         User::Leave( KErrDiskFull );
  1451         User::Leave( KErrDiskFull );
  1381         }
  1452         }
  1554         else if ( addErr == KErrDiskFull )
  1625         else if ( addErr == KErrDiskFull )
  1555             {
  1626             {
  1556             User::Leave( KErrDiskFull );
  1627             User::Leave( KErrDiskFull );
  1557             }
  1628             }
  1558         }
  1629         }
       
  1630 #ifdef __RAMDISK_PERF_ENABLE
       
  1631         // This feature will be turned on in the second phase.
       
  1632         //TRAP_IGNORE( iDBManager->UpdateDBsFromRamL(iAddedCount) );
       
  1633 #endif // __RAMDISK_PERF_ENABLE
  1559 
  1634 
  1560     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::AddPlaylistToCollectionL --->");
  1635     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::AddPlaylistToCollectionL --->");
  1561     }
  1636     }
  1562 
  1637 
  1563 // ---------------------------------------------------------------------------
  1638 // ---------------------------------------------------------------------------
  1920 //
  1995 //
  1921 void CMPXHarvesterFileHandlerImp::OpenDBForPathL( const TDesC& aPath )
  1996 void CMPXHarvesterFileHandlerImp::OpenDBForPathL( const TDesC& aPath )
  1922     {
  1997     {
  1923     Reset();
  1998     Reset();
  1924     TDriveNumber num = ::ExtractDrive( aPath );
  1999     TDriveNumber num = ::ExtractDrive( aPath );
       
  2000 #ifdef __RAMDISK_PERF_ENABLE
       
  2001     // EnsureRamSpaceL will copy dbs from ram if ram space is low or dbs exceeded max space.
       
  2002     iDBManager->EnsureRamSpaceL();
       
  2003 #endif // __RAMDISK_PERF_ENABLE
  1925     iCurDB = &iDBManager->GetDatabaseL( num );
  2004     iCurDB = &iDBManager->GetDatabaseL( num );
  1926     iCurTable = iCurDB->OpenFileL( aPath );
  2005     iCurTable = iCurDB->OpenFileL( aPath );
  1927     }
  2006     }
  1928 
  2007 
  1929 // ---------------------------------------------------------------------------
  2008 // ---------------------------------------------------------------------------
  1947     else
  2026     else
  1948         {
  2027         {
  1949         // Rollback the changes on databases in transaction
  2028         // Rollback the changes on databases in transaction
  1950         iDBManager->Rollback();
  2029         iDBManager->Rollback();
  1951         }
  2030         }
       
  2031 
       
  2032 #ifdef __RAMDISK_PERF_ENABLE
       
  2033     // copy dbs from ram drive
       
  2034     iDBManager->CopyDBsFromRamL();
       
  2035 #endif //__RAMDISK_PERF_ENABLE
  1952 
  2036 
  1953     if( aErr == KErrNone || aErr == KErrCancel )
  2037     if( aErr == KErrNone || aErr == KErrCancel )
  1954         {
  2038         {
  1955         aErr = iAddedCount;
  2039         aErr = iAddedCount;
  1956         }
  2040         }