imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagprocessor.cpp
branchRCL_3
changeset 9 2eb74cf6572e
parent 5 82749d516180
child 10 7403edfcf0fb
equal deleted inserted replaced
5:82749d516180 9:2eb74cf6572e
    22 #include <centralrepository.h>
    22 #include <centralrepository.h>
    23 
    23 
    24 #include <mpxcollectionutility.h>
    24 #include <mpxcollectionutility.h>
    25 #include <mpxmessagegeneraldefs.h>
    25 #include <mpxmessagegeneraldefs.h>
    26 #include <mpxcollectionmessage.h>
    26 #include <mpxcollectionmessage.h>
    27 #include <CoreApplicationUIsDomainPSKeys.h> 
    27 #include <coreapplicationuisdomainpskeys.h> 
    28 
    28 
    29 #include "thumbagprocessor.h"
    29 #include "thumbagprocessor.h"
    30 #include "thumbnaillog.h"
    30 #include "thumbnaillog.h"
    31 #include "thumbnailmanagerconstants.h"
    31 #include "thumbnailmanagerconstants.h"
    32 #include "thumbnailmanagerprivatecrkeys.h"
    32 #include "thumbnailmanagerprivatecrkeys.h"
    62 // ---------------------------------------------------------------------------
    62 // ---------------------------------------------------------------------------
    63 //
    63 //
    64 void CThumbAGProcessor::ConstructL()
    64 void CThumbAGProcessor::ConstructL()
    65     {
    65     {
    66     TN_DEBUG1( "CThumbAGProcessor::ConstructL() - begin" );
    66     TN_DEBUG1( "CThumbAGProcessor::ConstructL() - begin" );
    67     
       
    68 #ifdef _DEBUG
       
    69     iAddCounter = 0;
       
    70     iModCounter = 0;
       
    71     iDelCounter = 0;
       
    72 #endif
       
    73     
    67     
    74     iTMSession = CThumbnailManager::NewL( *this );
    68     iTMSession = CThumbnailManager::NewL( *this );
    75     iQueryAllItems = NULL;
    69     iQueryAllItems = NULL;
    76     iQueryPlaceholders = NULL;
    70     iQueryPlaceholders = NULL;
    77     iQuery = NULL;
    71     iQuery = NULL;
    84     // set auto create values from cenrep
    78     // set auto create values from cenrep
    85     CheckAutoCreateValuesL();
    79     CheckAutoCreateValuesL();
    86     
    80     
    87     iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityIdle);
    81     iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityIdle);
    88     
    82     
    89     //do some initializing async in RunL()
    83     SetForceRun( EFalse );    
    90     iInit = ETrue;
       
    91     iForceRun = EFalse;    
       
    92     iActive = EFalse;
    84     iActive = EFalse;
    93     
    85     
    94     iFormatObserver = CTMFormatObserver::NewL( *this );
    86     iFormatObserver = CTMFormatObserver::NewL( *this );
    95        
    87        
    96     iFormatting = EFalse;     
    88     iFormatting = EFalse;     
    97     iSessionDied = EFalse;
    89     iSessionDied = EFalse;
    98     
    90     
    99     iCollectionUtility = NULL;
    91     iCollectionUtility = NULL;
   100     
    92     
   101     iLight = CHWRMLight::NewL(this);
       
   102 
       
   103 #ifdef _DEBUG 
       
   104     if(iLight)
       
   105         {
       
   106         iLightMask = iLight->SupportedTargets();
       
   107         TN_DEBUG2( "CThumbAGProcessor::ConstructL() - iLightMask == %d", iLightMask );
       
   108         }
       
   109 #endif
       
   110         
       
   111     iActivityManager = CTMActivityManager::NewL( this, KBackgroundGenerationIdle);
    93     iActivityManager = CTMActivityManager::NewL( this, KBackgroundGenerationIdle);
   112     
    94 
   113     ActivateAO();
    95     UpdatePSValues(ETrue);
       
    96 
       
    97     if(iForegroundGenerationObserver)
       
    98       {
       
    99       delete iForegroundGenerationObserver;
       
   100       iForegroundGenerationObserver = NULL;
       
   101       }
       
   102     
       
   103     RProperty::Define(KTAGDPSNotification, KMPXHarvesting, RProperty::EInt);
       
   104     
       
   105 	//start foreground generation observer
       
   106     iForegroundGenerationObserver = CTMRPropertyObserver::NewL( *this, KTAGDPSNotification, KForceBackgroundGeneration, ETrue );  
   114     
   107     
   115     TN_DEBUG1( "CThumbAGProcessor::ConstructL() - end" );
   108     TN_DEBUG1( "CThumbAGProcessor::ConstructL() - end" );
   116     }
   109     }
   117 
   110 
   118 // ---------------------------------------------------------------------------
   111 // ---------------------------------------------------------------------------
   120 // ---------------------------------------------------------------------------
   113 // ---------------------------------------------------------------------------
   121 //
   114 //
   122 CThumbAGProcessor::~CThumbAGProcessor()
   115 CThumbAGProcessor::~CThumbAGProcessor()
   123     {
   116     {
   124     TN_DEBUG1( "CThumbAGProcessor::~CThumbAGProcessor() - begin" );
   117     TN_DEBUG1( "CThumbAGProcessor::~CThumbAGProcessor() - begin" );
       
   118     
       
   119     if(iForegroundGenerationObserver)
       
   120       {
       
   121       delete iForegroundGenerationObserver;
       
   122       iForegroundGenerationObserver = NULL;
       
   123       }
   125     
   124     
   126     if(iActivityManager)
   125     if(iActivityManager)
   127         {
   126         {
   128         delete iActivityManager;
   127         delete iActivityManager;
   129         iActivityManager = NULL;
   128         iActivityManager = NULL;
   142         delete iPeriodicTimer;
   141         delete iPeriodicTimer;
   143         }
   142         }
   144     
   143     
   145     if (!iInit)
   144     if (!iInit)
   146         {
   145         {
       
   146     /*
   147         iHarvesterClient.RemoveHarvesterEventObserver(*this);
   147         iHarvesterClient.RemoveHarvesterEventObserver(*this);
   148         iHarvesterClient.Close();
   148         iHarvesterClient.Close();*/
   149         }
   149         }
   150     
   150     
   151     if ( iCollectionUtility )
   151     if ( iCollectionUtility )
   152         {
   152         {
   153         iCollectionUtility->Close();
   153         iCollectionUtility->Close();
   174        {
   174        {
   175        iQueryAllItems->Cancel();
   175        iQueryAllItems->Cancel();
   176        delete iQueryAllItems;
   176        delete iQueryAllItems;
   177        iQueryAllItems = NULL;
   177        iQueryAllItems = NULL;
   178        }
   178        }
   179     
   179 
   180     iAddQueue.Close();
   180     iAddQueue.Close();
   181     iModifyQueue.Close();
   181     iModifyQueue.Close();
   182     iRemoveQueue.Close();
   182     iRemoveQueue.ResetAndDestroy();
   183     iQueryQueue.Close();
   183     iQueryQueue.Close();
   184     iPlaceholderQueue.Close();
   184     iPlaceholderQueue.Close();
       
   185 	  
       
   186     i2ndRoundGenerateQueue.Close();
   185     
   187     
   186     if (iTMSession)
   188     if (iTMSession)
   187         {
   189         {
   188         delete iTMSession;
   190         delete iTMSession;
   189         iTMSession = NULL;
   191         iTMSession = NULL;
   190         }
   192         }
   191     
   193     
   192     delete iFormatObserver;
   194     delete iFormatObserver;
   193     
       
   194     delete iLight;
       
   195     iLight = NULL;
       
   196     
   195     
   197     TN_DEBUG1( "CThumbAGProcessor::~CThumbAGProcessor() - end" );
   196     TN_DEBUG1( "CThumbAGProcessor::~CThumbAGProcessor() - end" );
   198     }
   197     }
   199 
   198 
   200 // -----------------------------------------------------------------------------
   199 // -----------------------------------------------------------------------------
   262                 if(!object)
   261                 if(!object)
   263                     {
   262                     {
   264                     continue;
   263                     continue;
   265                     }
   264                     }
   266                
   265                
   267                 if (iAddQueue.Find( object->Id() ) == KErrNotFound)
   266                 if (iAddQueue.Find( object->Id() ) == KErrNotFound && iModifyQueue.Find( object->Id()) == KErrNotFound  )
   268                     {
   267                     {
   269                     TRAP_IGNORE( iAddQueue.AppendL( object->Id() ));
   268                     TRAP_IGNORE( iAddQueue.AppendL( object->Id() ));
   270                     }
   269                     }
   271                 }
   270                 }
   272 #ifdef _DEBUG
   271 #ifdef _DEBUG
   278             iQueryAllItems = NULL;
   277             iQueryAllItems = NULL;
   279         }
   278         }
   280     else if(&aQuery == iQuery )
   279     else if(&aQuery == iQuery )
   281         {
   280         {
   282         TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted - Query completed");
   281         TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted - Query completed");
       
   282         
   283         if(iQueryActive)
   283         if(iQueryActive)
   284             {
   284             {
   285             iQueryReady = ETrue;
   285             iQueryReady = ETrue;
   286             iQueryActive = EFalse;
   286             iQueryActive = EFalse;
   287             }
   287             }
   288     
   288     
   289         // if no errors in query
   289         // if no errors in query
   290         if (aError == KErrNone && iQuery)
   290         if (aError == KErrNone && iQuery)
   291             {
   291             {
   292             iProcessingCount = iQuery->Count();
   292             iProcessingCount = iQuery->Count();
       
   293 			
       
   294             if( !iProcessingCount)
       
   295                 {
       
   296                 delete iQuery;
       
   297                 iQuery = NULL;
       
   298                 iProcessingCount = 0;
       
   299                 iModify = EFalse;
       
   300                 }
   293             }
   301             }
   294         else
   302         else
   295             {
   303             {
       
   304             TInt itemIndex(KErrNotFound);
       
   305             
       
   306             //cleanup current queue
       
   307             while(iQueryQueue.Count())
       
   308                 {
       
   309                 itemIndex = iLastQueue->Find(iQueryQueue[0]);
       
   310                 if(itemIndex >= 0)
       
   311                     {
       
   312                     iLastQueue->Remove( itemIndex );
       
   313                     }
       
   314                 iQueryQueue.Remove(0);
       
   315                 }
       
   316         
   296             delete iQuery;
   317             delete iQuery;
   297             iQuery = NULL;
   318             iQuery = NULL;
   298             iProcessingCount = 0;
   319             iProcessingCount = 0;
   299             TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted() Query FAILED!");   
   320             TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted() Query FAILED!");   
   300             }
   321             }
   313 // -----------------------------------------------------------------------------
   334 // -----------------------------------------------------------------------------
   314 //
   335 //
   315 void CThumbAGProcessor::ThumbnailPreviewReady( MThumbnailData& /*aThumbnail*/, 
   336 void CThumbAGProcessor::ThumbnailPreviewReady( MThumbnailData& /*aThumbnail*/, 
   316                                                TThumbnailRequestId /*aId*/)
   337                                                TThumbnailRequestId /*aId*/)
   317     {
   338     {
       
   339     TN_DEBUG1( "CThumbAGProcessor::ThumbnailPreviewReady()");
   318     // No implementation required
   340     // No implementation required
   319     }
   341     }
   320 
   342 
   321 // -----------------------------------------------------------------------------
   343 // -----------------------------------------------------------------------------
   322 // CThumbAGProcessor::ThumbnailReady()
   344 // CThumbAGProcessor::ThumbnailReady()
   324 //
   346 //
   325 void CThumbAGProcessor::ThumbnailReady( TInt aError, MThumbnailData& /*aThumbnail*/,
   347 void CThumbAGProcessor::ThumbnailReady( TInt aError, MThumbnailData& /*aThumbnail*/,
   326                                         TThumbnailRequestId /*aId*/ )
   348                                         TThumbnailRequestId /*aId*/ )
   327     {
   349     {
   328     TN_DEBUG2( "CThumbAGProcessor::ThumbnailReady() aError == %d", aError );
   350     TN_DEBUG2( "CThumbAGProcessor::ThumbnailReady() aError == %d", aError );
   329  
   351     
   330     iActive = EFalse; 
   352     iActiveCount--;
       
   353     
       
   354     if(iActiveCount <= 0)
       
   355         {
       
   356         iActiveCount = 0;
       
   357         iActive = EFalse;
       
   358         }
   331     
   359     
   332     // TNM server died, delete session
   360     // TNM server died, delete session
   333     if( aError == KErrServerTerminated )
   361     if( aError == KErrServerTerminated )
   334         {
   362         {
   335         TN_DEBUG1( "CThumbAGProcessor::ThumbnailReady() - **** THUMBNAIL SERVER DIED ****" );
   363         TN_DEBUG1( "CThumbAGProcessor::ThumbnailReady() - **** THUMBNAIL SERVER DIED ****" );
   347         
   375         
   348         return;
   376         return;
   349         }
   377         }
   350     
   378     
   351     ActivateAO();
   379     ActivateAO();
       
   380 	
   352     TN_DEBUG1( "CThumbAGProcessor::ThumbnailReady() - end" );
   381     TN_DEBUG1( "CThumbAGProcessor::ThumbnailReady() - end" );
   353     }
   382     }
   354 
   383 
   355 // ---------------------------------------------------------------------------
   384 // ---------------------------------------------------------------------------
   356 // CThumbAGProcessor::SetMdESession()
   385 // CThumbAGProcessor::SetMdESession()
   359 void CThumbAGProcessor::SetMdESession( CMdESession* aMdESession )
   388 void CThumbAGProcessor::SetMdESession( CMdESession* aMdESession )
   360     {
   389     {
   361     TN_DEBUG1( "CThumbAGProcessor::SetMdESession() - begin" );
   390     TN_DEBUG1( "CThumbAGProcessor::SetMdESession() - begin" );
   362     
   391     
   363     iMdESession = aMdESession;
   392     iMdESession = aMdESession;
       
   393     
       
   394     __ASSERT_DEBUG((iMdESession), User::Panic(_L("CThumbAGProcessor::SetMdESession() !iMdESession "), KErrBadHandle));
   364     
   395     
   365     TRAPD( err, iDefNamespace = &iMdESession->GetDefaultNamespaceDefL() );
   396     TRAPD( err, iDefNamespace = &iMdESession->GetDefaultNamespaceDefL() );
   366     if (err != KErrNone)
   397     if (err != KErrNone)
   367         {
   398         {
   368         TN_DEBUG1( "CThumbAGProcessor::SetMdESession - Error: GetDefaultNamespaceDefL leave" );
   399         TN_DEBUG2( "CThumbAGProcessor::SetMdESession() GetDefaultNamespaceDefL() err = %d", err );
   369         }
   400         }
   370     
   401     
   371     TRAP_IGNORE(QueryPlaceholdersL());
   402     __ASSERT_DEBUG((iDefNamespace), User::Panic(_L("CThumbAGProcessor::SetMdESession() !iDefNamespace "), KErrBadHandle));
   372     TRAP_IGNORE(QueryAllItemsL());
   403        
       
   404     //do async init
       
   405     iInit = ETrue;
   373     
   406     
   374 	ActivateAO();
   407 	ActivateAO();
   375     }
   408     }
   376 
   409 
   377 // ---------------------------------------------------------------------------
   410 // ---------------------------------------------------------------------------
   378 // CThumbAGProcessor::AddToQueue()
   411 // CThumbAGProcessor::AddToQueue()
   379 // ---------------------------------------------------------------------------
   412 // ---------------------------------------------------------------------------
   380 //
   413 //
   381 void CThumbAGProcessor::AddToQueueL( TObserverNotificationType aType, 
   414 void CThumbAGProcessor::AddToQueueL( TObserverNotificationType aType, 
   382                                     const RArray<TItemId>& aIDArray, TBool /*aPresent*/ )
   415                                     const RArray<TItemId>& aIDArray, 
       
   416                                     const RPointerArray<HBufC>& aObjectUriArray,
       
   417                                     TBool /*aPresent*/ )
   383     {
   418     {
   384     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - begin" );
   419     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - begin" );
   385 
   420 
   386     // update queues
   421     // update queues
   387     if (aType == ENotifyAdd)
   422     if (aType == ENotifyAdd)
   388         {
   423         {
   389         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyAdd" );
   424         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyAdd" );
   390         
   425         
   391         for (int i=0; i<aIDArray.Count(); i++)
   426         for (int i=0; i<aIDArray.Count(); i++)
   392             {
   427             {
   393             // only add to Add queue if not already in Add queue        
   428             // do not to append to Add queue if exist already in Add or 2nd Add queue (just processed)     
   394             if (iAddQueue.Find( aIDArray[i] ) == KErrNotFound)
   429             if (iAddQueue.Find( aIDArray[i] ) == KErrNotFound && i2ndRoundGenerateQueue.Find( aIDArray[i] ) == KErrNotFound)
   395                 {
   430                 {
   396                 iAddQueue.AppendL(aIDArray[i]); 
   431                 iAddQueue.AppendL(aIDArray[i]);
   397                 }
   432                 }
   398             }
   433             }
   399         }
   434         }
   400     else if (aType == ENotifyModify)
   435     else if (aType == ENotifyModify)
   401         {
   436         {
   402         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyModify" );
   437         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyModify" );
   403         
   438         
   404         if(iPHHarvesting)
   439         if(iPHHarvesting)
   405             {
   440             {
       
   441         
   406             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - PH  harvesting active, treat like add" );
   442             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - PH  harvesting active, treat like add" );
   407             for (int i=0; i<aIDArray.Count(); i++)
   443             for (int i=0; i<aIDArray.Count(); i++)
   408                 {
   444                 {
   409                 // only add to Add queue if not already in Add queue        
       
   410                 if (iAddQueue.Find( aIDArray[i] ) == KErrNotFound)
       
   411                     {
       
   412                     iAddQueue.AppendL(aIDArray[i]); 
       
   413                     }
       
   414                 
       
   415                 TInt itemIndex = iPlaceholderQueue.Find( aIDArray[i] );
   445                 TInt itemIndex = iPlaceholderQueue.Find( aIDArray[i] );
   416                                 
   446                                 
   417                 if (itemIndex >= 0)
   447                 if (itemIndex >= 0)
   418                     {
   448                     {
   419                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - remove from placeholder queue");
   449                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - remove from placeholder queue");
   420                     iPlaceholderQueue.Remove( itemIndex );
   450                     iPlaceholderQueue.Remove( itemIndex );
   421                     }
   451                     }
       
   452                 
       
   453                 if(iAddQueue.Find( aIDArray[i]) == KErrNotFound && i2ndRoundGenerateQueue.Find( aIDArray[i]))
       
   454                     {
       
   455                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - append to add queue");
       
   456                     iAddQueue.Append( aIDArray[i]);
       
   457                     }
   422                 }
   458                 }
   423             }
   459             }
   424         else
   460         else
   425             {
   461             {
   426             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - PH  harvesting finished, check is real modify!" );
   462             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - PH  harvesting finished, check is real modify!" );
   433                 
   469                 
   434                 if (itemIndex >= 0)
   470                 if (itemIndex >= 0)
   435                     {
   471                     {
   436                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - placeholder modify, remove from placeholder queue");
   472                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - placeholder modify, remove from placeholder queue");
   437                     iPlaceholderQueue.Remove( itemIndex );
   473                     iPlaceholderQueue.Remove( itemIndex );
   438                     iAddQueue.Append( aIDArray[i] );
       
   439                     }
   474                     }
   440                 else
   475                 else
   441                     {
   476                     {
   442                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - real modify");
   477                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - real modify");
   443                     itemIndex = iAddQueue.Find( aIDArray[i] );
   478                     itemIndex = iAddQueue.Find( aIDArray[i] );
   445                     if (itemIndex >= 0)
   480                     if (itemIndex >= 0)
   446                         {
   481                         {
   447                         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - remove from add queue");
   482                         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - remove from add queue");
   448                         iAddQueue.Remove( itemIndex );
   483                         iAddQueue.Remove( itemIndex );
   449                         }
   484                         }
       
   485 					else
       
   486 						{
       
   487 						
       
   488 						itemIndex = i2ndRoundGenerateQueue.Find( aIDArray[i] );
       
   489                                     
       
   490 	                    if (itemIndex >= 0)
       
   491 	                        {
       
   492 	                        TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - remove from 2nd round add queue");
       
   493 	                        i2ndRoundGenerateQueue.Remove( itemIndex );
       
   494 	                        }
       
   495 					}
   450                     
   496                     
   451                     if( iPlaceholderQueue.Find( aIDArray[i] ) == KErrNotFound )
   497                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - append to modify queue");
   452                         {
   498                     iModifyQueue.AppendL(aIDArray[i]);
   453                         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - append to modify queue");
       
   454                         iModifyQueue.AppendL(aIDArray[i]);
       
   455                         }
       
   456                     
   499                     
   457                     SetForceRun( ETrue );
   500                     SetForceRun( ETrue );
   458                     } 
   501                     } 
   459                 }
   502                 }
   460             }
   503             }
   461         }
   504         }
   462         else if (aType == ENotifyRemove)
   505         else if (aType == ENotifyRemove)
   463             {
   506             {
   464             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyRemove, remove IDs from all queues, append to Delete" );
   507             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyRemove, remove IDs from all queues");
   465             
   508             
   466             for (int i=0; i<aIDArray.Count(); i++)
   509             for (int i=0; i<aIDArray.Count(); i++)
   467                 {
   510                 {
   468                 // can be removed from Add queue
   511                 // can be removed from Add queue
   469                 TInt itemIndex = iAddQueue.Find( aIDArray[i] );
   512                 TInt itemIndex = iAddQueue.Find( aIDArray[i] );
   476                 itemIndex = iModifyQueue.Find( aIDArray[i] );
   519                 itemIndex = iModifyQueue.Find( aIDArray[i] );
   477                 if(itemIndex >= 0)
   520                 if(itemIndex >= 0)
   478                     {
   521                     {
   479                     iModifyQueue.Remove(itemIndex);
   522                     iModifyQueue.Remove(itemIndex);
   480                     }
   523                     }
   481                 
   524                 }
   482                 //add to remove queue
   525             
   483                 if (iRemoveQueue.Find( aIDArray[i] ) == KErrNotFound)
   526             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyRemove append URIs to remove queue");
   484                     {
   527             for (int i=0; i<aObjectUriArray.Count(); i++)
   485                     iRemoveQueue.AppendL(aIDArray[i]);
   528                 {
   486                     }
   529                 HBufC* temp = aObjectUriArray[i]->AllocL();
       
   530                 iRemoveQueue.Append( temp );
       
   531                 TN_DEBUG2( "CThumbAGProcessor::AddToQueueL() - %S", temp); 
   487                 }
   532                 }
   488             }
   533             }
   489 #ifdef _DEBUG
   534 #ifdef _DEBUG
   490         else
   535         else
   491             {
   536             {
   492 	        TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() -  should not come here" );
   537 	        TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() -  should not come here" );
   493             __ASSERT_DEBUG((EFalse), User::Panic(_L("CThumbAGProcessor::AddToQueueL()"), -2));
   538 	        User::Leave( KErrArgument );
   494 			return;
       
   495             }
   539             }
   496 #endif
   540 #endif
   497     
   541     
   498     ActivateAO(); 
   542     ActivateAO(); 
   499     
   543     
   505 // ---------------------------------------------------------------------------
   549 // ---------------------------------------------------------------------------
   506 //
   550 //
   507 void CThumbAGProcessor::CreateThumbnailsL( const CMdEObject* aObject )
   551 void CThumbAGProcessor::CreateThumbnailsL( const CMdEObject* aObject )
   508     {
   552     {
   509     TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() - begin" );
   553     TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() - begin" );
       
   554     
       
   555     __ASSERT_DEBUG((iTMSession), User::Panic(_L("CThumbAGProcessor::CreateThumbnailsL() !iTMSession "), KErrBadHandle));
       
   556     __ASSERT_DEBUG((iDefNamespace), User::Panic(_L("CThumbAGProcessor::CreateThumbnailsL() !iDefNamespace "), KErrBadHandle));
       
   557     
       
   558     if(!iTMSession || !iDefNamespace)
       
   559         {
       
   560         return;
       
   561         }
   510     
   562     
   511     TInt orientationVal = 0;
   563     TInt orientationVal = 0;
   512     TInt64 modifiedVal = 0;
   564     TInt64 modifiedVal = 0;
   513     
   565     
   514     CMdEProperty* orientation = NULL;
   566     CMdEProperty* orientation = NULL;
   515     CMdEObjectDef& objDef = iDefNamespace->GetObjectDefL( MdeConstants::Image::KImageObject );       
   567     CMdEObjectDef& imageObjectDef = iDefNamespace->GetObjectDefL( MdeConstants::Image::KImageObject );       
   516     TInt orientErr = aObject->Property( objDef.GetPropertyDefL( MdeConstants::Image::KOrientationProperty ), orientation, 0 );
   568     TInt orientErr = aObject->Property( imageObjectDef.GetPropertyDefL( MdeConstants::Image::KOrientationProperty ), orientation, 0 );
   517     
   569     
   518     if (orientErr == KErrNone)
   570     if (orientErr == KErrNone)
   519         {
   571         {
   520         orientationVal = orientation->Uint16ValueL();
   572         orientationVal = orientation->Uint16ValueL();
   521         }
   573         }
   522         
   574         
   523     CMdEProperty* modified = NULL;
   575     CMdEProperty* modified = NULL;
   524     CMdEObjectDef& objDef2 = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject );       
   576     CMdEObjectDef& baseObjDef = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject );       
   525     TInt modifyErr = aObject->Property( objDef2.GetPropertyDefL( MdeConstants::Object::KLastModifiedDateProperty ), modified, 0 );
   577     TInt modifyErr = aObject->Property( baseObjDef.GetPropertyDefL( MdeConstants::Object::KLastModifiedDateProperty ), modified, 0 );
   526     
   578 
   527     if (modifyErr >= 0)
   579     if (modifyErr >= 0)
   528         {
   580         {
   529         modifiedVal = modified->TimeValueL().Int64();
   581         modifiedVal = modified->TimeValueL().Int64();
   530         }
   582         }
   531     
   583     
   532     // modify existing thumbs
   584     // update thumbs
   533     if (iTMSession)
   585     if (iTMSession)
   534         {
   586         {
       
   587 		// 2nd round and modify updates both sizes if needed
       
   588         if( i2ndRound )
       
   589             {
       
   590             //generate both if needed
       
   591             TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() EOptimizeForQuality ");
       
   592             iTMSession->SetQualityPreferenceL( CThumbnailManager::EOptimizeForQuality );
       
   593             }
       
   594 		// 1st roung generation
       
   595         else
       
   596             {
       
   597             //1st round
       
   598             TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() EOptimizeForQualityWithPreview");
       
   599             iTMSession->SetQualityPreferenceL( CThumbnailManager::EOptimizeForQualityWithPreview );
       
   600             
       
   601             CMdEObjectDef& videoObjectDef = iDefNamespace->GetObjectDefL( MdeConstants::Video::KVideoObject );
       
   602             
       
   603             // add item to 2nd round queue 
       
   604             if(iLastQueue == &iAddQueue || iLastQueue == &iModifyQueue)
       
   605                 {
       
   606                 TN_DEBUG2( "CThumbAGProcessor::CreateThumbnailsL() - 1st round add/modify, append to 2nd round queue", aObject->Id() );
       
   607                 if(i2ndRoundGenerateQueue.Find(aObject->Id()) == KErrNotFound)
       
   608                     {
       
   609                     i2ndRoundGenerateQueue.Append( aObject->Id() );
       
   610                     }
       
   611                 }
       
   612             
       
   613            if( !(imageObjectDef.Id() == aObject->Def().Id() || videoObjectDef.Id() == aObject->Def().Id()) )
       
   614                 {
       
   615                 TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() 1st round and not image or video, skip");
       
   616                 ActivateAO();
       
   617                 return;
       
   618                 }
       
   619             }
       
   620 
   535         // run as lower priority than getting but higher that creating thumbnails
   621         // run as lower priority than getting but higher that creating thumbnails
   536         TRAPD(err, iTMSession->UpdateThumbnailsL(aObject->Id(), aObject->Uri(), orientationVal, modifiedVal, CActive::EPriorityIdle ));
   622         TRAPD(err, iTMSession->UpdateThumbnailsL(KNoId, aObject->Uri(), orientationVal, modifiedVal, CActive::EPriorityIdle ));
   537         
   623       
   538         if ( err != KErrNone )
   624         if ( err != KErrNone )
   539             {
   625             {
   540             TN_DEBUG2( "CThumbAGProcessor::UpdateThumbnailsL, iTMSession error == %d", err );
   626             TN_DEBUG2( "CThumbAGProcessor::CreateThumbnailsL, iTMSession error == %d", err );
   541             
   627             
   542             iSessionDied = ETrue;
   628             iSessionDied = ETrue;
   543             iActive = EFalse;
   629             iActive = EFalse;
   544             ActivateAO();
   630             ActivateAO();
   545             } 
   631             } 
   546         else
   632         else
   547             {
   633             {
       
   634             iActiveCount++;
   548             iActive = ETrue;
   635             iActive = ETrue;
   549             }
   636             }
   550         }
   637         }
   551     else
   638     else
   552         {
   639         {
   553         ActivateAO();
   640         ActivateAO();
   554         }
   641         }
   555         
   642         
   556 #ifdef _DEBUG
       
   557     if(iModify)
       
   558         {
       
   559         iModCounter++;
       
   560         }
       
   561     else
       
   562         {
       
   563         iAddCounter++;
       
   564         }
       
   565 #endif     
       
   566         
       
   567 #ifdef _DEBUG
       
   568     TN_DEBUG3( "CThumbAGProcessor::OUT-COUNTERS----------, Add = %d Modify = %d", 
       
   569                iAddCounter, iModCounter );
       
   570 #endif
       
   571    
       
   572     TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() - end" );
   643     TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() - end" );
   573     }
   644     }
   574 
   645 
   575 // ---------------------------------------------------------------------------
   646 // ---------------------------------------------------------------------------
   576 // CThumbAGProcessor::QueryL()
   647 // CThumbAGProcessor::QueryL()
   577 // ---------------------------------------------------------------------------
   648 // ---------------------------------------------------------------------------
   578 //
   649 //
   579 void CThumbAGProcessor::QueryL( RArray<TItemId>& aIDArray )
   650 void CThumbAGProcessor::QueryL( RArray<TItemId>& aIDArray )
   580     {
   651     {
   581     TN_DEBUG1( "CThumbAGProcessor::QueryL() - begin" );
   652     TN_DEBUG1( "CThumbAGProcessor::QueryL() - begin" );
       
   653     
       
   654     __ASSERT_DEBUG((iMdESession), User::Panic(_L("CThumbAGProcessor::QueryL() !iMdeSession "), KErrBadHandle));
       
   655     __ASSERT_DEBUG((iDefNamespace), User::Panic(_L("CThumbAGProcessor::QueryL() !iDefNamespace "), KErrBadHandle));
       
   656     
       
   657     if(!iMdESession  || !iDefNamespace)
       
   658         {
       
   659         return;
       
   660         }
       
   661     
       
   662 	//reset query queue
       
   663     iQueryQueue.Reset();
       
   664 	//set reference to current pprocessing queue
       
   665     iLastQueue = &aIDArray;
   582     
   666     
   583     iQueryReady = EFalse;
   667     iQueryReady = EFalse;
   584 
   668 
   585     // delete old query
   669     // delete old query
   586     if (iQuery)
   670     if (iQuery)
   594         
   678         
   595     TN_DEBUG3( "CThumbAGProcessor::QueryL() - fill begin aIDArray == %d, iQueryQueue == %d", aIDArray.Count(), iQueryQueue.Count() );
   679     TN_DEBUG3( "CThumbAGProcessor::QueryL() - fill begin aIDArray == %d, iQueryQueue == %d", aIDArray.Count(), iQueryQueue.Count() );
   596     
   680     
   597     for(TInt i=0;i < KMaxQueryItems && i < maxCount; i++)
   681     for(TInt i=0;i < KMaxQueryItems && i < maxCount; i++)
   598         {
   682         {
   599         TN_DEBUG2( "CThumbAGProcessor::QueryL() - fill %d", aIDArray[0] );
   683         TN_DEBUG2( "CThumbAGProcessor::QueryL() - fill %d", aIDArray[i] );
   600         iQueryQueue.Append( aIDArray[0] );
   684         iQueryQueue.Append( aIDArray[i] );
   601         aIDArray.Remove( 0 );
       
   602         }
   685         }
   603     
   686     
   604     TN_DEBUG3( "CThumbAGProcessor::QueryL() - fill end aIDArray == %d, iQueryQueue == %d", aIDArray.Count(), iQueryQueue.Count() );
   687     TN_DEBUG3( "CThumbAGProcessor::QueryL() - fill end aIDArray == %d, iQueryQueue == %d", aIDArray.Count(), iQueryQueue.Count() );
   605     
   688     
   606     CMdEObjectDef& objDef = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject );
   689     CMdEObjectDef& objDef = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject );
   637             }    
   720             }    
   638         }
   721         }
   639     
   722     
   640     iQuery->FindL();
   723     iQuery->FindL();
   641     
   724     
   642     iQueryQueue.Reset();
       
   643     
       
   644     TN_DEBUG1( "CThumbAGProcessor::QueryL() - end" );
   725     TN_DEBUG1( "CThumbAGProcessor::QueryL() - end" );
   645     }
   726     }
   646 
   727 
   647 
   728 
   648 // ---------------------------------------------------------------------------
   729 // ---------------------------------------------------------------------------
   652 
   733 
   653 void CThumbAGProcessor::QueryPlaceholdersL()
   734 void CThumbAGProcessor::QueryPlaceholdersL()
   654     {
   735     {
   655     TN_DEBUG1( "CThumbAGProcessor::QueryPlaceholdersL" );
   736     TN_DEBUG1( "CThumbAGProcessor::QueryPlaceholdersL" );
   656     
   737     
   657     CMdEObjectQuery::TState state(CMdEObjectQuery::EStateFirst);
   738     __ASSERT_DEBUG((iMdESession), User::Panic(_L("CThumbAGProcessor::QueryPlaceholdersL() !iMdeSession "), KErrBadHandle));
       
   739     __ASSERT_DEBUG((iDefNamespace), User::Panic(_L("CThumbAGProcessor::QueryPlaceholdersL() !iDefNamespace "), KErrBadHandle));
       
   740     
       
   741     if(!iMdESession  || !iDefNamespace)
       
   742          {
       
   743          return;
       
   744          }
   658     
   745     
   659     if( iQueryPlaceholders )
   746     if( iQueryPlaceholders )
   660         {
   747         {
   661         state = iQueryPlaceholders->State();
   748         if( !iQueryPlaceholders->IsComplete() )
   662     
       
   663         if(state == CMdEObjectQuery::EStateSearching )
       
   664             {
   749             {
   665             TN_DEBUG1( "CThumbAGProcessor::QueryPlaceholdersL active- skip" );
   750             TN_DEBUG1( "CThumbAGProcessor::QueryPlaceholdersL active- skip" );
   666             return;
   751             return;
   667             }
   752             }
   668         
   753         
   712     {
   797     {
   713     TN_DEBUG1( "CThumbAGProcessor::RunL() - begin" );
   798     TN_DEBUG1( "CThumbAGProcessor::RunL() - begin" );
   714     
   799     
   715     if (iSessionDied)
   800     if (iSessionDied)
   716         {
   801         {
       
   802         TN_DEBUG1( "CThumbAGProcessor::RunL() - iSessionDied" );
   717         delete iTMSession;
   803         delete iTMSession;
   718         iTMSession = NULL;
   804         iTMSession = NULL;
   719         }
   805         }
   720     
   806     
   721     if (iInit)
   807     if (iInit)
   722         {
   808         {
   723         TN_DEBUG1( "CThumbAGProcessor::RunL() - Do Initialisation" );
   809         TN_DEBUG1( "CThumbAGProcessor::RunL() - Do Initialisation 1" );
       
   810         
   724         iInit = EFalse;
   811         iInit = EFalse;
   725         TN_DEBUG1( "iHarvesterClient");
   812         iInit2 = ETrue;
   726         if( iHarvesterClient.Connect() == KErrNone )
   813 
   727             {
   814         iAddQueue.Reset();
   728             TN_DEBUG1( "iHarvesterClient connected");
   815         iModifyQueue.Reset();
   729             iHarvesterClient.AddHarvesterEventObserver( *this, EHEObserverTypeOverall, KMaxTInt );
   816         iRemoveQueue.ResetAndDestroy();
   730             iHarvesterClient.AddHarvesterEventObserver( *this, EHEObserverTypePlaceholder, KMaxTInt );
   817         iQueryQueue.Reset();
   731             iHarvesterClient.AddHarvesterEventObserver( *this, EHEObserverTypeMMC, KMaxTInt );
   818         iPlaceholderQueue.Reset();
   732             TN_DEBUG1( "iHarvesterClient AddHarvesterEventObserver added");
   819         
   733             }
   820         TRAP_IGNORE(QueryPlaceholdersL());
   734         
   821         TN_DEBUG1( "CThumbAGProcessor::RunL() - Initialisation 1 done" );
   735         TN_DEBUG1( "create MMPXCollectionUtility");
   822         ActivateAO();
   736         iCollectionUtility = MMPXCollectionUtility::NewL( this, KMcModeIsolated );
   823         return;
   737         TN_DEBUG1( "CThumbAGProcessor::RunL() - Initialisation done" );
   824         }
   738         
   825     
   739         iActivityManager->Start();
   826     if(iInit2)
   740         
   827         {
       
   828         TN_DEBUG1( "CThumbAGProcessor::RunL() - Do Initialisation 2" );
       
   829 		
       
   830         iInit2 = EFalse;
       
   831         TInt err(KErrNone);
       
   832         /*
       
   833         TN_DEBUG1( "CThumbAGProcessor::RunL() do iHarvesterClient connect");
       
   834         TInt err = iHarvesterClient.Connect();
       
   835         TN_DEBUG2( "CThumbAGProcessor::RunL() iHarvesterClient connect err = %d", err);
       
   836         
       
   837         __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGProcessor::RunL(), !iHarvesterClient "), err));
       
   838         
       
   839         if(  err == KErrNone )
       
   840             {
       
   841             TN_DEBUG1( "CThumbAGProcessor::RunL() add iHarvesterClient observer");
       
   842             err = iHarvesterClient.AddHarvesterEventObserver( *this, EHEObserverTypeOverall | EHEObserverTypePlaceholder, KMaxTInt );
       
   843             TN_DEBUG2( "CThumbAGProcessor::RunL() iHarvesterClient observer err = %d", err);
       
   844             __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGProcessor::RunL(), !iHarvesterClient "), err));
       
   845             }*/
       
   846  
       
   847         TN_DEBUG1( "CThumbAGProcessor::RunL() MMPXCollectionUtility");
       
   848         TRAP( err, iCollectionUtility = MMPXCollectionUtility::NewL( this, KMcModeIsolated ));
       
   849         TN_DEBUG2( "CThumbAGProcessor::RunL() create MMPXCollectionUtility err = %d", err);
       
   850         __ASSERT_DEBUG((iCollectionUtility), User::Panic(_L("CThumbAGProcessor::RunL(), !iCollectionUtility "), err));
       
   851         
       
   852         __ASSERT_DEBUG((iActivityManager), User::Panic(_L("CThumbAGProcessor::RunL(), !iActivityManager "), KErrBadHandle));
       
   853         if(iActivityManager)
       
   854             {
       
   855             iActivityManager->Start();
       
   856             }
       
   857         
       
   858         TRAP_IGNORE(QueryAllItemsL());
       
   859 		
       
   860         TN_DEBUG1( "CThumbAGProcessor::RunL() - Initialisation 2 done" );
   741         return;
   861         return;
   742         }
   862         }
   743     
   863     
   744     // restart session if died
   864     // restart session if died
   745     if (!iTMSession)
   865     if (!iTMSession)
   761         }    
   881         }    
   762    
   882    
   763     // do not run if request is already issued to TNM server even if forced
   883     // do not run if request is already issued to TNM server even if forced
   764     if( iActive)
   884     if( iActive)
   765         {
   885         {
   766         if(iActiveCount <= KMaxDaemonRequests)
   886         if(iActiveCount >= KMaxDaemonRequests)
   767             {
   887             {
   768             iActiveCount++;
       
   769             TN_DEBUG1( "CThumbAGProcessor::RunL() - waiting for previous to complete, abort..." );
   888             TN_DEBUG1( "CThumbAGProcessor::RunL() - waiting for previous to complete, abort..." );
   770             return;
   889             return;
   771             }
   890             }
   772         else
       
   773             {
       
   774             TN_DEBUG1( "CThumbAGProcessor::RunL() - iActive jammed - resetted" );
       
   775             iActive = EFalse;
       
   776             iActiveCount = 0;
       
   777             }     
       
   778         }
   891         }
   779     else
   892     else
   780         {
   893         {
   781         iActiveCount = 0;   
   894         iActiveCount = 0;   
   782         }
   895         }
   783     
   896     
       
   897     
   784     //force run can proceed from this point
   898     //force run can proceed from this point
   785 	if( iForceRun )
   899 #ifdef _DEBUG
       
   900 	if( iForegroundRun )
       
   901 		{
       
   902       	TN_DEBUG1( "void CThumbAGProcessor::RunL() KForceBackgroundGeneration enabled");
       
   903 	  	}
       
   904 	
       
   905     if( iForceRun )
       
   906         {
       
   907         TN_DEBUG1( "CThumbAGProcessor::RunL() - *** FORCED RUN ***");
       
   908         }
       
   909 #endif
       
   910 	
       
   911   	if( /*iForceRun || */iForegroundRun )
       
   912       	{
       
   913         TN_DEBUG1( "void CThumbAGProcessor::RunL() skip idle detection!");
       
   914       	CancelTimeout();
       
   915      	 }
       
   916   	else
   786 	    {
   917 	    {
   787 	    CancelTimeout();
   918         if(iActivityManager)
   788 	    TN_DEBUG1( "void CThumbAGProcessor::RunL() forced run, continue!");
   919             {
   789 	    }
   920             iIdle = iActivityManager->IsInactive();
   790 	else
   921             }
   791 	    {
   922 	    
   792 	    if( !iLights)
       
   793 	        {
       
   794             iIdle = ETrue;
       
   795             }
       
   796         else
       
   797             {
       
   798             iIdle = IsInactive();
       
   799             }
       
   800         
       
   801         if( !iIdle || iHarvesting || iMPXHarvesting || iPeriodicTimer->IsActive() )
   923         if( !iIdle || iHarvesting || iMPXHarvesting || iPeriodicTimer->IsActive() )
   802             {
   924             {
   803             #ifdef _DEBUG
       
   804             TN_DEBUG5( "iIdle = %d, iHarvesting = %d, iMPXHarvesting = %d, iPeriodicTimer->IsActive() = %d", 
       
   805                     iIdle, iHarvesting, iMPXHarvesting, iPeriodicTimer->IsActive());
       
   806             #endif
       
   807             TN_DEBUG1( "void CThumbAGProcessor::RunL() device not idle");
   925             TN_DEBUG1( "void CThumbAGProcessor::RunL() device not idle");
   808             return;
   926             return;
   809             }
   927             }
   810         else
   928         else
   811             {
   929             {
   830     //Handle completed MDS Query
   948     //Handle completed MDS Query
   831     if( iQueryReady && iProcessingCount)
   949     if( iQueryReady && iProcessingCount)
   832         {
   950         {
   833         TInt err(KErrNone);
   951         TInt err(KErrNone);
   834         //if force or non forced
   952         //if force or non forced
   835         if((iForceRun && iModify) || (!iForceRun && !iModify))
   953         if((iForceRun && iModify ) || (!iForceRun && !iModify ))
   836             {
   954             {
   837             TN_DEBUG1( "CThumbAGProcessor::RunL() - iQueryReady START" );
   955             TN_DEBUG1( "CThumbAGProcessor::RunL() - iQueryReady START" );
   838             
   956             
   839             const CMdEObject* object = &iQuery->Result( iProcessingCount-1 );
   957             const CMdEObject* object = &iQuery->Result( iProcessingCount-1 );
   840             iProcessingCount--;
   958             iProcessingCount--;
   841         
   959             
       
   960             TInt itemIndex = iLastQueue->Find( object->Id());
       
   961             if(itemIndex >= 0)
       
   962                 {
       
   963                 iLastQueue->Remove(itemIndex);
       
   964                 }
       
   965 				
   842             // process one item at once
   966             // process one item at once
   843             if ( object )
   967             if ( object )
   844                 {
   968                 {
       
   969                 //remove item from queryQueue when request is issued 
       
   970                 itemIndex = iQueryQueue.Find( object->Id());
       
   971                 if(itemIndex >= 0)
       
   972                     {
       
   973                     iQueryQueue.Remove(itemIndex);
       
   974                     }
       
   975             
   845                 TRAP( err, CreateThumbnailsL(object) );
   976                 TRAP( err, CreateThumbnailsL(object) );
   846             
   977                 TN_DEBUG2( "CThumbAGProcessor::RunL(), CreateThumbnailsL error == %d", err );
   847                 if ( err != KErrNone )
   978                 __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGProcessor::RunL(), CreateThumbnailsL() "), err));
   848                     { 
       
   849                     TN_DEBUG2( "CThumbAGProcessor::RunL(), CreateThumbnailsL error == %d", err );
       
   850                     }
       
   851                 }
   979                 }
   852             }
   980             }
   853         //force is coming, but executing non-forced query complete-> cancel old
   981         //force is coming, but executing non-forced query complete-> cancel old
   854         else
   982         else
   855             {
   983             {
   856             TN_DEBUG1( "CThumbAGProcessor::RunL() - deleting query" );
   984             TN_DEBUG1( "CThumbAGProcessor::RunL() - deleting query 1" );
   857             delete iQuery;
   985             delete iQuery;
   858             iQuery = NULL;
   986             iQuery = NULL;
   859             iQueryReady = EFalse;
   987             iQueryReady = EFalse;
   860             iProcessingCount = 0;
   988             iProcessingCount = 0;
       
   989             
       
   990             //move remainig IDs in query queue back to original queue
       
   991             while(iQueryQueue.Count())
       
   992                 {
       
   993                 if(iLastQueue)
       
   994                     {
       
   995                     if(iLastQueue->Find( iQueryQueue[0]) == KErrNotFound)
       
   996                         {
       
   997                         iLastQueue->Append(iQueryQueue[0]);
       
   998                         }
       
   999                     }
       
  1000                 iQueryQueue.Remove(0);
       
  1001                 }
       
  1002             iLastQueue = NULL;
   861             ActivateAO();
  1003             ActivateAO();
   862             return;    
  1004             return;    
   863             }
  1005             }
   864         
  1006         
   865         //is last query item
  1007         //is last query item
   871             iModify = EFalse;
  1013             iModify = EFalse;
   872             
  1014             
   873             //check if forced run needs to continue
  1015             //check if forced run needs to continue
   874             if (iModifyQueue.Count())
  1016             if (iModifyQueue.Count())
   875                 {
  1017                 {
   876                 iForceRun = ETrue;
  1018                 SetForceRun( ETrue );
   877                 }
  1019                 }
   878             else
  1020             else
   879                 {
  1021                 {
   880                 iForceRun = EFalse;
  1022                 SetForceRun( EFalse );
   881                 }   
  1023                 }   
   882             }
  1024             }
   883         //keep going if processing Remove items or if Add item fails
  1025         //keep going if processing Remove items or if Add item fails
   884         else if( iModify || err )
  1026         else if( iModify || err )
   885             {
  1027             {
   889     //waiting for MDS query to complete
  1031     //waiting for MDS query to complete
   890     else if( iQueryActive )
  1032     else if( iQueryActive )
   891         {
  1033         {
   892         if(iForceRun && !iModify)
  1034         if(iForceRun && !iModify)
   893             {
  1035             {
   894             iQuery->Cancel();
  1036             if(iQuery)
   895             delete iQuery;
  1037                 {
   896             iQuery = NULL;
  1038                 TN_DEBUG1( "CThumbAGProcessor::RunL() - deleting query 2" );
   897             TN_DEBUG1( "CThumbAGProcessor::RunL() - canceling query..." );
  1039                 iQuery->Cancel();
       
  1040                 delete iQuery;
       
  1041                 iQuery = NULL;
       
  1042                 }
       
  1043 
   898             iQueryReady = EFalse;
  1044             iQueryReady = EFalse;
   899             iQueryActive = EFalse;
  1045             iQueryActive = EFalse;
       
  1046             
       
  1047             //move remainig IDs in query queue back to original queue
       
  1048             while(iQueryQueue.Count())
       
  1049                 {
       
  1050                 if(iLastQueue)
       
  1051                     {
       
  1052                     if(iLastQueue->Find( iQueryQueue[0]) == KErrNotFound)
       
  1053                         {
       
  1054                         iLastQueue->Append(iQueryQueue[0]);
       
  1055                         }
       
  1056                     }
       
  1057                 iQueryQueue.Remove(0);
       
  1058                 }
       
  1059             iLastQueue = NULL;
       
  1060             
   900             ActivateAO();
  1061             ActivateAO();
   901             }
  1062             }
   902         else  
  1063         else  
   903             {
  1064             {
   904             TN_DEBUG1( "CThumbAGProcessor::RunL() - waiting for query to complete, abort..." );
  1065             TN_DEBUG1( "CThumbAGProcessor::RunL() - waiting for query to complete, abort..." );
   905             }    
  1066             }    
   906         }
  1067         }
   907 
  1068 
   908     // select queue to process, priority by type. Process modify events before new images
  1069     // no items in query queue, start new
       
  1070     // select queue to process, priority by type
   909     else if ( iModifyQueue.Count() > 0 )
  1071     else if ( iModifyQueue.Count() > 0 )
   910         {
  1072         {
   911         TN_DEBUG1( "void CThumbAGProcessor::RunL() update thumbnails");
  1073         TN_DEBUG1( "void CThumbAGProcessor::RunL() update thumbnails");
       
  1074         
       
  1075         i2ndRound = EFalse;
   912         
  1076         
   913         // query for object info
  1077         // query for object info
   914         iQueryActive = ETrue;
  1078         iQueryActive = ETrue;
   915         iModify = ETrue;
  1079         iModify = ETrue;
   916         QueryL( iModifyQueue );
  1080         QueryL( iModifyQueue );
   917        }
  1081        }
   918     else if ( iRemoveQueue.Count() > 0 )
       
   919         {
       
   920         TN_DEBUG1( "void CThumbAGProcessor::RunL() delete thumbnails");
       
   921         
       
   922         // delete thumbs by ID
       
   923         if (iTMSession)
       
   924             {
       
   925             iTMSession->DeleteThumbnails( iRemoveQueue[0] );
       
   926             }
       
   927         iRemoveQueue.Remove( 0 );
       
   928             
       
   929 #ifdef _DEBUG
       
   930         iDelCounter++;
       
   931         TN_DEBUG2( "CThumbAGProcessor::OUT-COUNTERS----------, Delete = %d", iDelCounter );
       
   932 #endif
       
   933         ActivateAO();
       
   934         }
       
   935     else if ( iAddQueue.Count() > 0 )
  1082     else if ( iAddQueue.Count() > 0 )
   936         {
  1083         {
   937         TN_DEBUG1( "void CThumbAGProcessor::RunL() create thumbnails");
  1084         TN_DEBUG1( "void CThumbAGProcessor::RunL() update 1st round thumbnails");
       
  1085         
       
  1086         i2ndRound = EFalse;
   938         
  1087         
   939         // query for object info
  1088         // query for object info
   940         iQueryActive = ETrue;
  1089         iQueryActive = ETrue;
   941         
  1090         
   942         QueryL( iAddQueue );     
  1091         QueryL( iAddQueue );     
       
  1092         }
       
  1093     else if ( iRemoveQueue.Count() > 0 )
       
  1094         {
       
  1095         TN_DEBUG1( "void CThumbAGProcessor::RunL() delete thumbnails");
       
  1096 
       
  1097         i2ndRound = EFalse;
       
  1098         
       
  1099         // delete thumbs by URI
       
  1100         __ASSERT_DEBUG((iTMSession), User::Panic(_L("CThumbAGProcessor::RunL() !iTMSession "), KErrBadHandle));
       
  1101         if(iTMSession)
       
  1102             {
       
  1103             HBufC* uri = iRemoveQueue[0];
       
  1104             TN_DEBUG2( "void CThumbAGProcessor::RunL() delete %S",  uri);
       
  1105             CThumbnailObjectSource* source = NULL;
       
  1106             TRAPD(err,  source = CThumbnailObjectSource::NewL( *uri, KNullDesC));
       
  1107                
       
  1108         	if(err == KErrNone)
       
  1109             	{
       
  1110                 iTMSession->DeleteThumbnails( *source );
       
  1111                 }
       
  1112             iRemoveQueue.Remove( 0 );
       
  1113             delete source;
       
  1114             delete uri;
       
  1115             }
       
  1116             
       
  1117         ActivateAO();
       
  1118         }
       
  1119     else if( i2ndRoundGenerateQueue.Count() > 0)
       
  1120         {
       
  1121         TN_DEBUG1( "void CThumbAGProcessor::RunL() update 2nd round thumbnails");
       
  1122             
       
  1123         // query for object info
       
  1124         iQueryActive = ETrue;
       
  1125         i2ndRound = ETrue;
       
  1126         QueryL( i2ndRoundGenerateQueue );     
   943         }
  1127         }
   944         
  1128         
   945     TN_DEBUG1( "CThumbAGProcessor::RunL() - end" );
  1129     TN_DEBUG1( "CThumbAGProcessor::RunL() - end" );
   946     }
  1130     }
   947 
  1131 
   968         }
  1152         }
   969     else if( aHEObserverType == EHEObserverTypeOverall)
  1153     else if( aHEObserverType == EHEObserverTypeOverall)
   970         {
  1154         {
   971         TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- type EHEObserverTypeOverall");
  1155         TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- type EHEObserverTypeOverall");
   972         }
  1156         }
   973     else
       
   974         {
       
   975         TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- type EHEObserverTypeMMC");
       
   976         }
       
   977     #endif
  1157     #endif
   978     
  1158     
   979     //placeholder harvesting
  1159     //placeholder harvesting
   980     if( aHEObserverType == EHEObserverTypePlaceholder)
  1160     if( aHEObserverType == EHEObserverTypePlaceholder)
   981         {
  1161         {
  1048                 // continue processing if needed
  1228                 // continue processing if needed
  1049                 StartTimeout();
  1229                 StartTimeout();
  1050                 }
  1230                 }
  1051             }
  1231             }
  1052         }
  1232         }
  1053     else if( aHEObserverType == EHEObserverTypeMMC)
  1233    
  1054         {
       
  1055         switch(aHarvesterEventState)
       
  1056             {
       
  1057             case EHEStateStarted:
       
  1058             case EHEStateHarvesting:
       
  1059             case EHEStateResumed:
       
  1060                 TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MMC harvesting started ");
       
  1061                 break;
       
  1062             case EHEStateFinished:
       
  1063                 TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MMC harvesting finished ");
       
  1064                 TRAP_IGNORE(QueryAllItemsL());
       
  1065             break;
       
  1066             };
       
  1067         }
       
  1068 
       
  1069     TN_DEBUG3( "CThumbAGProcessor::HarvestingUpdated -- end() iHarvesting == %d, iPHHarvesting == %d ", iHarvesting, iPHHarvesting);
  1234     TN_DEBUG3( "CThumbAGProcessor::HarvestingUpdated -- end() iHarvesting == %d, iPHHarvesting == %d ", iHarvesting, iPHHarvesting);
  1070     }
  1235     }
  1071 
  1236 
  1072 // ---------------------------------------------------------------------------
  1237 // ---------------------------------------------------------------------------
  1073 // CThumbAGProcessor::StartTimeout()
  1238 // CThumbAGProcessor::StartTimeout()
  1099 
  1264 
  1100 // ---------------------------------------------------------------------------
  1265 // ---------------------------------------------------------------------------
  1101 // CThumbAGProcessor::RunError()
  1266 // CThumbAGProcessor::RunError()
  1102 // ---------------------------------------------------------------------------
  1267 // ---------------------------------------------------------------------------
  1103 //
  1268 //
       
  1269 #ifdef _DEBUG
  1104 TInt CThumbAGProcessor::RunError(TInt aError)
  1270 TInt CThumbAGProcessor::RunError(TInt aError)
  1105     {
  1271 #else
  1106     TN_DEBUG1( "CThumbAGProcessor::RunError()");
  1272 TInt CThumbAGProcessor::RunError(TInt /*aError*/)
  1107     if (aError != KErrNone)
  1273 #endif
  1108         {
  1274     {
  1109         TN_DEBUG2( "CThumbAGProcessor::RunError = %d", aError );
  1275     TN_DEBUG2( "CThumbAGrocessor::RunError() %d", aError);
  1110         }
  1276     
  1111     
  1277     UpdatePSValues();
  1112     iActive = EFalse;
  1278         
  1113     
  1279     iActiveCount--;
       
  1280     
       
  1281     if(iActiveCount <= 0)
       
  1282         {
       
  1283         iActiveCount = 0;
       
  1284         iActive = EFalse;
       
  1285         }
       
  1286     
       
  1287 	ActivateAO();
       
  1288 	
  1114     // nothing to do
  1289     // nothing to do
  1115     return KErrNone;
  1290     return KErrNone;
  1116     }
  1291     }
  1117 
  1292 
  1118 // ---------------------------------------------------------------------------
  1293 // ---------------------------------------------------------------------------
  1120 // ---------------------------------------------------------------------------
  1295 // ---------------------------------------------------------------------------
  1121 //
  1296 //
  1122 void CThumbAGProcessor::ActivateAO()
  1297 void CThumbAGProcessor::ActivateAO()
  1123     {
  1298     {
  1124 #ifdef _DEBUG
  1299 #ifdef _DEBUG
  1125     TN_DEBUG6( "CThumbAGProcessor::Items in queue Add = %d, Mod = %d, Del = %d, Query = %d, iPlaceholder = %d", iAddQueue.Count(),  iModifyQueue.Count(), iRemoveQueue.Count(), iQueryQueue.Count(), iPlaceholderQueue.Count());
  1300     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());
       
  1301     TN_DEBUG2( "CThumbAGProcessor::ActivateAO() items in queue 2nd Add = %d", i2ndRoundGenerateQueue.Count());
       
  1302     TN_DEBUG3( "CThumbAGProcessor::ActivateAO() iActive = %d, iActiveCount = %d", iActive, iActiveCount);
       
  1303     TN_DEBUG3( "CThumbAGProcessor::ActivateAO() iHarvesting == %d, iMPXHarvesting == %d", iHarvesting, iMPXHarvesting);
       
  1304     TN_DEBUG4( "CThumbAGProcessor::ActivateAO() iIdle = %d, timer = %d, iForceRun = %d", iIdle, iPeriodicTimer->IsActive(), iForceRun);
       
  1305     TN_DEBUG4( "CThumbAGProcessor::ActivateAO() iModify = %d, iQueryReady = %d, iProcessingCount = %d", iModify, iQueryReady, iProcessingCount);
  1126 #endif
  1306 #endif
  1127     
  1307     
  1128     if(iFormatting)
  1308     if(iFormatting)
  1129         {
  1309         {
  1130         TN_DEBUG1( "CThumbAGProcessor::ActivateAO() - FORMATTING - DAEMON ON PAUSE");
  1310         TN_DEBUG1( "CThumbAGProcessor::ActivateAO() - FORMATTING - DAEMON ON PAUSE");
  1131         return;
  1311         return;
  1132         }
  1312         }
  1133         
  1313         
  1134     if( !IsActive() )
  1314     if( !IsActive() )
  1135         {
  1315         {
  1136 #ifdef _DEBUG
       
  1137         if( iForceRun )
       
  1138             {
       
  1139             TN_DEBUG1( "CThumbAGProcessor::ActivateAO() - *** FORCED RUN ***");
       
  1140             }
       
  1141 #endif
       
  1142         SetActive();
  1316         SetActive();
  1143         TRequestStatus* statusPtr = &iStatus;
  1317         TRequestStatus* statusPtr = &iStatus;
  1144         User::RequestComplete( statusPtr, KErrNone );
  1318         User::RequestComplete( statusPtr, KErrNone );
  1145         }
  1319         }
       
  1320 
       
  1321     UpdatePSValues();
  1146     }
  1322     }
  1147 
  1323 
  1148 // ---------------------------------------------------------------------------
  1324 // ---------------------------------------------------------------------------
  1149 // CThumbAGProcessor::PeriodicTimerCallBack()
  1325 // CThumbAGProcessor::PeriodicTimerCallBack()
  1150 // ---------------------------------------------------------------------------
  1326 // ---------------------------------------------------------------------------
  1221 
  1397 
  1222 // ---------------------------------------------------------------------------
  1398 // ---------------------------------------------------------------------------
  1223 // CThumbAGProcessor::RemoveFromQueues()
  1399 // CThumbAGProcessor::RemoveFromQueues()
  1224 // ---------------------------------------------------------------------------
  1400 // ---------------------------------------------------------------------------
  1225 //
  1401 //
       
  1402 #ifdef _DEBUG
  1226 void CThumbAGProcessor::RemoveFromQueues( const RArray<TItemId>& aIDArray, const TBool aRemoveFromDelete )
  1403 void CThumbAGProcessor::RemoveFromQueues( const RArray<TItemId>& aIDArray, const TBool aRemoveFromDelete )
       
  1404 #else
       
  1405 void CThumbAGProcessor::RemoveFromQueues( const RArray<TItemId>& aIDArray, const TBool /*aRemoveFromDelete*/ )
       
  1406 #endif
  1227     {
  1407     {
  1228     TN_DEBUG2( "CThumbAGProcessor::RemoveFromQueues() aRemoveFromDelete == %d - begin", aRemoveFromDelete );
  1408     TN_DEBUG2( "CThumbAGProcessor::RemoveFromQueues() aRemoveFromDelete == %d - begin", aRemoveFromDelete );
  1229     
  1409     
  1230     TInt itemIndex = KErrNotFound;
  1410     TInt itemIndex = KErrNotFound;
  1231     
  1411     
  1232     for (int i=0; i< aIDArray.Count(); i++)
  1412     for (int i=0; i< aIDArray.Count(); i++)
  1233         {
  1413         {
  1234         TN_DEBUG2( "CThumbAGProcessor::RemoveFromQueues() - %d", aIDArray[i]);
  1414         TN_DEBUG2( "CThumbAGProcessor::RemoveFromQueues() - %d", aIDArray[i]);
  1235         
  1415 
  1236         itemIndex = iPlaceholderQueue.Find( aIDArray[i] );
  1416         itemIndex = iPlaceholderQueue.Find( aIDArray[i] );
  1237                          
  1417                          
  1238         if(itemIndex >= 0)
  1418         if(itemIndex >= 0)
  1239             {
  1419             {
  1240             iPlaceholderQueue.Remove(itemIndex);
  1420             iPlaceholderQueue.Remove(itemIndex);
  1245         
  1425         
  1246         if(itemIndex >= 0)
  1426         if(itemIndex >= 0)
  1247             {
  1427             {
  1248             iAddQueue.Remove(itemIndex);
  1428             iAddQueue.Remove(itemIndex);
  1249             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iAddQueue" );
  1429             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iAddQueue" );
  1250             continue;
  1430             }
       
  1431 
       
  1432         itemIndex = i2ndRoundGenerateQueue.Find( aIDArray[i] );
       
  1433                 
       
  1434         if(itemIndex >= 0)
       
  1435             {
       
  1436             i2ndRoundGenerateQueue.Remove(itemIndex);
       
  1437             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - i2ndRoundGenerateQueue" );
  1251             }
  1438             }
  1252         
  1439         
  1253         itemIndex = iModifyQueue.Find( aIDArray[i] );
  1440         itemIndex = iModifyQueue.Find( aIDArray[i] );
  1254          
  1441          
  1255         if(itemIndex >= 0)
  1442         if(itemIndex >= 0)
  1257             iModifyQueue.Remove(itemIndex);
  1444             iModifyQueue.Remove(itemIndex);
  1258             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iModifyQueue" );
  1445             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iModifyQueue" );
  1259 			 
  1446 			 
  1260             if( iModifyQueue.Count() == 0)
  1447             if( iModifyQueue.Count() == 0)
  1261 			    {
  1448 			    {
  1262 			    iForceRun = EFalse;
  1449 			    SetForceRun( EFalse );
  1263 		        }
  1450 		        }
  1264 			 
  1451 			 
  1265             continue;
  1452             continue;
  1266             }
  1453             }
  1267     
  1454     
  1268         if( aRemoveFromDelete )
  1455         /*if( aRemoveFromDelete )
  1269             {
  1456             {
  1270             itemIndex = iRemoveQueue.Find( aIDArray[i] );
  1457             itemIndex = iRemoveQueue.Find( aIDArray[i] );
  1271              
  1458              
  1272             if(itemIndex >= 0)
  1459             if(itemIndex >= 0)
  1273                 {
  1460                 {
  1274                 iRemoveQueue.Remove(itemIndex);
  1461                 iRemoveQueue.Remove(itemIndex);
  1275                 TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iRemoveQueue" );
  1462                 TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iRemoveQueue" );
  1276                 continue;
  1463                 continue;
  1277                 }
  1464                 }
  1278             }
  1465             }*/
  1279         }
  1466         }
  1280     
  1467     
  1281     TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - end" );
  1468     TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - end" );
  1282     }
  1469     }
  1283 	
  1470 	
  1302 //
  1489 //
  1303 void CThumbAGProcessor::QueryAllItemsL()
  1490 void CThumbAGProcessor::QueryAllItemsL()
  1304     {
  1491     {
  1305     TN_DEBUG1( "CThumbAGProcessor::QueryAllItemsL" );
  1492     TN_DEBUG1( "CThumbAGProcessor::QueryAllItemsL" );
  1306     
  1493     
  1307     CMdEObjectQuery::TState state(CMdEObjectQuery::EStateFirst);
  1494     __ASSERT_DEBUG((iMdESession), User::Panic(_L("CThumbAGProcessor::QueryAllItemsL() !iMdeSession "), KErrBadHandle));
       
  1495     
       
  1496     if(!iMdESession)
       
  1497          {
       
  1498          return;
       
  1499          }
  1308     
  1500     
  1309     if( iQueryAllItems )
  1501     if( iQueryAllItems )
  1310         {
  1502         {
  1311         state = iQueryAllItems->State();
  1503         if( !iQueryAllItems->IsComplete() )
  1312     
       
  1313         if(state == CMdEObjectQuery::EStateSearching )
       
  1314             {
  1504             {
  1315             TN_DEBUG1( "CThumbAGProcessor::QueryAllItemsL active- skip" );
  1505             TN_DEBUG1( "CThumbAGProcessor::QueryAllItemsL active- skip" );
  1316             return;
  1506             return;
  1317             }
  1507             }
  1318         
  1508         
  1390                     StartTimeout();
  1580                     StartTimeout();
  1391                     break;
  1581                     break;
  1392                 default:
  1582                 default:
  1393                     break;
  1583                     break;
  1394                 }
  1584                 }
       
  1585             
       
  1586             //signal Server's stores about MPX harvesting state
       
  1587             if( iMPXHarvesting )
       
  1588                 {
       
  1589                 RProperty::Set(KTAGDPSNotification, KMPXHarvesting, ETrue);
       
  1590                 }
       
  1591             else
       
  1592                 {
       
  1593                 RProperty::Set(KTAGDPSNotification, KMPXHarvesting, EFalse);
       
  1594                 }
       
  1595                 
  1395             TN_DEBUG3( "CThumbAGProcessor::HandleCollectionMessage -- end() iHarvesting == %d, iMPXHarvesting == %d", iHarvesting, iMPXHarvesting);
  1596             TN_DEBUG3( "CThumbAGProcessor::HandleCollectionMessage -- end() iHarvesting == %d, iMPXHarvesting == %d", iHarvesting, iMPXHarvesting);
  1396             }
  1597             }
  1397         }
  1598         }
  1398     }
  1599     }
  1399 
  1600 
  1428 void CThumbAGProcessor::HandleCollectionMediaL( const CMPXMedia& /*aMedia*/,
  1629 void CThumbAGProcessor::HandleCollectionMediaL( const CMPXMedia& /*aMedia*/,
  1429                                                        TInt /*aError*/ )
  1630                                                        TInt /*aError*/ )
  1430     {
  1631     {
  1431     // not needed here
  1632     // not needed here
  1432     }
  1633     }
  1433 	
  1634 
  1434 // -----------------------------------------------------------------------------
  1635 // -----------------------------------------------------------------------------
  1435 // LightStatusChanged()
  1636 // ActivityChanged()
  1436 // -----------------------------------------------------------------------------
  1637 // -----------------------------------------------------------------------------
  1437 //
  1638 //
  1438 void CThumbAGProcessor::LightStatusChanged(TInt aTarget, CHWRMLight::TLightStatus aStatus)
  1639 void CThumbAGProcessor::ActivityChanged(const TBool aActive)
  1439     {
  1640     {
  1440     TN_DEBUG3( "void CThumbAGProcessor::LightStatusChanged() aTarget == %d, aStatus == %d", aTarget, aStatus);
  1641     TN_DEBUG2( "void CThumbAGProcessor::ActivityChanged() aActive == %d", aActive);
  1441     
  1642     if(aActive)
  1442      if( aStatus == CHWRMLight::ELightOff)
  1643         {
  1443         {
  1644         iIdle = EFalse;
  1444         TN_DEBUG1( "void CThumbAGProcessor::LightStatusChanged() -- OFF");
  1645         }
  1445         iLights = EFalse;
  1646     else
  1446 		
  1647         {
  1447         if(iAddQueue.Count() + iModifyQueue.Count() + iRemoveQueue.Count() > 0 )
  1648         iIdle = ETrue; 
       
  1649         
       
  1650         if(iAddQueue.Count() + iModifyQueue.Count() + iRemoveQueue.Count() + i2ndRoundGenerateQueue.Count() > 0 )
  1448             {
  1651             {
  1449             ActivateAO();
  1652             ActivateAO();
  1450             }
  1653             }
  1451         }
  1654         }
  1452     else
  1655     }
  1453         {
  1656 
  1454         TN_DEBUG1( "void CThumbAGProcessor::LightStatusChanged() -- ON");
       
  1455         iLights = ETrue;
       
  1456         }
       
  1457     }
       
  1458 
       
  1459 // -----------------------------------------------------------------------------
       
  1460 // IsInactive()
       
  1461 // -----------------------------------------------------------------------------
       
  1462 //
       
  1463 TBool CThumbAGProcessor::IsInactive()
       
  1464     {
       
  1465 #ifdef _DEBUG
       
  1466 TN_DEBUG2( "CThumbAGProcessor::IsInactive()= %d", User::InactivityTime().Int());
       
  1467 #endif
       
  1468 
       
  1469     if( User::InactivityTime() < TTimeIntervalSeconds(KBackgroundGenerationIdle) )
       
  1470       {
       
  1471       return EFalse;
       
  1472       }
       
  1473     return ETrue;
       
  1474     }
       
  1475 
       
  1476 // -----------------------------------------------------------------------------
       
  1477 // ActivityDetected()
       
  1478 // -----------------------------------------------------------------------------
       
  1479 //
       
  1480 void CThumbAGProcessor::ActivityDetected()
       
  1481     {
       
  1482     iIdle = EFalse;
       
  1483     }
       
  1484 
       
  1485 // -----------------------------------------------------------------------------
       
  1486 // InactivityDetected()
       
  1487 // -----------------------------------------------------------------------------
       
  1488 //
       
  1489 void CThumbAGProcessor::InactivityDetected()
       
  1490     {
       
  1491     iIdle = ETrue; 
       
  1492     
       
  1493     if(iAddQueue.Count() + iModifyQueue.Count() + iRemoveQueue.Count() > 0 )
       
  1494         {
       
  1495         ActivateAO();
       
  1496         }
       
  1497     }
       
  1498 
  1657 
  1499 // ---------------------------------------------------------------------------
  1658 // ---------------------------------------------------------------------------
  1500 // CThumbAGProcessor::FormatNotification
  1659 // CThumbAGProcessor::FormatNotification
  1501 // Handles a format operation
  1660 // Handles a format operation
  1502 // ---------------------------------------------------------------------------
  1661 // ---------------------------------------------------------------------------
  1510         {
  1669         {
  1511         ActivateAO();
  1670         ActivateAO();
  1512         }
  1671         }
  1513     }
  1672     }
  1514 
  1673 
       
  1674 // ---------------------------------------------------------------------------
       
  1675 // CThumbAGProcessor::RPropertyNotification
       
  1676 // Handles a RProperty changed operation
       
  1677 // ---------------------------------------------------------------------------
       
  1678 //
       
  1679 void CThumbAGProcessor::RPropertyNotification(const TInt aError, const TUid aKeyCategory, const TUint aPropertyKey, const TInt aValue)
       
  1680     {
       
  1681     TN_DEBUG5( "CThumbAGProcessor::RPropertyNotification() aError = %d, aPropertyKey = %d, aKeyCategory = %d, aValue = %d", aError, aPropertyKey, aKeyCategory, aValue );
       
  1682     
       
  1683     if(aPropertyKey == KForceBackgroundGeneration && aKeyCategory == KTAGDPSNotification )
       
  1684         {
       
  1685         if( aValue == 1 && aError == KErrNone )
       
  1686             {
       
  1687             iForegroundRun = ETrue;
       
  1688             ActivateAO();
       
  1689             }
       
  1690         else
       
  1691             {
       
  1692             iForegroundRun = EFalse;
       
  1693             }
       
  1694         }
       
  1695     }
       
  1696 
       
  1697 // ---------------------------------------------------------------------------
       
  1698 // CThumbAGProcessor::UpdateItemsLeft
       
  1699 // Update KItemsleft PS value if changed
       
  1700 // ---------------------------------------------------------------------------
       
  1701 //
       
  1702 void CThumbAGProcessor::UpdatePSValues(const TBool aDefine)
       
  1703     {
       
  1704     TInt itemsLeft = iModifyQueue.Count() + iAddQueue.Count();
       
  1705     TBool daemonProcessing = EFalse;
       
  1706     
       
  1707     if(itemsLeft + i2ndRoundGenerateQueue.Count() + iRemoveQueue.Count() > 0 )
       
  1708         {
       
  1709         daemonProcessing = ETrue;
       
  1710         }
       
  1711     
       
  1712     if(aDefine)
       
  1713         {
       
  1714         TN_DEBUG1( "CThumbAGProcessor::UpdatePSValues() define");
       
  1715         RProperty::Define(KTAGDPSNotification, KDaemonProcessing, RProperty::EInt);
       
  1716         RProperty::Set(KTAGDPSNotification, KDaemonProcessing, 0);
       
  1717         daemonProcessing = EFalse;
       
  1718         RProperty::Define(KTAGDPSNotification, KItemsleft, RProperty::EInt);
       
  1719         RProperty::Set(KTAGDPSNotification, KItemsleft, 0);
       
  1720         iPreviousItemsLeft = 0;
       
  1721         }
       
  1722     
       
  1723     if( daemonProcessing != iPreviousDaemonProcessing)
       
  1724         {
       
  1725         TN_DEBUG2( "CThumbAGProcessor::UpdatePSValues() update KDaemonProcessing == %d", daemonProcessing);
       
  1726         iPreviousDaemonProcessing = daemonProcessing;
       
  1727         RProperty::Set(KTAGDPSNotification, KDaemonProcessing, daemonProcessing);
       
  1728         }
       
  1729     
       
  1730     if( itemsLeft != iPreviousItemsLeft)
       
  1731         {
       
  1732         TN_DEBUG2( "CThumbAGProcessor::UpdatePSValues() update KItemsleft == %d", itemsLeft);
       
  1733         iPreviousItemsLeft = itemsLeft;
       
  1734         RProperty::Set(KTAGDPSNotification, KItemsleft, itemsLeft );
       
  1735         }
       
  1736     }
  1515 
  1737 
  1516 // End of file
  1738 // End of file