318 |
313 |
319 } |
314 } |
320 |
315 |
321 |
316 |
322 // ---------------------------------------------------------------------------- |
317 // ---------------------------------------------------------------------------- |
323 // CMPXDbManager::DoCopyDBsToRamL |
318 // CMPXDbManager::DoCopyDBToRam |
324 // ---------------------------------------------------------------------------- |
319 // ---------------------------------------------------------------------------- |
325 // |
320 // |
326 TBool CMPXDbManager::DoCopyDBToRamL( TDriveUnit aDrive, TBool aIsMTPInUse ) |
321 TBool CMPXDbManager::DoCopyDBToRam( TInt aIndex, TBool aIsMTPInUse ) |
327 { |
322 { |
328 #ifdef __RAMDISK_PERF_ENABLE |
323 #ifdef __RAMDISK_PERF_ENABLE |
329 MPX_DEBUG2("-->CMPXDbManager::DoCopyDBsToRamL drive=%d", (TInt)aDrive); |
324 MPX_DEBUG2("-->CMPXDbManager::DoCopyDBsToRam drive=%d", (TInt)iDatabaseHandles[aIndex].iDrive); |
330 TFileName dst; |
325 DatabaseHandle& database = iDatabaseHandles[aIndex]; |
331 TFileName src; |
326 TInt err = KErrNone; |
332 dst.Append(iRAMFolder); |
327 |
333 src.Append(aDrive.Name()); |
328 delete database.iOrigFullFilePath; |
334 src.Append(KDBFilePath); |
329 database.iOrigFullFilePath = 0; |
335 TRAPD( err, BaflUtils::EnsurePathExistsL( iFs, dst )); |
330 delete database.iTargetFullFilePath; |
336 if ( err != KErrNone ) |
331 database.iTargetFullFilePath = 0; |
337 { |
332 TRAP (err, |
|
333 database.iOrigFullFilePath = CreateFullFilenameL( database.iDrive ); |
|
334 database.iUseRAMdb = ETrue; // must turn this on to create RAM filename |
|
335 database.iTargetFullFilePath = CreateFullFilenameL( database.iDrive ); |
|
336 BaflUtils::EnsurePathExistsL( iFs, *database.iTargetFullFilePath )); |
|
337 database.iUseRAMdb = EFalse; |
|
338 if (err != KErrNone) |
|
339 { |
|
340 MPX_DEBUG1("CMPXDbManager::DoCopyDBsToRamL() CreateFilenameL or EnsurePathExistsL failed"); |
338 return EFalse; |
341 return EFalse; |
339 } |
342 } |
340 TFileName filename; |
343 MPX_DEBUG2("RAMDisk src path=%S", database.iOrigFullFilePath); |
341 filename.Format(KSecurePath, User::Identity().iUid, iDbFile); //x:\private\10281e17\[sldfdsf]mpxv2_5.db |
344 MPX_DEBUG2("RAMDisk dst path=%S", database.iTargetFullFilePath); |
342 src.Append(filename); |
345 |
343 MPX_DEBUG2("RAMDisk src path=%S", &src); |
346 if (!BlockDiskSpace( aIndex, aIsMTPInUse ) ) |
344 TEntry entry; |
|
345 iFs.Entry( src, entry ); |
|
346 if (!BlockDiskSpace( aDrive, entry.iSize, aIsMTPInUse ) ) |
|
347 { |
347 { |
348 MPX_DEBUG1("CMPXDbManager::DoCopyDBsToRamL() BlockDiskSpace failed"); |
348 MPX_DEBUG1("CMPXDbManager::DoCopyDBsToRamL() BlockDiskSpace failed"); |
349 return EFalse; // continue for next drive |
349 return EFalse; // continue for next drive |
350 } |
350 } |
351 TBuf<2> d; |
351 |
352 d.Append(aDrive.Name()); |
352 if ( BaflUtils::CopyFile(iFs, *database.iOrigFullFilePath, *database.iTargetFullFilePath ) != KErrNone ) |
353 HBufC* temp = HBufC::NewLC(KMaxFileName); |
353 { |
354 temp->Des().Append(d.Left(1)); |
354 RemoveDummyFile( aIndex ); |
355 temp->Des().Append(iDbFile->Des()); |
|
356 filename.Format(KSecurePath, User::Identity().iUid, temp); |
|
357 CleanupStack::PopAndDestroy(temp); |
|
358 dst.Append(filename); |
|
359 MPX_DEBUG2("RAMDisk dst path=%S", &dst); |
|
360 TInt index( GetDatabaseIndex((TInt)aDrive) ); |
|
361 delete iDatabaseHandles[index].iOrigFullFilePath; |
|
362 iDatabaseHandles[index].iOrigFullFilePath = 0; |
|
363 delete iDatabaseHandles[index].iTargetFullFilePath; |
|
364 iDatabaseHandles[index].iTargetFullFilePath = 0; |
|
365 |
|
366 // Save these path so it is convenient to copy back |
|
367 iDatabaseHandles[index].iOrigFullFilePath = HBufC::NewL(src.Length()); |
|
368 iDatabaseHandles[index].iTargetFullFilePath = HBufC::NewL(dst.Length()); |
|
369 |
|
370 iDatabaseHandles[index].iOrigFullFilePath->Des().Append(src); |
|
371 iDatabaseHandles[index].iTargetFullFilePath->Des().Append(dst); |
|
372 |
|
373 TRAP(err, CloseDatabaseL(aDrive)); |
|
374 if ( err != KErrNone ) |
|
375 { |
|
376 MPX_DEBUG2("<--CMPXDbManager::DoCopyDBsToRamL error=%d", err); |
|
377 TInt index(GetDatabaseIndex((TInt)aDrive)); |
|
378 if ( index >= 0 ) |
|
379 { |
|
380 RemoveDummyFile( index ); |
|
381 } |
|
382 return EFalse; |
355 return EFalse; |
383 } |
356 } |
384 User::LeaveIfError( BaflUtils::CopyFile(iFs, src, dst )); |
357 MPX_DEBUG2("RAMDisk Database copied=%d", (TInt)database.iDrive); |
385 OpenDatabaseL((TInt)aDrive); |
358 database.iUseRAMdb = ETrue; // succeeded moving DB to RAM |
386 |
|
387 MPX_DEBUG2("RAMDisk Database opened=%d", (TInt)aDrive); |
|
388 MPX_DEBUG1("<--CMPXDbManager::DoCopyDBsToRamL"); |
359 MPX_DEBUG1("<--CMPXDbManager::DoCopyDBsToRamL"); |
389 return ETrue; |
360 return ETrue; |
|
361 #else |
|
362 return EFalse; |
390 #endif //__RAMDISK_PERF_ENABLE |
363 #endif //__RAMDISK_PERF_ENABLE |
391 } |
364 } |
392 |
365 |
393 // ---------------------------------------------------------------------------- |
366 // ---------------------------------------------------------------------------- |
394 // Copy all DBs from RAM disk back to normal drives |
367 // Copy all DBs from RAM disk back to normal drives |
395 // ---------------------------------------------------------------------------- |
368 // ---------------------------------------------------------------------------- |
396 // |
369 // |
397 EXPORT_C void CMPXDbManager::CopyDBsFromRamL() |
370 EXPORT_C void CMPXDbManager::CopyDBsFromRamL() |
398 { |
371 { |
|
372 MPX_FUNC("CMPXDbManager::CopyDBsFromRamL"); |
399 #ifdef __RAMDISK_PERF_ENABLE |
373 #ifdef __RAMDISK_PERF_ENABLE |
400 MPX_DEBUG1("-->CMPXDbManager::CopyDBsFromRamL"); |
|
401 if( iRAMDiskPerfEnabled ) |
374 if( iRAMDiskPerfEnabled ) |
402 { |
375 { |
403 TInt transactionCount = iTransactionCount; |
376 TInt transactionCount = iTransactionCount; |
404 if (iTransactionCount > 0) |
377 if (iTransactionCount > 0) |
405 { |
378 { |
406 iTransactionCount = 0; |
379 iTransactionCount = 0; |
407 DoCommitL(); |
380 TRAP_IGNORE( DoCommitL() ); |
408 } |
381 } |
409 |
382 |
410 TInt count(iDatabaseHandles.Count()); |
383 TInt count(iDatabaseHandles.Count()); |
411 for (TInt i = 0; i < count && iDatabaseHandles[i].iUseRAMdb; ++i) |
384 TInt leaveError = KErrNone; |
412 { |
385 iRAMInUse = EFalse; |
413 TRAPD(err, DoCopyDBFromRamL(i)); |
386 // Should not leave until all the databases have been copied from RAM drive. |
414 if ( err != KErrNone ) |
387 for (TInt i = 0; i < count; ++i) |
|
388 { |
|
389 if ( !iDatabaseHandles[i].iUseRAMdb ) |
415 { |
390 { |
416 MPX_DEBUG2("<--CMPXDbManager::CopyDBsFromRamL error=%d", err); |
391 continue; |
417 //anyting wrong, delete the temp file and open database from drive |
392 } |
|
393 TRAPD( error, CloseDatabaseAtIndexL( i ) ); |
|
394 if ( error ) |
|
395 { |
|
396 // Can't close db on RAM drive, so cleanup. |
|
397 MPX_DEBUG2("CMPXDbManager::CopyDBsFromRamL CloseDatabaseAtIndexL fail: error = %d", error); |
|
398 // Delete database on RAM drive. |
|
399 BaflUtils::DeleteFile(iFs, *iDatabaseHandles[i].iTargetFullFilePath); |
|
400 // Delete dummy file |
418 RemoveDummyFile(i); |
401 RemoveDummyFile(i); |
419 // delete Db on RAM |
402 } |
420 User::LeaveIfError( BaflUtils::DeleteFile(iFs, |
403 else |
421 *iDatabaseHandles[i].iTargetFullFilePath)); |
404 { |
|
405 DoCopyDBFromRam(i); |
422 } |
406 } |
423 iDatabaseHandles[i].iUseRAMdb = EFalse; |
407 iDatabaseHandles[i].iUseRAMdb = EFalse; |
424 // open db from drive |
408 // open db from drive |
425 OpenDatabaseL( iDatabaseHandles[i].iDrive ); |
409 TRAP( error, OpenDatabaseAtIndexL( i ) ); |
426 } |
410 if ( error && !leaveError ) |
|
411 { |
|
412 leaveError = error; |
|
413 } |
|
414 } |
|
415 |
|
416 // leave if error |
|
417 User::LeaveIfError(leaveError); |
427 |
418 |
428 if (transactionCount > 0) |
419 if (transactionCount > 0) |
429 { |
420 { |
430 DoBeginL(); |
421 DoBeginL(); |
431 iTransactionCount = transactionCount; |
422 iTransactionCount = transactionCount; |
432 } |
423 } |
433 } |
424 } |
434 iRAMInUse = EFalse; |
425 #endif //__RAMDISK_PERF_ENABLE |
|
426 } |
|
427 |
|
428 |
|
429 // ---------------------------------------------------------------------------- |
|
430 // CMPXDbManager::DoCopyDBsToRam |
|
431 // ---------------------------------------------------------------------------- |
|
432 // |
|
433 void CMPXDbManager::DoCopyDBFromRam( TInt aIndex ) |
|
434 { |
|
435 #ifdef __RAMDISK_PERF_ENABLE |
|
436 MPX_DEBUG1("-->CMPXDbManager::DoCopyDBsFromRam"); |
|
437 DatabaseHandle& database = iDatabaseHandles[aIndex]; |
|
438 |
|
439 //Copy Db from RAM to replace dummy file |
|
440 TRAPD(error, ReplaceFileL( *database.iTargetFullFilePath, database.iDummyFilePath)); |
|
441 MPX_DEBUG2("CMPXDbManager::CopyDBsFromRam RAMDisk copied over dummy, error=%d", error); |
|
442 |
|
443 // done with RAM DB (whether copying succeeded or not) so can delete it |
|
444 // can ignore errors since we cannot do anything if this fails |
|
445 BaflUtils::DeleteFile(iFs, *database.iTargetFullFilePath); |
|
446 MPX_DEBUG1("CMPXDbManager::DoCopyDBsFromRam RAM DB deleted"); |
435 |
447 |
436 MPX_DEBUG1("<--CMPXDbManager::CopyDBsFromRamL"); |
448 if ( error == KErrNone ) |
437 #endif //__RAMDISK_PERF_ENABLE |
449 { |
438 } |
450 // Delete old DB on drive |
439 |
451 // Can ignore error: either original does not exist or something is wrong and can't help it |
440 |
452 BaflUtils::DeleteFile(iFs, *database.iOrigFullFilePath); |
441 // ---------------------------------------------------------------------------- |
453 MPX_DEBUG1("CMPXDbManager::DoCopyDBsFromRam old DB on drive deleted"); |
442 // CMPXDbManager::DoCopyDBsToRamL |
454 |
443 // ---------------------------------------------------------------------------- |
455 // Rename dummy file to be original file name |
444 // |
456 error = BaflUtils::RenameFile(iFs, database.iDummyFilePath, *database.iOrigFullFilePath); |
445 void CMPXDbManager::DoCopyDBFromRamL( TInt aIndex ) |
457 MPX_DEBUG2("CMPXDbManager::CopyDBsFromRam dummy file renamed, error=%d", error); |
446 { |
458 if ( error ) |
447 #ifdef __RAMDISK_PERF_ENABLE |
459 { |
448 MPX_DEBUG1("-->CMPXDbManager::DoCopyDBsFromRamL"); |
460 // Error renaming dummy file, delete dummy file. |
449 MPX_DEBUG2("-->CMPXDbManager::DoCopyDBsFromRamL Drive %d will be closed before copying db from RAM.", |
461 RemoveDummyFile(aIndex); |
450 iDatabaseHandles[aIndex].iDrive); |
462 } |
451 |
463 } |
452 CloseDatabaseL(iDatabaseHandles[aIndex].iDrive); |
464 else |
453 |
465 { |
454 // Delete existing DB on drive |
466 RemoveDummyFile(aIndex); |
455 User::LeaveIfError( BaflUtils::DeleteFile(iFs, |
467 MPX_DEBUG1("CMPXDbManager::DoCopyDBsFromRam dummy file deleted"); |
456 *iDatabaseHandles[aIndex].iOrigFullFilePath)); |
468 } |
457 MPX_DEBUG1("CMPXDbManager::DoCopyDBsFromRamL old DB on drive deleted"); |
469 |
458 |
470 MPX_DEBUG1("<--CMPXDbManager::DoCopyDBsFromRam"); |
459 // Rename dummy file to be orignal file name |
|
460 User::LeaveIfError( BaflUtils::RenameFile(iFs, |
|
461 iDatabaseHandles[aIndex].iDummyFilePath, |
|
462 *iDatabaseHandles[aIndex].iOrigFullFilePath) ); |
|
463 MPX_DEBUG1("CMPXDbManager::CopyDBsFromRamL RAMDisk renamed."); |
|
464 |
|
465 //Copy Db from RAM to replace dummy file |
|
466 ReplaceFileL( *iDatabaseHandles[aIndex].iTargetFullFilePath, *iDatabaseHandles[aIndex].iOrigFullFilePath); |
|
467 |
|
468 MPX_DEBUG1("CMPXDbManager::CopyDBsFromRamL RAMDisk copied back."); |
|
469 |
|
470 // Delete existing DB on RAM |
|
471 User::LeaveIfError( BaflUtils::DeleteFile(iFs, *iDatabaseHandles[aIndex].iTargetFullFilePath)); |
|
472 MPX_DEBUG1("CMPXDbManager::DoCopyDBsFromRamL RAMDisk deleted"); |
|
473 |
|
474 MPX_DEBUG1("<--CMPXDbManager::DoCopyDBsFromRamL"); |
|
475 #endif //__RAMDISK_PERF_ENABLE |
471 #endif //__RAMDISK_PERF_ENABLE |
476 } |
472 } |
477 |
473 |
478 // ---------------------------------------------------------------------------- |
474 // ---------------------------------------------------------------------------- |
479 // CMPXDbManager::ReplaceFileL |
475 // CMPXDbManager::ReplaceFileL |
480 // |
476 // |
481 // Replaces a file with another writing over the destination file. |
477 // Replaces a file with another writing over the destination file. |
482 // Leaves on error. |
478 // Leaves on error. |
483 // Implementation follows CFileMan::Copy except that |
479 // Implementation follows CFileMan::Copy except that |
484 // - we don't resize target file to zero |
480 // - we don't resize target file to zero |
485 // - we can assume that files already exist |
481 // - we can assume that source file already exists |
486 // - we don't copy file attributes & timestamp |
482 // - we don't copy file attributes & timestamp |
487 // ---------------------------------------------------------------------------- |
483 // ---------------------------------------------------------------------------- |
488 // |
484 // |
489 void CMPXDbManager::ReplaceFileL( const TDesC& aSrcName, const TDesC& aDstName ) |
485 void CMPXDbManager::ReplaceFileL( const TDesC& aSrcName, const TDesC& aDstName ) |
490 { |
486 { |
750 |
763 |
751 if (iInitialized == EFalse) |
764 if (iInitialized == EFalse) |
752 { |
765 { |
753 User::Leave(KErrNotReady); |
766 User::Leave(KErrNotReady); |
754 } |
767 } |
755 |
768 |
|
769 TDriveUnit drive(aDrive); |
|
770 TDriveUnit cdrive(KRootDrive()); |
|
771 TBool found(EFalse); |
|
772 |
|
773 if ((drive != cdrive) && !IsRemoteDrive(static_cast<TDriveNumber>(aDrive))) |
|
774 { |
|
775 TInt count(iDatabaseHandles.Count()); |
|
776 for (TInt i = 0; i < count; ++i) |
|
777 { |
|
778 if (iDatabaseHandles[i].iDrive == aDrive) |
|
779 { |
|
780 TInt transactionCount = iTransactionCount; |
|
781 if (iTransactionCount > 0) |
|
782 { |
|
783 iTransactionCount = 0; |
|
784 DoCommitL(); |
|
785 } |
|
786 |
|
787 #ifdef __RAMDISK_PERF_ENABLE |
|
788 if ( iRAMDiskPerfEnabled && iDatabaseHandles[i].iUseRAMdb ) |
|
789 { |
|
790 MPX_DEBUG2("CMPXDbManager::CloseDatabaseL found %d at RAM", aDrive); |
|
791 TRAPD( err, CloseDatabaseAtIndexL( i ) ); |
|
792 if ( err != KErrNone ) |
|
793 { |
|
794 // Can't close db on RAM drive, so cleanup. |
|
795 MPX_DEBUG2("CMPXDbManager::CloseDatabaseL CloseDatabaseAtIndexL fail: error = %d", err); |
|
796 // Delete dummy file |
|
797 RemoveDummyFile(i); |
|
798 iDatabaseHandles[i].iUseRAMdb = EFalse; |
|
799 // Delete database on RAM drive. |
|
800 User::LeaveIfError( BaflUtils::DeleteFile(iFs, *iDatabaseHandles[i].iTargetFullFilePath) ); |
|
801 } |
|
802 else |
|
803 { |
|
804 DoCopyDBFromRam(i); |
|
805 } |
|
806 iDatabaseHandles[i].iUseRAMdb = EFalse; |
|
807 } |
|
808 else |
|
809 #endif |
|
810 { |
|
811 MPX_DEBUG2("CMPXDbManager::CloseDatabaseL found %d", aDrive); |
|
812 CloseDatabaseAtIndexL( i ); |
|
813 } |
|
814 |
|
815 if (transactionCount > 0) |
|
816 { |
|
817 DoBeginL(); |
|
818 iTransactionCount = transactionCount; |
|
819 } |
|
820 |
|
821 found = ETrue; |
|
822 break; |
|
823 } |
|
824 } |
|
825 } |
|
826 if (!found) |
|
827 { |
|
828 MPX_DEBUG1("CMPXDbManager::CloseDatabaseL not found"); |
|
829 User::Leave(KErrArgument); |
|
830 } |
|
831 |
|
832 } |
|
833 |
|
834 void CMPXDbManager::CloseDatabaseAtIndexL( TInt aIndex ) |
|
835 { |
756 // Close all prepared statements if a db is closed |
836 // Close all prepared statements if a db is closed |
757 // |
837 // |
758 ResetPreparedQueries(); |
838 ResetPreparedQueries(); |
759 |
839 |
760 TDriveUnit drive(aDrive); |
840 if (iDatabaseHandles[aIndex].iOpen) |
761 TDriveUnit cdrive(KRootDrive()); |
841 { |
762 TBool found(EFalse); |
842 MPX_DEBUG1("CMPXDbManager::CloseDatabaseAtIndexL found open"); |
763 |
843 DetachDatabaseL( aIndex ); |
764 if ((drive != cdrive) && !IsRemoteDrive(static_cast<TDriveNumber>(aDrive))) |
844 } |
765 { |
845 } |
766 TInt count(iDatabaseHandles.Count()); |
|
767 for (TInt i = 0; i < count; ++i) |
|
768 { |
|
769 if (iDatabaseHandles[i].iDrive == aDrive) |
|
770 { |
|
771 MPX_DEBUG2("CMPXDbManager::CloseDatabaseL found %d", aDrive); |
|
772 if (iDatabaseHandles[i].iOpen) |
|
773 { |
|
774 MPX_DEBUG1("CMPXDbManager::CloseDatabaseL found open"); |
|
775 DetachDatabaseL(drive); |
|
776 } |
|
777 |
|
778 found = ETrue; |
|
779 break; |
|
780 } |
|
781 } |
|
782 } |
|
783 if (!found) |
|
784 { |
|
785 MPX_DEBUG1("CMPXDbManager::CloseDatabaseL not found"); |
|
786 User::Leave(KErrArgument); |
|
787 } |
|
788 |
|
789 } |
|
790 |
846 |
791 // ---------------------------------------------------------------------------- |
847 // ---------------------------------------------------------------------------- |
792 // Closes all databases. |
848 // Closes all databases. |
793 // ---------------------------------------------------------------------------- |
849 // ---------------------------------------------------------------------------- |
794 // |
850 // |
1742 |
1800 |
1743 // ---------------------------------------------------------------------------- |
1801 // ---------------------------------------------------------------------------- |
1744 // Attaches a specified database. |
1802 // Attaches a specified database. |
1745 // ---------------------------------------------------------------------------- |
1803 // ---------------------------------------------------------------------------- |
1746 // |
1804 // |
1747 void CMPXDbManager::AttachDatabaseL( |
1805 void CMPXDbManager::AttachDatabaseL( TInt aIndex ) |
1748 TDriveUnit aDrive) |
|
1749 { |
1806 { |
1750 MPX_FUNC("CMPXDbManager::AttachDatabaseL"); |
1807 MPX_FUNC("CMPXDbManager::AttachDatabaseL"); |
1751 |
1808 ASSERT( aIndex < iDatabaseHandles.Count() ); |
1752 TBool found(EFalse); |
1809 DatabaseHandle & database = iDatabaseHandles[ aIndex ]; |
1753 |
1810 if (!database.iOpen) |
1754 TInt count(iDatabaseHandles.Count()); |
1811 { |
1755 for (TInt i = 0; i < count; ++i) |
1812 HBufC* filename = CreateFilenameL( database.iDrive ); |
1756 { |
1813 CleanupStack::PushL(filename); |
1757 if (iDatabaseHandles[i].iDrive == aDrive) |
|
1758 { |
|
1759 if (!iDatabaseHandles[i].iOpen) |
|
1760 { |
|
1761 HBufC* filename = CreateFilenameL(aDrive); |
|
1762 CleanupStack::PushL(filename); |
|
1763 |
1814 |
1764 #ifdef __RAMDISK_PERF_ENABLE |
1815 #ifdef __RAMDISK_PERF_ENABLE |
1765 if( iDatabaseHandles[i].iUseRAMdb ) |
1816 if( database.iUseRAMdb ) |
1766 { |
1817 { |
1767 delete iDatabaseHandles[i].iAliasname; |
1818 delete database.iAliasname; |
1768 iDatabaseHandles[i].iAliasname = HBufC::NewL(KAliasName().Length()); |
1819 database.iAliasname = HBufC::NewL(KAliasName().Length()); |
1769 HBufC* temp = HBufC::NewLC(2); // form of DE, DF, DX,... |
1820 HBufC* temp = HBufC::NewLC(2); // form of DE, DF, DX,... |
1770 temp->Des().Append(iRAMDrive); // length == 2 |
1821 temp->Des().Append(iRAMDrive); // length == 2 |
1771 TDriveUnit pdrive(aDrive); |
1822 TDriveUnit pdrive( database.iDrive ); |
1772 temp->Des().Append(pdrive.Name().Left(1)); //length == 2+ 1 |
1823 temp->Des().Append(pdrive.Name().Left(1)); //length == 2+ 1 |
1773 iDatabaseHandles[i].iAliasname->Des().Format(KRAMAliasName, temp); |
1824 database.iAliasname->Des().Format(KRAMAliasName, temp); |
1774 MPX_DEBUG2("CMPXDbManager::AttachDatabaseL - RAM change aliasname of %S", iDatabaseHandles[i].iAliasname ); |
1825 MPX_DEBUG2("CMPXDbManager::AttachDatabaseL - RAM change aliasname of %S", database.iAliasname ); |
1775 CleanupStack::PopAndDestroy(temp); |
1826 CleanupStack::PopAndDestroy(temp); |
1776 } |
1827 } |
1777 else |
1828 else |
1778 #endif //__RAMDISK_PERF_ENABLE |
1829 #endif //__RAMDISK_PERF_ENABLE |
1779 { |
1830 { |
1780 delete iDatabaseHandles[i].iAliasname; |
1831 delete database.iAliasname; |
1781 TDriveUnit drive(aDrive); |
1832 TDriveUnit drive( database.iDrive ); |
1782 const TDesC& driveName = drive.Name(); |
1833 const TDesC& driveName = drive.Name(); |
1783 iDatabaseHandles[i].iAliasname = HBufC::NewL(KAliasName().Length()); |
1834 database.iAliasname = HBufC::NewL(KAliasName().Length()); |
1784 iDatabaseHandles[i].iAliasname->Des().Format(KAliasName, &driveName); |
1835 database.iAliasname->Des().Format(KAliasName, &driveName); |
1785 MPX_DEBUG2("CMPXDbManager::AttachDatabaseL - normal change aliasname of %S", iDatabaseHandles[i].iAliasname); |
1836 MPX_DEBUG2("CMPXDbManager::AttachDatabaseL - normal change aliasname of %S", database.iAliasname); |
1786 } |
1837 } |
1787 |
1838 |
1788 TInt err = iDatabase.Attach(filename->Des(), *(iDatabaseHandles[i].iAliasname)); |
1839 TInt err = iDatabase.Attach( *filename, *database.iAliasname ); |
1789 MPX_DEBUG2("CMPXDbManager::AttachDatabaseL - Attach Error =%d", err); |
1840 MPX_DEBUG2("CMPXDbManager::AttachDatabaseL - Attach Error =%d", err); |
1790 User::LeaveIfError(err); |
1841 User::LeaveIfError(err); |
1791 iDatabaseHandles[i].iOpen = ETrue; |
1842 database.iOpen = ETrue; |
1792 |
1843 |
1793 CleanupStack::PopAndDestroy(filename); |
1844 CleanupStack::PopAndDestroy(filename); |
1794 } |
1845 } |
1795 else |
1846 else |
1796 { |
1847 { |
1797 MPX_DEBUG1("CMPXDbManager::AttachDatabaseL - found already open"); |
1848 MPX_DEBUG1("CMPXDbManager::AttachDatabaseL - found already open"); |
1798 } |
|
1799 |
|
1800 found = ETrue; |
|
1801 break; |
|
1802 } |
|
1803 } |
|
1804 if (!found) |
|
1805 { |
|
1806 MPX_DEBUG1("CMPXDbManager::AttachDatabaseL - not found"); |
|
1807 User::Leave(KErrNotFound); |
|
1808 } |
1849 } |
1809 } |
1850 } |
1810 |
1851 |
1811 // ---------------------------------------------------------------------------- |
1852 // ---------------------------------------------------------------------------- |
1812 // Detaches a specified database. |
1853 // Detaches a specified database. |
1813 // ---------------------------------------------------------------------------- |
1854 // ---------------------------------------------------------------------------- |
1814 // |
1855 // |
1815 void CMPXDbManager::DetachDatabaseL( |
1856 void CMPXDbManager::DetachDatabaseL( TInt aIndex ) |
1816 TDriveUnit aDrive) |
|
1817 { |
1857 { |
1818 MPX_FUNC("CMPXDbManager::DetachDatabaseL"); |
1858 MPX_FUNC("CMPXDbManager::DetachDatabaseL"); |
1819 |
1859 |
1820 ASSERT(iInitialized); |
1860 ASSERT( iInitialized && aIndex < iDatabaseHandles.Count() ); |
1821 TBool found(EFalse); |
1861 DatabaseHandle & database = iDatabaseHandles[ aIndex ]; |
1822 |
1862 if ( database.iOpen ) |
1823 TInt count(iDatabaseHandles.Count()); |
1863 { |
1824 for (TInt i = 0; i < count; ++i) |
1864 MPX_DEBUG2("CMPXDbManager::DetachDatabaseL iAliasname=%S is open",database.iAliasname ); |
1825 { |
1865 TInt err = iDatabase.Detach(*(database.iAliasname)); |
1826 if (iDatabaseHandles[i].iDrive == aDrive) |
1866 if ( err ) |
1827 { |
1867 { |
1828 #ifdef __RAMDISK_PERF_ENABLE |
1868 MPX_DEBUG2("CMPXDbManager::DetachDatabaseL detach failed Error=%d", err); |
1829 if ( iDatabaseHandles[i].iOpen || iDatabaseHandles[i].iUseRAMdb ) |
1869 } |
1830 #else //__RAMDISK_PERF_ENABLE |
1870 User::LeaveIfError(err); |
1831 if ( iDatabaseHandles[i].iOpen ) |
1871 database.iOpen = EFalse; |
1832 #endif //__RAMDISK_PERF_ENABLE |
|
1833 |
|
1834 { |
|
1835 MPX_DEBUG1("CMPXDbManager::DetachDatabaseL found drive that is opening"); |
|
1836 TInt err = iDatabase.Detach(*(iDatabaseHandles[i].iAliasname)); |
|
1837 if ( err ) |
|
1838 { |
|
1839 MPX_DEBUG2("CMPXDbManager::DetachDatabaseL detach failed Error=%d", err); |
|
1840 } |
|
1841 else |
|
1842 { |
|
1843 MPX_DEBUG2("CMPXDbManager::DetachDatabaseL iAliasname=%S", iDatabaseHandles[i].iAliasname); |
|
1844 } |
|
1845 User::LeaveIfError(err); |
|
1846 iDatabaseHandles[i].iOpen = EFalse; |
|
1847 } |
|
1848 |
|
1849 found = ETrue; |
|
1850 break; |
|
1851 } |
|
1852 } |
|
1853 if (!found) |
|
1854 { |
|
1855 MPX_DEBUG1("CMPXDbManager::DetachDatabaseL drive not found in iDatabaseHandlers"); |
|
1856 User::Leave(KErrNotFound); |
|
1857 } |
1872 } |
1858 } |
1873 } |
1859 |
1874 |
1860 // ---------------------------------------------------------------------------- |
1875 // ---------------------------------------------------------------------------- |
1861 // Creates the absolute database filename on a specified drive. |
1876 // Creates the absolute database filename on a specified drive. |
2603 |
2616 |
2604 // --------------------------------------------------------------------------- |
2617 // --------------------------------------------------------------------------- |
2605 // CMPXDbManager::BlockDiskSpaceL |
2618 // CMPXDbManager::BlockDiskSpaceL |
2606 // --------------------------------------------------------------------------- |
2619 // --------------------------------------------------------------------------- |
2607 // |
2620 // |
2608 TBool CMPXDbManager::BlockDiskSpace( TDriveUnit aDrive, TInt aOrigDbSize, TBool aIsMTPInUse ) |
2621 TBool CMPXDbManager::BlockDiskSpace( TInt aIndex, TBool aIsMTPInUse ) |
2609 { |
2622 { |
2610 #ifdef __RAMDISK_PERF_ENABLE |
2623 #ifdef __RAMDISK_PERF_ENABLE |
2611 |
2624 |
2612 MPX_DEBUG2("-->CMPXDbManager::BlockDiskSpaceL %d", (TInt)aDrive ); |
2625 MPX_DEBUG2("-->CMPXDbManager::BlockDiskSpaceL %d", aIndex ); |
2613 |
2626 DatabaseHandle & database = iDatabaseHandles[aIndex]; |
2614 // if current DB size can not fit in RAM, abort now |
2627 // if current DB size can not fit in RAM, abort now |
2615 TInt ramDrive; |
2628 TInt ramDrive; |
2616 RFs::CharToDrive(iRAMDrive, ramDrive); |
2629 RFs::CharToDrive(iRAMDrive, ramDrive); |
2617 TVolumeInfo vol; |
2630 TVolumeInfo vol; |
2618 TInt err = iFs.Volume( vol, ramDrive ); |
2631 TInt err = iFs.Volume( vol, ramDrive ); |
2619 if ( vol.iFree <= aOrigDbSize + KMPMinimumRAMSizeToRun ) |
2632 TEntry origDb; |
|
2633 iFs.Entry( *database.iOrigFullFilePath, origDb ); |
|
2634 if ( vol.iFree <= origDb.iSize + KMPMinimumRAMSizeToRun ) |
2620 { |
2635 { |
2621 MPX_DEBUG1("-->CMPXDbManager::BlockDiskSpaceL Not enough even for copy original DB file, leave" ); |
2636 MPX_DEBUG1("-->CMPXDbManager::BlockDiskSpaceL Not enough even for copy original DB file, leave" ); |
2622 return EFalse; |
2637 return EFalse; |
2623 } |
2638 } |
2624 |
2639 |
2625 // ensure you have the disk volume and database |
2640 // ensure you have the disk volume and database |
2626 err = iFs.Volume( vol, (TInt)aDrive ); |
2641 err = iFs.Volume( vol, database.iDrive ); |
2627 if (err != KErrNone) |
2642 if (err != KErrNone) |
2628 { |
2643 { |
2629 MPX_DEBUG2("CMPXDbManager::BlockDiskSpaceL Volume not available on drive %d", (TInt)aDrive); |
2644 MPX_DEBUG2("CMPXDbManager::BlockDiskSpaceL Volume not available on drive %d", database.iDrive); |
2630 return EFalse; |
|
2631 } |
|
2632 |
|
2633 TInt index( GetDatabaseIndex((TInt)aDrive) ); |
|
2634 if (index < 0) |
|
2635 { |
|
2636 MPX_DEBUG2("CMPXDbManager::BlockDiskSpaceL Database not available for drive %d", (TInt)aDrive); |
|
2637 return EFalse; |
2645 return EFalse; |
2638 } |
2646 } |
2639 |
2647 |
2640 // Check if the drive has enough space to block |
2648 // Check if the drive has enough space to block |
2641 MPX_DEBUG2("CMPXDbManager::BlockDiskSpaceL Disk total free space in bytes =%Lu", vol.iFree); |
2649 MPX_DEBUG2("CMPXDbManager::BlockDiskSpaceL Disk total free space in bytes =%Lu", vol.iFree); |
2642 TInt64 blockingSize( CalculateInitalDummyDBSize( vol, aOrigDbSize, aIsMTPInUse )); |
2650 TInt64 blockingSize( CalculateInitalDummyDBSize( vol, origDb.iSize, aIsMTPInUse )); |
2643 MPX_DEBUG2("CMPXDbManager::BlockDiskSpaceL Disk blocking size =%Lu", blockingSize); |
2651 MPX_DEBUG2("CMPXDbManager::BlockDiskSpaceL Disk blocking size =%Lu", blockingSize); |
2644 if ( vol.iFree <= blockingSize + 1*KMPMegaByte ) |
2652 if ( vol.iFree <= blockingSize + 1*KMPMegaByte ) |
2645 { |
2653 { |
2646 MPX_DEBUG1("CMPXDbManager::BlockDiskSpaceL NOk to block"); |
2654 MPX_DEBUG1("CMPXDbManager::BlockDiskSpaceL NOk to block"); |
2647 return EFalse; |
2655 return EFalse; |
2648 } |
2656 } |
2649 |
2657 |
2650 // Create and resize the dummy file |
2658 // Create and resize the dummy file |
2651 TFileName dummyDbFileName; |
|
2652 TChar ch; |
2659 TChar ch; |
2653 RFs::DriveToChar((TInt)aDrive, ch ); |
2660 RFs::DriveToChar(database.iDrive, ch ); |
2654 dummyDbFileName.Format( KDummyDbFile, (TUint)ch); |
2661 database.iDummyFilePath.Format( KDummyDbFile, (TUint)ch); |
2655 RFile dummyDb; |
2662 RFile dummyDb; |
2656 err = dummyDb.Replace( iFs, dummyDbFileName, EFileWrite ); |
2663 err = dummyDb.Replace( iFs, database.iDummyFilePath, EFileWrite ); |
2657 if (err != KErrNone) |
2664 if (err != KErrNone) |
2658 { |
2665 { |
2659 MPX_DEBUG2("CMPXDbManager::BlockDiskSpaceL Can't open dummy file %d", err); |
2666 MPX_DEBUG2("CMPXDbManager::BlockDiskSpaceL Can't open dummy file %d", err); |
|
2667 database.iDummyFilePath.Zero(); |
2660 return EFalse; |
2668 return EFalse; |
2661 } |
2669 } |
2662 err = dummyDb.SetSize( blockingSize ); |
2670 err = dummyDb.SetSize( blockingSize ); |
2663 if ( err ) |
2671 if ( err ) |
2664 { |
2672 { |
2665 MPX_DEBUG2("CMPXDbManager::BlockDiskSpaceL Can't resize dummy file %d", err); |
2673 MPX_DEBUG2("CMPXDbManager::BlockDiskSpaceL Can't resize dummy file %d", err); |
2666 dummyDb.Close(); |
2674 dummyDb.Close(); |
|
2675 RemoveDummyFile(aIndex); |
2667 return EFalse; |
2676 return EFalse; |
2668 } |
2677 } |
2669 |
2678 |
2670 dummyDb.Close(); |
2679 dummyDb.Close(); |
2671 MPX_DEBUG1("CMPXDbManager::BlockDiskSpaceL Ok to block"); |
2680 MPX_DEBUG1("CMPXDbManager::BlockDiskSpaceL Ok to block"); |
2672 |
|
2673 iDatabaseHandles[index].iDummyFilePath.Copy(dummyDbFileName); |
|
2674 MPX_DEBUG1("<--CMPXDbManager::BlockDiskSpace"); |
2681 MPX_DEBUG1("<--CMPXDbManager::BlockDiskSpace"); |
2675 |
2682 |
2676 return ETrue; |
2683 return ETrue; |
2677 #else |
2684 #else |
2678 return EFalse; |
2685 return EFalse; |