mtpfws/mtpfw/src/cmtpobjectstore.cpp
changeset 49 c20dd21d1eb4
parent 31 a26669f87b46
child 51 64200268cac2
equal deleted inserted replaced
41:2c19c7cf5550 49:c20dd21d1eb4
    31 #include "cmtpdpidstore.h"
    31 #include "cmtpdpidstore.h"
    32 #include "cmtppkgidstore.h"
    32 #include "cmtppkgidstore.h"
    33 #include "cmtpdeltadatamgr.h"
    33 #include "cmtpdeltadatamgr.h"
    34 #include <e32hashtab.h>
    34 #include <e32hashtab.h>
    35 #include "cmtpstoragemgr.h"
    35 #include "cmtpstoragemgr.h"
       
    36 #include "mtpdebug.h"
       
    37 #include "OstTraceDefinitions.h"
       
    38 #ifdef OST_TRACE_COMPILER_IN_USE
       
    39 #include "cmtpobjectstoreTraces.h"
       
    40 #endif
       
    41 
    36 
    42 
    37 _LIT(KMTPDbDriveLocation, "c:");
    43 _LIT(KMTPDbDriveLocation, "c:");
    38 _LIT(KMTPBackSlash, "\\");
    44 _LIT(KMTPBackSlash, "\\");
    39 _LIT(KMTPHandleObjectDbName, "MTPObjectStore.db");
    45 _LIT(KMTPHandleObjectDbName, "MTPObjectStore.db");
    40 _LIT(KMTPNoBackupFolderName, "nobackup");
    46 _LIT(KMTPNoBackupFolderName, "nobackup");
    45 _LIT(KSQLSuidHash, "SuidIndex");
    51 _LIT(KSQLSuidHash, "SuidIndex");
    46 _LIT(KSQLCreateSuidIndexText,"CREATE INDEX SuidIndex on HandleStore (SuidHash)");
    52 _LIT(KSQLCreateSuidIndexText,"CREATE INDEX SuidIndex on HandleStore (SuidHash)");
    47 _LIT(KSQLParentHandle, "ParentHandleIndex");
    53 _LIT(KSQLParentHandle, "ParentHandleIndex");
    48 _LIT(KSQLCreateParentHandleText,"CREATE INDEX ParentHandleIndex on HandleStore (ParentHandle)");
    54 _LIT(KSQLCreateParentHandleText,"CREATE INDEX ParentHandleIndex on HandleStore (ParentHandle)");
    49 _LIT(KMTPFormat, "MTP");
    55 _LIT(KMTPFormat, "MTP");
    50 __FLOG_STMT(_LIT8(KComponent,"MTPObjectStore");)
       
    51 const TInt KMaxLimitCommitInEnumeration = 1024;
    56 const TInt KMaxLimitCommitInEnumeration = 1024;
    52 const TInt KMaxLimitCommitAfterEnumeration = 256;
    57 const TInt KMaxLimitCommitAfterEnumeration = 256;
    53 const TInt KMaxLimitCompactInEnumeration = 2048;
    58 const TInt KMaxLimitCompactInEnumeration = 2048;
    54 const TInt KMaxLimitCompactAfterEnumeration = 1024;
    59 const TInt KMaxLimitCompactAfterEnumeration = 1024;
    55 const TInt KSnapshotGranularity = 128; 
    60 const TInt KSnapshotGranularity = 128; 
    68     CleanupStack::Pop(self);
    73     CleanupStack::Pop(self);
    69     return self;
    74     return self;
    70 
    75 
    71     }
    76     }
    72 
    77 
       
    78 CMTPObjectStore::CSnapshotWorker::~CSnapshotWorker()
       
    79     {
       
    80     Cancel();
       
    81     }
    73 void CMTPObjectStore::CSnapshotWorker::RunL()
    82 void CMTPObjectStore::CSnapshotWorker::RunL()
    74     {
    83     {
    75     iObjectStore->CleanDBSnapshotL(iOnlyRoot);
    84     iObjectStore->CleanDBSnapshotL(iOnlyRoot);
    76     }
    85     }
    77 
    86 
   137 	iBatched_SuidHashID.Close();
   146 	iBatched_SuidHashID.Close();
   138 	CloseDb();
   147 	CloseDb();
   139 	iSingletons.Close();
   148 	iSingletons.Close();
   140 	iNonPersistentDPList.Close();
   149 	iNonPersistentDPList.Close();
   141 	iEnumeratingCacheObjList.ResetAndDestroy();
   150 	iEnumeratingCacheObjList.ResetAndDestroy();
   142 	__FLOG_CLOSE;
       
   143 	}
   151 	}
   144 
   152 
   145 /**
   153 /**
   146  Provides a reference to the object meta data store database.
   154  Provides a reference to the object meta data store database.
   147  @return The object information store database.
   155  @return The object information store database.
   190 void CMTPObjectStore::MarkNonPersistentObjectsL(TUint aDataProviderId, TUint32)
   198 void CMTPObjectStore::MarkNonPersistentObjectsL(TUint aDataProviderId, TUint32)
   191 	{
   199 	{
   192 	TInt result = iNonPersistentDPList.InsertInOrder(aDataProviderId);
   200 	TInt result = iNonPersistentDPList.InsertInOrder(aDataProviderId);
   193 	if(result != KErrAlreadyExists)
   201 	if(result != KErrAlreadyExists)
   194 		{
   202 		{
   195 		User::LeaveIfError(result);
   203 		LEAVEIFERROR(result,
       
   204 		        OstTrace1( TRACE_ERROR, CMTPOBJECTSTORE_MARKNONPERSISTENTOBJECTSL, "insert DpId %d into iNonPersistentDPList error!", aDataProviderId ));
   196 		}
   205 		}
   197 	}
   206 	}
   198 
   207 
   199 void CMTPObjectStore::MarkDPLoadedL(TUint aDataProviderId, TBool aFlag)
   208 void CMTPObjectStore::MarkDPLoadedL(TUint aDataProviderId, TBool aFlag)
   200 	{
   209 	{
   201 	__FLOG(_L8("MarkDPFlafFalseL - Entry"));
   210     OstTraceFunctionEntry0( CMTPOBJECTSTORE_MARKDPLOADEDL_ENTRY );
   202 	if (!aFlag)
   211 	if (!aFlag)
   203 		{
   212 		{
   204 		_LIT(KSQLMarkfalgDPFalse, "UPDATE HandleStore SET DPFlag = %u WHERE DataProviderId = %u");
   213 		_LIT(KSQLMarkfalgDPFalse, "UPDATE HandleStore SET DPFlag = %u WHERE DataProviderId = %u");
   205 		iSqlStatement.Format(KSQLMarkfalgDPFalse, aFlag, aDataProviderId);
   214 		iSqlStatement.Format(KSQLMarkfalgDPFalse, aFlag, aDataProviderId);
   206 		User::LeaveIfError(iDatabase.Execute(iSqlStatement));
   215 		LEAVEIFERROR(iDatabase.Execute(iSqlStatement),
   207 		}
   216 		        OstTrace0( TRACE_ERROR, CMTPOBJECTSTORE_MARKDPLOADEDL, "UPDATE HandleStore SET DPFlag error!" ));
   208 	__FLOG(_L8("MarkNonPersistentObjectsL - Exit"));
   217 		        
       
   218 		}
       
   219 	OstTraceFunctionExit0( CMTPOBJECTSTORE_MARKDPLOADEDL_EXIT );
   209 	}
   220 	}
   210 
   221 
   211 TBool CMTPObjectStore::FilterObject(const RDbTable& aCurrRow,const TUint32 aStorageID,const TUint32 aFormatCode,const TUint32 aDpID) const
   222 TBool CMTPObjectStore::FilterObject(const RDbTable& aCurrRow,const TUint32 aStorageID,const TUint32 aFormatCode,const TUint32 aDpID) const
   212     {
   223     {
   213     return  ( ((KMTPStorageAll==aStorageID) ||(aCurrRow.ColUint32(EObjectStoreStorageId)== aStorageID)) 
   224     return  ( ((KMTPStorageAll==aStorageID) ||(aCurrRow.ColUint32(EObjectStoreStorageId)== aStorageID)) 
   335 	TFileName suid;
   346 	TFileName suid;
   336 	suid.CopyLC(aObject.DesC(CMTPObjectMetaData::ESuid));
   347 	suid.CopyLC(aObject.DesC(CMTPObjectMetaData::ESuid));
   337 	TUint32 handle = HandleL(suid);
   348 	TUint32 handle = HandleL(suid);
   338 	if (handle != KMTPHandleNone)
   349 	if (handle != KMTPHandleNone)
   339 	    {
   350 	    {
   340 	    __FLOG(_L8("CommitReserverd leave for duplicate suid."));
   351 	    OstTrace0(TRACE_ERROR, CMTPOBJECTSTORE_COMMITRESERVEDOBJECTHANDLEL,
       
   352 	            "CommitReserverd leave for duplicate suid.");
   341 	    User::Leave(KErrAlreadyExists);
   353 	    User::Leave(KErrAlreadyExists);
   342 	    }
   354 	    }
   343 	TUint32 suidHash = DefaultHash::Des16(suid);
   355 	TUint32 suidHash = DefaultHash::Des16(suid);
   344 	
   356 	
   345 	//After the PutL called the cursor's position is not well defined.
   357 	//After the PutL called the cursor's position is not well defined.
   433 	reinterpret_cast<RDbTable*> (aTable)->Cancel();
   445 	reinterpret_cast<RDbTable*> (aTable)->Cancel();
   434 	}
   446 	}
   435 
   447 
   436 void CMTPObjectStore::InsertObjectL(CMTPObjectMetaData& aObject)
   448 void CMTPObjectStore::InsertObjectL(CMTPObjectMetaData& aObject)
   437 	{
   449 	{
   438 	__FLOG(_L8("InsertObjectL - Entry"));
   450     OstTraceFunctionEntry0( CMTPOBJECTSTORE_INSERTOBJECTL_ENTRY );
       
   451 
   439 	iCachedHandle = 0;
   452 	iCachedHandle = 0;
   440 	iCachedSuidHash = 0;
   453 	iCachedSuidHash = 0;
   441 	TBool needToInsert = EFalse;
   454 	TBool needToInsert = EFalse;
   442 	TBool needUpdateOwner = EFalse;
   455 	TBool needUpdateOwner = EFalse;
   443 	TUint dpId(aObject.Uint(CMTPObjectMetaData::EDataProviderId));
   456 	TUint dpId(aObject.Uint(CMTPObjectMetaData::EDataProviderId));
   444 
   457 
   445 	if ((aObject.DesC(CMTPObjectMetaData::ESuid)).Length() > KMaxFileName)
   458 	if ((aObject.DesC(CMTPObjectMetaData::ESuid)).Length() > KMaxFileName)
   446 	{
   459 	{
   447 	// The length of object uid should not excceeds KMaxFileName
   460 	// The length of object uid should not excceeds KMaxFileName
       
   461 	OstTrace0( TRACE_ERROR, DUP4_CMTPOBJECTSTORE_INSERTOBJECTL, "The length of object uid excceeds KMaxFileName" );
   448 	User::Leave( KErrBadName );
   462 	User::Leave( KErrBadName );
   449 	}
   463 	}
   450 
   464 
   451 	TFileName suid;
   465 	TFileName suid;
   452 	suid.CopyLC(aObject.DesC(CMTPObjectMetaData::ESuid));
   466 	suid.CopyLC(aObject.DesC(CMTPObjectMetaData::ESuid));
   490 					needUpdateOwner = ETrue;
   504 					needUpdateOwner = ETrue;
   491 					}
   505 					}
   492 				delete iEnumeratingCacheObjList[found];
   506 				delete iEnumeratingCacheObjList[found];
   493 				iEnumeratingCacheObjList.Remove(found);
   507 				iEnumeratingCacheObjList.Remove(found);
   494 				}
   508 				}
   495 			__FLOG_VA(_L8("Found in Snapshot"));
   509 			OstTrace0(TRACE_NORMAL, CMTPOBJECTSTORE_INSERTOBJECTL, "Found in Snapshot");
   496 			}
   510 			}
   497 		else
   511 		else
   498 			{//This is a totally new object. insert it after check the db to prevent user wrong operation
   512 			{//This is a totally new object. insert it after check the db to prevent user wrong operation
   499 			handle = HandleL(aObject.DesC(CMTPObjectMetaData::ESuid));
   513 			handle = HandleL(aObject.DesC(CMTPObjectMetaData::ESuid));
   500 			if (handle == KMTPHandleNone)
   514 			if (handle == KMTPHandleNone)
   512 						needUpdateOwner = ETrue;
   526 						needUpdateOwner = ETrue;
   513 						}
   527 						}
   514 					}
   528 					}
   515 				CleanupStack::PopAndDestroy(object);
   529 				CleanupStack::PopAndDestroy(object);
   516 				}
   530 				}
   517 			__FLOG_VA(_L8("Not Found in Snapshot"));
   531 			OstTrace0(TRACE_NORMAL, DUP1_CMTPOBJECTSTORE_INSERTOBJECTL, "Not Found in Snapshot");
   518 			}
   532 			}
   519 		__FLOG_VA((_L8("InsertObjectL Under enmueration, needUpdateOwner %d needToInsert %d"), needUpdateOwner, needToInsert));
   533 		OstTraceExt2(TRACE_NORMAL, DUP2_CMTPOBJECTSTORE_INSERTOBJECTL, 
       
   534 		        "InsertObjectL Under enmueration, needUpdateOwner %d needToInsert %d", needUpdateOwner, needToInsert);
   520 		}
   535 		}
   521 	else
   536 	else
   522 		{
   537 		{
   523 		handle = HandleL(aObject.DesC(CMTPObjectMetaData::ESuid));
   538 		handle = HandleL(aObject.DesC(CMTPObjectMetaData::ESuid));
   524 		if (handle != KMTPHandleNone)
   539 		if (handle != KMTPHandleNone)
   525 			{
   540 			{
   526 				//Leaves if id already exists in suid map table 
   541 				//Leaves if id already exists in suid map table 
       
   542             OstTrace1( TRACE_ERROR, DUP5_CMTPOBJECTSTORE_INSERTOBJECTL, "id %d already exists in suid map table", handle );
   527 			User::Leave(KErrAlreadyExists);
   543 			User::Leave(KErrAlreadyExists);
   528 			}
   544 			}
   529 		// dp is not enumerating, do a plain insert
   545 		// dp is not enumerating, do a plain insert
   530 		needToInsert = ETrue;
   546 		needToInsert = ETrue;
   531 		__FLOG_VA((_L8("InsertObjectL After enmueration, needUpdateOwner %d needToInsert %d"), needUpdateOwner, needToInsert));
   547         OstTraceExt2(TRACE_NORMAL, DUP3_CMTPOBJECTSTORE_INSERTOBJECTL, 
       
   548                 "InsertObjectL After enmueration, needUpdateOwner %d needToInsert %d", needUpdateOwner, needToInsert);		
   532 		}
   549 		}
   533 		
   550 		
   534 	if (needToInsert)//needToInsert and needUpdateOwner can't be true at same time
   551 	if (needToInsert)//needToInsert and needUpdateOwner can't be true at same time
   535 		{
   552 		{
   536 		TUint32 parentHandle(aObject.Uint(CMTPObjectMetaData::EParentHandle));
   553 		TUint32 parentHandle(aObject.Uint(CMTPObjectMetaData::EParentHandle));
   582 			{
   599 			{
   583 			iMtpDeltaDataMgr->UpdateDeltaDataTableL(id, CMtpDeltaDataMgr::EAdded);
   600 			iMtpDeltaDataMgr->UpdateDeltaDataTableL(id, CMtpDeltaDataMgr::EAdded);
   584 			}
   601 			}
   585 		}
   602 		}
   586 
   603 
   587 	__FLOG(_L8("InsertObjectL - Exit"));
   604 	OstTraceFunctionExit0( CMTPOBJECTSTORE_INSERTOBJECTL_EXIT );
   588 	}
   605 	}
   589 
   606 
   590 void CMTPObjectStore::IncTranOpsNumL()
   607 void CMTPObjectStore::IncTranOpsNumL()
   591 	{
   608 	{
   592 	iTransactionOps++;
   609 	iTransactionOps++;
   593 	if (iTransactionOps % iMaxCommitLimit == 0)
   610 	if (iTransactionOps % iMaxCommitLimit == 0)
   594 		{
   611 		{
   595 		CommitTransactionL();
   612 		CommitTransactionL();
   596 		if (iTransactionOps % iMaxCompactLimit == 0)
   613 		if (iTransactionOps % iMaxCompactLimit == 0)
   597 			{
   614 			{
   598 			User::LeaveIfError(iDatabase.Compact());
   615 			LEAVEIFERROR(iDatabase.Compact(),
       
   616 			        OstTrace0( TRACE_ERROR, CMTPOBJECTSTORE_INCTRANOPSNUML, "database compact error!" ));    
   599 			}
   617 			}
   600 		BeginTransactionL();
   618 		BeginTransactionL();
   601 		}
   619 		}
   602 	}
   620 	}
   603 
   621 
   604 void CMTPObjectStore::BeginTransactionL()
   622 void CMTPObjectStore::BeginTransactionL()
   605 	{
   623 	{
   606 	if (!iDatabase.InTransaction())
   624 	if (!iDatabase.InTransaction())
   607 		{
   625 		{
   608 		User::LeaveIfError(iDatabase.Begin());
   626 		LEAVEIFERROR(iDatabase.Begin(),
       
   627 		        OstTrace0( TRACE_ERROR, CMTPOBJECTSTORE_BEGINTRANSACTIONL, "database begin error!" ));
   609 		}
   628 		}
   610 	}
   629 	}
   611 
   630 
   612 void CMTPObjectStore::CommitTransactionL()
   631 void CMTPObjectStore::CommitTransactionL()
   613 	{
   632 	{
   614 	__FLOG(_L8("CommitTransactionL Entry"));
   633 	OstTraceFunctionEntry0( CMTPOBJECTSTORE_COMMITTRANSACTIONL_ENTRY );
   615 	if (iDatabase.InTransaction())
   634 	if (iDatabase.InTransaction())
   616 		{
   635 		{
   617 		User::LeaveIfError(iDatabase.Commit());
   636 		LEAVEIFERROR(iDatabase.Commit(),
   618 		}
   637 		        OstTrace0( TRACE_ERROR, CMTPOBJECTSTORE_COMMITTRANSACTIONL, "database commit error!" ));
   619 	__FLOG(_L8("CommitTransactionL Exit"));
   638 		        
       
   639 		}
       
   640 	OstTraceFunctionExit0( CMTPOBJECTSTORE_COMMITTRANSACTIONL_EXIT );
   620 	}
   641 	}
   621 
   642 
   622 void CMTPObjectStore::InsertObjectsL(RPointerArray<CMTPObjectMetaData>& aObjects)
   643 void CMTPObjectStore::InsertObjectsL(RPointerArray<CMTPObjectMetaData>& aObjects)
   623 	{
   644 	{
   624 	TInt count = aObjects.Count();
   645 	TInt count = aObjects.Count();
   639 		{
   660 		{
   640 		//To avoid this modification will not generate duplicate SUID
   661 		//To avoid this modification will not generate duplicate SUID
   641 		TUint32 handle2 = HandleL(suid);
   662 		TUint32 handle2 = HandleL(suid);
   642 		if (handle2 != KMTPHandleNone && handle2 != handle)
   663 		if (handle2 != KMTPHandleNone && handle2 != handle)
   643 		    {
   664 		    {
   644 		    __FLOG(_L8("ModifyObjectL leave for duplicate suid."));
   665 		    OstTrace0(TRACE_ERROR, CMTPOBJECTSTORE_MODIFYOBJECTL, "ModifyObjectL leave for duplicate suid.");
   645 		    User::Leave(KErrAlreadyExists); 
   666 		    User::Leave(KErrAlreadyExists); 
   646 		    }
   667 		    }
   647 		
   668 		
   648 		//After the PutL called the cursor's position is not well defined.
   669 		//After the PutL called the cursor's position is not well defined.
   649 		iCachedHandle = 0;
   670 		iCachedHandle = 0;
   682 				}
   703 				}
   683 			}
   704 			}
   684 		}
   705 		}
   685 	else
   706 	else
   686 		{
   707 		{
       
   708         OstTrace1( TRACE_ERROR, DUP1_CMTPOBJECTSTORE_MODIFYOBJECTL, "LocateByHandleL failed for handle %d", handle );
   687 		User::Leave(KErrNotFound);
   709 		User::Leave(KErrNotFound);
   688 		}
   710 		}
   689 	}
   711 	}
   690 
   712 
   691 TBool CMTPObjectStore::ObjectL(const TMTPTypeUint32& aHandle, CMTPObjectMetaData& aBuf) const
   713 TBool CMTPObjectStore::ObjectL(const TMTPTypeUint32& aHandle, CMTPObjectMetaData& aBuf) const
   733 const TPtrC CMTPObjectStore::ObjectSuidL(TUint32 aHandle) const
   755 const TPtrC CMTPObjectStore::ObjectSuidL(TUint32 aHandle) const
   734 	{
   756 	{
   735 	//iBatched owns the memory of Suid ?
   757 	//iBatched owns the memory of Suid ?
   736 	if (!LocateByHandleL(aHandle))
   758 	if (!LocateByHandleL(aHandle))
   737 		{
   759 		{
       
   760         OstTrace1( TRACE_ERROR, CMTPOBJECTSTORE_OBJECTSUIDL, "LocateByHandleL failed for handle %d", aHandle );
   738 		User::Leave(KErrNotFound);
   761 		User::Leave(KErrNotFound);
   739 		}
   762 		}
   740     DbColReadStreamL(iBatched, EObjectStoreSUID, iSuidBuf);
   763     DbColReadStreamL(iBatched, EObjectStoreSUID, iSuidBuf);
   741 	return iSuidBuf;
   764 	return iSuidBuf;
   742 	}
   765 	}
   743 
   766 
   744 TMTPTypeUint128 CMTPObjectStore::PuidL(TUint32 aHandle)
   767 TMTPTypeUint128 CMTPObjectStore::PuidL(TUint32 aHandle)
   745 	{
   768 	{
   746 	if (!LocateByHandleL(aHandle))
   769 	if (!LocateByHandleL(aHandle))
   747 		{
   770 		{
       
   771         OstTrace1( TRACE_ERROR, CMTPOBJECTSTORE_PUIDL_TUINT32, "LocateByHandleL failed for handle %d", aHandle );
   748 		User::Leave(KErrNotFound);
   772 		User::Leave(KErrNotFound);
   749 		}
   773 		}
   750 	TUint64 highHalfPOUID = static_cast<TUint64> (iBatched.ColInt64(EObjectStorePOUID));
   774 	TUint64 highHalfPOUID = static_cast<TUint64> (iBatched.ColInt64(EObjectStorePOUID));
   751 	// We actually use the first 64 bits to represent the PUID. this will represent 2^64=16 G xG objects, it is reasonable 
   775 	// We actually use the first 64 bits to represent the PUID. this will represent 2^64=16 G xG objects, it is reasonable 
   752 	//to assume the Phone, as a resource-constrained device, never will reach that number, therefore, we choose
   776 	//to assume the Phone, as a resource-constrained device, never will reach that number, therefore, we choose
   758 
   782 
   759 TMTPTypeUint128 CMTPObjectStore::PuidL(const TDesC& aSuid)
   783 TMTPTypeUint128 CMTPObjectStore::PuidL(const TDesC& aSuid)
   760 	{
   784 	{
   761 	if (!LocateBySuidL(aSuid))
   785 	if (!LocateBySuidL(aSuid))
   762 		{
   786 		{
       
   787         OstTraceExt1( TRACE_ERROR, CMTPOBJECTSTORE_PUIDL_TDESC, "LocateByHandleL failed for suid %S", aSuid );
   763 		User::Leave(KErrNotFound);
   788 		User::Leave(KErrNotFound);
   764 		}
   789 		}
   765 	TUint64 highHalfPOUID = static_cast<TUint64> (iBatched_SuidHashID.ColInt64(EObjectStorePOUID));
   790 	TUint64 highHalfPOUID = static_cast<TUint64> (iBatched_SuidHashID.ColInt64(EObjectStorePOUID));
   766 	// We actually use the first 64 bits to represent the PUID. this will represent 2^64=16 G xG objects, it is reasonable 
   791 	// We actually use the first 64 bits to represent the PUID. this will represent 2^64=16 G xG objects, it is reasonable 
   767 	//to assume the Phone, as a resource-constrained device, never will reach that number, therefore, we choose
   792 	//to assume the Phone, as a resource-constrained device, never will reach that number, therefore, we choose
   771 	return result;
   796 	return result;
   772 	}
   797 	}
   773 
   798 
   774 void CMTPObjectStore::RemoveObjectL(const TMTPTypeUint32& aHandle)
   799 void CMTPObjectStore::RemoveObjectL(const TMTPTypeUint32& aHandle)
   775     {
   800     {
   776     __FLOG_VA((_L8("RemoveObjectL Entry Handle = 0x%x"), aHandle.Value()));
   801     OstTraceFunctionEntry0( CMTPOBJECTSTORE_REMOVEOBJECTL_ENTRY );
       
   802     OstTrace1(TRACE_NORMAL, CMTPOBJECTSTORE_REMOVEOBJECTL, 
       
   803             "Handle = 0x%x", aHandle.Value());
   777     if (LocateByHandleL(aHandle.Value()))
   804     if (LocateByHandleL(aHandle.Value()))
   778         {
   805         {
   779         if (iSingletons.DpController().EnumerateState() != CMTPDataProviderController::EEnumeratedFulllyCompleted &&
   806         if (iSingletons.DpController().EnumerateState() != CMTPDataProviderController::EEnumeratedFulllyCompleted &&
   780                 IsMediaFormat(iBatched.ColUint16(EObjectStoreFormatCode)))
   807                 IsMediaFormat(iBatched.ColUint16(EObjectStoreFormatCode)))
   781             {
   808             {
   784             }
   811             }
   785         iCachedSuidHash = 0;
   812         iCachedSuidHash = 0;
   786         iCachedHandle = 0;
   813         iCachedHandle = 0;
   787         iReferenceMgr->RemoveReferencesL(aHandle.Value());
   814         iReferenceMgr->RemoveReferencesL(aHandle.Value());
   788         iBatched.DeleteL();
   815         iBatched.DeleteL();
   789         __FLOG(_L8("RemoveObjectL From iBacthed"));
   816         OstTrace0(TRACE_NORMAL, DUP1_CMTPOBJECTSTORE_REMOVEOBJECTL, "RemoveObjectL From iBacthed");
   790         IncTranOpsNumL();
   817         IncTranOpsNumL();
   791         }
   818         }
   792     __FLOG(_L8("RemoveObjectL Exit"));
   819     OstTraceFunctionExit0( CMTPOBJECTSTORE_REMOVEOBJECTL_EXIT );
   793     }
   820     }
   794 
   821 
   795 void CMTPObjectStore::RemoveObjectL(const TDesC& aSuid)
   822 void CMTPObjectStore::RemoveObjectL(const TDesC& aSuid)
   796 	{
   823 	{
   797 	if(LocateBySuidL(aSuid))
   824 	if(LocateBySuidL(aSuid))
   852 /**
   879 /**
   853  Clean unloaded data provider contents from object store
   880  Clean unloaded data provider contents from object store
   854  */
   881  */
   855 void CMTPObjectStore::CleanL()
   882 void CMTPObjectStore::CleanL()
   856 	{
   883 	{
   857 	__FLOG(_L8("CleanL - Entry"));
   884 	OstTraceFunctionEntry0( CMTPOBJECTSTORE_CLEANL_ENTRY );
   858 	
   885 	
   859 	RemoveUndefinedObjectsL();
   886 	RemoveUndefinedObjectsL();
   860 	Swi::RSisRegistrySession sisSession;
   887 	Swi::RSisRegistrySession sisSession;
   861 	User::LeaveIfError(sisSession.Connect());
   888 	LEAVEIFERROR(sisSession.Connect(),
       
   889 	        OstTrace0( TRACE_ERROR, DUP1_CMTPOBJECTSTORE_CLEANL, "can't connect to sisSession!" ));
   862 	CleanupClosePushL(sisSession);
   890 	CleanupClosePushL(sisSession);
   863 
   891 
   864 	const RArray<TUint>& loadedDPIDs = iPkgIDStore->DPIDL();
   892 	const RArray<TUint>& loadedDPIDs = iPkgIDStore->DPIDL();
   865 	RArray<TUint> unInstalledDpIDs;
   893 	RArray<TUint> unInstalledDpIDs;
   866 	CleanupClosePushL(unInstalledDpIDs);
   894 	CleanupClosePushL(unInstalledDpIDs);
   869 		TUid pkgUid = TUid::Uid(iPkgIDStore->PKGIDL(idx));
   897 		TUid pkgUid = TUid::Uid(iPkgIDStore->PKGIDL(idx));
   870 		if (!sisSession.IsInstalledL(pkgUid))
   898 		if (!sisSession.IsInstalledL(pkgUid))
   871 			{
   899 			{
   872 			//DP is uninstalled, remove DP related data from database.
   900 			//DP is uninstalled, remove DP related data from database.
   873 			TUint thisID = loadedDPIDs[idx];
   901 			TUint thisID = loadedDPIDs[idx];
   874 			__FLOG_1(_L("Data provider[%d] is removed from device!"),thisID);
   902 			OstTrace1(TRACE_NORMAL, CMTPOBJECTSTORE_CLEANL, "Data provider[%d] is removed from device!", thisID);
   875 			unInstalledDpIDs.AppendL(thisID);
   903 			unInstalledDpIDs.AppendL(thisID);
   876 			}
   904 			}
   877 		}
   905 		}
   878 	for (TUint index = 0; index < unInstalledDpIDs.Count(); ++index)
   906 	for (TUint index = 0; index < unInstalledDpIDs.Count(); ++index)
   879 		{
   907 		{
   880 		RemoveObjectsL(unInstalledDpIDs[index]);
   908 		RemoveObjectsL(unInstalledDpIDs[index]);
   881 		iPkgIDStore->RemoveL(unInstalledDpIDs[index]);
   909 		iPkgIDStore->RemoveL(unInstalledDpIDs[index]);
   882 		}
   910 		}
   883 	CleanupStack::PopAndDestroy(&unInstalledDpIDs);
   911 	CleanupStack::PopAndDestroy(&unInstalledDpIDs);
   884 	CleanupStack::PopAndDestroy(&sisSession);
   912 	CleanupStack::PopAndDestroy(&sisSession);
   885 	__FLOG(_L8("CleanL - Exit"));
   913 	OstTraceFunctionExit0( CMTPOBJECTSTORE_CLEANL_EXIT );
   886 	}
   914 	}
   887 
   915 
   888 TUint CMTPObjectStore::ObjectOwnerId(const TMTPTypeUint32& aHandle) const
   916 TUint CMTPObjectStore::ObjectOwnerId(const TMTPTypeUint32& aHandle) const
   889     {
   917     {
   890     if (!LocateByHandleL(aHandle.Value()))
   918     if (!LocateByHandleL(aHandle.Value()))
   903 /**
   931 /**
   904  Second phase constructor.
   932  Second phase constructor.
   905  */
   933  */
   906 void CMTPObjectStore::ConstructL()
   934 void CMTPObjectStore::ConstructL()
   907 	{
   935 	{
   908 	__FLOG_OPEN(KMTPSubsystem, KComponent);
       
   909 	iMaxCommitLimit = KMaxLimitCommitInEnumeration;
   936 	iMaxCommitLimit = KMaxLimitCommitInEnumeration;
   910 	iMaxCompactLimit = KMaxLimitCompactInEnumeration;
   937 	iMaxCompactLimit = KMaxLimitCompactInEnumeration;
   911 	iSingletons.OpenL();
   938 	iSingletons.OpenL();
   912 	InitializeDbL();
   939 	InitializeDbL();
   913 	iCompactor = CDbCompactor::NewL(&iDatabase);
   940 	iCompactor = CDbCompactor::NewL(&iDatabase);
   914 	iMtpDeltaDataMgr = CMtpDeltaDataMgr::NewL(iDatabase);
   941 	iMtpDeltaDataMgr = CMtpDeltaDataMgr::NewL(iDatabase);
   915 	iReferenceMgr = CMTPReferenceMgr::NewL(*this);
   942 	iReferenceMgr = CMTPReferenceMgr::NewL(*this);
   916 	iDPIDStore = CMTPDPIDStore::NewL(iDatabase);
   943 	iDPIDStore = CMTPDPIDStore::NewL(iDatabase);
   917 	iPkgIDStore = CMTPPkgIDStore::NewL(iDatabase);
   944 	iPkgIDStore = CMTPPkgIDStore::NewL(iDatabase);
   918 	User::LeaveIfError(iBatched.Open(iDatabase, KSQLHandleTableName, RDbRowSet::EUpdatable));
   945 	LEAVEIFERROR(iBatched.Open(iDatabase, KSQLHandleTableName, RDbRowSet::EUpdatable),
   919 	User::LeaveIfError(iBatched.SetIndex(KSQLHandleId));
   946 	        OstTrace0( TRACE_ERROR, CMTPOBJECTSTORE_CONSTRUCTL, "iBatched open error!" ));  
   920 	User::LeaveIfError(iBatched_SuidHashID.Open(iDatabase, KSQLHandleTableName, RDbRowSet::EUpdatable));
   947 	LEAVEIFERROR(iBatched.SetIndex(KSQLHandleId),
   921 	User::LeaveIfError(iBatched_SuidHashID.SetIndex(KSQLSuidHash));
   948 	        OstTrace0( TRACE_ERROR, DUP1_CMTPOBJECTSTORE_CONSTRUCTL, "set index for iBatched error!" ));
       
   949 	LEAVEIFERROR(iBatched_SuidHashID.Open(iDatabase, KSQLHandleTableName, RDbRowSet::EUpdatable),
       
   950 	        OstTrace0( TRACE_ERROR, DUP2_CMTPOBJECTSTORE_CONSTRUCTL, "iBatched_SuidHashID open error!" ));
       
   951 	LEAVEIFERROR(iBatched_SuidHashID.SetIndex(KSQLSuidHash),
       
   952 	        OstTrace0( TRACE_ERROR, DUP3_CMTPOBJECTSTORE_CONSTRUCTL, "set index for iBatched_SuidHashID error!"));
       
   953 
   922 	iHandleAllocator = CMTPHandleAllocator::NewL(*this);
   954 	iHandleAllocator = CMTPHandleAllocator::NewL(*this);
   923 	iSentinal = CEnumertingCacheItem::NewL(0, 0, 0, 0, 0, 0);
   955 	iSentinal = CEnumertingCacheItem::NewL(0, 0, 0, 0, 0, 0);
   924 	BeginTransactionL();
   956 	BeginTransactionL();
   925 	}
   957 	}
   926 
   958 
   970  */
  1002  */
   971 void CMTPObjectStore::CreateDbL(const TDesC& aFileName)
  1003 void CMTPObjectStore::CreateDbL(const TDesC& aFileName)
   972 	{
  1004 	{
   973 	BaflUtils::EnsurePathExistsL(iSingletons.Fs(), aFileName);
  1005 	BaflUtils::EnsurePathExistsL(iSingletons.Fs(), aFileName);
   974 
  1006 
   975 	User::LeaveIfError(iDatabase.Replace(iSingletons.Fs(), aFileName, KMTPFormat));
  1007 	LEAVEIFERROR(iDatabase.Replace(iSingletons.Fs(), aFileName, KMTPFormat),
       
  1008 	        OstTrace0( TRACE_ERROR, CMTPOBJECTSTORE_CREATEDBL, " a new non-secure database create error!" ));
       
  1009 	        
   976 	// Create table and index
  1010 	// Create table and index
   977 	CreateHandleTableL();
  1011 	CreateHandleTableL();
   978 	CreateHandleIndexL();
  1012 	CreateHandleIndexL();
   979 	iUpdateDeltaDataTable = ETrue;
  1013 	iUpdateDeltaDataTable = ETrue;
   980 	}
  1014 	}
  1010  */
  1044  */
  1011 void CMTPObjectStore::CreateHandleTableL()
  1045 void CMTPObjectStore::CreateHandleTableL()
  1012 	{
  1046 	{
  1013 	if (!DBUtility::IsTableExistsL(iDatabase, KSQLHandleTableName))
  1047 	if (!DBUtility::IsTableExistsL(iDatabase, KSQLHandleTableName))
  1014 		{
  1048 		{
  1015 		User::LeaveIfError(iDatabase.Execute(KSQLCreateHandleTableText));
  1049 		LEAVEIFERROR(iDatabase.Execute(KSQLCreateHandleTableText),
       
  1050 		        OstTrace0( TRACE_ERROR, CMTPOBJECTSTORE_CREATEHANDLETABLEL, "TABLE HandleStore create failed!" ));
  1016 		}
  1051 		}
  1017 	}
  1052 	}
  1018 
  1053 
  1019 /**
  1054 /**
  1020  Create three index on the table: 1. Handle, 2. SuidHash, 3. ParentHandle
  1055  Create three index on the table: 1. Handle, 2. SuidHash, 3. ParentHandle
  1023 	{
  1058 	{
  1024 	if (DBUtility::IsTableExistsL(iDatabase, KSQLHandleTableName))
  1059 	if (DBUtility::IsTableExistsL(iDatabase, KSQLHandleTableName))
  1025 		{
  1060 		{
  1026 		if (!DBUtility::IsIndexExistsL(iDatabase, KSQLHandleTableName, KSQLHandleId))
  1061 		if (!DBUtility::IsIndexExistsL(iDatabase, KSQLHandleTableName, KSQLHandleId))
  1027 			{
  1062 			{
  1028 			User::LeaveIfError(iDatabase.Execute(KSQLCreateHandleIndexText));
  1063 			LEAVEIFERROR(iDatabase.Execute(KSQLCreateHandleIndexText),
       
  1064 			        OstTrace0( TRACE_ERROR, CMTPOBJECTSTORE_CREATEHANDLEINDEXL, "INDEX HandleIndex on HandleStore create failed!" ));
  1029 			}
  1065 			}
  1030 
  1066 
  1031 		if (!DBUtility::IsIndexExistsL(iDatabase, KSQLHandleTableName, KSQLSuidHash))
  1067 		if (!DBUtility::IsIndexExistsL(iDatabase, KSQLHandleTableName, KSQLSuidHash))
  1032 			{
  1068 			{
  1033 			User::LeaveIfError(iDatabase.Execute(KSQLCreateSuidIndexText));
  1069 			LEAVEIFERROR(iDatabase.Execute(KSQLCreateSuidIndexText),
       
  1070 			        OstTrace0( TRACE_ERROR, DUP1_CMTPOBJECTSTORE_CREATEHANDLEINDEXL, "INDEX SuidIndex on HandleStore create failed!" ));
  1034 			}
  1071 			}
  1035 
  1072 
  1036 		if (!DBUtility::IsIndexExistsL(iDatabase, KSQLHandleTableName, KSQLParentHandle))
  1073 		if (!DBUtility::IsIndexExistsL(iDatabase, KSQLHandleTableName, KSQLParentHandle))
  1037 			{
  1074 			{
  1038 			User::LeaveIfError(iDatabase.Execute(KSQLCreateParentHandleText));
  1075 			LEAVEIFERROR(iDatabase.Execute(KSQLCreateParentHandleText),
       
  1076 			        OstTrace0( TRACE_ERROR, DUP2_CMTPOBJECTSTORE_CREATEHANDLEINDEXL, "INDEX ParentHandleIndex on HandleStore create failed!" ));
  1039 			}
  1077 			}
  1040 		}
  1078 		}
  1041 	else
  1079 	else
  1042 		{
  1080 		{
       
  1081         OstTrace0( TRACE_ERROR, DUP3_CMTPOBJECTSTORE_CREATEHANDLEINDEXL, "HandleStore table doesn't exist" );
  1043 		User::Leave(KErrNotFound);
  1082 		User::Leave(KErrNotFound);
  1044 		}
  1083 		}
  1045 	}
  1084 	}
  1046 
  1085 
  1047 /**
  1086 /**
  1066 
  1105 
  1067 	}
  1106 	}
  1068 
  1107 
  1069 TBool CMTPObjectStore::LocateByHandleL(const TUint aHandle, const TBool aReadTable /*default = ETrue*/) const
  1108 TBool CMTPObjectStore::LocateByHandleL(const TUint aHandle, const TBool aReadTable /*default = ETrue*/) const
  1070 	{
  1109 	{
  1071 	__FLOG_VA((_L8("LocateByHandleL - Entry aHandle 0x%x"), aHandle));
  1110     OstTraceFunctionEntry1( CMTPOBJECTSTORE_LOCATEBYHANDLEL_ENTRY, this );    
       
  1111 	OstTrace1(TRACE_NORMAL, CMTPOBJECTSTORE_LOCATEBYHANDLEL, "aHandle 0x%x", aHandle);
  1072 	TBool result = EFalse;
  1112 	TBool result = EFalse;
  1073 	if(IsInvalidHandle(aHandle))
  1113 	if(IsInvalidHandle(aHandle))
  1074 		{
  1114 		{
  1075 		__FLOG_VA((_L8("LocateByHandleL - Exit result 0x%x"), result));
  1115 		OstTraceFunctionExitExt( CMTPOBJECTSTORE_LOCATEBYHANDLEL_EXIT, this, result );
  1076 		return result;
  1116 		return result;
  1077 		}
  1117 		}
  1078 	
  1118 	
  1079 	if (iCachedHandle == aHandle)
  1119 	if (iCachedHandle == aHandle)
  1080 		{
  1120 		{
  1081 		__FLOG(_L8("CacheHit"));
  1121 		OstTrace0(TRACE_NORMAL, DUP1_CMTPOBJECTSTORE_LOCATEBYHANDLEL, "CacheHit");
  1082 		result = ETrue;
  1122 		result = ETrue;
  1083 		}
  1123 		}
  1084 	else
  1124 	else
  1085 		{
  1125 		{
  1086 		if (iBatched.SeekL(aHandle))
  1126 		if (iBatched.SeekL(aHandle))
  1095 		}
  1135 		}
  1096 	if (result && aReadTable)
  1136 	if (result && aReadTable)
  1097 		{
  1137 		{
  1098 		iBatched.GetL();
  1138 		iBatched.GetL();
  1099 		}
  1139 		}
  1100 	__FLOG_VA((_L8("LocateByHandleL - Exit result 0x%x"), result));
  1140 	OstTraceFunctionExitExt( DUP1_CMTPOBJECTSTORE_LOCATEBYHANDLEL_EXIT, this, result );
  1101 	return result;
  1141 	return result;
  1102 	}
  1142 	}
  1103 
  1143 
  1104 TBool CMTPObjectStore::LocateBySuidL(const TDesC& aSuid) const
  1144 TBool CMTPObjectStore::LocateBySuidL(const TDesC& aSuid) const
  1105 	{
  1145 	{
  1269     //Currently, i only do this for File DP since it is non-persistent, later, if we take the proposal that 
  1309     //Currently, i only do this for File DP since it is non-persistent, later, if we take the proposal that 
  1270     //1. FileDP is the last DP to be enumerated.
  1310     //1. FileDP is the last DP to be enumerated.
  1271     //2. FileDP will san the whole file system, and will try to enumerate all of the objects(might on behalf of another DP) if the objects is still not
  1311     //2. FileDP will san the whole file system, and will try to enumerate all of the objects(might on behalf of another DP) if the objects is still not
  1272     // in the object store after all other DP finish its enumeration.
  1312     // in the object store after all other DP finish its enumeration.
  1273     //3. Then notify the related DP about the newly added objects by notification API;
  1313     //3. Then notify the related DP about the newly added objects by notification API;
  1274     __FLOG(_L8("EstablishDBSnapshotL - Entry"));
  1314     OstTraceFunctionEntry0( CMTPOBJECTSTORE_ESTABLISHDBSNAPSHOTL_ENTRY );
       
  1315     
  1275     RDbTable temp;
  1316     RDbTable temp;
  1276     CleanupClosePushL(temp);
  1317     CleanupClosePushL(temp);
  1277     User::LeaveIfError(temp.Open(iDatabase, KSQLHandleTableName, RDbRowSet::EUpdatable));
  1318     LEAVEIFERROR(temp.Open(iDatabase, KSQLHandleTableName, RDbRowSet::EUpdatable),
       
  1319             OstTrace0( TRACE_ERROR, DUP1_CMTPOBJECTSTORE_ESTABLISHDBSNAPSHOTL, "HandleStore table open failed!" ));
  1278     if(!iCacheExist)
  1320     if(!iCacheExist)
  1279         {
  1321         {
  1280         TInt32 count = temp.CountL(RDbRowSet::EQuick);
  1322         TInt32 count = temp.CountL(RDbRowSet::EQuick);
  1281         iEnumeratingCacheObjList.ReserveL(count);
  1323         iEnumeratingCacheObjList.ReserveL(count);
  1282         }
  1324         }
  1319                 result = iEnumeratingCacheObjList.InsertInOrder(item, TLinearOrder<CEnumertingCacheItem>(CEnumertingCacheItem::Compare));
  1361                 result = iEnumeratingCacheObjList.InsertInOrder(item, TLinearOrder<CEnumertingCacheItem>(CEnumertingCacheItem::Compare));
  1320                 }
  1362                 }
  1321             
  1363             
  1322             if(result != KErrAlreadyExists)
  1364             if(result != KErrAlreadyExists)
  1323                 {
  1365                 {
  1324                 User::LeaveIfError(result);
  1366                 LEAVEIFERROR(result,
       
  1367                         OstTrace1( TRACE_ERROR, DUP2_CMTPOBJECTSTORE_ESTABLISHDBSNAPSHOTL, "insert into iEnumeratingCacheObjList failed, error code %d", result));
  1325                 CleanupStack::Pop(item);
  1368                 CleanupStack::Pop(item);
  1326                 }
  1369                 }
  1327             else
  1370             else
  1328                 {
  1371                 {
  1329                 CleanupStack::PopAndDestroy(item);
  1372                 CleanupStack::PopAndDestroy(item);
  1333         temp.NextL();
  1376         temp.NextL();
  1334         }
  1377         }
  1335 
  1378 
  1336     CleanupStack::PopAndDestroy(&temp);
  1379     CleanupStack::PopAndDestroy(&temp);
  1337     iCacheExist = ETrue;
  1380     iCacheExist = ETrue;
  1338     __FLOG_VA((_L8("EstablishDBSnapshotL - Exit build %d items"), iEnumeratingCacheObjList.Count()));
  1381     OstTrace1(TRACE_NORMAL, CMTPOBJECTSTORE_ESTABLISHDBSNAPSHOTL, 
       
  1382             "EstablishDBSnapshotL - Exit build %d items", iEnumeratingCacheObjList.Count());   
       
  1383     OstTraceFunctionExit0( CMTPOBJECTSTORE_ESTABLISHDBSNAPSHOTL_EXIT );
  1339     }
  1384     }
  1340 /*
  1385 /*
  1341  * All Objects enumeration complete
  1386  * All Objects enumeration complete
  1342  */
  1387  */
  1343 void CMTPObjectStore::ObjectsEnumComplete()
  1388 void CMTPObjectStore::ObjectsEnumComplete()
  1350     iEnumeratingCacheObjList.ResetAndDestroy();
  1395     iEnumeratingCacheObjList.ResetAndDestroy();
  1351     iUpdateDeltaDataTable = ETrue;
  1396     iUpdateDeltaDataTable = ETrue;
  1352     iMaxCommitLimit = KMaxLimitCommitAfterEnumeration;
  1397     iMaxCommitLimit = KMaxLimitCommitAfterEnumeration;
  1353     iMaxCompactLimit = KMaxLimitCompactAfterEnumeration;
  1398     iMaxCompactLimit = KMaxLimitCompactAfterEnumeration;
  1354     CommitTransactionL();
  1399     CommitTransactionL();
  1355     User::LeaveIfError(iDatabase.Compact());
  1400     LEAVEIFERROR(iDatabase.Compact(),
       
  1401             OstTrace0( TRACE_ERROR, CMTPOBJECTSTORE_OBJECTSENUMCOMPLETE, "database compact failed!" ));  
  1356     BeginTransactionL();
  1402     BeginTransactionL();
  1357     }
  1403     }
  1358 
  1404 
  1359 
  1405 
  1360 void CMTPObjectStore::CleanDBSnapshotL(TBool aOnlyRoot/* = EFalse*/)
  1406 void CMTPObjectStore::CleanDBSnapshotL(TBool aOnlyRoot/* = EFalse*/)
  1362     //For those items left in the iEnumeratingCacheObjList, remove the object entry if the DPID of the handle is not persistent. and populate the 
  1408     //For those items left in the iEnumeratingCacheObjList, remove the object entry if the DPID of the handle is not persistent. and populate the 
  1363     //roundtrip table if needed.
  1409     //roundtrip table if needed.
  1364     //and then close the iEnumeratingCacheObjList to release the memory.
  1410     //and then close the iEnumeratingCacheObjList to release the memory.
  1365     //_LIT(KInsert, "CMTPObjectStore::CleanDBSnapshot");
  1411     //_LIT(KInsert, "CMTPObjectStore::CleanDBSnapshot");
  1366     //volatile TTimer t(KInsert);
  1412     //volatile TTimer t(KInsert);
  1367     __FLOG(_L8("CleanDBSnapshotL Entry"));
  1413     OstTraceFunctionEntry0( CMTPOBJECTSTORE_CLEANDBSNAPSHOTL_ENTRY );
  1368     if (iSnapshotWorker == NULL)
  1414     if (iSnapshotWorker == NULL)
  1369         {
  1415         {
  1370         iSnapshotCleanPos = iEnumeratingCacheObjList.Count() - 1;
  1416         iSnapshotCleanPos = iEnumeratingCacheObjList.Count() - 1;
  1371         iSnapshotWorker = CSnapshotWorker::NewL(this, aOnlyRoot);
  1417         iSnapshotWorker = CSnapshotWorker::NewL(this, aOnlyRoot);
  1372         }
  1418         }
  1378            ||(!aOnlyRoot)) //everything
  1424            ||(!aOnlyRoot)) //everything
  1379             {
  1425             {
  1380             TInt rc = iNonPersistentDPList.FindInOrder(iEnumeratingCacheObjList[iSnapshotCleanPos]->iDpID);
  1426             TInt rc = iNonPersistentDPList.FindInOrder(iEnumeratingCacheObjList[iSnapshotCleanPos]->iDpID);
  1381             if (rc != KErrNotFound)
  1427             if (rc != KErrNotFound)
  1382                 {//This is a non persistent DP.
  1428                 {//This is a non persistent DP.
  1383                 __FLOG_VA((_L8("Remove Object 0x%x"), iEnumeratingCacheObjList[iSnapshotCleanPos]->iObjHandleId));
  1429                 OstTrace1(TRACE_NORMAL, CMTPOBJECTSTORE_CLEANDBSNAPSHOTL, 
       
  1430                         "Remove Object 0x%x", iEnumeratingCacheObjList[iSnapshotCleanPos]->iObjHandleId);
  1384                 RemoveObjectL(iEnumeratingCacheObjList[iSnapshotCleanPos]->iObjHandleId);
  1431                 RemoveObjectL(iEnumeratingCacheObjList[iSnapshotCleanPos]->iObjHandleId);
  1385                 }
  1432                 }
  1386             }
  1433             }
  1387         }
  1434         }
  1388     
  1435     
  1398         iSnapshotCleanPos = 0;
  1445         iSnapshotCleanPos = 0;
  1399         delete iSnapshotWorker;
  1446         delete iSnapshotWorker;
  1400         iSnapshotWorker = NULL;
  1447         iSnapshotWorker = NULL;
  1401         }
  1448         }
  1402     
  1449     
  1403     __FLOG(_L8("CleanDBSnapshotL Exit"));
  1450     OstTraceFunctionExit0( CMTPOBJECTSTORE_CLEANDBSNAPSHOTL_EXIT );
  1404     }
  1451     }
  1405 
  1452 
  1406 void CMTPObjectStore::RemoveUndefinedObjectsL()
  1453 void CMTPObjectStore::RemoveUndefinedObjectsL()
  1407     {
  1454     {
  1408     __FLOG(_L8("CompactDBSnapshotL Entry"));
  1455     OstTraceFunctionEntry0( CMTPOBJECTSTORE_REMOVEUNDEFINEDOBJECTSL_ENTRY );
  1409     
  1456     
  1410     if (iCleanUndefined)
  1457     if (iCleanUndefined)
  1411         {
  1458         {
       
  1459         OstTraceFunctionExit0( CMTPOBJECTSTORE_REMOVEUNDEFINEDOBJECTSL_EXIT );
  1412         return;
  1460         return;
  1413         }
  1461         }
  1414     
  1462     
  1415     TInt32 count = 0;
  1463     TInt32 count = 0;
  1416     RDbTable temp;
  1464     RDbTable temp;
  1417     CleanupClosePushL(temp);
  1465     CleanupClosePushL(temp);
  1418     User::LeaveIfError(temp.Open(iDatabase, KSQLHandleTableName, RDbRowSet::EUpdatable));
  1466     LEAVEIFERROR(temp.Open(iDatabase, KSQLHandleTableName, RDbRowSet::EUpdatable),
       
  1467             OstTrace0( TRACE_ERROR, DUP1_CMTPOBJECTSTORE_REMOVEUNDEFINEDOBJECTSL, "HandleStore Table open error!" ));        
  1419     count = temp.CountL(RDbRowSet::EQuick);
  1468     count = temp.CountL(RDbRowSet::EQuick);
  1420 
  1469 
  1421     __FLOG_VA((_L8("Count before deletion %d "), count));
  1470     OstTrace1(TRACE_NORMAL, CMTPOBJECTSTORE_REMOVEUNDEFINEDOBJECTSL, 
       
  1471             "Count before deletion %d ", count);
  1422     CleanupStack::PopAndDestroy(&temp);
  1472     CleanupStack::PopAndDestroy(&temp);
  1423     
  1473     
  1424     if (count > KMaxLimitSnapshotSize)
  1474     if (count > KMaxLimitSnapshotSize)
  1425         {
  1475         {
  1426         // Delete all object with undefined format
  1476         // Delete all object with undefined format
  1427         _LIT(KSQLDeleteObjectText, "DELETE FROM HandleStore WHERE FormatCode = %u");
  1477         _LIT(KSQLDeleteObjectText, "DELETE FROM HandleStore WHERE FormatCode = %u");
  1428         iSqlStatement.Format(KSQLDeleteObjectText, EMTPFormatCodeUndefined);
  1478         iSqlStatement.Format(KSQLDeleteObjectText, EMTPFormatCodeUndefined);
  1429         User::LeaveIfError(iDatabase.Execute(iSqlStatement));    
  1479         LEAVEIFERROR(iDatabase.Execute(iSqlStatement),
       
  1480                 OstTrace0( TRACE_ERROR, DUP2_CMTPOBJECTSTORE_REMOVEUNDEFINEDOBJECTSL, "DELETE FROM HandleStore failed!")); 
  1430         }
  1481         }
  1431     
  1482     
  1432     iCleanUndefined = ETrue;
  1483     iCleanUndefined = ETrue;
  1433 
  1484 
  1434     
  1485     
  1435     __FLOG(_L8("CompactDBSnapshotL Exit"));    
  1486     OstTraceFunctionExit0( DUP1_CMTPOBJECTSTORE_REMOVEUNDEFINEDOBJECTSL_EXIT );
  1436     }
  1487     }
  1437 
  1488 
  1438 
  1489 
  1439 CMTPObjectStore::CEnumertingCacheItem::CEnumertingCacheItem(TUint32 aSuidHash, TUint32 aHandle, TUint32 aParent, TUint32 aFormat, TUint64 aId, TUint8 aDpID)
  1490 CMTPObjectStore::CEnumertingCacheItem::CEnumertingCacheItem(TUint32 aSuidHash, TUint32 aHandle, TUint32 aParent, TUint32 aFormat, TUint64 aId, TUint8 aDpID)
  1440 	{
  1491 	{