diff -r 7197e789b953 -r ffa62e555b02 imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagprocessor.cpp --- a/imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagprocessor.cpp Fri Apr 16 15:16:16 2010 +0300 +++ b/imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagprocessor.cpp Mon May 03 12:48:51 2010 +0300 @@ -201,11 +201,62 @@ // CThumbAGProcessor::HandleQueryNewResults() // ----------------------------------------------------------------------------- // -void CThumbAGProcessor::HandleQueryNewResults( CMdEQuery& /*aQuery*/, - const TInt /*aFirstNewItemIndex*/, - const TInt /*aNewItemCount*/ ) +void CThumbAGProcessor::HandleQueryNewResults( CMdEQuery& aQuery, + const TInt aFirstNewItemIndex, + const TInt aNewItemCount ) { - // No implementation required + // PH & AllItems query results are handled here + if (aNewItemCount > 0) + { + if(&aQuery == iQueryPlaceholders) + { + TN_DEBUG2( "CThumbAGProcessor::HandleQueryNewResults - iQueryPlaceholders, %d new", aNewItemCount); + + for(TInt i = aFirstNewItemIndex; i < iQueryPlaceholders->Count(); i++) + { + const CMdEObject* object = &iQueryPlaceholders->Result(i); + + if(!object) + { + continue; + } + + if(!object->Placeholder()) + { + TN_DEBUG2( "CThumbAGProcessor::HandleQueryNewResults %d not placeholder", object->Id()); + continue; + } + + // ignore if fails + iPlaceholderQueue.InsertInOrder(object->Id(), Compare); + } + } + else if(&aQuery == iQueryAllItems) + { + TN_DEBUG2( "CThumbAGProcessor::HandleQueryNewResults - QueryAllItems, %d new", aNewItemCount); + + for(TInt i = aFirstNewItemIndex; i < iQueryAllItems->Count(); i++) + { + const CMdEObject* object = &iQueryAllItems->Result(i); + + if(!object) + { + continue; + } + + if (iAddQueue.FindInOrder(object->Id(), Compare) == KErrNotFound && + iModifyQueue.FindInOrder(object->Id(), Compare) == KErrNotFound ) + { + // ignore if fails + iAddQueue.InsertInOrder(object->Id(), Compare); + } + } + } + } + else + { + TN_DEBUG1( "CThumbAGProcessor::HandleQueryNewResults - error, no new items"); + } } // ----------------------------------------------------------------------------- @@ -221,67 +272,28 @@ TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted - iQueryPlaceholders completed"); iPlaceholderQueue.Reset(); - // if no errors in query - if (aError == KErrNone ) + + //free query + delete iQueryPlaceholders; + iQueryPlaceholders = NULL; + + if(iDoQueryAllItems) { - for(TInt i = 0; i < iQueryPlaceholders->Count(); i++) - { - const CMdEObject* object = &iQueryPlaceholders->Result(i); - - if(!object) - { - continue; - } - - if(!object->Placeholder()) - { - TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted %d not placeholder", object->Id()); - continue; - } - - /*if (iPlaceholderQueue.Find( object->Id() ) == KErrNotFound) - { - TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted %d added to placeholder queue", object->Id());*/ - TRAP_IGNORE( iPlaceholderQueue.AppendL( object->Id() )); - //} - } - } - delete iQueryPlaceholders; - iQueryPlaceholders = NULL; - - if(iDoQueryAllItems) - { - iDoQueryAllItems = EFalse; - TRAP_IGNORE(QueryAllItemsL()); - } + iDoQueryAllItems = EFalse; + TRAP_IGNORE(QueryAllItemsL()); + } } else if(&aQuery == iQueryAllItems) { TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted - QueryAllItems completed"); - // if no errors in query - if (aError == KErrNone ) - { - for(TInt i = 0; i < iQueryAllItems->Count(); i++) - { - const CMdEObject* object = &iQueryAllItems->Result(i); - - if(!object) - { - continue; - } - - if (iAddQueue.Find( object->Id() ) == KErrNotFound && iModifyQueue.Find( object->Id()) == KErrNotFound ) - { - TRAP_IGNORE( iAddQueue.AppendL( object->Id() )); - } - } + #ifdef _DEBUG TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted IN-COUNTERS---------- Amount: %d, Add",iQueryAllItems->Count()); #endif - } - //free query - delete iQueryAllItems; - iQueryAllItems = NULL; + + //free query + delete iQueryAllItems; + iQueryAllItems = NULL; } else if(&aQuery == iQuery ) { @@ -302,7 +314,7 @@ { TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted() some result items missing"); - RArray iQueryQueueDelta; + RArray queryQueueDelta; TInt itemIndex(KErrNotFound); @@ -324,23 +336,26 @@ if(!found) { TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted() missing from results item %d", iQueryQueue[queryItem] ); - iQueryQueueDelta.Append( iQueryQueue[queryItem] ); + + // ignore if fails + queryQueueDelta.InsertInOrder(iQueryQueue[queryItem], Compare); } } - TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted() missing items total count %d", iQueryQueueDelta.Count()); + TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted() missing items total count %d", queryQueueDelta.Count()); //cleanup from previous queue it item is not found from MDS - while(iQueryQueueDelta.Count()) + while(queryQueueDelta.Count()) { - itemIndex = iLastQueue->Find(iQueryQueueDelta[0]); + itemIndex = iLastQueue->FindInOrder(queryQueueDelta[0], Compare); + if(itemIndex >= 0) { TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted() remove items %d", iQueryQueue[0]); iLastQueue->Remove( itemIndex ); } - iQueryQueueDelta.Remove(0); + queryQueueDelta.Remove(0); } - iQueryQueueDelta.Close(); + queryQueueDelta.Close(); } // no results, reset query @@ -354,23 +369,8 @@ } else { - TInt itemIndex(KErrNotFound); - - //cleanup current queue - while(iQueryQueue.Count()) - { - itemIndex = iLastQueue->Find(iQueryQueue[0]); - 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 @@ -479,9 +479,10 @@ for (int i=0; i= 0) { @@ -503,10 +503,11 @@ iPlaceholderQueue.Remove( itemIndex ); } - if(iAddQueue.Find( aIDArray[i]) == KErrNotFound && i2ndRoundGenerateQueue.Find( aIDArray[i])) + if(iAddQueue.FindInOrder(aIDArray[i], Compare) == KErrNotFound && + i2ndRoundGenerateQueue.FindInOrder(aIDArray[i], Compare) == KErrNotFound) { TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - append to add queue"); - iAddQueue.Append( aIDArray[i]); + User::LeaveIfError(iAddQueue.InsertInOrder(aIDArray[i], Compare)); } } } @@ -518,7 +519,7 @@ for (int i=0; i= 0) { @@ -528,7 +529,7 @@ else { TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - real modify"); - itemIndex = iAddQueue.Find( aIDArray[i] ); + itemIndex = iAddQueue.FindInOrder(aIDArray[i], Compare); if (itemIndex >= 0) { @@ -536,9 +537,8 @@ iAddQueue.Remove( itemIndex ); } else - { - - itemIndex = i2ndRoundGenerateQueue.Find( aIDArray[i] ); + { + itemIndex = i2ndRoundGenerateQueue.FindInOrder(aIDArray[i], Compare); if (itemIndex >= 0) { @@ -548,7 +548,7 @@ } TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - append to modify queue"); - iModifyQueue.AppendL(aIDArray[i]); + User::LeaveIfError(iModifyQueue.InsertInOrder(aIDArray[i], Compare)); SetForceRun( ETrue ); } @@ -562,14 +562,14 @@ for (int i=0; i= 0) { iAddQueue.Remove(itemIndex); } // ..and Modify Queue - itemIndex = iModifyQueue.Find( aIDArray[i] ); + itemIndex = iModifyQueue.FindInOrder(aIDArray[i], Compare); if(itemIndex >= 0) { iModifyQueue.Remove(itemIndex); @@ -657,15 +657,16 @@ if(iLastQueue == &iAddQueue || iLastQueue == &iModifyQueue) { TN_DEBUG2( "CThumbAGProcessor::CreateThumbnailsL() - 1st round add/modify, append to 2nd round queue", aObject->Id() ); - if(i2ndRoundGenerateQueue.Find(aObject->Id()) == KErrNotFound) + if(i2ndRoundGenerateQueue.FindInOrder(aObject->Id(), Compare) == KErrNotFound) { - i2ndRoundGenerateQueue.Append( aObject->Id() ); + // ignore if fails + i2ndRoundGenerateQueue.InsertInOrder(aObject->Id(), Compare); } } - if( !(imageObjectDef.Id() == aObject->Def().Id() || videoObjectDef.Id() == aObject->Def().Id()) ) + if( imageObjectDef.Id() != aObject->Def().Id() ) { - TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() 1st round and not image or video, skip"); + TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() 1st round not image"); ActivateAO(); return; } @@ -731,10 +732,11 @@ 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.Append( aIDArray[i] ); + 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() ); @@ -836,7 +838,7 @@ audioPHObjectCondition.SetPlaceholderOnly( ETrue ); audioPHObjectCondition.SetNotPresent( ETrue ); - iQueryPlaceholders->FindL(); + iQueryPlaceholders->FindL(KMaxTInt, KMaxQueryItems2); TN_DEBUG1( "CThumbAGProcessor::QueryPlaceholdersL - end" ); } @@ -895,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)); } @@ -967,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"); @@ -1009,17 +1006,17 @@ const CMdEObject* object = &iQuery->Result( iProcessingCount-1 ); iProcessingCount--; - TInt itemIndex = iLastQueue->Find( object->Id()); - 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.Find( object->Id()); + itemIndex = iQueryQueue.FindInOrder(object->Id(), Compare); if(itemIndex >= 0) { iQueryQueue.Remove(itemIndex); @@ -1033,27 +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->Find( iQueryQueue[0]) == KErrNotFound) - { - iLastQueue->Append(iQueryQueue[0]); - } - } - iQueryQueue.Remove(0); - } - iLastQueue = NULL; - ActivateAO(); - return; + DeleteAndCancelQuery(); + ActivateAO(); + return; } //is last query item @@ -1071,31 +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->Find( iQueryQueue[0]) == KErrNotFound) - { - iLastQueue->Append(iQueryQueue[0]); - } - } - iQueryQueue.Remove(0); - } - iLastQueue = NULL; - + DeleteAndCancelQuery(); ActivateAO(); } else @@ -1168,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() // --------------------------------------------------------------------------- // @@ -1268,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); } // --------------------------------------------------------------------------- @@ -1349,13 +1382,6 @@ return; } - if( !IsActive() ) - { - SetActive(); - TRequestStatus* statusPtr = &iStatus; - User::RequestComplete( statusPtr, KErrNone ); - } - //check if forced run needs to continue if (iModifyQueue.Count()) { @@ -1366,6 +1392,14 @@ iModify = EFalse; SetForceRun( EFalse ); } + + if( !IsActive() && ((!iActive && !iQueryActive) || iForceRun )) + { + TN_DEBUG1( "CThumbAGProcessor::ActivateAO() - Activated"); + SetActive(); + TRequestStatus* statusPtr = &iStatus; + User::RequestComplete( statusPtr, KErrNone ); + } UpdatePSValues(); } @@ -1462,32 +1496,28 @@ { TN_DEBUG2( "CThumbAGProcessor::RemoveFromQueues() - %d", aIDArray[i]); - itemIndex = iPlaceholderQueue.Find( aIDArray[i] ); - + itemIndex = iPlaceholderQueue.FindInOrder(aIDArray[i], Compare); if(itemIndex >= 0) { iPlaceholderQueue.Remove(itemIndex); TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iPlaceholderQueue" ); } - itemIndex = iAddQueue.Find( aIDArray[i] ); - + itemIndex = iAddQueue.FindInOrder(aIDArray[i], Compare); if(itemIndex >= 0) { iAddQueue.Remove(itemIndex); TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iAddQueue" ); } - itemIndex = i2ndRoundGenerateQueue.Find( aIDArray[i] ); - + itemIndex = i2ndRoundGenerateQueue.FindInOrder(aIDArray[i], Compare); if(itemIndex >= 0) { i2ndRoundGenerateQueue.Remove(itemIndex); TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - i2ndRoundGenerateQueue" ); } - itemIndex = iModifyQueue.Find( aIDArray[i] ); - + itemIndex = iModifyQueue.FindInOrder(aIDArray[i], Compare); if(itemIndex >= 0) { iModifyQueue.Remove(itemIndex); @@ -1499,34 +1529,19 @@ } } - itemIndex = iQueryQueue.Find( aIDArray[i] ); - + itemIndex = iQueryQueue.FindInOrder(aIDArray[i], Compare); if(itemIndex >= 0) { iQueryQueue.Remove(itemIndex); TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iQueryQueue" ); } - - itemIndex = iPlaceholderQueue.Find( aIDArray[i] ); - + + itemIndex = iPlaceholderQueue.FindInOrder(aIDArray[i], Compare); if(itemIndex >= 0) { iPlaceholderQueue.Remove(itemIndex); TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iPlaceholderQueue" ); } - - /* - if( aRemoveFromDelete ) - { - itemIndex = iRemoveQueue.Find( aIDArray[i] ); - - if(itemIndex >= 0) - { - iRemoveQueue.Remove(itemIndex); - TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iRemoveQueue" ); - continue; - } - }*/ } TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - end" ); @@ -1593,7 +1608,7 @@ CMdEObjectCondition& audioPHObjectCondition = rootCondition.AddObjectConditionL(audioObjDef); - iQueryAllItems->FindL(); + iQueryAllItems->FindL(KMaxTInt, KMaxQueryItems2); TN_DEBUG1( "CThumbAGProcessor::QueryAllItemsL - end" ); } @@ -1770,12 +1785,20 @@ daemonProcessing = ETrue; } - //disable 2nd round generarion when there is items in 1st round queues - //or 2nd queue is empty - if( !i2ndRoundGenerateQueue.Count() || itemsLeft ) + //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) { @@ -1803,4 +1826,15 @@ } } +// --------------------------------------------------------------------------- +// CThumbAGProcessor::Compare +// Comparison function for logaritmic use of queue arrays +// --------------------------------------------------------------------------- +// +TInt CThumbAGProcessor::Compare(const TItemId& aLeft, const TItemId& aRight) + { + return (aLeft - aRight); + } + + // End of file