diff -r 235a7fc86938 -r 2edacbf5d3f9 imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagprocessor.cpp --- a/imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagprocessor.cpp Tue Feb 02 00:23:15 2010 +0200 +++ b/imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagprocessor.cpp Fri Mar 19 09:35:30 2010 +0200 @@ -21,14 +21,15 @@ #include #include +#include +#include +#include +#include + #include "thumbagprocessor.h" #include "thumbnaillog.h" #include "thumbnailmanagerconstants.h" #include "thumbnailmanagerprivatecrkeys.h" -#include "thumbagformatobserver.h" -#include -#include -#include // --------------------------------------------------------------------------- // CThumbAGProcessor::NewL() @@ -64,14 +65,9 @@ { TN_DEBUG1( "CThumbAGProcessor::ConstructL() - begin" ); -#ifdef _DEBUG - iAddCounter = 0; - iModCounter = 0; - iDelCounter = 0; -#endif - iTMSession = CThumbnailManager::NewL( *this ); - + iQueryAllItems = NULL; + iQueryPlaceholders = NULL; iQuery = NULL; iQueryActive = EFalse; iModify = EFalse; @@ -84,18 +80,31 @@ iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityIdle); - //do some initializing async in RunL() - iInit = ETrue; - iForceRun = EFalse; + SetForceRun( EFalse ); iActive = EFalse; - iFormatObserver = CThumbAGFormatObserver::NewL( this ); + iFormatObserver = CTMFormatObserver::NewL( *this ); iFormatting = EFalse; iSessionDied = EFalse; iCollectionUtility = NULL; - + + iActivityManager = CTMActivityManager::NewL( this, KBackgroundGenerationIdle); + + UpdatePSValues(ETrue); + + if(iForegroundGenerationObserver) + { + delete iForegroundGenerationObserver; + iForegroundGenerationObserver = NULL; + } + + RProperty::Define(KTAGDPSNotification, KMPXHarvesting, RProperty::EInt); + + //start foreground generation observer + iForegroundGenerationObserver = CTMRPropertyObserver::NewL( *this, KTAGDPSNotification, KForceBackgroundGeneration, ETrue ); + TN_DEBUG1( "CThumbAGProcessor::ConstructL() - end" ); } @@ -107,6 +116,25 @@ { TN_DEBUG1( "CThumbAGProcessor::~CThumbAGProcessor() - begin" ); + if(iForegroundGenerationObserver) + { + delete iForegroundGenerationObserver; + iForegroundGenerationObserver = NULL; + } + + if(iActivityManager) + { + delete iActivityManager; + iActivityManager = NULL; + } + + if (iInactivityTimer) + { + iInactivityTimer->Cancel(); + delete iInactivityTimer; + iInactivityTimer = NULL; + } + if(iPeriodicTimer) { iPeriodicTimer->Cancel(); @@ -115,8 +143,9 @@ if (!iInit) { + /* iHarvesterClient.RemoveHarvesterEventObserver(*this); - iHarvesterClient.Close(); + iHarvesterClient.Close();*/ } if ( iCollectionUtility ) @@ -127,6 +156,13 @@ Cancel(); + if(iQueryPlaceholders) + { + iQueryPlaceholders->Cancel(); + delete iQueryPlaceholders; + iQueryPlaceholders = NULL; + } + if (iQuery) { iQuery->Cancel(); @@ -134,21 +170,20 @@ iQuery = NULL; } - if (iQueryForPlaceholders) + if (iQueryAllItems) { - iQueryForPlaceholders->Cancel(); - delete iQueryForPlaceholders; - iQueryForPlaceholders = NULL; + iQueryAllItems->Cancel(); + delete iQueryAllItems; + iQueryAllItems = NULL; } - + iAddQueue.Close(); iModifyQueue.Close(); - iRemoveQueue.Close(); + iRemoveQueue.ResetAndDestroy(); iQueryQueue.Close(); - iPresentQueue.Close(); - iTempModifyQueue.Close(); - iTempAddQueue.Close(); - iPlaceholderIDs.Close(); + iPlaceholderQueue.Close(); + + i2ndRoundGenerateQueue.Close(); if (iTMSession) { @@ -176,65 +211,119 @@ // CThumbAGProcessor::HandleQueryCompleted() // ----------------------------------------------------------------------------- // -void CThumbAGProcessor::HandleQueryCompleted( CMdEQuery& /*aQuery*/, const TInt aError ) +void CThumbAGProcessor::HandleQueryCompleted( CMdEQuery& aQuery, const TInt aError ) { - - if( iQueryForPlaceholdersActive && iQueryForPlaceholders) + TN_DEBUG3( "CThumbAGProcessor::HandleQueryCompleted, aError == %d Count== %d", aError, aQuery.Count()); + + if(&aQuery == iQueryPlaceholders) { - TN_DEBUG3( "CThumbAGProcessor::HandleQueryCompletedv2, aError == %d Count== %d", aError, iQueryForPlaceholders->Count()); + TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted - iQueryPlaceholders completed"); + iPlaceholderQueue.Reset(); // if no errors in query if (aError == KErrNone ) { - - for(TInt i = 0; i < iQueryForPlaceholders->Count(); i++) + 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; + } + 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 = &iQueryForPlaceholders->Result(i); - + const CMdEObject* object = &iQueryAllItems->Result(i); + if(!object) - continue; - - if(!object->Placeholder()) { - TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompletedv2 %d not placeholder",object->Id()); continue; } - - if (iPlaceholderIDs.Find( object->Id() ) == KErrNotFound) - { - TRAP_IGNORE( iPlaceholderIDs.AppendL( object->Id() )); - } + + 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 } - else + //free query + delete iQueryAllItems; + iQueryAllItems = NULL; + } + else if(&aQuery == iQuery ) + { + TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted - Query completed"); + + if(iQueryActive) { - TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted() FAILED!"); + iQueryReady = ETrue; + iQueryActive = EFalse; } - - iQueryForPlaceholdersActive = EFalse; - } - - else if(iQueryActive) - { - TN_DEBUG3( "CThumbAGProcessor::HandleQueryCompleted, aError == %d Count== %d", aError, iQuery->Count()); - iQueryReady = ETrue; - iQueryActive = EFalse; // if no errors in query if (aError == KErrNone && iQuery) { iProcessingCount = iQuery->Count(); + + if( !iProcessingCount) + { + delete iQuery; + iQuery = NULL; + iProcessingCount = 0; + iModify = EFalse; + } } 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() FAILED!"); + TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted() Query FAILED!"); } } else { TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted() - NO QUERY ACTIVE"); + __ASSERT_DEBUG((EFalse), User::Panic(_L("CThumbAGProcessor::HandleQueryCompleted()"), -1)); } ActivateAO(); @@ -247,6 +336,7 @@ void CThumbAGProcessor::ThumbnailPreviewReady( MThumbnailData& /*aThumbnail*/, TThumbnailRequestId /*aId*/) { + TN_DEBUG1( "CThumbAGProcessor::ThumbnailPreviewReady()"); // No implementation required } @@ -258,8 +348,14 @@ TThumbnailRequestId /*aId*/ ) { TN_DEBUG2( "CThumbAGProcessor::ThumbnailReady() aError == %d", aError ); - - iActive = EFalse; + + iActiveCount--; + + if(iActiveCount <= 0) + { + iActiveCount = 0; + iActive = EFalse; + } // TNM server died, delete session if( aError == KErrServerTerminated ) @@ -268,7 +364,7 @@ iSessionDied = ETrue; - if( !iTimerActive) + if( !iPeriodicTimer->IsActive()) { StartTimeout(); } @@ -281,6 +377,7 @@ } ActivateAO(); + TN_DEBUG1( "CThumbAGProcessor::ThumbnailReady() - end" ); } @@ -294,11 +391,19 @@ iMdESession = aMdESession; + __ASSERT_DEBUG((iMdESession), User::Panic(_L("CThumbAGProcessor::SetMdESession() !iMdESession "), KErrBadHandle)); + TRAPD( err, iDefNamespace = &iMdESession->GetDefaultNamespaceDefL() ); if (err != KErrNone) { - TN_DEBUG1( "CThumbAGProcessor::SetMdESession - Error: GetDefaultNamespaceDefL leave" ); + TN_DEBUG2( "CThumbAGProcessor::SetMdESession() GetDefaultNamespaceDefL() err = %d", err ); } + + __ASSERT_DEBUG((iDefNamespace), User::Panic(_L("CThumbAGProcessor::SetMdESession() !iDefNamespace "), KErrBadHandle)); + + //do async init + iInit = ETrue; + ActivateAO(); } @@ -307,149 +412,133 @@ // --------------------------------------------------------------------------- // void CThumbAGProcessor::AddToQueueL( TObserverNotificationType aType, - const RArray& aIDArray, TBool aPresent ) + const RArray& aIDArray, + const RPointerArray& aObjectUriArray, + TBool /*aPresent*/ ) { TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - begin" ); - - if(aPresent) - { - TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - Add to SetPresentQueue" ); - for (int i=0; i= 0) + { + TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - remove from placeholder queue"); + iPlaceholderQueue.Remove( itemIndex ); + } + + if(iAddQueue.Find( aIDArray[i]) == KErrNotFound && i2ndRoundGenerateQueue.Find( aIDArray[i])) + { + TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - append to add queue"); + iAddQueue.Append( aIDArray[i]); + } + } + } + else + { + TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - PH harvesting finished, check is real modify!" ); - for (int i=0; i= 0 ) - { - TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - harvesting now ended for this placeholder - not Real ENotifyModify" ); - iPlaceholderIDs.Remove(itemIndex); - TN_DEBUG2( "CThumbAGProcessor::AddToQueueL() - placeholders left %d", iPlaceholderIDs.Count() ); - if (iAddQueue.Find( aIDArray[i] ) == KErrNotFound) - { - iAddQueue.AppendL(aIDArray[i]); - } - if (iTempModifyQueue.Find( aIDArray[i] ) == KErrNotFound) - { - iTempModifyQueue.AppendL( aIDArray[i] ); - } - } - else if ( iTempAddQueue.Find( aIDArray[i] ) == KErrNotFound) - { - TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - Real ENotifyModify, force run" ); - iModifyQueue.InsertL( aIDArray[i], 0 ); - - TInt itemIndex = iAddQueue.Find( aIDArray[i] ); - if(itemIndex >= 0) + TInt itemIndex(KErrNotFound); + + for (int i=0; i= 0) + { + TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - placeholder modify, remove from placeholder queue"); + iPlaceholderQueue.Remove( itemIndex ); + } + else + { + TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - real modify"); + itemIndex = iAddQueue.Find( aIDArray[i] ); + + if (itemIndex >= 0) + { + TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - remove from add queue"); + iAddQueue.Remove( itemIndex ); + } + else + { + + itemIndex = i2ndRoundGenerateQueue.Find( aIDArray[i] ); + + if (itemIndex >= 0) + { + TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - remove from 2nd round add queue"); + i2ndRoundGenerateQueue.Remove( itemIndex ); + } + } + + TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - append to modify queue"); + iModifyQueue.AppendL(aIDArray[i]); + + SetForceRun( ETrue ); + } + } + } + } + else if (aType == ENotifyRemove) + { + TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyRemove, remove IDs from all queues"); + + for (int i=0; i= 0) { iAddQueue.Remove(itemIndex); } - itemIndex = iPresentQueue.Find( aIDArray[i] ); - if(itemIndex >= 0) + + // ..and Modify Queue + itemIndex = iModifyQueue.Find( aIDArray[i] ); + if(itemIndex >= 0) { - iPresentQueue.Remove(itemIndex); + iModifyQueue.Remove(itemIndex); } - SetForceRun( ETrue ); - } - else - { - if (iTempModifyQueue.Find( aIDArray[i] ) == KErrNotFound) - { - TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - harvesting now ended for this file - not Real ENotifyModify" ); - iTempModifyQueue.AppendL( aIDArray[i] ); - } - else - { - TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - harvesting ended allready for this file - Real ENotifyModify, force run" ); - iModifyQueue.InsertL( aIDArray[i], 0 ); - TInt itemIndex = iAddQueue.Find( aIDArray[i] ); - if(itemIndex >= 0) - { - iAddQueue.Remove(itemIndex); - } - itemIndex = iPresentQueue.Find( aIDArray[i] ); - if(itemIndex >= 0) - { - iPresentQueue.Remove(itemIndex); - } - SetForceRun( ETrue ); - } - } - } - } - else if (aType == ENotifyRemove) - { - TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyRemove" ); - - for (int i=0; iAllocL(); + iRemoveQueue.Append( temp ); + TN_DEBUG2( "CThumbAGProcessor::AddToQueueL() - %S", temp); + } + } +#ifdef _DEBUG + else { - // only add to Remove queue if not already in Remove queue - if (iRemoveQueue.Find( aIDArray[i] ) == KErrNotFound) - { - iRemoveQueue.AppendL(aIDArray[i]); - } - - // can be removed from Add queue - TInt itemIndex = iAddQueue.Find( aIDArray[i] ); - if(itemIndex >= 0) - { - iAddQueue.Remove(itemIndex); - } - // ..and Present Queue - itemIndex = iPresentQueue.Find( aIDArray[i] ); - if(itemIndex >= 0) - { - iPresentQueue.Remove(itemIndex); - } - // ..and Modify Queue - itemIndex = iModifyQueue.Find( aIDArray[i] ); - if(itemIndex >= 0) - { - iModifyQueue.Remove(itemIndex); - } - } - } - else - { - // should not come here - TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - should not come here" ); - return; - } - + TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - should not come here" ); + User::Leave( KErrArgument ); + } +#endif + ActivateAO(); TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - end" ); @@ -463,109 +552,94 @@ { TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() - begin" ); - if( iModify ) + __ASSERT_DEBUG((iTMSession), User::Panic(_L("CThumbAGProcessor::CreateThumbnailsL() !iTMSession "), KErrBadHandle)); + __ASSERT_DEBUG((iDefNamespace), User::Panic(_L("CThumbAGProcessor::CreateThumbnailsL() !iDefNamespace "), KErrBadHandle)); + + if(!iTMSession || !iDefNamespace) { - TInt orientationVal = 0; - TInt64 modifiedVal = 0; - - CMdEProperty* orientation = NULL; - CMdEObjectDef& objDef = iDefNamespace->GetObjectDefL( MdeConstants::Image::KImageObject ); - TInt orientErr = aObject->Property( objDef.GetPropertyDefL( MdeConstants::Image::KOrientationProperty ), orientation, 0 ); + return; + } + + TInt orientationVal = 0; + TInt64 modifiedVal = 0; + + CMdEProperty* orientation = NULL; + CMdEObjectDef& imageObjectDef = iDefNamespace->GetObjectDefL( MdeConstants::Image::KImageObject ); + TInt orientErr = aObject->Property( imageObjectDef.GetPropertyDefL( MdeConstants::Image::KOrientationProperty ), orientation, 0 ); + + if (orientErr == KErrNone) + { + orientationVal = orientation->Uint16ValueL(); + } - if (orientErr == KErrNone) - { - orientationVal = orientation->Uint16ValueL(); - } - - CMdEProperty* modified = NULL; - CMdEObjectDef& objDef2 = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject ); - TInt modifyErr = aObject->Property( objDef2.GetPropertyDefL( MdeConstants::Object::KLastModifiedDateProperty ), modified, 0 ); - - if (modifyErr >= 0) + CMdEProperty* modified = NULL; + CMdEObjectDef& baseObjDef = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject ); + TInt modifyErr = aObject->Property( baseObjDef.GetPropertyDefL( MdeConstants::Object::KLastModifiedDateProperty ), modified, 0 ); + + if (modifyErr >= 0) + { + modifiedVal = modified->TimeValueL().Int64(); + } + + // update thumbs + if (iTMSession) + { + // 2nd round and modify updates both sizes if needed + if( i2ndRound ) { - modifiedVal = modified->TimeValueL().Int64(); + //generate both if needed + TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() EOptimizeForQuality "); + iTMSession->SetQualityPreferenceL( CThumbnailManager::EOptimizeForQuality ); } - - // modify existing thumbs - if (iTMSession) + // 1st roung generation + else { - // run as lower priority than getting but higher that creating thumbnails - TRAPD(err, iTMSession->UpdateThumbnailsL(aObject->Id(), aObject->Uri(), orientationVal, modifiedVal, CActive::EPriorityIdle )); + //1st round + TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() EOptimizeForQualityWithPreview"); + iTMSession->SetQualityPreferenceL( CThumbnailManager::EOptimizeForQualityWithPreview ); + + CMdEObjectDef& videoObjectDef = iDefNamespace->GetObjectDefL( MdeConstants::Video::KVideoObject ); - if ( err != KErrNone ) + // add item to 2nd round queue + if(iLastQueue == &iAddQueue || iLastQueue == &iModifyQueue) { - TN_DEBUG2( "CThumbAGProcessor::UpdateThumbnailsL, iTMSession error == %d", err ); - - iSessionDied = ETrue; - iActive = EFalse; + TN_DEBUG2( "CThumbAGProcessor::CreateThumbnailsL() - 1st round add/modify, append to 2nd round queue", aObject->Id() ); + if(i2ndRoundGenerateQueue.Find(aObject->Id()) == KErrNotFound) + { + i2ndRoundGenerateQueue.Append( aObject->Id() ); + } + } + + if( !(imageObjectDef.Id() == aObject->Def().Id() || videoObjectDef.Id() == aObject->Def().Id()) ) + { + TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() 1st round and not image or video, skip"); ActivateAO(); - } - else - { - iActive = ETrue; + return; } } + + // run as lower priority than getting but higher that creating thumbnails + TRAPD(err, iTMSession->UpdateThumbnailsL(KNoId, aObject->Uri(), orientationVal, modifiedVal, CActive::EPriorityIdle )); + + if ( err != KErrNone ) + { + TN_DEBUG2( "CThumbAGProcessor::CreateThumbnailsL, iTMSession error == %d", err ); + + iSessionDied = ETrue; + iActive = EFalse; + ActivateAO(); + } else { - ActivateAO(); + iActiveCount++; + iActive = ETrue; } - -#ifdef _DEBUG - iModCounter++; -#endif } else { - CThumbnailObjectSource* source = NULL; - CMdEProperty* mimeType = NULL; - CMdEObjectDef& objDef = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject ); - TInt mime = aObject->Property( objDef.GetPropertyDefL( MdeConstants::Object::KItemTypeProperty ), mimeType, 0 ); - - // create new thumbs - if (mime != KErrNotFound) - { - source = CThumbnailObjectSource::NewLC(aObject->Uri(), aObject->Id(), mimeType->TextValueL()); - } - else - { - source = CThumbnailObjectSource::NewLC(aObject->Uri(), aObject->Id()); - } + ActivateAO(); + } - if (iTMSession) - { - // run as very low priority task - TInt id = iTMSession->CreateThumbnails(*source, CActive::EPriorityIdle ); - if ( id < 0 ) - { - TN_DEBUG2( "CThumbAGProcessor::CreateThumbnailsL, iTMSession error == %d", id ); - - iSessionDied = ETrue; - iActive = EFalse; - CleanupStack::PopAndDestroy( source ); - ActivateAO(); - } - else - { - iActive = ETrue; - CleanupStack::PopAndDestroy( source ); - } - - } - else - { - ActivateAO(); - } - -#ifdef _DEBUG - iAddCounter++; -#endif - } - -#ifdef _DEBUG - TN_DEBUG3( "CThumbAGProcessor::OUT-COUNTERS----------, Add = %d Modify = %d", - iAddCounter, iModCounter ); -#endif - TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() - end" ); } @@ -577,6 +651,19 @@ { TN_DEBUG1( "CThumbAGProcessor::QueryL() - begin" ); + __ASSERT_DEBUG((iMdESession), User::Panic(_L("CThumbAGProcessor::QueryL() !iMdeSession "), KErrBadHandle)); + __ASSERT_DEBUG((iDefNamespace), User::Panic(_L("CThumbAGProcessor::QueryL() !iDefNamespace "), KErrBadHandle)); + + if(!iMdESession || !iDefNamespace) + { + return; + } + + //reset query queue + iQueryQueue.Reset(); + //set reference to current pprocessing queue + iLastQueue = &aIDArray; + iQueryReady = EFalse; // delete old query @@ -593,9 +680,8 @@ for(TInt i=0;i < KMaxQueryItems && i < maxCount; i++) { - TN_DEBUG2( "CThumbAGProcessor::QueryL() - fill %d", aIDArray[0] ); - iQueryQueue.Append( aIDArray[0] ); - aIDArray.Remove( 0 ); + TN_DEBUG2( "CThumbAGProcessor::QueryL() - fill %d", aIDArray[i] ); + iQueryQueue.Append( aIDArray[i] ); } TN_DEBUG3( "CThumbAGProcessor::QueryL() - fill end aIDArray == %d, iQueryQueue == %d", aIDArray.Count(), iQueryQueue.Count() ); @@ -636,11 +722,73 @@ iQuery->FindL(); - iQueryQueue.Reset(); - TN_DEBUG1( "CThumbAGProcessor::QueryL() - end" ); } + +// --------------------------------------------------------------------------- +// CThumbAGProcessor::QueryForPlaceholders() +// --------------------------------------------------------------------------- +// + +void CThumbAGProcessor::QueryPlaceholdersL() + { + TN_DEBUG1( "CThumbAGProcessor::QueryPlaceholdersL" ); + + __ASSERT_DEBUG((iMdESession), User::Panic(_L("CThumbAGProcessor::QueryPlaceholdersL() !iMdeSession "), KErrBadHandle)); + __ASSERT_DEBUG((iDefNamespace), User::Panic(_L("CThumbAGProcessor::QueryPlaceholdersL() !iDefNamespace "), KErrBadHandle)); + + if(!iMdESession || !iDefNamespace) + { + return; + } + + if( iQueryPlaceholders ) + { + if( !iQueryPlaceholders->IsComplete() ) + { + TN_DEBUG1( "CThumbAGProcessor::QueryPlaceholdersL active- skip" ); + return; + } + + // delete old query + iQueryPlaceholders->Cancel(); + delete iQueryPlaceholders; + iQueryPlaceholders = NULL; + } + + TN_DEBUG1( "CThumbAGProcessor::QueryPlaceholdersL - start" ); + + CMdEObjectDef& imageObjDef = iDefNamespace->GetObjectDefL( MdeConstants::Image::KImageObject ); + CMdEObjectDef& videoObjDef = iDefNamespace->GetObjectDefL( MdeConstants::Video::KVideoObject ); + CMdEObjectDef& audioObjDef = iDefNamespace->GetObjectDefL( MdeConstants::Audio::KAudioObject ); + + CMdEObjectDef& objDef = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject); + iQueryPlaceholders = iMdESession->NewObjectQueryL( *iDefNamespace, objDef, this ); + + iQueryPlaceholders->SetResultMode( EQueryResultModeItem ); + + CMdELogicCondition& rootCondition = iQueryPlaceholders->Conditions(); + rootCondition.SetOperator( ELogicConditionOperatorOr ); + + CMdEObjectCondition& imagePHObjectCondition = rootCondition.AddObjectConditionL(imageObjDef); + imagePHObjectCondition.SetPlaceholderOnly( ETrue ); + imagePHObjectCondition.SetNotPresent( ETrue ); + + CMdEObjectCondition& videoPHObjectCondition = rootCondition.AddObjectConditionL(videoObjDef); + videoPHObjectCondition.SetPlaceholderOnly( ETrue ); + videoPHObjectCondition.SetNotPresent( ETrue ); + + CMdEObjectCondition& audioPHObjectCondition = rootCondition.AddObjectConditionL(audioObjDef); + audioPHObjectCondition.SetPlaceholderOnly( ETrue ); + audioPHObjectCondition.SetNotPresent( ETrue ); + + iQueryPlaceholders->FindL(); + + TN_DEBUG1( "CThumbAGProcessor::QueryPlaceholdersL - end" ); + } + + // --------------------------------------------------------------------------- // CThumbAGProcessor::RunL() // --------------------------------------------------------------------------- @@ -651,26 +799,65 @@ if (iSessionDied) { + TN_DEBUG1( "CThumbAGProcessor::RunL() - iSessionDied" ); delete iTMSession; iTMSession = NULL; } if (iInit) { - TN_DEBUG1( "CThumbAGProcessor::RunL() - Do Initialisation" ); + TN_DEBUG1( "CThumbAGProcessor::RunL() - Do Initialisation 1" ); + iInit = EFalse; - TN_DEBUG1( "iHarvesterClient"); - if( iHarvesterClient.Connect() == KErrNone ) + iInit2 = ETrue; + + iAddQueue.Reset(); + iModifyQueue.Reset(); + iRemoveQueue.ResetAndDestroy(); + iQueryQueue.Reset(); + iPlaceholderQueue.Reset(); + + TRAP_IGNORE(QueryPlaceholdersL()); + TN_DEBUG1( "CThumbAGProcessor::RunL() - Initialisation 1 done" ); + ActivateAO(); + return; + } + + if(iInit2) + { + TN_DEBUG1( "CThumbAGProcessor::RunL() - Do Initialisation 2" ); + + iInit2 = EFalse; + TInt err(KErrNone); + /* + TN_DEBUG1( "CThumbAGProcessor::RunL() do iHarvesterClient connect"); + TInt err = iHarvesterClient.Connect(); + TN_DEBUG2( "CThumbAGProcessor::RunL() iHarvesterClient connect err = %d", err); + + __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGProcessor::RunL(), !iHarvesterClient "), err)); + + if( err == KErrNone ) { - TN_DEBUG1( "iHarvesterClient connected"); - iHarvesterClient.AddHarvesterEventObserver( *this, EHEObserverTypeOverall, KMaxTInt ); - iHarvesterClient.AddHarvesterEventObserver( *this, EHEObserverTypePlaceholder, KMaxTInt ); - TN_DEBUG1( "iHarvesterClient AddHarvesterEventObserver added"); + TN_DEBUG1( "CThumbAGProcessor::RunL() add iHarvesterClient observer"); + err = iHarvesterClient.AddHarvesterEventObserver( *this, EHEObserverTypeOverall | EHEObserverTypePlaceholder, KMaxTInt ); + TN_DEBUG2( "CThumbAGProcessor::RunL() iHarvesterClient observer err = %d", err); + __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGProcessor::RunL(), !iHarvesterClient "), err)); + }*/ + + TN_DEBUG1( "CThumbAGProcessor::RunL() MMPXCollectionUtility"); + TRAP( err, iCollectionUtility = MMPXCollectionUtility::NewL( this, KMcModeIsolated )); + TN_DEBUG2( "CThumbAGProcessor::RunL() create MMPXCollectionUtility err = %d", err); + __ASSERT_DEBUG((iCollectionUtility), User::Panic(_L("CThumbAGProcessor::RunL(), !iCollectionUtility "), err)); + + __ASSERT_DEBUG((iActivityManager), User::Panic(_L("CThumbAGProcessor::RunL(), !iActivityManager "), KErrBadHandle)); + if(iActivityManager) + { + iActivityManager->Start(); } - TN_DEBUG1( "create MMPXCollectionUtility"); - iCollectionUtility = MMPXCollectionUtility::NewL( this, KMcModeIsolated ); - TN_DEBUG1( "CThumbAGProcessor::RunL() - Initialisation done" ); + TRAP_IGNORE(QueryAllItemsL()); + + TN_DEBUG1( "CThumbAGProcessor::RunL() - Initialisation 2 done" ); return; } @@ -684,9 +871,11 @@ if (err != KErrNone) { iTMSession = NULL; + ActivateAO(); TN_DEBUG2( "CThumbAGProcessor::RunL() - Session restart failed, error == %d", err ); } - else { + else + { iSessionDied = EFalse; } } @@ -694,95 +883,123 @@ // do not run if request is already issued to TNM server even if forced if( iActive) { - if(iActiveCount <= KMaxDaemonRequests) + if(iActiveCount >= KMaxDaemonRequests) { - iActiveCount++; TN_DEBUG1( "CThumbAGProcessor::RunL() - waiting for previous to complete, abort..." ); return; } - else - { - TN_DEBUG1( "CThumbAGProcessor::RunL() - iActive jammed - resetted" ); - iActive = EFalse; - iActiveCount = 0; - } } else { iActiveCount = 0; } - //Iforce run can proceed from this point - if( !iForceRun ) + + //force run can proceed from this point +#ifdef _DEBUG + if( iForegroundRun ) + { + TN_DEBUG1( "void CThumbAGProcessor::RunL() KForceBackgroundGeneration enabled"); + } + + if( iForceRun ) { - //check if harvesting or waiting timeout - if( iHarvesting || iTimerActive || iMPXHarvesting ) + TN_DEBUG1( "CThumbAGProcessor::RunL() - *** FORCED RUN ***"); + } +#endif + + if( /*iForceRun || */iForegroundRun ) + { + TN_DEBUG1( "void CThumbAGProcessor::RunL() skip idle detection!"); + CancelTimeout(); + } + else + { + if(iActivityManager) { - TN_DEBUG1( "void CThumbAGProcessor::RunL() Harvester or timer active, abort"); + iIdle = iActivityManager->IsInactive(); + } + + if( !iIdle || iHarvesting || iMPXHarvesting || iPeriodicTimer->IsActive() ) + { + TN_DEBUG1( "void CThumbAGProcessor::RunL() device not idle"); return; } else { //check is server idle - TInt idle(-1); - - TInt ret = RProperty::Get(KServerIdle, KIdle, idle); - - if(ret == KErrNone ) - { - if(!idle) - { - //start wait timer and retry on after callback - TN_DEBUG1( "CThumbAGProcessor::RunL() server not idle, wait... " ); - if( !iTimerActive) - { - StartTimeout(); - } - return; - } - } - else - { - TN_DEBUG2( "CThumbAGProcessor::RunL() get KServerIdle failed %d, continue...", ret ); - } + TInt serveIdle(KErrNotFound); + TInt ret = RProperty::Get(KServerIdle, KIdle, serveIdle); + + if(ret == KErrNone ) + { + if(!serveIdle) + { + //start inactivity timer and retry on after callback + TN_DEBUG1( "void CThumbAGProcessor::RunL() server not idle"); + StartTimeout(); + return; + } + } + TN_DEBUG1( "void CThumbAGProcessor::RunL() device and server idle, process"); } - } - else - { - TN_DEBUG1( "void CThumbAGProcessor::RunL() forced run"); - } - + } //Handle completed MDS Query if( iQueryReady && iProcessingCount) { TInt err(KErrNone); - if((iForceRun && iModify) || (!iForceRun && !iModify)) + //if force or non forced + if((iForceRun && iModify ) || (!iForceRun && !iModify )) { TN_DEBUG1( "CThumbAGProcessor::RunL() - iQueryReady START" ); - 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 ) { - TRAP( err, CreateThumbnailsL(object) ); + //remove item from queryQueue when request is issued + itemIndex = iQueryQueue.Find( object->Id()); + if(itemIndex >= 0) + { + iQueryQueue.Remove(itemIndex); + } - if ( err != KErrNone ) - { - TN_DEBUG2( "CThumbAGProcessor::RunL(), CreateThumbnailsL error == %d", err ); - } + TRAP( err, CreateThumbnailsL(object) ); + TN_DEBUG2( "CThumbAGProcessor::RunL(), CreateThumbnailsL error == %d", err ); + __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGProcessor::RunL(), CreateThumbnailsL() "), err)); } } + //force is coming, but executing non-forced query complete-> cancel old else { - TN_DEBUG1( "CThumbAGProcessor::RunL() - deleting query" ); + 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; } @@ -798,13 +1015,12 @@ //check if forced run needs to continue if (iModifyQueue.Count()) { - iForceRun = ETrue; + SetForceRun( ETrue ); } else { - iForceRun = EFalse; - } - + SetForceRun( EFalse ); + } } //keep going if processing Remove items or if Add item fails else if( iModify || err ) @@ -813,16 +1029,35 @@ } } //waiting for MDS query to complete - else if( iQueryActive || iQueryForPlaceholdersActive ) + else if( iQueryActive ) { - if(iForceRun && !iModify && iQueryActive) + if(iForceRun && !iModify) { - iQuery->Cancel(); - delete iQuery; - iQuery = NULL; - TN_DEBUG1( "CThumbAGProcessor::RunL() - canceling query..." ); + 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; + ActivateAO(); } else @@ -831,52 +1066,66 @@ } } - // select queue to process, priority by type. Process modify events before new images + // no items in query queue, start new + // select queue to process, priority by type else if ( iModifyQueue.Count() > 0 ) { TN_DEBUG1( "void CThumbAGProcessor::RunL() update thumbnails"); + i2ndRound = EFalse; + // query for object info iQueryActive = ETrue; iModify = ETrue; QueryL( iModifyQueue ); } - else if ( iRemoveQueue.Count() > 0 ) - { - TN_DEBUG1( "void CThumbAGProcessor::RunL() delete thumbnails"); - - // delete thumbs by ID - if (iTMSession) - { - iTMSession->DeleteThumbnails( iRemoveQueue[0] ); - } - iRemoveQueue.Remove( 0 ); - -#ifdef _DEBUG - iDelCounter++; - TN_DEBUG2( "CThumbAGProcessor::OUT-COUNTERS----------, Delete = %d", iDelCounter ); -#endif - ActivateAO(); - } else if ( iAddQueue.Count() > 0 ) { - TN_DEBUG1( "void CThumbAGProcessor::RunL() add thumbnails"); + TN_DEBUG1( "void CThumbAGProcessor::RunL() update 1st round thumbnails"); + + i2ndRound = EFalse; // query for object info iQueryActive = ETrue; QueryL( iAddQueue ); } - else if ( iPresentQueue.Count() > 0 ) + else if ( iRemoveQueue.Count() > 0 ) { - TN_DEBUG1( "void CThumbAGProcessor::RunL() add thumbnails for present thumbnails" ); - + TN_DEBUG1( "void CThumbAGProcessor::RunL() delete thumbnails"); + + i2ndRound = EFalse; + + // delete thumbs by URI + __ASSERT_DEBUG((iTMSession), User::Panic(_L("CThumbAGProcessor::RunL() !iTMSession "), KErrBadHandle)); + if(iTMSession) + { + HBufC* uri = iRemoveQueue[0]; + TN_DEBUG2( "void CThumbAGProcessor::RunL() delete %S", uri); + CThumbnailObjectSource* source = NULL; + TRAPD(err, source = CThumbnailObjectSource::NewL( *uri, KNullDesC)); + + if(err == KErrNone) + { + iTMSession->DeleteThumbnails( *source ); + } + iRemoveQueue.Remove( 0 ); + delete source; + delete uri; + } + + ActivateAO(); + } + else if( i2ndRoundGenerateQueue.Count() > 0) + { + TN_DEBUG1( "void CThumbAGProcessor::RunL() update 2nd round thumbnails"); + // query for object info iQueryActive = ETrue; - - QueryL( iPresentQueue ); + i2ndRound = ETrue; + QueryL( i2ndRoundGenerateQueue ); } - + TN_DEBUG1( "CThumbAGProcessor::RunL() - end" ); } @@ -895,62 +1144,94 @@ TInt /*aItemsLeft*/ ) { TN_DEBUG3( "CThumbAGProcessor::HarvestingUpdated -- start() aHEObserverType = %d, aHarvesterEventState = %d", aHEObserverType, aHarvesterEventState ); - + + #ifdef _DEBUG + if( aHEObserverType == EHEObserverTypePlaceholder) + { + TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- type EHEObserverTypePlaceholder"); + } + else if( aHEObserverType == EHEObserverTypeOverall) + { + TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- type EHEObserverTypeOverall"); + } + #endif + + //placeholder harvesting if( aHEObserverType == EHEObserverTypePlaceholder) { - TRAP_IGNORE( QueryForPlaceholdersL() ); - return; - } - - if( aHEObserverType != EHEObserverTypeOverall) - { - return; - } + switch(aHarvesterEventState) + { + case EHEStateStarted: + case EHEStateHarvesting: + case EHEStateResumed: + { + iPHHarvestingTemp = ETrue; + break; + } + case EHEStatePaused: + case EHEStateFinished: + case EHEStateUninitialized: + { + iPHHarvestingTemp = EFalse; + break; + } + }; - switch(aHarvesterEventState) - { - case EHEStateStarted: - case EHEStateHarvesting: - case EHEStatePaused: - case EHEStateResumed: - { - iHarvestingTemp = ETrue; - break; - } - case EHEStateFinished: - case EHEStateUninitialized: - { - iHarvestingTemp = EFalse; - break; - } - }; - - if(iHarvestingTemp == iHarvesting) - { - TN_DEBUG2( "CThumbAGProcessor::HarvestingUpdated -- no change %d", iHarvesting); - } - else - { - iHarvesting = iHarvestingTemp; - - if( iHarvesting ) + if(iPHHarvestingTemp != iPHHarvesting) { - TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS harvesterin started"); - CancelTimeout(); - } - else - { - TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS harvesting finished "); - // continue processing if needed - StartTimeout(); - - iTempModifyQueue.Reset(); - iTempAddQueue.Reset(); - iPlaceholderIDs.Reset(); + iPHHarvesting = iPHHarvestingTemp; + + if( iPHHarvesting ) + { + TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS placeholder harvesterin started"); + } + else + { + TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS placeholder harvesting finished"); + TRAP_IGNORE(QueryPlaceholdersL()); + } } } - - TN_DEBUG3( "CThumbAGProcessor::HarvestingUpdated -- end() iHarvesting == %d, iMPXHarvesting == %d", iHarvesting, iMPXHarvesting); + //overall harvesting + else if ( aHEObserverType == EHEObserverTypeOverall) + { + switch(aHarvesterEventState) + { + case EHEStateStarted: + case EHEStateHarvesting: + case EHEStatePaused: + case EHEStateResumed: + { + iHarvestingTemp = ETrue; + break; + } + case EHEStateFinished: + case EHEStateUninitialized: + { + iHarvestingTemp = EFalse; + break; + } + }; + + if(iHarvestingTemp != iHarvesting) + { + iHarvesting = iHarvestingTemp; + + if( iHarvesting ) + { + TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS harvesterin started"); + CancelTimeout(); + } + else + { + TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS harvesting finished "); + // continue processing if needed + StartTimeout(); + } + } + } + + TN_DEBUG3( "CThumbAGProcessor::HarvestingUpdated -- end() iHarvesting == %d, iPHHarvesting == %d ", iHarvesting, iPHHarvesting); } // --------------------------------------------------------------------------- @@ -959,17 +1240,13 @@ // void CThumbAGProcessor::StartTimeout() { + TN_DEBUG1( "CThumbAGProcessor::StartTimeout()"); CancelTimeout(); if(!iHarvesting && !iMPXHarvesting && !iPeriodicTimer->IsActive()) { - iPeriodicTimer->Start( KHarvestingCompleteTimeout, KHarvestingCompleteTimeout, + iPeriodicTimer->Start( KHarvestingCompleteTimeout, KHarvestingCompleteTimeout, TCallBack(PeriodicTimerCallBack, this)); - iTimerActive = ETrue; - } - else - { - iTimerActive = EFalse; } } @@ -979,26 +1256,36 @@ // void CThumbAGProcessor::CancelTimeout() { - if(iTimerActive) - { - iPeriodicTimer->Cancel(); - } - iTimerActive = EFalse; + if(iPeriodicTimer->IsActive()) + { + iPeriodicTimer->Cancel(); + } } // --------------------------------------------------------------------------- // CThumbAGProcessor::RunError() // --------------------------------------------------------------------------- // +#ifdef _DEBUG TInt CThumbAGProcessor::RunError(TInt aError) +#else +TInt CThumbAGProcessor::RunError(TInt /*aError*/) +#endif { - if (aError != KErrNone) + TN_DEBUG2( "CThumbAGrocessor::RunError() %d", aError); + + UpdatePSValues(); + + iActiveCount--; + + if(iActiveCount <= 0) { - TN_DEBUG2( "CThumbAGProcessor::RunError = %d", aError ); + iActiveCount = 0; + iActive = EFalse; } - iActive = EFalse; - + ActivateAO(); + // nothing to do return KErrNone; } @@ -1009,24 +1296,29 @@ // void CThumbAGProcessor::ActivateAO() { +#ifdef _DEBUG + TN_DEBUG6( "CThumbAGProcessor::ActivateAO() items in queue Add = %d, Mod = %d, Del = %d, Query = %d, iPlaceholder = %d", iAddQueue.Count(), iModifyQueue.Count(), iRemoveQueue.Count(), iQueryQueue.Count(), iPlaceholderQueue.Count()); + TN_DEBUG2( "CThumbAGProcessor::ActivateAO() items in queue 2nd Add = %d", i2ndRoundGenerateQueue.Count()); + TN_DEBUG3( "CThumbAGProcessor::ActivateAO() iActive = %d, iActiveCount = %d", iActive, iActiveCount); + TN_DEBUG3( "CThumbAGProcessor::ActivateAO() iHarvesting == %d, iMPXHarvesting == %d", iHarvesting, iMPXHarvesting); + TN_DEBUG4( "CThumbAGProcessor::ActivateAO() iIdle = %d, timer = %d, iForceRun = %d", iIdle, iPeriodicTimer->IsActive(), iForceRun); + TN_DEBUG4( "CThumbAGProcessor::ActivateAO() iModify = %d, iQueryReady = %d, iProcessingCount = %d", iModify, iQueryReady, iProcessingCount); +#endif + if(iFormatting) { TN_DEBUG1( "CThumbAGProcessor::ActivateAO() - FORMATTING - DAEMON ON PAUSE"); return; } - if( !IsActive() && (!iHarvesting || iForceRun )) + if( !IsActive() ) { -#ifdef _DEBUG - if( iForceRun ) - { - TN_DEBUG1( "CThumbAGProcessor::ActivateAO() - *** FORCED RUN ***"); - } -#endif SetActive(); TRequestStatus* statusPtr = &iStatus; User::RequestComplete( statusPtr, KErrNone ); } + + UpdatePSValues(); } // --------------------------------------------------------------------------- @@ -1063,15 +1355,24 @@ TBool audioFull( EFalse ); // get cenrep values - rep->Get( KAutoCreateImageGrid, imageGrid ); - rep->Get( KAutoCreateImageList, imageList ); - rep->Get( KAutoCreateImageFullscreen, imageFull ); - rep->Get( KAutoCreateVideoGrid, videoGrid ); - rep->Get( KAutoCreateVideoList, videoList ); - rep->Get( KAutoCreateVideoFullscreen, videoFull ); - rep->Get( KAutoCreateAudioGrid, audioGrid ); - rep->Get( KAutoCreateAudioList, audioList ); - rep->Get( KAutoCreateAudioFullscreen, audioFull ); + TInt ret = rep->Get( KAutoCreateImageGrid, imageGrid ); + TN_DEBUG2( "CThumbAGProcessor::CheckAutoCreateValuesL() KAutoCreateImageGrid %d", ret); + ret = rep->Get( KAutoCreateImageList, imageList ); + TN_DEBUG2( "CThumbAGProcessor::CheckAutoCreateValuesL() KAutoCreateImageList %d", ret); + ret = rep->Get( KAutoCreateImageFullscreen, imageFull ); + TN_DEBUG2( "CThumbAGProcessor::CheckAutoCreateValuesL() KAutoCreateImageFullscreen %d", ret); + ret = rep->Get( KAutoCreateVideoGrid, videoGrid ); + TN_DEBUG2( "CThumbAGProcessor::CheckAutoCreateValuesL() KAutoCreateVideoGrid %d", ret); + ret = rep->Get( KAutoCreateVideoList, videoList ); + TN_DEBUG2( "CThumbAGProcessor::CheckAutoCreateValuesL() KAutoCreateVideoList %d", ret); + ret = rep->Get( KAutoCreateVideoFullscreen, videoFull ); + TN_DEBUG2( "CThumbAGProcessor::CheckAutoCreateValuesL() KAutoCreateVideoFullscreen %d", ret); + ret = rep->Get( KAutoCreateAudioGrid, audioGrid ); + TN_DEBUG2( "CThumbAGProcessor::CheckAutoCreateValuesL() KAutoCreateAudioGrid %d", ret); + ret = rep->Get( KAutoCreateAudioList, audioList ); + TN_DEBUG2( "CThumbAGProcessor::CheckAutoCreateValuesL() KAutoCreateAudioList %d", ret); + ret = rep->Get( KAutoCreateAudioFullscreen, audioFull ); + TN_DEBUG2( "CThumbAGProcessor::CheckAutoCreateValuesL() KAutoCreateAudioFullscreen %d", ret); iAutoImage = EFalse; iAutoVideo = EFalse; @@ -1098,7 +1399,11 @@ // CThumbAGProcessor::RemoveFromQueues() // --------------------------------------------------------------------------- // +#ifdef _DEBUG void CThumbAGProcessor::RemoveFromQueues( const RArray& aIDArray, const TBool aRemoveFromDelete ) +#else +void CThumbAGProcessor::RemoveFromQueues( const RArray& aIDArray, const TBool /*aRemoveFromDelete*/ ) +#endif { TN_DEBUG2( "CThumbAGProcessor::RemoveFromQueues() aRemoveFromDelete == %d - begin", aRemoveFromDelete ); @@ -1107,6 +1412,14 @@ for (int i=0; i< aIDArray.Count(); i++) { TN_DEBUG2( "CThumbAGProcessor::RemoveFromQueues() - %d", aIDArray[i]); + + itemIndex = iPlaceholderQueue.Find( aIDArray[i] ); + + if(itemIndex >= 0) + { + iPlaceholderQueue.Remove(itemIndex); + TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iPlaceholderQueue" ); + } itemIndex = iAddQueue.Find( aIDArray[i] ); @@ -1114,44 +1427,42 @@ { iAddQueue.Remove(itemIndex); TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iAddQueue" ); - continue; } - - itemIndex = iPresentQueue.Find( aIDArray[i] ); + + itemIndex = i2ndRoundGenerateQueue.Find( aIDArray[i] ); if(itemIndex >= 0) { - iPresentQueue.Remove(itemIndex); - TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iPresentQueue" ); - continue; + i2ndRoundGenerateQueue.Remove(itemIndex); + TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - i2ndRoundGenerateQueue" ); } - + itemIndex = iModifyQueue.Find( aIDArray[i] ); if(itemIndex >= 0) - { - iModifyQueue.Remove(itemIndex); - TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iModifyQueue" ); + { + iModifyQueue.Remove(itemIndex); + TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iModifyQueue" ); - if( iModifyQueue.Count() == 0) - { - iForceRun = EFalse; - } + if( iModifyQueue.Count() == 0) + { + SetForceRun( EFalse ); + } - continue; - } + continue; + } - if( aRemoveFromDelete ) - { - itemIndex = iRemoveQueue.Find( aIDArray[i] ); + /*if( aRemoveFromDelete ) + { + itemIndex = iRemoveQueue.Find( aIDArray[i] ); - if(itemIndex >= 0) - { - iRemoveQueue.Remove(itemIndex); - TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iRemoveQueue" ); - continue; - } - } + if(itemIndex >= 0) + { + iRemoveQueue.Remove(itemIndex); + TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iRemoveQueue" ); + continue; + } + }*/ } TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - end" ); @@ -1173,75 +1484,57 @@ } // --------------------------------------------------------------------------- -// CThumbAGProcessor::SetFormat() -// --------------------------------------------------------------------------- -// - -void CThumbAGProcessor::SetFormat(TBool aStatus) - { - TN_DEBUG2( "CThumbAGProcessor::SetFormat(%d) - end", aStatus ); - - iFormatting = aStatus; - if(!aStatus) - { - ActivateAO(); - } - } - -// --------------------------------------------------------------------------- // CThumbAGProcessor::QueryForPlaceholders() // --------------------------------------------------------------------------- // - -void CThumbAGProcessor::QueryForPlaceholdersL() +void CThumbAGProcessor::QueryAllItemsL() { - TN_DEBUG1( "CThumbAGProcessor::QueryForPlaceholders" ); - if(iQueryForPlaceholdersActive) + TN_DEBUG1( "CThumbAGProcessor::QueryAllItemsL" ); + + __ASSERT_DEBUG((iMdESession), User::Panic(_L("CThumbAGProcessor::QueryAllItemsL() !iMdeSession "), KErrBadHandle)); + + if(!iMdESession) + { + return; + } + + if( iQueryAllItems ) { - TN_DEBUG1( "CThumbAGProcessor::QueryForPlaceholders - skip" ); - return; + if( !iQueryAllItems->IsComplete() ) + { + TN_DEBUG1( "CThumbAGProcessor::QueryAllItemsL active- skip" ); + return; + } + + // delete old query + iQueryAllItems->Cancel(); + delete iQueryAllItems; + iQueryAllItems = NULL; } - TN_DEBUG1( "CThumbAGProcessor::QueryForPlaceholders - start" ); - - // delete old query - if (iQueryForPlaceholders) - { - iQueryForPlaceholdersActive = EFalse; - iQueryForPlaceholders->Cancel(); - delete iQueryForPlaceholders; - iQueryForPlaceholders = NULL; - } + TN_DEBUG1( "CThumbAGProcessor::QueryAllItemsL - start" ); CMdEObjectDef& imageObjDef = iDefNamespace->GetObjectDefL( MdeConstants::Image::KImageObject ); CMdEObjectDef& videoObjDef = iDefNamespace->GetObjectDefL( MdeConstants::Video::KVideoObject ); CMdEObjectDef& audioObjDef = iDefNamespace->GetObjectDefL( MdeConstants::Audio::KAudioObject ); CMdEObjectDef& objDef = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject); - iQueryForPlaceholders = iMdESession->NewObjectQueryL( *iDefNamespace, objDef, this ); + iQueryAllItems = iMdESession->NewObjectQueryL( *iDefNamespace, objDef, this ); - iQueryForPlaceholders->SetResultMode( EQueryResultModeItem ); + iQueryAllItems->SetResultMode( EQueryResultModeItem ); - CMdELogicCondition& rootCondition = iQueryForPlaceholders->Conditions(); + CMdELogicCondition& rootCondition = iQueryAllItems->Conditions(); rootCondition.SetOperator( ELogicConditionOperatorOr ); CMdEObjectCondition& imagePHObjectCondition = rootCondition.AddObjectConditionL(imageObjDef); - imagePHObjectCondition.SetPlaceholderOnly( ETrue ); - imagePHObjectCondition.SetNotPresent( ETrue ); CMdEObjectCondition& videoPHObjectCondition = rootCondition.AddObjectConditionL(videoObjDef); - videoPHObjectCondition.SetPlaceholderOnly( ETrue ); - videoPHObjectCondition.SetNotPresent( ETrue ); CMdEObjectCondition& audioPHObjectCondition = rootCondition.AddObjectConditionL(audioObjDef); - audioPHObjectCondition.SetPlaceholderOnly( ETrue ); - audioPHObjectCondition.SetNotPresent( ETrue ); - iQueryForPlaceholders->FindL(); + iQueryAllItems->FindL(); - iQueryForPlaceholdersActive = ETrue; - - TN_DEBUG1( "CThumbAGProcessor::QueryForPlaceholders - end" ); + TN_DEBUG1( "CThumbAGProcessor::QueryAllItemsL - end" ); } // ----------------------------------------------------------------------------- @@ -1250,9 +1543,7 @@ // Handle collection message. // ----------------------------------------------------------------------------- // - -void CThumbAGProcessor::HandleCollectionMessage( CMPXMessage* aMessage, - TInt aError ) +void CThumbAGProcessor::HandleCollectionMessage( CMPXMessage* aMessage, TInt aError ) { if ( aError != KErrNone || !aMessage ) { @@ -1271,40 +1562,50 @@ { TInt op( *aMessage->Value( KMPXMessageGeneralType ) ); - switch( op ) - { - //when MTP sync or music collection is started then pause processing - case EMcMsgRefreshStart: - case EMcMsgUSBMTPStart: - TN_DEBUG1("CThumbAGProcessor::HandleCollectionMessage MPX refresh started" ); - iMPXHarvesting = ETrue; - CancelTimeout(); - break; - //when MTP sync or music collection refresh is complete then resume processing - case EMcMsgRefreshEnd: - case EMcMsgUSBMTPEnd: - case EMcMsgUSBMTPNotActive: - TN_DEBUG1("CThumbAGProcessor::HandleCollectionMessage MPX refresh finished/not active" ); - iMPXHarvesting = EFalse; - StartTimeout(); - break; - default: - break; - } - TN_DEBUG3( "CThumbAGProcessor::HandleCollectionMessage -- end() iHarvesting == %d, iMPXHarvesting == %d", iHarvesting, iMPXHarvesting); + switch( op ) + { + //when MTP sync or music collection is started then pause processing + case EMcMsgRefreshStart: + case EMcMsgUSBMTPStart: + TN_DEBUG1("CThumbAGProcessor::HandleCollectionMessage MPX refresh started" ); + iMPXHarvesting = ETrue; + CancelTimeout(); + break; + //when MTP sync or music collection refresh is complete then resume processing + case EMcMsgRefreshEnd: + case EMcMsgUSBMTPEnd: + case EMcMsgUSBMTPNotActive: + TN_DEBUG1("CThumbAGProcessor::HandleCollectionMessage MPX refresh finished/not active" ); + iMPXHarvesting = EFalse; + StartTimeout(); + break; + default: + break; + } + + //signal Server's stores about MPX harvesting state + if( iMPXHarvesting ) + { + RProperty::Set(KTAGDPSNotification, KMPXHarvesting, ETrue); + } + else + { + RProperty::Set(KTAGDPSNotification, KMPXHarvesting, EFalse); + } + + TN_DEBUG3( "CThumbAGProcessor::HandleCollectionMessage -- end() iHarvesting == %d, iMPXHarvesting == %d", iHarvesting, iMPXHarvesting); } } } + // ----------------------------------------------------------------------------- // CThumbAGProcessor::HandleOpenL // From MMPXCollectionObserver // Handles the collection entries being opened. // ----------------------------------------------------------------------------- // -void CThumbAGProcessor::HandleOpenL( const CMPXMedia& /*aEntries*/, - TInt /*aIndex*/, - TBool /*aComplete*/, - TInt /*aError*/ ) +void CThumbAGProcessor::HandleOpenL( const CMPXMedia& /*aEntries*/, TInt /*aIndex*/, + TBool /*aComplete*/, TInt /*aError*/ ) { // not needed here } @@ -1331,4 +1632,107 @@ // not needed here } +// ----------------------------------------------------------------------------- +// ActivityChanged() +// ----------------------------------------------------------------------------- +// +void CThumbAGProcessor::ActivityChanged(const TBool aActive) + { + TN_DEBUG2( "void CThumbAGProcessor::ActivityChanged() aActive == %d", aActive); + if(aActive) + { + iIdle = EFalse; + } + else + { + iIdle = ETrue; + + if(iAddQueue.Count() + iModifyQueue.Count() + iRemoveQueue.Count() + i2ndRoundGenerateQueue.Count() > 0 ) + { + ActivateAO(); + } + } + } + + +// --------------------------------------------------------------------------- +// CThumbAGProcessor::FormatNotification +// Handles a format operation +// --------------------------------------------------------------------------- +// +void CThumbAGProcessor::FormatNotification( TBool aFormat ) + { + TN_DEBUG2( "CThumbAGProcessor::FormatNotification(%d)", aFormat ); + + iFormatting = aFormat; + if(!aFormat) + { + ActivateAO(); + } + } + +// --------------------------------------------------------------------------- +// CThumbAGProcessor::RPropertyNotification +// Handles a RProperty changed operation +// --------------------------------------------------------------------------- +// +void CThumbAGProcessor::RPropertyNotification(const TInt aError, const TUid aKeyCategory, const TUint aPropertyKey, const TInt aValue) + { + TN_DEBUG5( "CThumbAGProcessor::RPropertyNotification() aError = %d, aPropertyKey = %d, aKeyCategory = %d, aValue = %d", aError, aPropertyKey, aKeyCategory, aValue ); + + if(aPropertyKey == KForceBackgroundGeneration && aKeyCategory == KTAGDPSNotification ) + { + if( aValue == 1 && aError == KErrNone ) + { + iForegroundRun = ETrue; + ActivateAO(); + } + else + { + iForegroundRun = EFalse; + } + } + } + +// --------------------------------------------------------------------------- +// CThumbAGProcessor::UpdateItemsLeft +// Update KItemsleft PS value if changed +// --------------------------------------------------------------------------- +// +void CThumbAGProcessor::UpdatePSValues(const TBool aDefine) + { + TInt itemsLeft = iModifyQueue.Count() + iAddQueue.Count(); + TBool daemonProcessing = EFalse; + + if(itemsLeft + i2ndRoundGenerateQueue.Count() + iRemoveQueue.Count() > 0 ) + { + daemonProcessing = ETrue; + } + + if(aDefine) + { + TN_DEBUG1( "CThumbAGProcessor::UpdatePSValues() define"); + RProperty::Define(KTAGDPSNotification, KDaemonProcessing, RProperty::EInt); + RProperty::Set(KTAGDPSNotification, KDaemonProcessing, 0); + daemonProcessing = EFalse; + RProperty::Define(KTAGDPSNotification, KItemsleft, RProperty::EInt); + RProperty::Set(KTAGDPSNotification, KItemsleft, 0); + iPreviousItemsLeft = 0; + } + + if( daemonProcessing != iPreviousDaemonProcessing) + { + TN_DEBUG2( "CThumbAGProcessor::UpdatePSValues() update KDaemonProcessing == %d", daemonProcessing); + iPreviousDaemonProcessing = daemonProcessing; + RProperty::Set(KTAGDPSNotification, KDaemonProcessing, daemonProcessing); + } + + if( itemsLeft != iPreviousItemsLeft) + { + TN_DEBUG2( "CThumbAGProcessor::UpdatePSValues() update KItemsleft == %d", itemsLeft); + iPreviousItemsLeft = itemsLeft; + RProperty::Set(KTAGDPSNotification, KItemsleft, itemsLeft ); + } + } + // End of file