photosgallery/viewframework/medialists/src/glxcachemanager.cpp
branchRCL_3
changeset 23 b023a8d2866a
parent 21 f9e827349359
child 24 ea65f74e6de4
equal deleted inserted replaced
21:f9e827349359 23:b023a8d2866a
   220 // -----------------------------------------------------------------------------
   220 // -----------------------------------------------------------------------------
   221 //
   221 //
   222 void CGlxCacheManager::HandleGarbageCollectionL(TBool aStart)
   222 void CGlxCacheManager::HandleGarbageCollectionL(TBool aStart)
   223     {
   223     {
   224     TRACER("CGlxCacheManager::HandleGarbageCollection");
   224     TRACER("CGlxCacheManager::HandleGarbageCollection");
       
   225     GLX_DEBUG2("CGlxCacheManager::HandleGarbageCollectionL() aStart=%d", aStart);
   225     TInt freeMemory = 0;
   226     TInt freeMemory = 0;
   226        
   227     HAL::Get(HALData::EMemoryRAMFree, freeMemory);
   227        HAL::Get( HALData::EMemoryRAMFree, freeMemory );
   228     GLX_DEBUG2("CGlxCacheManager::HandleGarbageCollectionL() freeMemory=%d", freeMemory);
   228            
   229 
   229        if(aStart)
   230     if (aStart)
   230            {
   231         {
   231            if(freeMemory < KGlxLowerMemoryLimitForCleanUp)
   232         if (freeMemory < KGlxLowerMemoryLimitForCleanUp)
   232                {
   233             {
   233                // 2 page - 30 Items for Flush
   234             // 2 page - 30 Items for Flush
   234                TInt count = 2;  
   235             TInt count = 2;
   235                if(freeMemory < (KGlxLowerMemoryLimitForCleanUp/2))
   236             if (freeMemory < (KGlxLowerMemoryLimitForCleanUp / 2))
   236                    {
   237                 {
   237                    // If Memory is below this limit it's ok i can wait for 60 items to clean-up
   238                 // If Memory is below this limit it's ok i can wait for 60 items to clean-up
   238                    count = KGlxNoOfPagesToFlushInCriticalLowMemory;
   239                 count = KGlxNoOfPagesToFlushInCriticalLowMemory;
   239                    }
   240                 }
   240                // Cancel Clean-up before Flush Page; Clean-up will be starting just after Flush page
   241             // Cancel Clean-up before Flush Page; Clean-up will be starting just after Flush page
   241                iGarbageCollector->CancelCleanup(); 
   242             iGarbageCollector->CancelCleanup();
   242                iGarbageCollector->FlushPagesL(count);
   243             iGarbageCollector->FlushPagesL(count);
   243                iGarbageCollector->CleanupL();
   244             iGarbageCollector->CleanupL();
   244                iCleanUpOnGoing = ETrue;         // Clean up is Started now i can call CancelClean-up to Stop Clean Up
   245             iCleanUpOnGoing = ETrue; // Clean up is Started now i can call CancelClean-up to Stop Clean Up
   245                }
   246             }
   246            else if((freeMemory < KGlxUpperMemoryLimitForCleanUp) && !iCleanUpOnGoing)
   247         else if ((freeMemory < KGlxUpperMemoryLimitForCleanUp)
   247                {
   248                 && !iCleanUpOnGoing)
   248                iGarbageCollector->CleanupL();
   249             {
   249                iCleanUpOnGoing = ETrue;         // Clean up is Started now i can call CancelClean-up to Stop Clean Up
   250             iGarbageCollector->CleanupL();
   250                }
   251             iCleanUpOnGoing = ETrue; // Clean up is Started now i can call CancelClean-up to Stop Clean Up
   251            // This is Added to Keep Assure Clean-up is not going to Disturb normal Flow if there is Enough Memory
   252             }
   252            // We Remove this Code After Evaluation of Use of this Code
   253         // This is Added to Keep Assure Clean-up is not going to Disturb normal Flow if there is Enough Memory
   253            else if(iCleanUpOnGoing)
   254         // We Remove this Code After Evaluation of Use of this Code
   254                {
   255         else if (iCleanUpOnGoing)
   255                iGarbageCollector->CancelCleanup();
   256             {
   256                iCleanUpOnGoing = EFalse;
   257             iGarbageCollector->CancelCleanup();
   257                }
   258             iCleanUpOnGoing = EFalse;
   258                
   259             }
   259            }
   260         }
   260        else if(freeMemory < KGlxLowerMemoryLimitForCleanUp)
   261     else if (freeMemory < KGlxLowerMemoryLimitForCleanUp)
   261            {
   262         {
   262            // 2 page - 30 Items for Flush
   263         // 2 page - 30 Items for Flush
   263            TInt count = 2;
   264         TInt count = 2;
   264            if(freeMemory < (KGlxLowerMemoryLimitForCleanUp/2))
   265         if (freeMemory < (KGlxLowerMemoryLimitForCleanUp / 2))
   265                {
   266             {
   266                // If Memory is below this limit it's ok i can wait for 60 items to clean-up
   267             // If Memory is below this limit it's ok i can wait for 60 items to clean-up
   267                count = KGlxNoOfPagesToFlushInCriticalLowMemory;
   268             count = KGlxNoOfPagesToFlushInCriticalLowMemory;
   268                }
   269             }
   269            // Cancel Clean-up before Flush Page; Clean-up will be starting just after Flush page
   270         // Cancel Clean-up before Flush Page; Clean-up will be starting just after Flush page
   270            iGarbageCollector->CancelCleanup();
   271         iGarbageCollector->CancelCleanup();
   271            iGarbageCollector->FlushPagesL(count);
   272         iGarbageCollector->FlushPagesL(count);
   272            iGarbageCollector->CleanupL();
   273         iGarbageCollector->CleanupL();
   273            iCleanUpOnGoing = ETrue;          // Clean up is Started now i can call CancelClean-up to Stop Clean Up
   274         iCleanUpOnGoing = ETrue; // Clean up is Started now i can call CancelClean-up to Stop Clean Up
   274         }
   275         }
   275     else if(iCleanUpOnGoing)
   276     else if(iCleanUpOnGoing)
   276         {
   277         {
   277         iGarbageCollector->CancelCleanup();
   278         iGarbageCollector->CancelCleanup();
   278         iCleanUpOnGoing = EFalse;
   279         iCleanUpOnGoing = EFalse;
   279         }
   280         }
       
   281     GLX_DEBUG2("CGlxCacheManager::HandleGarbageCollectionL() iCleanUpOnGoing=%d", iCleanUpOnGoing);
   280     }
   282     }
   281 		
   283 		
   282 // -----------------------------------------------------------------------------
   284 // -----------------------------------------------------------------------------
   283 // Match
   285 // Match
   284 // return ETrue if path levels match
   286 // return ETrue if path levels match
   312 	
   314 	
   313 // -----------------------------------------------------------------------------
   315 // -----------------------------------------------------------------------------
   314 // HandleCollectionMediaL
   316 // HandleCollectionMediaL
   315 // -----------------------------------------------------------------------------
   317 // -----------------------------------------------------------------------------
   316 //
   318 //
   317 void CGlxCacheManager::HandleCollectionMediaL(const TGlxIdSpaceId& aIdSpaceId, const CMPXMedia& aMedia, TInt aError, TBool aRequestNextAttr)
   319 void CGlxCacheManager::HandleCollectionMediaL(
       
   320         const TGlxIdSpaceId& aIdSpaceId, const CMPXMedia& aMedia,
       
   321         TInt aError, TBool aRequestNextAttr)
   318     {
   322     {
   319     TRACER("CGlxCacheManager::HandleCollectionMediaL");
   323     TRACER("CGlxCacheManager::HandleCollectionMediaL");
   320     
   324     
   321     iRequestOwner = NULL;
   325     iRequestOwner = NULL;
   322 
   326 
  1039     			collection.MediaL(*path, iRequestedAttrs.Array(), attrSpecs);
  1043     			collection.MediaL(*path, iRequestedAttrs.Array(), attrSpecs);
  1040 #endif
  1044 #endif
  1041     			CleanupStack::PopAndDestroy(path);
  1045     			CleanupStack::PopAndDestroy(path);
  1042     			
  1046     			
  1043     			iRequestOwner = list;
  1047     			iRequestOwner = list;
  1044     			}		
  1048                 }
  1045     			
  1049 
  1046     		CleanupStack::PopAndDestroy(attrSpecs);	
  1050             CleanupStack::PopAndDestroy(attrSpecs);
  1047     		}
  1051             }
  1048     		
  1052 
       
  1053         if (iRequestedItemIds.Count())
       
  1054             {
       
  1055             GLX_DEBUG1("CGlxCacheManager::MaintainCacheL() - Cleanup needed here!");
       
  1056             // Clean-up is needed here; Considering Current Memory Condition
       
  1057             HandleGarbageCollectionL(ETrue);
       
  1058             }
       
  1059 
  1049         if ( !iRequestOwner )
  1060         if ( !iRequestOwner )
  1050             {
  1061             {
  1051             if ( iTempError )
  1062             if ( iTempError )
  1052                 {
  1063                 {
  1053                 // Reawaken in a while to check again
  1064                 // Reawaken in a while to check again
  1355     if (index != KErrNotFound)
  1366     if (index != KErrNotFound)
  1356         {
  1367         {
  1357         iCaches[index]->ReserveUsersL( aCount );
  1368         iCaches[index]->ReserveUsersL( aCount );
  1358         }
  1369         }
  1359     }
  1370     }
       
  1371 
  1360 //OOM 
  1372 //OOM 
  1361 // -----------------------------------------------------------------------------
  1373 // -----------------------------------------------------------------------------
  1362 // Start cache cleanup on Low memory event from OOM
  1374 // Start cache cleanup on Low memory event from OOM
  1363 // -----------------------------------------------------------------------------
  1375 // -----------------------------------------------------------------------------
  1364 //   
  1376 //   
  1365 void CGlxCacheManager::ReleaseRAML(TBool aFlushOnRequest)
  1377 void CGlxCacheManager::ReleaseRAML(TBool aFlushOnRequest)
  1366 {
  1378     {
  1367     TRACER("CGlxCacheManager::ReleaseRAM");
  1379     TRACER("CGlxCacheManager::ReleaseRAM");
  1368     if(aFlushOnRequest)
  1380     if (aFlushOnRequest)
  1369         {
  1381         {
  1370         HandleGarbageCollectionL(aFlushOnRequest);        
  1382         HandleGarbageCollectionL(aFlushOnRequest);
  1371         }
  1383         }
  1372 	else
  1384     else
  1373 	{
  1385         {
  1374 		iGarbageCollector->CleanupL(); 	 				
  1386         iGarbageCollector->CleanupL();
  1375 	} 	
  1387         }
  1376 }
  1388     }
       
  1389 
  1377 // -----------------------------------------------------------------------------
  1390 // -----------------------------------------------------------------------------
  1378 // Force a cleanup on particular media id : remove all attributes
  1391 // Force a cleanup on particular media id : remove all attributes
  1379 // -----------------------------------------------------------------------------
  1392 // -----------------------------------------------------------------------------
  1380 // 
  1393 // 
  1381 void CGlxCacheManager::ForceCleanupMedia(TGlxIdSpaceId aSpaceId, 
  1394 void CGlxCacheManager::ForceCleanupMedia(TGlxIdSpaceId aSpaceId,