imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagprocessor.cpp
branchRCL_3
changeset 11 85a88bc05e45
parent 10 ee674526fac5
child 13 ffb2d5dd62e9
--- a/imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagprocessor.cpp	Wed Apr 14 16:16:51 2010 +0300
+++ b/imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagprocessor.cpp	Tue Apr 27 16:57:55 2010 +0300
@@ -369,23 +369,8 @@
             }
         else
             {
-            TInt itemIndex(KErrNotFound);
-            
-            //cleanup current queue
-            while(iQueryQueue.Count())
-                {
-                itemIndex = iLastQueue->FindInOrder(iQueryQueue[0], Compare);
-                if(itemIndex >= 0)
-                    {
-                    iLastQueue->Remove( itemIndex );
-                    }
-                iQueryQueue.Remove(0);
-                }
-        
-            delete iQuery;
-            iQuery = NULL;
-            iProcessingCount = 0;
-            TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted() Query FAILED!");   
+            DeleteAndCancelQuery();
+            TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted() Query FAILED!"); 
             }
         }
     else
@@ -746,11 +731,12 @@
     TInt maxCount = aIDArray.Count();
         
     TN_DEBUG3( "CThumbAGProcessor::QueryL() - fill begin aIDArray == %d, iQueryQueue == %d", aIDArray.Count(), iQueryQueue.Count() );
-      
-    for(TInt i=0;i < KMaxQueryItems && i < maxCount; i++)
+    
+    for(TInt i=0; i < KMaxQueryItems && i < maxCount; i++)
         {
-        TN_DEBUG2( "CThumbAGProcessor::QueryL() - fill %d", aIDArray[i] );
-        iQueryQueue.InsertInOrder(aIDArray[i], Compare);
+        TN_DEBUG2( "CThumbAGProcessor::QueryL() - fill %d", aIDArray[0] );
+        iQueryQueue.InsertInOrder(aIDArray[0], Compare);
+        aIDArray.Remove(0);
         }
     
     TN_DEBUG3( "CThumbAGProcessor::QueryL() - fill end aIDArray == %d, iQueryQueue == %d", aIDArray.Count(), iQueryQueue.Count() );
@@ -911,7 +897,7 @@
         if(  err == KErrNone )
             {
             TN_DEBUG1( "CThumbAGProcessor::RunL() add iHarvesterClient observer");
-            err = iHarvesterClient.AddHarvesterEventObserver( *this, EHEObserverTypeOverall | EHEObserverTypePlaceholder, KMaxTInt );
+            err = iHarvesterClient.AddHarvesterEventObserver( *this, EHEObserverTypeOverall | EHEObserverTypeMMC | EHEObserverTypePlaceholder, KMaxTInt );
             TN_DEBUG2( "CThumbAGProcessor::RunL() iHarvesterClient observer err = %d", err);
             __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGProcessor::RunL(), !iHarvesterClient "), err));
             }
@@ -983,14 +969,9 @@
       	{
         TN_DEBUG1( "void CThumbAGProcessor::RunL() skip idle detection!");
       	CancelTimeout();
-     	 }
+     	}
   	else
 	    {
-        if(iActivityManager)
-            {
-            iIdle = iActivityManager->IsInactive();
-            }
-	    
         if( !iIdle || iHarvesting || iMPXHarvesting || iPeriodicTimer->IsActive() )
             {
             TN_DEBUG1( "void CThumbAGProcessor::RunL() device not idle");
@@ -1025,15 +1006,15 @@
             const CMdEObject* object = &iQuery->Result( iProcessingCount-1 );
             iProcessingCount--;
             
-            TInt itemIndex = iLastQueue->FindInOrder(object->Id(), Compare);
-            if(itemIndex >= 0)
-                {
-                iLastQueue->Remove(itemIndex);
-                }
-				
-            // process one item at once
             if ( object )
                 {
+                TInt itemIndex = iLastQueue->FindInOrder(object->Id(), Compare);
+                if(itemIndex >= 0)
+                    {
+                    iLastQueue->Remove(itemIndex);
+                    }
+				
+                //process one item at once
                 //remove item from queryQueue when request is issued 
                 itemIndex = iQueryQueue.FindInOrder(object->Id(), Compare);
                 if(itemIndex >= 0)
@@ -1049,28 +1030,9 @@
         //force is coming, but executing non-forced query complete-> cancel old
         else
             {
-            TN_DEBUG1( "CThumbAGProcessor::RunL() - deleting query 1" );
-            delete iQuery;
-            iQuery = NULL;
-            iQueryReady = EFalse;
-            iProcessingCount = 0;
-            
-            //move remainig IDs in query queue back to original queue
-            while(iQueryQueue.Count())
-                {
-                if(iLastQueue)
-                    {
-                    if(iLastQueue->FindInOrder(iQueryQueue[0], Compare) == KErrNotFound)
-                        {
-                        //ignore if fails
-                        iLastQueue->InsertInOrder(iQueryQueue[0], Compare);
-                        }
-                    }
-                iQueryQueue.Remove(0);
-                }
-            iLastQueue = NULL;
-            ActivateAO();
-            return;    
+            DeleteAndCancelQuery();
+	        ActivateAO();
+            return;  
             }
         
         //is last query item
@@ -1088,32 +1050,7 @@
         {
         if(iForceRun && !iModify)
             {
-            if(iQuery)
-                {
-                TN_DEBUG1( "CThumbAGProcessor::RunL() - deleting query 2" );
-                iQuery->Cancel();
-                delete iQuery;
-                iQuery = NULL;
-                }
-
-            iQueryReady = EFalse;
-            iQueryActive = EFalse;
-            
-            //move remainig IDs in query queue back to original queue
-            while(iQueryQueue.Count())
-                {
-                if(iLastQueue)
-                    {
-                    if(iLastQueue->FindInOrder(iQueryQueue[0], Compare) == KErrNotFound)
-                        {
-                        //ignore if fails
-                        iLastQueue->InsertInOrder(iQueryQueue[0], Compare);
-                        }
-                    }
-                iQueryQueue.Remove(0);
-                }
-            iLastQueue = NULL;
-            
+            DeleteAndCancelQuery();
             ActivateAO();
             }
         else  
@@ -1186,6 +1123,44 @@
     }
 
 // ---------------------------------------------------------------------------
+// CThumbAGProcessor::DeleteAndCancelQuery()
+// ---------------------------------------------------------------------------
+//
+void CThumbAGProcessor::DeleteAndCancelQuery()
+    {
+    TN_DEBUG1( "CThumbAGProcessor::DeleteAndCancelQuery() in" );
+    
+    if(iQuery)
+        {
+        TN_DEBUG1( "CThumbAGProcessor::DeleteAndCancelQuery() - deleting query" );
+        iQuery->Cancel();
+        delete iQuery;
+        iQuery = NULL;
+        }
+    
+    iQueryReady = EFalse;
+    iQueryActive = EFalse;
+    iProcessingCount = 0;
+    
+    //move remainig IDs in query queue back to original queue
+    while(iQueryQueue.Count())
+        {
+        if(iLastQueue)
+            {
+            if(iLastQueue->FindInOrder(iQueryQueue[0], Compare) == KErrNotFound)
+                {
+                //ignore if fails
+                iLastQueue->InsertInOrder(iQueryQueue[0], Compare);
+                }
+            }
+        iQueryQueue.Remove(0);
+        }
+    iLastQueue = NULL;
+    
+    TN_DEBUG1( "CThumbAGProcessor::DeleteAndCancelQuery() out" );
+    }
+
+// ---------------------------------------------------------------------------
 // CThumbAGProcessor::DoCancel()
 // ---------------------------------------------------------------------------
 //
@@ -1286,8 +1261,48 @@
                 }
             }
         }
+    //MMC harvesting
+    else if( aHEObserverType == EHEObserverTypeMMC)
+        {
+        switch(aHarvesterEventState)
+            {
+            case EHEStateStarted:
+            case EHEStateHarvesting:
+            case EHEStatePaused:
+            case EHEStateResumed:
+                {
+                iMMCHarvestingTemp = ETrue;
+                break;
+                }
+            case EHEStateFinished:
+            case EHEStateUninitialized:
+                {
+                iMMCHarvestingTemp = EFalse;
+                break;
+                }
+            };
+        
+        if(iMMCHarvestingTemp != iMMCHarvesting)
+            {
+            iMMCHarvesting = iMMCHarvestingTemp;
+            
+            if( iMMCHarvesting )
+                {
+                TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS MMC harvesterin started");
+                if(iPreviousItemsLeft != KErrNotReady)
+                    {
+                    iPreviousItemsLeft = KErrNotReady;
+                    RProperty::Set(KTAGDPSNotification, KDaemonProcessing, iPreviousItemsLeft);
+                    }
+                }
+            else
+                {
+                TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS MMC harvesting finished ");
+                }
+            }
+        }
    
-    TN_DEBUG3( "CThumbAGProcessor::HarvestingUpdated -- end() iHarvesting == %d, iPHHarvesting == %d ", iHarvesting, iPHHarvesting);
+    TN_DEBUG4( "CThumbAGProcessor::HarvestingUpdated -- end() iHarvesting == %d, iPHHarvesting == %d iMMCHarvesting == %d ", iHarvesting, iPHHarvesting, iMMCHarvesting);
     }
 
 // ---------------------------------------------------------------------------
@@ -1770,19 +1785,19 @@
         daemonProcessing = ETrue;
         }
     
-    //disable 2nd round generarion when there is items in 1st round queues
-    //or 2nd queue is empty 
-    if( !i2ndRoundGenerateQueue.Count() || itemsLeft )
-        {
-        i2ndRound = EFalse;
-        }
-    
     //adjust items left to containing also items not yet processed but removed from queue under processing
     if((iLastQueue == &iModifyQueue || iLastQueue == &iAddQueue) && !i2ndRound)
         {
         itemsLeft +=iQueryQueue.Count();
         }
     
+    //cancel 2nd round generarion when there is items in 1st round queues
+    if(itemsLeft && i2ndRound)
+        {
+        DeleteAndCancelQuery();
+        i2ndRound = EFalse;
+        }
+        
     TN_DEBUG2( "CThumbAGProcessor::UpdatePSValues() KItemsleft == %d", itemsLeft);
     
     if(aDefine)