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