mtpfws/mtpfw/src/cmtpobjectstore.cpp
branchRCL_3
changeset 23 f5809cfbf6d5
parent 16 3673b591050c
child 24 523717cdb0ad
--- a/mtpfws/mtpfw/src/cmtpobjectstore.cpp	Tue Apr 27 17:30:23 2010 +0300
+++ b/mtpfws/mtpfw/src/cmtpobjectstore.cpp	Tue May 11 16:59:11 2010 +0300
@@ -25,7 +25,6 @@
 #include <mtp/tmtptypeuint32.h>
 #include "cmtphandleallocator.h"
 #include "cmtpobjectstore.h"
-#include "cmtpreferencemgr.h"
 #include "dbutility.h"
 #include "cmtpdataprovidercontroller.h"
 #include "cmtpdataprovider.h"
@@ -54,6 +53,8 @@
 const TInt KMaxLimitCompactInEnumeration = 2048;
 const TInt KMaxLimitCompactAfterEnumeration = 1024;
 const TInt KSnapshotGranularity = 128; 
+const TInt KMaxLimitSnapshotSize = 50000;
+
 
 
 
@@ -768,7 +769,7 @@
             }
         iCachedSuidHash = 0;
         iCachedHandle = 0;
-        
+        iReferenceMgr->RemoveReferencesL(aHandle.Value());
         iBatched.DeleteL();
         __FLOG(_L8("RemoveObjectL From iBacthed"));
         IncTranOpsNumL();
@@ -787,6 +788,8 @@
 			}
 		iCachedSuidHash = 0;
 		iCachedHandle = 0;
+		//no need to call GetL already all it in LocateBySuidL
+		iReferenceMgr->RemoveReferencesL(iBatched_SuidHashID.ColUint32(EObjectStoreHandleId));
 		iBatched_SuidHashID.DeleteL();
 		IncTranOpsNumL();
 		}
@@ -837,6 +840,8 @@
 void CMTPObjectStore::CleanL()
 	{
 	__FLOG(_L8("CleanL - Entry"));
+	
+	RemoveUndefinedObjectsL();
 	Swi::RSisRegistrySession sisSession;
 	User::LeaveIfError(sisSession.Connect());
 	CleanupClosePushL(sisSession);
@@ -1375,6 +1380,39 @@
     __FLOG(_L8("CleanDBSnapshotL Exit"));
     }
 
+void CMTPObjectStore::RemoveUndefinedObjectsL()
+    {
+    __FLOG(_L8("CompactDBSnapshotL Entry"));
+    
+    if (iCleanUndefined)
+        {
+        return;
+        }
+    
+    TInt32 count = 0;
+    RDbTable temp;
+    CleanupClosePushL(temp);
+    User::LeaveIfError(temp.Open(iDatabase, KSQLHandleTableName, RDbRowSet::EUpdatable));
+    count = temp.CountL(RDbRowSet::EQuick);
+
+    __FLOG_VA((_L8("Count before deletion %d "), count));
+    CleanupStack::PopAndDestroy(&temp);
+    
+    if (count > KMaxLimitSnapshotSize)
+        {
+        // Delete all object with undefined format
+        _LIT(KSQLDeleteObjectText, "DELETE FROM HandleStore WHERE FormatCode = %u");
+        iSqlStatement.Format(KSQLDeleteObjectText, EMTPFormatCodeUndefined);
+        User::LeaveIfError(iDatabase.Execute(iSqlStatement));    
+        }
+    
+    iCleanUndefined = ETrue;
+
+    
+    __FLOG(_L8("CompactDBSnapshotL Exit"));    
+    }
+
+
 CMTPObjectStore::CEnumertingCacheItem::CEnumertingCacheItem(TUint32 aSuidHash, TUint32 aHandle, TUint32 aParent, TUint32 aFormat, TUint64 aId, TUint8 aDpID)
 	{
 	iObjSuiIdHash = aSuidHash;