imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagprocessor.cpp
branchRCL_3
changeset 37 f759b6186ab5
parent 28 ff2fb7658ff7
child 38 2b4b06654caa
equal deleted inserted replaced
28:ff2fb7658ff7 37:f759b6186ab5
    48 
    48 
    49 // ---------------------------------------------------------------------------
    49 // ---------------------------------------------------------------------------
    50 // CThumbAGProcessor::CThumbAGProcessor()
    50 // CThumbAGProcessor::CThumbAGProcessor()
    51 // ---------------------------------------------------------------------------
    51 // ---------------------------------------------------------------------------
    52 //
    52 //
    53 CThumbAGProcessor::CThumbAGProcessor(): CActive( CActive::EPriorityStandard )
    53 CThumbAGProcessor::CThumbAGProcessor(): CActive( CActive::EPriorityStandard ), iMMCHarvestingItemsLeftTemp(0), 
       
    54         iPHHarvestingItemsLeftTemp(0)
    54     {
    55     {
    55     TN_DEBUG1( "CThumbAGProcessor::CThumbAGProcessor() - begin" );
    56     TN_DEBUG1( "CThumbAGProcessor::CThumbAGProcessor() - begin" );
    56     
    57     
    57     CActiveScheduler::Add( this );
    58     CActiveScheduler::Add( this );
    58     }
    59     }
    80     iActiveCount = 0;
    81     iActiveCount = 0;
    81     
    82     
    82     // set auto create values from cenrep
    83     // set auto create values from cenrep
    83     CheckAutoCreateValuesL();
    84     CheckAutoCreateValuesL();
    84     
    85     
    85     iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityIdle);
    86     iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityStandard);
       
    87     
       
    88     iMountTimer = CPeriodic::NewL(CActive::EPriorityUserInput);
    86     
    89     
    87     SetForceRun( EFalse );    
    90     SetForceRun( EFalse );    
    88     iActive = EFalse;
       
    89     
    91     
    90     iFormatObserver = CTMFormatObserver::NewL( *this );
    92     iFormatObserver = CTMFormatObserver::NewL( *this );
    91        
    93        
    92     iFormatting = EFalse;     
    94     iFormatting = EFalse;     
    93     iSessionDied = EFalse;
    95     iSessionDied = EFalse;
    94     
    96     
    95     iCollectionUtility = NULL;
    97     iCollectionUtility = NULL;
    96     
    98     
    97     iActivityManager = CTMActivityManager::NewL( this, KBackgroundGenerationIdle);
    99     iActivityManager = CTMActivityManager::NewL( this, KBackgroundGenerationIdle);
    98 
   100 
    99     UpdatePSValues(ETrue);
   101     UpdatePSValues(ETrue, ETrue);
   100     
   102     
   101     RProperty::Define(KTAGDPSNotification, KMPXHarvesting, RProperty::EInt);
   103     RProperty::Define(KTAGDPSNotification, KMPXHarvesting, RProperty::EInt);
   102     
   104     
   103 	//start foreground generation observer
   105 	//start foreground generation observer
   104     iForegroundGenerationObserver = CTMRPropertyObserver::NewL( *this, KTAGDPSNotification, KForceBackgroundGeneration, ETrue );  
   106     iForegroundGenerationObserver = CTMRPropertyObserver::NewL( *this, KTAGDPSNotification, KForceBackgroundGeneration, ETrue );  
   115     TN_DEBUG1( "CThumbAGProcessor::~CThumbAGProcessor() - begin" );
   117     TN_DEBUG1( "CThumbAGProcessor::~CThumbAGProcessor() - begin" );
   116     
   118     
   117     Shutdown();
   119     Shutdown();
   118     
   120     
   119     Cancel();
   121     Cancel();
       
   122     
       
   123     if (iTMSession)
       
   124         {
       
   125         iTMSession->RemoveRequestObserver();
       
   126         delete iTMSession;
       
   127         iTMSession = NULL;
       
   128         }
       
   129     
       
   130     if(iMountTimer)
       
   131         {
       
   132         iMountTimer->Cancel();
       
   133         delete iMountTimer;
       
   134         iMountTimer = NULL;
       
   135         }
   120     
   136     
   121     if(iPeriodicTimer)
   137     if(iPeriodicTimer)
   122         {
   138         {
   123         iPeriodicTimer->Cancel();
   139         iPeriodicTimer->Cancel();
   124         delete iPeriodicTimer;
   140         delete iPeriodicTimer;
   175     if ( iCollectionUtility )
   191     if ( iCollectionUtility )
   176         {
   192         {
   177         iCollectionUtility->Close();
   193         iCollectionUtility->Close();
   178         iCollectionUtility = NULL;
   194         iCollectionUtility = NULL;
   179         }
   195         }
   180 
   196     
   181     iAddQueue.Close();
   197     for(TInt i=0;i<iGenerationQueue.Count();i++)
   182     iModifyQueue.Close();
   198         {
   183     iRemoveQueue.ResetAndDestroy();
   199         delete iGenerationQueue[i].iUri;
       
   200         iGenerationQueue[i].iUri = NULL;
       
   201         }
       
   202     
       
   203     iGenerationQueue.Reset();
       
   204     iGenerationQueue.Close();
       
   205     
   184     iQueryQueue.Close();
   206     iQueryQueue.Close();
   185     iPlaceholderQueue.Close();
       
   186 	  
       
   187     i2ndRoundGenerateQueue.Close();
       
   188     
       
   189     if (iTMSession)
       
   190         {
       
   191         iTMSession->RemoveRequestObserver();
       
   192         delete iTMSession;
       
   193         iTMSession = NULL;
       
   194         }
       
   195     
   207     
   196     TN_DEBUG1( "CThumbAGProcessor::~CThumbAGProcessor() - end" );
   208     TN_DEBUG1( "CThumbAGProcessor::~CThumbAGProcessor() - end" );
   197     }
   209     }
   198 
   210 
   199 // ---------------------------------------------------------------------------
   211 // ---------------------------------------------------------------------------
   202 //
   214 //
   203 void CThumbAGProcessor::Shutdown()
   215 void CThumbAGProcessor::Shutdown()
   204     {
   216     {
   205     TN_DEBUG1( "CThumbAGProcessor::Shutdown()" );
   217     TN_DEBUG1( "CThumbAGProcessor::Shutdown()" );
   206     iShutdown = ETrue;
   218     iShutdown = ETrue;
   207     UpdatePSValues();
   219     UpdatePSValues(EFalse, EFalse);
   208     }
   220     }
   209 
   221 
   210 // -----------------------------------------------------------------------------
   222 // -----------------------------------------------------------------------------
   211 // CThumbAGProcessor::HandleQueryNewResults()
   223 // CThumbAGProcessor::HandleQueryNewResults()
   212 // -----------------------------------------------------------------------------
   224 // -----------------------------------------------------------------------------
   242                     TN_DEBUG2( "CThumbAGProcessor::HandleQueryNewResults %d not placeholder", object->Id());
   254                     TN_DEBUG2( "CThumbAGProcessor::HandleQueryNewResults %d not placeholder", object->Id());
   243                     continue;
   255                     continue;
   244                     }
   256                     }
   245                
   257                
   246                 // ignore if fails
   258                 // ignore if fails
   247                 iPlaceholderQueue.InsertInOrder(object->Id(), Compare);               
   259                 TThumbnailGenerationItem item;
       
   260                 item.iItemId = object->Id();
       
   261                 item.iPlaceholder = ETrue;
       
   262                 
       
   263                 SetGenerationItemType( item, object->Def().Id());
       
   264                 
       
   265                 AppendProcessingQueue( item );
   248                 }  
   266                 }  
   249             }
   267             }
   250         else if(&aQuery == iQueryAllItems)
   268         else if(&aQuery == iQueryAllItems)
   251             {
   269             {
   252             TN_DEBUG2( "CThumbAGProcessor::HandleQueryNewResults - QueryAllItems, %d new", aNewItemCount);
   270             TN_DEBUG2( "CThumbAGProcessor::HandleQueryNewResults - QueryAllItems, %d new", aNewItemCount);
   253     
   271             
   254             for(TInt i = aFirstNewItemIndex; i < iQueryAllItems->Count(); i++)
   272             for(TInt i = aFirstNewItemIndex; i < iQueryAllItems->Count(); i++)
   255                 {    
   273                 {    
   256                 const CMdEObject* object = &iQueryAllItems->Result(i);
   274                 const CMdEObject* object = &iQueryAllItems->Result(i);
   257                
   275                
   258                 if(!object)
   276                 if(!object)
   259                     {
   277                     {
   260                     continue;
   278                     continue;
   261                     }
   279                     }
   262                
   280 
   263                 if (iAddQueue.FindInOrder(object->Id(), Compare) == KErrNotFound && 
   281                 TThumbnailGenerationItem item;
   264                     iModifyQueue.FindInOrder(object->Id(), Compare) == KErrNotFound )
   282                 item.iItemId = object->Id();
   265                     {
   283                 
   266                     // ignore if fails
   284                 SetGenerationItemType(item, object->Def().Id());
   267                     iAddQueue.InsertInOrder(object->Id(), Compare);
   285                 
   268                     }
   286                 TInt itemIndex = iGenerationQueue.FindInOrder(item, Compare);
       
   287                 
       
   288                 item.iPlaceholder = object->Placeholder(); 
       
   289                 
       
   290                 AppendProcessingQueue( item );
   269                 }
   291                 }
   270             }    
   292             }    
   271         }
   293         }
   272     else
   294     else
   273         {
   295         {
   289         }
   311         }
   290     
   312     
   291     if(&aQuery == iQueryPlaceholders)
   313     if(&aQuery == iQueryPlaceholders)
   292         {
   314         {
   293         TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted - iQueryPlaceholders completed");
   315         TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted - iQueryPlaceholders completed");
   294         
       
   295         iPlaceholderQueue.Reset();
       
   296         
   316         
   297         //free query
   317         //free query
   298         delete iQueryPlaceholders;
   318         delete iQueryPlaceholders;
   299         iQueryPlaceholders = NULL;
   319         iQueryPlaceholders = NULL;
   300        
   320        
   329         // if no errors in query
   349         // if no errors in query
   330         if (aError == KErrNone && iQuery)
   350         if (aError == KErrNone && iQuery)
   331             {
   351             {
   332             iProcessingCount = iQuery->Count();
   352             iProcessingCount = iQuery->Count();
   333 			
   353 			
   334             if(iProcessingCount != iQueryQueue.Count())
   354             if(iProcessingCount != iQueryQueue.Count() )
   335                 {
   355                 {
   336                 TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted() some result items missing");
   356                 TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted() some result items missing");
   337                 
   357                 
   338                 RArray<TItemId> queryQueueDelta;
   358                 RArray<TItemId> queryQueueDelta;
   339                 
   359                 
   340                 TInt itemIndex(KErrNotFound);
   360                     //search delta items which were queried, but not found
   341                 
   361                      for(TInt queryItem =0; queryItem < iQueryQueue.Count();queryItem++)
   342                 //search delta items which were queried, but not found
   362                          {
   343                  for(TInt queryItem =0; queryItem < iQueryQueue.Count();queryItem++)
   363                          TBool found(EFalse);
   344                      {
   364                          for(TInt queryResult = 0; queryResult < iQuery->Count(); queryResult++)
   345                      TBool found(EFalse);
   365                             {    
   346                      for(TInt queryResult = 0; queryResult < iQuery->Count(); queryResult++)
   366                             const CMdEObject* object = &iQuery->Result(queryResult);
   347                         {    
   367                             
   348                         const CMdEObject* object = &iQuery->Result(queryResult);
   368                             if( iQueryQueue[queryItem] == object->Id())
   349                         
   369                                 {
   350                         if( iQueryQueue[queryItem] == object->Id())
   370                                 found = ETrue;
       
   371                                 break;
       
   372                                 }
       
   373                             }
       
   374                              
       
   375                          if(!found)
       
   376                              {
       
   377                              TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted() %d missing from query results", iQueryQueue[queryItem] );
       
   378                              
       
   379                              // ignore if fails
       
   380                              queryQueueDelta.InsertInOrder(iQueryQueue[queryItem], CompareId);
       
   381                              }
       
   382                          }
       
   383                      
       
   384                      TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted() missing items found %d", queryQueueDelta.Count()); 
       
   385                      //cleanup from previous queue it item is not found from MDS
       
   386                      while(queryQueueDelta.Count())
       
   387                          {
       
   388                          TThumbnailGenerationItem item;
       
   389                          item.iItemId = queryQueueDelta[0];
       
   390                          TInt itemIndex = iQueryQueue.FindInOrder(item.iItemId, CompareId);
       
   391                          
       
   392                          if(itemIndex >= 0)
       
   393                              {
       
   394                              TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted() remove %d from iQueryQueue", queryQueueDelta[0]);
       
   395                              iQueryQueue.Remove( itemIndex );
       
   396                              
       
   397                              //remove from procesing queue
       
   398                              itemIndex = iGenerationQueue.FindInOrder(item, Compare);
       
   399                              
       
   400                              if(itemIndex >= 0)
       
   401                                  {
       
   402                                  
       
   403                                  if( iUnknown )
       
   404                                      {
       
   405                                      TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted() mark %d as EGenerationItemTypeNotFound in iGenerationQueue", queryQueueDelta[0]);
       
   406                                      //mark to be removed, cleanup is done below
       
   407                                      iGenerationQueue[itemIndex].iItemType = EGenerationItemTypeNotFound;
       
   408                                      }
       
   409                                  else
       
   410                                      {
       
   411                                      TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted() remove %d from iGenerationQueue", queryQueueDelta[0]);
       
   412                                      iGenerationQueue.Remove( itemIndex );
       
   413                                      }
       
   414                                  }
       
   415                              }
       
   416                          queryQueueDelta.Remove(0);
       
   417                          }
       
   418                      queryQueueDelta.Close();
       
   419                     }
       
   420 
       
   421                 if(iUnknown)
       
   422                     {
       
   423                     for(TInt i = 0; i < iQuery->Count(); i++)
       
   424                       {    
       
   425                       const CMdEObject* object = &iQuery->Result(i);
       
   426                      
       
   427                       if(!object)
       
   428                           {
       
   429                           continue;
       
   430                           }
       
   431 
       
   432                           TThumbnailGenerationItem tempItem;
       
   433                           tempItem.iItemId = object->Id();
       
   434                           TInt itemIndex = iGenerationQueue.FindInOrder(tempItem, Compare);
       
   435                                            
       
   436                         if(itemIndex >= 0)
   351                             {
   437                             {
   352                             found = ETrue;
   438                             TThumbnailGenerationItem& item = iGenerationQueue[itemIndex]; 
   353                             break;
   439                             
       
   440                             if(iGenerationQueue[itemIndex].iItemType == EGenerationItemTypeNotFound)
       
   441                                 {
       
   442                                 TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted() remove EGenerationItemTypeNotFound %d item from iGenerationQueue", item.iItemId);
       
   443                                 iGenerationQueue.Remove(itemIndex);
       
   444                                 continue;
       
   445                                 }
       
   446                             
       
   447                                 SetGenerationItemType(item, object->Def().Id());
       
   448                                     
       
   449                                 if(item.iItemType == EGenerationItemTypeUnknown )
       
   450                                   {
       
   451                                   TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted() remove unknown item %d", item.iItemId);
       
   452                                   iGenerationQueue.Remove(itemIndex);
       
   453                                   continue;
       
   454                                   }
       
   455                               
       
   456                               item.iPlaceholder = object->Placeholder(); 
       
   457                                       
   354                             }
   458                             }
   355                         }
   459                         }
   356                          
   460                 
   357                      if(!found)
   461                         iQueryQueue.Reset();
   358                          {
   462                         iProcessingCount = 0;
   359                          TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted() missing from results item %d", iQueryQueue[queryItem] );
   463                         iUnknown = EFalse;
   360                          
   464                     }
   361                          // ignore if fails
       
   362                          queryQueueDelta.InsertInOrder(iQueryQueue[queryItem], Compare);
       
   363                          }
       
   364                      }
       
   365                  
       
   366                  TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted() missing items total count %d", queryQueueDelta.Count()); 
       
   367                  //cleanup from previous queue it item is not found from MDS
       
   368                  while(queryQueueDelta.Count())
       
   369                      {
       
   370                      itemIndex = iLastQueue->FindInOrder(queryQueueDelta[0], Compare);
       
   371                      
       
   372                      if(itemIndex >= 0)
       
   373                          {
       
   374                          TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted() remove items %d", iQueryQueue[0]);
       
   375                          iLastQueue->Remove( itemIndex );
       
   376                          }
       
   377                      queryQueueDelta.Remove(0);
       
   378                      }
       
   379                  queryQueueDelta.Close();
       
   380                 }
       
   381             
   465             
   382             // no results, reset query
   466             // no results, reset query
   383             if( !iProcessingCount)
   467             if( !iProcessingCount )
   384                 {
   468                 {
   385                 delete iQuery;
   469                 delete iQuery;
   386                 iQuery = NULL;
   470                 iQuery = NULL;
   387                 iProcessingCount = 0;
       
   388                 iModify = EFalse;
   471                 iModify = EFalse;
   389                 }
   472                 }
   390             }
   473             }
   391         else
   474         else
   392             {
   475             {
   414     TN_DEBUG1( "CThumbAGProcessor::ThumbnailPreviewReady()");
   497     TN_DEBUG1( "CThumbAGProcessor::ThumbnailPreviewReady()");
   415     // No implementation required
   498     // No implementation required
   416     }
   499     }
   417 
   500 
   418 // -----------------------------------------------------------------------------
   501 // -----------------------------------------------------------------------------
   419 // CThumbAGProcessor::ThumbnailReady()
   502 // CThumbAGProcessor::ThumbnailReady()d
   420 // -----------------------------------------------------------------------------
   503 // -----------------------------------------------------------------------------
   421 //
   504 //
   422 void CThumbAGProcessor::ThumbnailReady( TInt aError, MThumbnailData& /*aThumbnail*/,
   505 void CThumbAGProcessor::ThumbnailReady( TInt aError, MThumbnailData& /*aThumbnail*/,
   423                                         TThumbnailRequestId /*aId*/ )
   506                                         TThumbnailRequestId /*aId*/ )
   424     {
   507     {
   425     TN_DEBUG2( "CThumbAGProcessor::ThumbnailReady() aError == %d", aError );
   508     TN_DEBUG2( "CThumbAGProcessor::ThumbnailReady() aError == %d", aError );
   426     
   509     
   427     iActiveCount--;
   510     iActiveCount--;
   428     
       
   429     if(iActiveCount <= 0)
       
   430         {
       
   431         iActiveCount = 0;
       
   432         iActive = EFalse;
       
   433         }
       
   434     
   511     
   435     // TNM server died, delete session
   512     // TNM server died, delete session
   436     if( aError == KErrServerTerminated )
   513     if( aError == KErrServerTerminated )
   437         {
   514         {
   438         TN_DEBUG1( "CThumbAGProcessor::ThumbnailReady() - **** THUMBNAIL SERVER DIED ****" );
   515         TN_DEBUG1( "CThumbAGProcessor::ThumbnailReady() - **** THUMBNAIL SERVER DIED ****" );
   467         {
   544         {
   468         TN_DEBUG1( "CThumbAGProcessor::ThumbnailRequestReady() - delete" );
   545         TN_DEBUG1( "CThumbAGProcessor::ThumbnailRequestReady() - delete" );
   469     
   546     
   470         iActiveCount--;
   547         iActiveCount--;
   471         
   548         
   472         if(iActiveCount <= 0)
       
   473             {
       
   474             iActiveCount = 0;
       
   475             iActive = EFalse;
       
   476             }
       
   477     
       
   478         ActivateAO();
   549         ActivateAO();
   479         }
   550         }
   480     }
   551     }
   481 
   552 
   482 // ---------------------------------------------------------------------------
   553 // ---------------------------------------------------------------------------
   483 // CThumbAGProcessor::SetMdESession()
   554 // CThumbAGProcessor::SetMdESession()
   484 // ---------------------------------------------------------------------------
   555 // ---------------------------------------------------------------------------
   485 //
   556 //
   486 void CThumbAGProcessor::SetMdESession( CMdESession* aMdESession )
   557 void CThumbAGProcessor::SetMdESessionL( CMdESession* aMdESession )
   487     {
   558     {
   488     TN_DEBUG1( "CThumbAGProcessor::SetMdESession() - begin" );
   559     TN_DEBUG1( "CThumbAGProcessor::SetMdESession() - begin" );
   489     
   560     
   490     iMdESession = aMdESession;
   561     iMdESession = aMdESession;
   491     
   562     
   493     
   564     
   494     TRAPD( err, iDefNamespace = &iMdESession->GetDefaultNamespaceDefL() );
   565     TRAPD( err, iDefNamespace = &iMdESession->GetDefaultNamespaceDefL() );
   495     if (err != KErrNone)
   566     if (err != KErrNone)
   496         {
   567         {
   497         TN_DEBUG2( "CThumbAGProcessor::SetMdESession() GetDefaultNamespaceDefL() err = %d", err );
   568         TN_DEBUG2( "CThumbAGProcessor::SetMdESession() GetDefaultNamespaceDefL() err = %d", err );
   498         }
   569         __ASSERT_DEBUG((iDefNamespace), User::Panic(_L("CThumbAGProcessor::SetMdESession() !iDefNamespace "), KErrBadHandle));
   499     
   570         }
   500     __ASSERT_DEBUG((iDefNamespace), User::Panic(_L("CThumbAGProcessor::SetMdESession() !iDefNamespace "), KErrBadHandle));
   571     else
   501        
   572         {
   502     //do async init
   573         iImageObjectDef = &iDefNamespace->GetObjectDefL( MdeConstants::Image::KImageObject );
   503     iInit = ETrue;
   574         __ASSERT_DEBUG((iImageObjectDef), User::Panic(_L("CThumbAGProcessor::SetMdESession() !iDefNamespace "), KErrBadHandle));
   504     
   575         iVideoObjectDef = &iDefNamespace->GetObjectDefL( MdeConstants::Video::KVideoObject );
   505 	ActivateAO();
   576         __ASSERT_DEBUG((iVideoObjectDef), User::Panic(_L("CThumbAGProcessor::SetMdESession() !iVideoObjectDef "), KErrBadHandle));
       
   577         iAudioObjectDef = &iDefNamespace->GetObjectDefL( MdeConstants::Audio::KAudioObject );
       
   578         __ASSERT_DEBUG((iAudioObjectDef), User::Panic(_L("CThumbAGProcessor::SetMdESession() !iAudioObjectDef "), KErrBadHandle));
       
   579         
       
   580         //do async init
       
   581         iInit = ETrue;
       
   582 
       
   583         ActivateAO();
       
   584         }
   506     }
   585     }
   507 
   586 
   508 // ---------------------------------------------------------------------------
   587 // ---------------------------------------------------------------------------
   509 // CThumbAGProcessor::AddToQueue()
   588 // CThumbAGProcessor::AddToQueue()
   510 // ---------------------------------------------------------------------------
   589 // ---------------------------------------------------------------------------
   511 //
   590 //
   512 void CThumbAGProcessor::AddToQueueL( TObserverNotificationType aType, 
   591 void CThumbAGProcessor::AddToQueueL( TObserverNotificationType aType, 
       
   592                                     TThumbnailGenerationItemType aItemType,
   513                                     const RArray<TItemId>& aIDArray, 
   593                                     const RArray<TItemId>& aIDArray, 
   514                                     const RPointerArray<HBufC>& aObjectUriArray,
   594                                     const RPointerArray<HBufC>& aObjectUriArray,
   515                                     TBool /*aPresent*/ )
   595                                     TBool /*aPresent*/ )
   516     {
   596     {
   517     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - begin" );
   597     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - begin" );
       
   598     
   518 
   599 
   519     // update queues
   600     // update queues
   520     if (aType == ENotifyAdd)
   601     if (aType == ENotifyAdd)
   521         {
   602         {
   522         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyAdd" );
   603         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyAdd" );
   523         
   604         
   524         for (int i=0; i<aIDArray.Count(); i++)
   605         for (int i=0; i<aIDArray.Count(); i++)
   525             {
   606             {
   526             // do not to append to Add queue if exist already in Add or 2nd Add queue (just processed)     
   607             TThumbnailGenerationItem item;
   527             if (iAddQueue.FindInOrder(aIDArray[i], Compare) == KErrNotFound && 
   608             item.iItemId = aIDArray[i];      
   528                 i2ndRoundGenerateQueue.FindInOrder(aIDArray[i], Compare) == KErrNotFound)
   609             item.iItemType = aItemType;
   529                 {
   610             
   530                 User::LeaveIfError(iAddQueue.InsertInOrder(aIDArray[i], Compare));    
   611             SetGenerationItemAction(item, aItemType);
   531                 }
   612             
       
   613             if(iPHHarvesting)
       
   614                 {
       
   615                 item.iPlaceholder = ETrue;
       
   616                 }
       
   617 
       
   618             AppendProcessingQueue( item );
   532             }
   619             }
   533         }
   620         }
   534     else if (aType == ENotifyModify)
   621     else if (aType == ENotifyModify)
   535         {
   622         {
   536         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyModify" );
   623         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyModify" );
   538         if(iPHHarvesting)
   625         if(iPHHarvesting)
   539             {        
   626             {        
   540             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - PH  harvesting active, treat like add" );
   627             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - PH  harvesting active, treat like add" );
   541             for (int i=0; i<aIDArray.Count(); i++)
   628             for (int i=0; i<aIDArray.Count(); i++)
   542                 {
   629                 {
   543                 TInt itemIndex = iPlaceholderQueue.FindInOrder(aIDArray[i], Compare);
   630                 TThumbnailGenerationItem item;
       
   631                 item.iItemId = aIDArray[i];
       
   632                 item.iItemType = aItemType;
       
   633                 
       
   634                 TInt itemIndex = iGenerationQueue.FindInOrder(item, Compare);
   544                                 
   635                                 
   545                 if (itemIndex >= 0)
   636                 if (itemIndex >= 0)
   546                     {
   637                     {
   547                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - remove from placeholder queue");
   638                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - set as non-placeholder");
   548                     iPlaceholderQueue.Remove( itemIndex );
   639                     iGenerationQueue[itemIndex].iPlaceholder = EFalse;
   549                     }
   640                     }
       
   641                 else
       
   642                     {
       
   643                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - append");
       
   644 
       
   645                      item.iPlaceholder = EFalse;
       
   646                      SetGenerationItemAction( item, aItemType );
       
   647                      AppendProcessingQueue( item );
       
   648                     }
       
   649                 }
       
   650             }
       
   651         else
       
   652             {
       
   653             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - PH  harvesting finished, check is real modify!" );
       
   654             
       
   655             TInt itemIndex(KErrNotFound);
       
   656             
       
   657             for (int i=0; i<aIDArray.Count(); i++)
       
   658                 {
       
   659                 TThumbnailGenerationItem item;
       
   660                 item.iItemId = aIDArray[i];
       
   661                 item.iItemType = aItemType;
   550                 
   662                 
   551                 if(iAddQueue.FindInOrder(aIDArray[i], Compare) == KErrNotFound && 
   663                 itemIndex = iGenerationQueue.FindInOrder(item, Compare);
   552                    i2ndRoundGenerateQueue.FindInOrder(aIDArray[i], Compare) == KErrNotFound)
       
   553                     {
       
   554                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - append to add queue");
       
   555                     User::LeaveIfError(iAddQueue.InsertInOrder(aIDArray[i], Compare));
       
   556                     }
       
   557                 }
       
   558             }
       
   559         else
       
   560             {
       
   561             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - PH  harvesting finished, check is real modify!" );
       
   562             
       
   563             TInt itemIndex(KErrNotFound);
       
   564             
       
   565             for (int i=0; i<aIDArray.Count(); i++)
       
   566                 {
       
   567                 itemIndex = iPlaceholderQueue.FindInOrder(aIDArray[i], Compare);
       
   568                 
   664                 
   569                 if (itemIndex >= 0)
   665                 if (itemIndex >= 0)
   570                     {
   666                     {
   571                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - placeholder modify, remove from placeholder queue");
   667                     if( iGenerationQueue[itemIndex].iPlaceholder )
   572                     iPlaceholderQueue.Remove( itemIndex );
   668                         {
       
   669                         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - placeholder modify");
       
   670                         iGenerationQueue[itemIndex].iPlaceholder = EFalse;
       
   671                         }
       
   672                     else
       
   673                         {
       
   674                         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - real modify");
       
   675                         iGenerationQueue[itemIndex].iItemAction = EGenerationItemActionModify;
       
   676                         SetForceRun( ETrue );
       
   677                         }
   573                     }
   678                     }
   574                 else
   679                 else
   575                     {
   680                     {
   576                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - real modify");
   681                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - append");
   577                     itemIndex = iAddQueue.FindInOrder(aIDArray[i], Compare);
   682                     SetGenerationItemAction( item, aItemType);
   578                                     
   683                     item.iPlaceholder = EFalse;
   579                     if (itemIndex >= 0)
   684                     AppendProcessingQueue( item );
   580                         {
   685                     }
   581                         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - remove from add queue");
   686                 }
   582                         iAddQueue.Remove( itemIndex );
   687             }
   583                         }
   688         }
   584 					else
   689         else if (aType == ENotifyRemove && aItemType == EGenerationItemTypeAny)
   585 						{						
       
   586 						itemIndex = i2ndRoundGenerateQueue.FindInOrder(aIDArray[i], Compare);
       
   587                                     
       
   588 	                    if (itemIndex >= 0)
       
   589 	                        {
       
   590 	                        TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - remove from 2nd round add queue");
       
   591 	                        i2ndRoundGenerateQueue.Remove( itemIndex );
       
   592 	                        }
       
   593 					}
       
   594                     
       
   595                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - append to modify queue");
       
   596                     User::LeaveIfError(iModifyQueue.InsertInOrder(aIDArray[i], Compare));
       
   597                     
       
   598                     SetForceRun( ETrue );
       
   599                     } 
       
   600                 }
       
   601             }
       
   602         }
       
   603         else if (aType == ENotifyRemove)
       
   604             {
   690             {
   605             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyRemove, remove IDs from all queues");
   691             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyRemove, remove IDs from all queues");
   606             
   692             
   607             for (int i=0; i<aIDArray.Count(); i++)
   693             for (int i=0; i<aIDArray.Count(); i++)
   608                 {
   694                 {
   609                 // can be removed from Add queue
   695                 TThumbnailGenerationItem item;
   610                 TInt itemIndex = iAddQueue.FindInOrder(aIDArray[i], Compare);
   696                 item.iItemId = aIDArray[i];
       
   697                 item.iItemType = aItemType;
       
   698 
       
   699                 TInt itemIndex = iGenerationQueue.FindInOrder(item, Compare);
       
   700                 
   611                 if(itemIndex >= 0)
   701                 if(itemIndex >= 0)
   612                     {
   702                     {
   613                     iAddQueue.Remove(itemIndex);
   703                     iGenerationQueue[itemIndex].iItemAction = EGenerationItemActionDelete;
   614                     }
   704                     delete iGenerationQueue[itemIndex].iUri;
   615     
   705                     iGenerationQueue[itemIndex].iUri = NULL;
   616                 // ..and Modify Queue
   706                     
   617                 itemIndex = iModifyQueue.FindInOrder(aIDArray[i], Compare);
   707                     if( aObjectUriArray[i])
   618                 if(itemIndex >= 0)
   708                         {
       
   709                         iGenerationQueue[itemIndex].iUri = aObjectUriArray[i]->AllocL();
       
   710                         }
       
   711                     else
       
   712                         {
       
   713                         //invalid URI remove from processing queue
       
   714                         iGenerationQueue.Remove(itemIndex);
       
   715                         }
       
   716                     }
       
   717                 else
   619                     {
   718                     {
   620                     iModifyQueue.Remove(itemIndex);
   719                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - append");
   621                     }
   720                     item.iItemAction = EGenerationItemActionDelete;
   622                 }
   721                     delete item.iUri;
   623             
   722                     item.iUri = NULL;
   624             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyRemove append URIs to remove queue");
   723                     
   625             for (int i=0; i<aObjectUriArray.Count(); i++)
   724                     if( aObjectUriArray[i])
   626                 {
   725                         {
   627                 HBufC* temp = aObjectUriArray[i]->AllocL();
   726                         item.iUri = aObjectUriArray[i]->AllocL();
   628                 iRemoveQueue.Append( temp );
   727                         CleanupStack::PushL( item.iUri );
   629                 TN_DEBUG2( "CThumbAGProcessor::AddToQueueL() - %S", temp); 
   728                         User::LeaveIfError( iGenerationQueue.InsertInOrder(item, Compare) );
       
   729                         CleanupStack::Pop();
       
   730                         }
       
   731                     
       
   732                     //owned by item
       
   733                     item.iUri = NULL;
       
   734                     }
       
   735                 
       
   736                 TN_DEBUG2( "CThumbAGProcessor::AddToQueueL() - %S", aObjectUriArray[i]); 
   630                 }
   737                 }
   631             }
   738             }
   632 #ifdef _DEBUG
   739 #ifdef _DEBUG
   633         else
   740         else
   634             {
   741             {
   635 	        TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() -  should not come here" );
   742 	        TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() -  should not come here" );
       
   743 	        __ASSERT_DEBUG((EFalse), User::Panic(_L("CThumbAGProcessor::AddToQueueL()"), KErrArgument));
   636 	        User::Leave( KErrArgument );
   744 	        User::Leave( KErrArgument );
   637             }
   745             }
   638 #endif
   746 #endif
   639     
   747     
   640     ActivateAO(); 
   748     ActivateAO(); 
   660     
   768     
   661     TInt orientationVal = 0;
   769     TInt orientationVal = 0;
   662     TInt64 modifiedVal = 0;
   770     TInt64 modifiedVal = 0;
   663     
   771     
   664     CMdEProperty* orientation = NULL;
   772     CMdEProperty* orientation = NULL;
   665     CMdEObjectDef& imageObjectDef = iDefNamespace->GetObjectDefL( MdeConstants::Image::KImageObject );       
   773        
   666     TInt orientErr = aObject->Property( imageObjectDef.GetPropertyDefL( MdeConstants::Image::KOrientationProperty ), orientation, 0 );
   774     TInt orientErr = aObject->Property( iImageObjectDef->GetPropertyDefL( MdeConstants::Image::KOrientationProperty ), orientation, 0 );
   667     
   775     
   668     if (orientErr == KErrNone)
   776     if (orientErr == KErrNone)
   669         {
   777         {
   670         orientationVal = orientation->Uint16ValueL();
   778         orientationVal = orientation->Uint16ValueL();
   671         }
   779         }
   686         if( i2ndRound )
   794         if( i2ndRound )
   687             {
   795             {
   688             //generate both if needed
   796             //generate both if needed
   689             TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() EOptimizeForQuality ");
   797             TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() EOptimizeForQuality ");
   690             iTMSession->SetQualityPreferenceL( CThumbnailManager::EOptimizeForQuality );
   798             iTMSession->SetQualityPreferenceL( CThumbnailManager::EOptimizeForQuality );
       
   799             
       
   800             TN_DEBUG2( "CThumbAGProcessor::CreateThumbnailsL() - 2nd round add remove from queue", aObject->Id() );
       
   801                         
       
   802             TThumbnailGenerationItem item;
       
   803             item.iItemId = aObject->Id();
       
   804             TInt itemIndex = iGenerationQueue.FindInOrder(item, Compare);
       
   805             
       
   806             if(itemIndex >=0 )
       
   807                 {
       
   808                 if(iGenerationQueue[itemIndex].iItemAction == EGenerationItemAction2ndAdd)
       
   809                     {
       
   810                     iGenerationQueue.Remove(itemIndex);
       
   811                     }
       
   812                 }
   691             }
   813             }
   692 		// 1st roung generation
   814 		// 1st roung generation
   693         else
   815         else
   694             {
   816             {
   695             //1st round
   817             //1st round
   696             TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() EOptimizeForQualityWithPreview");
   818             TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() EOptimizeForQualityWithPreview");
   697             iTMSession->SetQualityPreferenceL( CThumbnailManager::EOptimizeForQualityWithPreview );
   819             iTMSession->SetQualityPreferenceL( CThumbnailManager::EOptimizeForQualityWithPreview );
   698             
   820             
   699             CMdEObjectDef& videoObjectDef = iDefNamespace->GetObjectDefL( MdeConstants::Video::KVideoObject );
       
   700             
       
   701             // add item to 2nd round queue 
   821             // add item to 2nd round queue 
   702             if(iLastQueue == &iAddQueue || iLastQueue == &iModifyQueue)
   822             TN_DEBUG2( "CThumbAGProcessor::CreateThumbnailsL() - 1st round add/modify, append to 2nd round queue", aObject->Id() );
   703                 {
   823             
   704                 TN_DEBUG2( "CThumbAGProcessor::CreateThumbnailsL() - 1st round add/modify, append to 2nd round queue", aObject->Id() );
   824             TThumbnailGenerationItem item;
   705                 if(i2ndRoundGenerateQueue.FindInOrder(aObject->Id(), Compare) == KErrNotFound)
   825             item.iItemId = aObject->Id();
       
   826             TInt itemIndex = iGenerationQueue.FindInOrder(item, Compare);
       
   827             
       
   828             if(itemIndex >=0 )
       
   829                 {
       
   830                 if(iGenerationQueue[itemIndex].iItemAction == EGenerationItemActionModify)
   706                     {
   831                     {
   707                     // ignore if fails
   832                     iGenerationQueue.Remove(itemIndex);
   708                     i2ndRoundGenerateQueue.InsertInOrder(aObject->Id(), Compare);
   833                     }
   709                     }
   834                 //change 1st round item for 2nd round processing
   710                 }
   835                 //2nd round item can be deleted
   711             
   836                 else if(iGenerationQueue[itemIndex].iItemAction == EGenerationItemActionAdd)
   712             /*CMdEProperty* inDefaultFolder = NULL;
   837                     {
   713             TBool inDefaultFolderVal(ETrue);
   838                     iGenerationQueue[itemIndex].iItemAction = EGenerationItemAction2ndAdd;
   714             TInt inDefaultFolderErr = aObject->Property( baseObjDef.GetPropertyDefL( MdeConstants::Object::KInDefaultFolder ), inDefaultFolder, 0 );
   839                     }
   715             
   840                 else
   716             if(inDefaultFolder &&  inDefaultFolderErr >= 0 )
   841                     {
   717                 {
   842                     iGenerationQueue.Remove(itemIndex);
   718                 inDefaultFolderVal = inDefaultFolder->BoolValueL();
   843                     }
   719                 }*/
       
   720             
       
   721 		   // Symbian^3 specific
       
   722            if( !(( imageObjectDef.Id() == aObject->Def().Id() || videoObjectDef.Id() == aObject->Def().Id()) 
       
   723                    /*&& inDefaultFolderVal*/ ) )
       
   724                 {
       
   725                 TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() 1st round; not image or video in default folder, skip");
       
   726                 ActivateAO();
       
   727                 return;
       
   728                 }
   844                 }
   729             }
   845             }
   730 
   846 
   731         // run as lower priority than getting but higher that creating thumbnails
   847         // run as lower priority than getting but higher that creating thumbnails
   732         TRAPD(err, iTMSession->UpdateThumbnailsL(KNoId, aObject->Uri(), orientationVal, modifiedVal, CActive::EPriorityIdle ));
   848         TRAPD(err, iTMSession->UpdateThumbnailsL(KNoId, aObject->Uri(), orientationVal, modifiedVal, CActive::EPriorityIdle ));
   734         if ( err != KErrNone )
   850         if ( err != KErrNone )
   735             {
   851             {
   736             TN_DEBUG2( "CThumbAGProcessor::CreateThumbnailsL, iTMSession error == %d", err );
   852             TN_DEBUG2( "CThumbAGProcessor::CreateThumbnailsL, iTMSession error == %d", err );
   737             
   853             
   738             iSessionDied = ETrue;
   854             iSessionDied = ETrue;
   739             iActive = EFalse;
       
   740             ActivateAO();
   855             ActivateAO();
   741             } 
   856             } 
   742         else
   857         else
   743             {
   858             {
   744             iActiveCount++;
   859             iActiveCount++;
   745             iActive = ETrue;
       
   746             }
   860             }
   747         }
   861         }
   748     else
   862     else
   749         {
   863         {
   750         ActivateAO();
   864         ActivateAO();
   755 
   869 
   756 // ---------------------------------------------------------------------------
   870 // ---------------------------------------------------------------------------
   757 // CThumbAGProcessor::QueryL()
   871 // CThumbAGProcessor::QueryL()
   758 // ---------------------------------------------------------------------------
   872 // ---------------------------------------------------------------------------
   759 //
   873 //
   760 void CThumbAGProcessor::QueryL( RArray<TItemId>& aIDArray )
   874 void CThumbAGProcessor::QueryL(/*RArray<TItemId>& aIDArray*/TThumbnailGenerationItemAction aAction  )
   761     {
   875     {
   762     TN_DEBUG1( "CThumbAGProcessor::QueryL() - begin" );
   876     TN_DEBUG1( "CThumbAGProcessor::QueryL() - begin" );
   763     
   877     
   764     __ASSERT_DEBUG((iMdESession), User::Panic(_L("CThumbAGProcessor::QueryL() !iMdeSession "), KErrBadHandle));
   878     __ASSERT_DEBUG((iMdESession), User::Panic(_L("CThumbAGProcessor::QueryL() !iMdeSession "), KErrBadHandle));
   765     __ASSERT_DEBUG((iDefNamespace), User::Panic(_L("CThumbAGProcessor::QueryL() !iDefNamespace "), KErrBadHandle));
   879     __ASSERT_DEBUG((iDefNamespace), User::Panic(_L("CThumbAGProcessor::QueryL() !iDefNamespace "), KErrBadHandle));
   770         }
   884         }
   771     
   885     
   772 	//reset query queue
   886 	//reset query queue
   773     iQueryQueue.Reset();
   887     iQueryQueue.Reset();
   774 	//set reference to current pprocessing queue
   888 	//set reference to current pprocessing queue
   775     iLastQueue = &aIDArray;
       
   776     
   889     
   777     iQueryReady = EFalse;
   890     iQueryReady = EFalse;
   778 
   891 
   779     // delete old query
   892     // delete old query
   780     if (iQuery)
   893     if (iQuery)
   782         delete iQuery;
   895         delete iQuery;
   783         iQuery = NULL;
   896         iQuery = NULL;
   784         }
   897         }
   785     
   898     
   786     //move ID from source queue to Query queue
   899     //move ID from source queue to Query queue
   787     TInt maxCount = aIDArray.Count();
   900     TInt maxCount = iGenerationQueue.Count();
   788         
   901         
   789     TN_DEBUG3( "CThumbAGProcessor::QueryL() - fill begin aIDArray == %d, iQueryQueue == %d", aIDArray.Count(), iQueryQueue.Count() );
   902     TN_DEBUG3( "CThumbAGProcessor::QueryL() - fill begin iGenerationQueue == %d, iQueryQueue == %d", iGenerationQueue.Count(), iQueryQueue.Count() );
   790     
   903     
   791     for(TInt i=0; i < KMaxQueryItems && i < maxCount; i++)
   904     
   792         {
   905     TInt itemCount(0);
   793         TN_DEBUG2( "CThumbAGProcessor::QueryL() - fill %d", aIDArray[0] );
   906     for(TInt i=0; itemCount < KMaxQueryItems && i < maxCount; i++)
   794         iQueryQueue.InsertInOrder(aIDArray[0], Compare);
   907         {
   795         aIDArray.Remove(0);
   908         TInt itemIndex(KErrNotFound);
   796         }
   909         switch(aAction)
   797     
   910             {
   798     TN_DEBUG3( "CThumbAGProcessor::QueryL() - fill end aIDArray == %d, iQueryQueue == %d", aIDArray.Count(), iQueryQueue.Count() );
   911             //1st round items
       
   912             case EGenerationItemActionAdd:
       
   913                 if(iGenerationQueue[i].iItemAction == aAction )
       
   914                     {
       
   915                     itemIndex = i;
       
   916                     }
       
   917                 break;
       
   918             case EGenerationItemActionModify:
       
   919                 if( iGenerationQueue[i].iItemAction == aAction )
       
   920                     {
       
   921                     itemIndex = i;
       
   922                     }
       
   923                 break;
       
   924             case EGenerationItemAction2ndAdd:
       
   925                 if( iGenerationQueue[i].iItemAction == aAction )
       
   926                     {
       
   927                     itemIndex = i;
       
   928                     }
       
   929                 break;
       
   930             //unknown stuff
       
   931             case EGenerationItemActionResolveType:
       
   932                 if( iGenerationQueue[i].iItemType == EGenerationItemTypeUnknown )
       
   933                     {
       
   934                     itemIndex = i;
       
   935                     }
       
   936                 break;
       
   937             default:
       
   938                 break;
       
   939             };
       
   940         
       
   941         if( itemIndex >= 0 )
       
   942             {
       
   943             TN_DEBUG2( "CThumbAGProcessor::QueryL() - fill %d", iGenerationQueue[itemIndex].iItemId );        
       
   944             iQueryQueue.InsertInOrder(iGenerationQueue[itemIndex].iItemId, CompareId);
       
   945             itemCount++;
       
   946             }
       
   947         }
       
   948     
       
   949     if(!itemCount)
       
   950         {
       
   951         TN_DEBUG1( "CThumbAGProcessor::QueryL() - empty query, cancel?!");
       
   952         iQueryActive = EFalse;
       
   953         __ASSERT_DEBUG((iMdESession), User::Panic(_L("CThumbAGProcessor::QueryL() empty! "), KErrNotFound));
       
   954         return;
       
   955         }
       
   956     
       
   957     TN_DEBUG3( "CThumbAGProcessor::QueryL() - fill end iGenerationQueue == %d, iQueryQueue == %d", iGenerationQueue.Count(), iQueryQueue.Count() );
   799     
   958     
   800     CMdEObjectDef& objDef = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject );
   959     CMdEObjectDef& objDef = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject );
   801     iQuery = iMdESession->NewObjectQueryL( *iDefNamespace, objDef, this );
   960     iQuery = iMdESession->NewObjectQueryL( *iDefNamespace, objDef, this );
   802     iQuery->SetResultMode( EQueryResultModeItem );
   961     iQuery->SetResultMode( EQueryResultModeItem );
   803 
   962 
   808     CleanupClosePushL( iQueryQueue );
   967     CleanupClosePushL( iQueryQueue );
   809     rootCondition.AddObjectConditionL( iQueryQueue );
   968     rootCondition.AddObjectConditionL( iQueryQueue );
   810     CleanupStack::Pop( &iQueryQueue );
   969     CleanupStack::Pop( &iQueryQueue );
   811     
   970     
   812     // add object type conditions 
   971     // add object type conditions 
   813     if (!iModify)
   972     if (!(iModify || iUnknown))
   814         {
   973         {
   815         CMdELogicCondition& objDefCondition = rootCondition.AddLogicConditionL( ELogicConditionOperatorOr );
   974         CMdELogicCondition& objDefCondition = rootCondition.AddLogicConditionL( ELogicConditionOperatorOr );
   816         
   975         
   817         if (iAutoImage)
   976         if (iAutoImage)
   818             {
   977             {
   840 // ---------------------------------------------------------------------------
   999 // ---------------------------------------------------------------------------
   841 // CThumbAGProcessor::QueryForPlaceholders()
  1000 // CThumbAGProcessor::QueryForPlaceholders()
   842 // ---------------------------------------------------------------------------
  1001 // ---------------------------------------------------------------------------
   843 //
  1002 //
   844 
  1003 
   845 void CThumbAGProcessor::QueryPlaceholdersL()
  1004 void CThumbAGProcessor::QueryPlaceholdersL(TBool aPresent)
   846     {
  1005     {
   847     TN_DEBUG1( "CThumbAGProcessor::QueryPlaceholdersL" );
  1006     TN_DEBUG1( "CThumbAGProcessor::QueryPlaceholdersL" );
   848     
  1007     
   849     __ASSERT_DEBUG((iMdESession), User::Panic(_L("CThumbAGProcessor::QueryPlaceholdersL() !iMdeSession "), KErrBadHandle));
  1008     __ASSERT_DEBUG((iMdESession), User::Panic(_L("CThumbAGProcessor::QueryPlaceholdersL() !iMdeSession "), KErrBadHandle));
   850     __ASSERT_DEBUG((iDefNamespace), User::Panic(_L("CThumbAGProcessor::QueryPlaceholdersL() !iDefNamespace "), KErrBadHandle));
  1009     __ASSERT_DEBUG((iDefNamespace), User::Panic(_L("CThumbAGProcessor::QueryPlaceholdersL() !iDefNamespace "), KErrBadHandle));
   882     CMdELogicCondition& rootCondition = iQueryPlaceholders->Conditions();
  1041     CMdELogicCondition& rootCondition = iQueryPlaceholders->Conditions();
   883     rootCondition.SetOperator( ELogicConditionOperatorOr );
  1042     rootCondition.SetOperator( ELogicConditionOperatorOr );
   884     
  1043     
   885     CMdEObjectCondition& imagePHObjectCondition = rootCondition.AddObjectConditionL(imageObjDef);
  1044     CMdEObjectCondition& imagePHObjectCondition = rootCondition.AddObjectConditionL(imageObjDef);
   886     imagePHObjectCondition.SetPlaceholderOnly( ETrue );
  1045     imagePHObjectCondition.SetPlaceholderOnly( ETrue );
   887     imagePHObjectCondition.SetNotPresent( ETrue );
  1046     imagePHObjectCondition.SetNotPresent( aPresent );
   888     
  1047     
   889     CMdEObjectCondition& videoPHObjectCondition = rootCondition.AddObjectConditionL(videoObjDef);
  1048     CMdEObjectCondition& videoPHObjectCondition = rootCondition.AddObjectConditionL(videoObjDef);
   890     videoPHObjectCondition.SetPlaceholderOnly( ETrue );
  1049     videoPHObjectCondition.SetPlaceholderOnly( ETrue );
   891     videoPHObjectCondition.SetNotPresent( ETrue );
  1050     videoPHObjectCondition.SetNotPresent( aPresent );
   892     
  1051     
   893     CMdEObjectCondition& audioPHObjectCondition = rootCondition.AddObjectConditionL(audioObjDef);
  1052     CMdEObjectCondition& audioPHObjectCondition = rootCondition.AddObjectConditionL(audioObjDef);
   894     audioPHObjectCondition.SetPlaceholderOnly( ETrue );
  1053     audioPHObjectCondition.SetPlaceholderOnly( ETrue );
   895     audioPHObjectCondition.SetNotPresent( ETrue );
  1054     audioPHObjectCondition.SetNotPresent( aPresent );
   896     
  1055     
   897     iQueryPlaceholders->FindL(KMaxTInt, KMaxQueryItems2);   
  1056     iQueryPlaceholders->FindL(KMaxTInt, KMaxQueryBatchSize);   
   898    
  1057    
   899     TN_DEBUG1( "CThumbAGProcessor::QueryPlaceholdersL - end" );
  1058     TN_DEBUG1( "CThumbAGProcessor::QueryPlaceholdersL - end" );
   900     }
  1059     }
   901 
  1060 
   902 
  1061 
   926         TN_DEBUG1( "CThumbAGProcessor::RunL() - Do Initialisation 1" );
  1085         TN_DEBUG1( "CThumbAGProcessor::RunL() - Do Initialisation 1" );
   927         
  1086         
   928         iInit = EFalse;
  1087         iInit = EFalse;
   929         iInit2 = ETrue;
  1088         iInit2 = ETrue;
   930 
  1089 
   931         iAddQueue.Reset();
  1090         iGenerationQueue.Reset();
   932         iModifyQueue.Reset();
       
   933         iRemoveQueue.ResetAndDestroy();
       
   934         iQueryQueue.Reset();
  1091         iQueryQueue.Reset();
   935         iPlaceholderQueue.Reset();
  1092         
   936         
  1093 		//query all not present placeholders
   937         TRAP_IGNORE(QueryPlaceholdersL());
  1094         TRAP_IGNORE(QueryPlaceholdersL( ETrue ));
   938 		//query all items after PH query
  1095 		//query all items after PH query
   939         iDoQueryAllItems = ETrue;
  1096         iDoQueryAllItems = ETrue;
   940         TN_DEBUG1( "CThumbAGProcessor::RunL() - Initialisation 1 done" );
  1097         TN_DEBUG1( "CThumbAGProcessor::RunL() - Initialisation 1 done" );
   941         ActivateAO();
  1098         ActivateAO();
   942         return;
  1099         return;
   952 #ifdef  MDS_MODIFY_OBSERVER        
  1109 #ifdef  MDS_MODIFY_OBSERVER        
   953         TN_DEBUG1( "CThumbAGProcessor::RunL() do iHarvesterClient connect");
  1110         TN_DEBUG1( "CThumbAGProcessor::RunL() do iHarvesterClient connect");
   954         err = iHarvesterClient.Connect();
  1111         err = iHarvesterClient.Connect();
   955         TN_DEBUG2( "CThumbAGProcessor::RunL() iHarvesterClient connect err = %d", err);
  1112         TN_DEBUG2( "CThumbAGProcessor::RunL() iHarvesterClient connect err = %d", err);
   956         
  1113         
   957         __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGProcessor::RunL(), !iHarvesterClient "), err));
  1114         __ASSERT_DEBUG((err == KErrNone), User::Panic(_L("CThumbAGProcessor::RunL(), !iHarvesterClient "), err));
   958         
  1115         
   959         if(  err == KErrNone )
  1116         if(  err == KErrNone )
   960             {
  1117             {
   961             TN_DEBUG1( "CThumbAGProcessor::RunL() add iHarvesterClient observer");
  1118             TN_DEBUG1( "CThumbAGProcessor::RunL() add iHarvesterClient observer");
   962             err = iHarvesterClient.AddHarvesterEventObserver( *this, EHEObserverTypeOverall | EHEObserverTypeMMC | EHEObserverTypePlaceholder, KMaxTInt );
  1119             err = iHarvesterClient.AddHarvesterEventObserver( *this, EHEObserverTypeOverall | EHEObserverTypeMMC | EHEObserverTypePlaceholder, 20 );
   963             TN_DEBUG2( "CThumbAGProcessor::RunL() iHarvesterClient observer err = %d", err);
  1120             TN_DEBUG2( "CThumbAGProcessor::RunL() iHarvesterClient observer err = %d", err);
       
  1121             
       
  1122             if( !err )
       
  1123                 {
       
  1124                 TN_DEBUG1( "CThumbAGProcessor::RunL() add iHarvesterClient observer failed");
       
  1125                 // if we fail observer harvester, fake it
       
  1126                 iHarvesterActivated = ETrue;
       
  1127                 }
   964             __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGProcessor::RunL(), !iHarvesterClient "), err));
  1128             __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGProcessor::RunL(), !iHarvesterClient "), err));
   965             }
  1129             }
   966 #endif
  1130 #endif
   967  
  1131  
   968         TN_DEBUG1( "CThumbAGProcessor::RunL() MMPXCollectionUtility");
  1132         TN_DEBUG1( "CThumbAGProcessor::RunL() MMPXCollectionUtility");
   982     
  1146     
   983     // restart session if died
  1147     // restart session if died
   984     if (!iTMSession)
  1148     if (!iTMSession)
   985         {
  1149         {
   986         TN_DEBUG1( "CThumbAGProcessor::RunL() - open TNM session");
  1150         TN_DEBUG1( "CThumbAGProcessor::RunL() - open TNM session");
   987         iActive = EFalse;
       
   988         TRAPD( err, iTMSession = CThumbnailManager::NewL( *this ) );
  1151         TRAPD( err, iTMSession = CThumbnailManager::NewL( *this ) );
   989 		
  1152 		
   990         if (err != KErrNone)
  1153         if (err != KErrNone)
   991             {
  1154             {
   992             iTMSession = NULL;
  1155             iTMSession = NULL;
   999             iSessionDied = EFalse;
  1162             iSessionDied = EFalse;
  1000             }
  1163             }
  1001         }    
  1164         }    
  1002    
  1165    
  1003     // do not run if request is already issued to TNM server even if forced
  1166     // do not run if request is already issued to TNM server even if forced
  1004     if( iActive)
  1167     if(iActiveCount >= KMaxDaemonRequests)
  1005         {
  1168         {
  1006         if(iActiveCount >= KMaxDaemonRequests)
  1169         TN_DEBUG1( "CThumbAGProcessor::RunL() - waiting for previous to complete, abort..." );
  1007             {
  1170         return;
  1008             TN_DEBUG1( "CThumbAGProcessor::RunL() - waiting for previous to complete, abort..." );
  1171         }
  1009             return;
       
  1010             }
       
  1011         }
       
  1012     else
       
  1013         {
       
  1014         iActiveCount = 0;   
       
  1015         }
       
  1016     
       
  1017     
  1172     
  1018     //force run can proceed from this point
  1173     //force run can proceed from this point
  1019 #ifdef _DEBUG
  1174 #ifdef _DEBUG
  1020 	if( iForegroundRun )
  1175 	if( iForegroundRun )
  1021 		{
  1176 		{
  1060     //Handle completed MDS Query
  1215     //Handle completed MDS Query
  1061     if( iQueryReady && iProcessingCount)
  1216     if( iQueryReady && iProcessingCount)
  1062         {
  1217         {
  1063         TInt err(KErrNone);
  1218         TInt err(KErrNone);
  1064         //if force or non forced
  1219         //if force or non forced
  1065         if((iForceRun && iModify ) || (!iForceRun && !iModify ))
  1220 		//if unknown items or mount timer is active, abort processing
       
  1221 
       
  1222         if(((iForceRun && iModify ) || (!iForceRun && !iModify )) && !iUnknownItemCount && !iMountTimer->IsActive())
  1066             {
  1223             {
  1067             TN_DEBUG1( "CThumbAGProcessor::RunL() - iQueryReady START" );
  1224             TN_DEBUG1( "CThumbAGProcessor::RunL() - iQueryReady START" );
  1068             
  1225             
  1069             const CMdEObject* object = &iQuery->Result( iProcessingCount-1 );
  1226             const CMdEObject* object = &iQuery->Result( iProcessingCount-1 );
  1070             iProcessingCount--;
  1227             iProcessingCount--;
  1071             
  1228             
  1072             if ( object )
  1229             if ( object )
  1073                 {
  1230                 {
  1074                 TInt itemIndex = iLastQueue->FindInOrder(object->Id(), Compare);
       
  1075                 if(itemIndex >= 0)
       
  1076                     {
       
  1077                     iLastQueue->Remove(itemIndex);
       
  1078                     }
       
  1079 				
       
  1080                 //process one item at once
  1231                 //process one item at once
  1081                 //remove item from queryQueue when request is issued 
  1232                 //remove item from queryQueue when request is issued 
  1082                 itemIndex = iQueryQueue.FindInOrder(object->Id(), Compare);
  1233  
       
  1234                 TInt itemIndex = iQueryQueue.FindInOrder(object->Id(), CompareId);
  1083                 if(itemIndex >= 0)
  1235                 if(itemIndex >= 0)
  1084                     {
  1236                     {
  1085                     iQueryQueue.Remove(itemIndex);
  1237                     iQueryQueue.Remove(itemIndex);
  1086                     }
  1238                     }
  1087             
  1239             
  1088                 TRAP( err, CreateThumbnailsL(object) );
  1240                 TRAP( err, CreateThumbnailsL( object ) );
  1089                 TN_DEBUG2( "CThumbAGProcessor::RunL(), CreateThumbnailsL error == %d", err );
  1241                 TN_DEBUG2( "CThumbAGProcessor::RunL(), CreateThumbnailsL error == %d", err );
  1090                 __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGProcessor::RunL(), CreateThumbnailsL() "), err));
  1242                 __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGProcessor::RunL(), CreateThumbnailsL() "), err));
  1091                 }
  1243                 }
  1092             }
  1244             }
  1093         //force is coming, but executing non-forced query complete-> cancel old
  1245         //force is coming, but executing non-forced query complete-> cancel old
  1094         else
  1246         else
  1095             {
  1247             {
  1096 			//cancel query and move items back to original processing queue
  1248 			//cancel query
       
  1249             TN_DEBUG1( "CThumbAGProcessor::RunL() - cancel processing query" );
  1097             DeleteAndCancelQuery( ETrue );
  1250             DeleteAndCancelQuery( ETrue );
  1098 	        ActivateAO();
  1251 	        ActivateAO();
  1099             return;  
  1252             return;  
  1100             }
  1253             }
  1101         
  1254         
  1111         }
  1264         }
  1112     //waiting for MDS query to complete
  1265     //waiting for MDS query to complete
  1113     else if( iQueryActive )
  1266     else if( iQueryActive )
  1114         {
  1267         {
  1115 		//state mismatch
  1268 		//state mismatch
  1116         if(iForceRun && !iModify)
  1269         if(iForceRun && !(iModify || iUnknown))
  1117             {
  1270             {
  1118 			//cancel query and move items back to original processing queue
  1271 			//cancel query and move items back to original processing queue
  1119             DeleteAndCancelQuery(ETrue);
  1272             DeleteAndCancelQuery(ETrue);
  1120             ActivateAO();
  1273             ActivateAO();
  1121             }
  1274             }
  1122         else  
  1275         else  
  1123             {
  1276             {
  1124             TN_DEBUG1( "CThumbAGProcessor::RunL() - waiting for query to complete, abort..." );
  1277             TN_DEBUG1( "CThumbAGProcessor::RunL() - waiting for query to complete, abort..." );
  1125             }    
  1278             }    
  1126         }
  1279         }
  1127 
  1280     else if ( iUnknownItemCount > 0 )
       
  1281         {
       
  1282         TN_DEBUG1( "void CThumbAGProcessor::RunL() unknown items in queue");
       
  1283         
       
  1284         i2ndRound = EFalse;
       
  1285         iModify = EFalse;
       
  1286         iUnknown = ETrue;
       
  1287         iQueryActive = ETrue;
       
  1288 
       
  1289         QueryL( EGenerationItemActionResolveType );
       
  1290        }
  1128     // no items in query queue, start new
  1291     // no items in query queue, start new
  1129     // select queue to process, priority by type
  1292     // select queue to process, priority by type
  1130     else if ( iModifyQueue.Count() > 0 )
  1293     else if ( iModifyItemCount > 0 )
  1131         {
  1294         {
  1132         TN_DEBUG1( "void CThumbAGProcessor::RunL() update thumbnails");
  1295         TN_DEBUG1( "void CThumbAGProcessor::RunL() update thumbnails");
  1133         
  1296         
  1134         i2ndRound = EFalse;
  1297         i2ndRound = EFalse;
  1135         
  1298         
  1136         // query for object info
  1299         // query for object info
  1137         iQueryActive = ETrue;
  1300         iQueryActive = ETrue;
  1138         iModify = ETrue;
  1301         iModify = ETrue;
  1139         QueryL( iModifyQueue );
  1302         iUnknown = EFalse;
       
  1303         QueryL( EGenerationItemActionModify );
  1140        }
  1304        }
  1141     else if ( iAddQueue.Count() > 0 )
  1305     else if ( iAddItemCount > 0 )
  1142         {
  1306         {
  1143         TN_DEBUG1( "void CThumbAGProcessor::RunL() update 1st round thumbnails");
  1307         TN_DEBUG1( "void CThumbAGProcessor::RunL() update 1st round thumbnails");
  1144         
  1308         
  1145         i2ndRound = EFalse;
  1309         i2ndRound = EFalse;
  1146         
  1310         iUnknown = EFalse;
  1147         // query for object info
  1311         // query for object info
  1148         iQueryActive = ETrue;
  1312         iQueryActive = ETrue;
  1149         
  1313         
  1150         QueryL( iAddQueue );     
  1314         QueryL( EGenerationItemActionAdd );     
  1151         }
  1315         }
  1152     else if ( iRemoveQueue.Count() > 0 )
  1316     else if ( iDeleteItemCount > 0 )
  1153         {
  1317         {
  1154         TN_DEBUG1( "void CThumbAGProcessor::RunL() delete thumbnails");
  1318         TN_DEBUG1( "void CThumbAGProcessor::RunL() delete thumbnails");
  1155 
       
  1156         i2ndRound = EFalse;
  1319         i2ndRound = EFalse;
  1157         
  1320         iUnknown = EFalse;
  1158         // delete thumbs by URI
  1321         // delete thumbs by URI
  1159         __ASSERT_DEBUG((iTMSession), User::Panic(_L("CThumbAGProcessor::RunL() !iTMSession "), KErrBadHandle));
  1322         __ASSERT_DEBUG((iTMSession), User::Panic(_L("CThumbAGProcessor::RunL() !iTMSession "), KErrBadHandle));
  1160         if(iTMSession)
  1323         if(iTMSession)
  1161             {
  1324             {
  1162             HBufC* uri = iRemoveQueue[0];
  1325             TInt itemIndex(KErrNotFound);
  1163             TN_DEBUG2( "void CThumbAGProcessor::RunL() delete %S",  uri);
  1326                                 
  1164             CThumbnailObjectSource* source = NULL;
  1327             for(TInt i=0;i<iGenerationQueue.Count() || itemIndex == KErrNotFound;i++)
  1165             TRAPD(err,  source = CThumbnailObjectSource::NewL( *uri, KNullDesC));
  1328                 {
  1166                
  1329                 if(iGenerationQueue[i].iItemAction == EGenerationItemActionDelete)
  1167         	if(err == KErrNone)
  1330                     {
  1168             	{
  1331                     itemIndex = i;
  1169                 iTMSession->DeleteThumbnails( *source );
  1332                     }
  1170                 }
  1333                 }
  1171             iRemoveQueue.Remove( 0 );
  1334         
  1172             delete source;
  1335             if(itemIndex >= 0)
  1173             delete uri;
  1336                 {
  1174             
  1337                 if(!iGenerationQueue[itemIndex].iUri)
  1175             iActiveCount++;
  1338                     {
  1176             iActive = ETrue;
  1339                     //URI is invalid
  1177             }
  1340                     TN_DEBUG1( "void CThumbAGProcessor::RunL() unable to delete URI inbalid");
  1178         }
  1341                     iGenerationQueue.Remove( itemIndex );
  1179     else if( i2ndRoundGenerateQueue.Count() > 0)
  1342                     ActivateAO();
       
  1343                     return;
       
  1344                     }
       
  1345 
       
  1346                 TN_DEBUG2( "void CThumbAGProcessor::RunL() delete %S",  iGenerationQueue[itemIndex].iUri);
       
  1347                 CThumbnailObjectSource* source = NULL;                
       
  1348                 TRAPD(err,  source = CThumbnailObjectSource::NewL( *iGenerationQueue[itemIndex].iUri, KNullDesC));
       
  1349                    
       
  1350                 if(err == KErrNone)
       
  1351                     {
       
  1352                     iTMSession->DeleteThumbnails( *source );
       
  1353                     }
       
  1354                 delete source;
       
  1355                 
       
  1356                 delete iGenerationQueue[itemIndex].iUri;
       
  1357                 iGenerationQueue[itemIndex].iUri = NULL;
       
  1358                 iGenerationQueue.Remove( itemIndex );
       
  1359                 
       
  1360                 iActiveCount++;
       
  1361                 }
       
  1362             }
       
  1363         }
       
  1364     else if( i2ndAddItemCount > 0)
  1180         {
  1365         {
  1181         TN_DEBUG1( "void CThumbAGProcessor::RunL() update 2nd round thumbnails");
  1366         TN_DEBUG1( "void CThumbAGProcessor::RunL() update 2nd round thumbnails");
  1182             
  1367             
  1183         // query for object info
  1368         // query for object info
  1184         iQueryActive = ETrue;
  1369         iQueryActive = ETrue;
  1185         i2ndRound = ETrue;
  1370         i2ndRound = ETrue;
  1186         QueryL( i2ndRoundGenerateQueue );     
  1371         iUnknown = EFalse;
       
  1372         QueryL( EGenerationItemAction2ndAdd );     
  1187         }
  1373         }
  1188         
  1374         
  1189     TN_DEBUG1( "CThumbAGProcessor::RunL() - end" );
  1375     TN_DEBUG1( "CThumbAGProcessor::RunL() - end" );
  1190     }
  1376     }
  1191 
  1377 
  1210     iProcessingCount = 0;
  1396     iProcessingCount = 0;
  1211     
  1397     
  1212     //move remainig IDs in query queue back to original queue
  1398     //move remainig IDs in query queue back to original queue
  1213     while(iQueryQueue.Count())
  1399     while(iQueryQueue.Count())
  1214         {
  1400         {
  1215         if(aRestoreItems && iLastQueue)
  1401         if(!aRestoreItems )
  1216             {
  1402             {
  1217             if(iLastQueue->FindInOrder(iQueryQueue[0], Compare) == KErrNotFound)
  1403             TThumbnailGenerationItem item;
  1218                 {
  1404             item.iItemId = iQueryQueue[0];
  1219                 //ignore if fails
  1405             TInt itemIndex = iGenerationQueue.FindInOrder(item, Compare);
  1220                 iLastQueue->InsertInOrder(iQueryQueue[0], Compare);
  1406                 
       
  1407             if(itemIndex >= 0)
       
  1408                 {
       
  1409                 delete iGenerationQueue[itemIndex].iUri;
       
  1410                 iGenerationQueue[itemIndex].iUri = NULL;
       
  1411                 iGenerationQueue.Remove(itemIndex);
  1221                 }
  1412                 }
  1222             }
  1413             }
  1223         iQueryQueue.Remove(0);
  1414         iQueryQueue.Remove(0);
  1224         }
  1415         }
  1225     iLastQueue = NULL;
  1416 
  1226     
       
  1227     TN_DEBUG1( "CThumbAGProcessor::DeleteAndCancelQuery() out" );
  1417     TN_DEBUG1( "CThumbAGProcessor::DeleteAndCancelQuery() out" );
  1228     }
  1418     }
  1229 
  1419 
  1230 // ---------------------------------------------------------------------------
  1420 // ---------------------------------------------------------------------------
  1231 // CThumbAGProcessor::DoCancel()
  1421 // CThumbAGProcessor::DoCancel()
  1237     }
  1427     }
  1238 
  1428 
  1239 void CThumbAGProcessor::HarvestingUpdated( 
  1429 void CThumbAGProcessor::HarvestingUpdated( 
  1240          HarvesterEventObserverType aHEObserverType, 
  1430          HarvesterEventObserverType aHEObserverType, 
  1241          HarvesterEventState aHarvesterEventState,
  1431          HarvesterEventState aHarvesterEventState,
  1242          TInt /*aItemsLeft*/ )
  1432          TInt aItemsLeft )
  1243     {
  1433     {
  1244     TN_DEBUG3( "CThumbAGProcessor::HarvestingUpdated -- start() aHEObserverType = %d, aHarvesterEventState = %d", aHEObserverType, aHarvesterEventState );
  1434     TN_DEBUG4( "CThumbAGProcessor::HarvestingUpdated -- start() aHEObserverType = %d, aHarvesterEventState = %d, aItemsLeft = %d", aHEObserverType, aHarvesterEventState, aItemsLeft );
  1245     
  1435     
  1246     if(iShutdown)
  1436 	if(iShutdown)
  1247         {
  1437         {
  1248         return;
  1438         return;
  1249         }
  1439         }
  1250 
  1440 
       
  1441     if(!iHarvesterActivated)
       
  1442         {
       
  1443         iHarvesterActivated = ETrue;
       
  1444         }
       
  1445     
  1251     #ifdef _DEBUG
  1446     #ifdef _DEBUG
  1252     if( aHEObserverType == EHEObserverTypePlaceholder)
  1447     if( aHEObserverType == EHEObserverTypePlaceholder)
  1253         {
  1448         {
  1254         TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- type EHEObserverTypePlaceholder");
  1449         TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- type EHEObserverTypePlaceholder");
  1255         }
  1450         }
  1256     else if( aHEObserverType == EHEObserverTypeOverall)
  1451     else if( aHEObserverType == EHEObserverTypeOverall)
  1257         {
  1452         {
  1258         TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- type EHEObserverTypeOverall");
  1453         TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- type EHEObserverTypeOverall");
       
  1454         }
       
  1455     else if( aHEObserverType == EHEObserverTypeMMC)
       
  1456         {
       
  1457         TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- type EHEObserverTypeMMC");
  1259         }
  1458         }
  1260     #endif
  1459     #endif
  1261     
  1460     
  1262     //placeholder harvesting
  1461     //placeholder harvesting
  1263     if( aHEObserverType == EHEObserverTypePlaceholder)
  1462     if( aHEObserverType == EHEObserverTypePlaceholder)
  1289                 TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS placeholder harvesterin started");
  1488                 TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS placeholder harvesterin started");
  1290                 }
  1489                 }
  1291             else
  1490             else
  1292                 {
  1491                 {
  1293                 TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS placeholder harvesting finished");
  1492                 TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS placeholder harvesting finished");
  1294                 TRAP_IGNORE(QueryPlaceholdersL());
  1493                 //query present placeholders
  1295                 }
  1494                 TRAP_IGNORE(QueryPlaceholdersL( EFalse ));
       
  1495                 iDoQueryAllItems = EFalse;
       
  1496                 iPHHarvestingItemsLeftTemp = 0;
       
  1497                 }
       
  1498             }
       
  1499         
       
  1500         //restart mount timout if PH item count is increasing durin MMC harvesting 
       
  1501         if(iMMCHarvesting && iPHHarvesting && aItemsLeft > iPHHarvestingItemsLeftTemp)
       
  1502           {
       
  1503           //if items count increasing, restart mount timeout 
       
  1504             TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- PH count increasing, restart mount timeout");
       
  1505             
       
  1506            if(iMountTimer->IsActive())
       
  1507               {
       
  1508               iMountTimer->Cancel();
       
  1509               }
       
  1510 
       
  1511             iMountTimer->Start( KMountTimeout, KMountTimeout, TCallBack(MountTimerCallBack, this));
       
  1512           }
       
  1513           
       
  1514         //we are interestead of only PHs during MMC harvesting
       
  1515         if( iMMCHarvesting )
       
  1516             {
       
  1517             iPHHarvestingItemsLeftTemp = aItemsLeft;
  1296             }
  1518             }
  1297         }
  1519         }
  1298     //overall harvesting
  1520     //overall harvesting
  1299     else if ( aHEObserverType == EHEObserverTypeOverall)
  1521     else if ( aHEObserverType == EHEObserverTypeOverall)
  1300         {
  1522         {
  1320             {
  1542             {
  1321             iHarvesting = iHarvestingTemp;
  1543             iHarvesting = iHarvestingTemp;
  1322             
  1544             
  1323             if( iHarvesting )
  1545             if( iHarvesting )
  1324                 {
  1546                 {
  1325                 TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS harvesterin started");
  1547                 TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS harvesting started");
  1326                 CancelTimeout();
  1548                 CancelTimeout();
  1327                 }
  1549                 }
  1328             else
  1550             else
  1329                 {
  1551                 {
  1330                 TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS harvesting finished ");
  1552                 TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS harvesting finished ");
  1331                 // continue processing if needed
  1553                 // continue processing if needed
  1332                 StartTimeout();
  1554                 StartTimeout();
       
  1555                 
       
  1556                 if(iMountTimer->IsActive())
       
  1557                     {
       
  1558                     iMountTimer->Cancel();
       
  1559                     }
  1333                 }
  1560                 }
  1334             }
  1561             }
  1335         }
  1562         }
  1336     //MMC harvesting
  1563     //MMC harvesting
  1337     else if( aHEObserverType == EHEObserverTypeMMC)
  1564     else if( aHEObserverType == EHEObserverTypeMMC)
  1359             iMMCHarvesting = iMMCHarvestingTemp;
  1586             iMMCHarvesting = iMMCHarvestingTemp;
  1360             
  1587             
  1361             if( iMMCHarvesting )
  1588             if( iMMCHarvesting )
  1362                 {
  1589                 {
  1363                 TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS MMC harvesterin started");
  1590                 TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS MMC harvesterin started");
  1364                 if(iPreviousItemsLeft != KErrNotReady)
  1591                 UpdatePSValues(EFalse, ETrue);
       
  1592                 iMMCHarvestingItemsLeftTemp = 0;
       
  1593                 }
       
  1594             else
       
  1595                 {
       
  1596 				//activate timeout if overall harvesting is not active
       
  1597                 if(!iHarvesting)
  1365                     {
  1598                     {
  1366                     iPreviousItemsLeft = KErrNotReady;
  1599                     StartTimeout();
  1367                     RProperty::Set(KTAGDPSNotification, KDaemonProcessing, iPreviousItemsLeft);
  1600                     }
  1368                     }
       
  1369                 }
       
  1370             else
       
  1371                 {
       
  1372                 TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS MMC harvesting finished ");
  1601                 TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS MMC harvesting finished ");
  1373                 }
  1602                 }
  1374             }
  1603             }
       
  1604         
       
  1605         //restart mount timout if MMC item count is still increasing 
       
  1606         if(iMMCHarvesting && aItemsLeft > iMMCHarvestingItemsLeftTemp)
       
  1607             {
       
  1608               TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MMC count increasing, restart mount timeout");
       
  1609               
       
  1610              if(iMountTimer->IsActive())
       
  1611                 {
       
  1612                 iMountTimer->Cancel();
       
  1613                 }
       
  1614 
       
  1615               iMountTimer->Start( KMountTimeout, KMountTimeout, TCallBack(MountTimerCallBack, this));
       
  1616             }
       
  1617         
       
  1618             iMMCHarvestingItemsLeftTemp = aItemsLeft;
  1375         }
  1619         }
  1376    
  1620    
  1377     TN_DEBUG4( "CThumbAGProcessor::HarvestingUpdated -- end() iHarvesting == %d, iPHHarvesting == %d iMMCHarvesting == %d ", iHarvesting, iPHHarvesting, iMMCHarvesting);
  1621     TN_DEBUG4( "CThumbAGProcessor::HarvestingUpdated -- end() iHarvesting == %d, iPHHarvesting == %d iMMCHarvesting == %d ", iHarvesting, iPHHarvesting, iMMCHarvesting);
  1378     }
  1622     }
  1379 
  1623 
  1397 // CThumbAGProcessor::StopTimeout()
  1641 // CThumbAGProcessor::StopTimeout()
  1398 // ---------------------------------------------------------------------------
  1642 // ---------------------------------------------------------------------------
  1399 //
  1643 //
  1400 void CThumbAGProcessor::CancelTimeout()
  1644 void CThumbAGProcessor::CancelTimeout()
  1401     {
  1645     {
       
  1646     TN_DEBUG1( "CThumbAGProcessor::CancelTimeout()");
  1402     if(iPeriodicTimer->IsActive())
  1647     if(iPeriodicTimer->IsActive())
  1403         {
  1648         {
  1404         iPeriodicTimer->Cancel();
  1649         iPeriodicTimer->Cancel();
  1405         }
  1650         }
  1406     }
  1651     }
  1415 TInt CThumbAGProcessor::RunError(TInt /*aError*/)
  1660 TInt CThumbAGProcessor::RunError(TInt /*aError*/)
  1416 #endif
  1661 #endif
  1417     {
  1662     {
  1418     TN_DEBUG2( "CThumbAGrocessor::RunError() %d", aError);
  1663     TN_DEBUG2( "CThumbAGrocessor::RunError() %d", aError);
  1419     
  1664     
  1420     UpdatePSValues();
  1665     UpdatePSValues(EFalse, EFalse);
  1421         
  1666         
  1422     iActiveCount--;
  1667     iActiveCount--;
  1423     
       
  1424     if(iActiveCount <= 0)
       
  1425         {
       
  1426         iActiveCount = 0;
       
  1427         iActive = EFalse;
       
  1428         }
       
  1429     
  1668     
  1430 	ActivateAO();
  1669 	ActivateAO();
  1431 	
  1670 	
  1432     // nothing to do
  1671     // nothing to do
  1433     return KErrNone;
  1672     return KErrNone;
  1437 // CThumbAGProcessor::ActivateAO()
  1676 // CThumbAGProcessor::ActivateAO()
  1438 // ---------------------------------------------------------------------------
  1677 // ---------------------------------------------------------------------------
  1439 //
  1678 //
  1440 void CThumbAGProcessor::ActivateAO()
  1679 void CThumbAGProcessor::ActivateAO()
  1441     {
  1680     {
  1442 #ifdef _DEBUG
  1681     UpdateItemCounts();
  1443     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());
       
  1444     TN_DEBUG2( "CThumbAGProcessor::ActivateAO() items in queue 2nd Add = %d", i2ndRoundGenerateQueue.Count());
       
  1445     TN_DEBUG3( "CThumbAGProcessor::ActivateAO() iActive = %d, iActiveCount = %d", iActive, iActiveCount);
       
  1446     TN_DEBUG3( "CThumbAGProcessor::ActivateAO() iHarvesting == %d, iMPXHarvesting == %d", iHarvesting, iMPXHarvesting);
       
  1447     TN_DEBUG4( "CThumbAGProcessor::ActivateAO() iIdle = %d, timer = %d, iForceRun = %d", iIdle, iPeriodicTimer->IsActive(), iForceRun);
       
  1448     TN_DEBUG4( "CThumbAGProcessor::ActivateAO() iModify = %d, iQueryReady = %d, iProcessingCount = %d", iModify, iQueryReady, iProcessingCount);
       
  1449 #endif
       
  1450     
  1682     
  1451     if(iFormatting)
  1683     if(iFormatting)
  1452         {
  1684         {
  1453         TN_DEBUG1( "CThumbAGProcessor::ActivateAO() - FORMATTING - DAEMON ON PAUSE");
  1685         TN_DEBUG1( "CThumbAGProcessor::ActivateAO() - FORMATTING - DAEMON ON PAUSE");
  1454         return;
  1686         return;
  1455         }
  1687         }
  1456         
  1688     
  1457     //check if forced run needs to continue
  1689     //check if forced run needs to continue
  1458     if (iModifyQueue.Count())
  1690     if ( iModifyItemCount || iUnknownItemCount > 0 )
  1459         {
  1691         {
  1460         SetForceRun( ETrue );
  1692         SetForceRun( ETrue );
  1461         }
  1693         }
  1462     else
  1694     else
  1463         {
  1695         {
  1464         iModify = EFalse;
  1696         iModify = EFalse;
  1465         SetForceRun( EFalse );
  1697         SetForceRun( EFalse );
  1466         }
  1698         }
  1467     
  1699     
  1468     if( !IsActive() && !iShutdown && ((!iActive && !iQueryActive) || iForceRun ))
  1700     if( !IsActive() && !iShutdown && ((iActiveCount == 0 && !iQueryActive) || iForceRun ))
  1469         {
  1701         {
  1470         TN_DEBUG1( "CThumbAGProcessor::ActivateAO() - Activated");
  1702         TN_DEBUG1( "CThumbAGProcessor::ActivateAO() - Activated");
  1471         SetActive();
  1703         SetActive();
  1472         TRequestStatus* statusPtr = &iStatus;
  1704         TRequestStatus* statusPtr = &iStatus;
  1473         User::RequestComplete( statusPtr, KErrNone );
  1705         User::RequestComplete( statusPtr, KErrNone );
  1474         }
  1706         }
  1475 
  1707 
  1476     UpdatePSValues();
  1708     UpdatePSValues(EFalse, EFalse);
  1477     }
  1709     }
  1478 
  1710 
  1479 // ---------------------------------------------------------------------------
  1711 // ---------------------------------------------------------------------------
  1480 // CThumbAGProcessor::PeriodicTimerCallBack()
  1712 // CThumbAGProcessor::PeriodicTimerCallBack()
  1481 // ---------------------------------------------------------------------------
  1713 // ---------------------------------------------------------------------------
  1560 void CThumbAGProcessor::RemoveFromQueues( const RArray<TItemId>& aIDArray, const TBool /*aRemoveFromDelete*/ )
  1792 void CThumbAGProcessor::RemoveFromQueues( const RArray<TItemId>& aIDArray, const TBool /*aRemoveFromDelete*/ )
  1561 #endif
  1793 #endif
  1562     {
  1794     {
  1563     TN_DEBUG2( "CThumbAGProcessor::RemoveFromQueues() aRemoveFromDelete == %d - begin", aRemoveFromDelete );
  1795     TN_DEBUG2( "CThumbAGProcessor::RemoveFromQueues() aRemoveFromDelete == %d - begin", aRemoveFromDelete );
  1564     
  1796     
  1565     TInt itemIndex = KErrNotFound;
  1797     TInt itemIndex(KErrNotFound);
  1566     
  1798     
  1567     for (int i=0; i< aIDArray.Count(); i++)
  1799     for (int i=0; i< aIDArray.Count(); i++)
  1568         {
  1800         {
       
  1801         TThumbnailGenerationItem item;
       
  1802         item.iItemId = aIDArray[i];
  1569         TN_DEBUG2( "CThumbAGProcessor::RemoveFromQueues() - %d", aIDArray[i]);
  1803         TN_DEBUG2( "CThumbAGProcessor::RemoveFromQueues() - %d", aIDArray[i]);
  1570 
  1804 
  1571         itemIndex = iPlaceholderQueue.FindInOrder(aIDArray[i], Compare);                        
  1805         itemIndex = iGenerationQueue.FindInOrder(item, Compare);                        
  1572         if(itemIndex >= 0)
  1806         if(itemIndex >= 0)
  1573             {
  1807             {
  1574             iPlaceholderQueue.Remove(itemIndex);
  1808             delete iGenerationQueue[itemIndex].iUri;
  1575             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iPlaceholderQueue" );
  1809             iGenerationQueue[itemIndex].iUri = NULL;
       
  1810             iGenerationQueue.Remove(itemIndex);
       
  1811             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iGenerationQueue" );
  1576             }
  1812             }
  1577                 
  1813                 
  1578         itemIndex = iAddQueue.FindInOrder(aIDArray[i], Compare);       
  1814         itemIndex = iQueryQueue.FindInOrder(aIDArray[i], CompareId);                    
  1579         if(itemIndex >= 0)
       
  1580             {
       
  1581             iAddQueue.Remove(itemIndex);
       
  1582             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iAddQueue" );
       
  1583             }
       
  1584 
       
  1585         itemIndex = i2ndRoundGenerateQueue.FindInOrder(aIDArray[i], Compare);               
       
  1586         if(itemIndex >= 0)
       
  1587             {
       
  1588             i2ndRoundGenerateQueue.Remove(itemIndex);
       
  1589             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - i2ndRoundGenerateQueue" );
       
  1590             }
       
  1591         
       
  1592         itemIndex = iModifyQueue.FindInOrder(aIDArray[i], Compare);       
       
  1593         if(itemIndex >= 0)
       
  1594             {
       
  1595             iModifyQueue.Remove(itemIndex);
       
  1596             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iModifyQueue" );
       
  1597 			 
       
  1598             if( iModifyQueue.Count() == 0)
       
  1599 			    {
       
  1600 			    SetForceRun( EFalse );
       
  1601 		        }
       
  1602             }
       
  1603             
       
  1604         itemIndex = iQueryQueue.FindInOrder(aIDArray[i], Compare);                    
       
  1605         if(itemIndex >= 0)
  1815         if(itemIndex >= 0)
  1606             {
  1816             {
  1607             iQueryQueue.Remove(itemIndex);
  1817             iQueryQueue.Remove(itemIndex);
  1608             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iQueryQueue" );
  1818             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iQueryQueue" );
  1609             }
  1819             }
  1610          
  1820         }
  1611         itemIndex = iPlaceholderQueue.FindInOrder(aIDArray[i], Compare); 
  1821     
  1612         if(itemIndex >= 0)
  1822     ActivateAO();
  1613         	{
       
  1614             iPlaceholderQueue.Remove(itemIndex);
       
  1615             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iPlaceholderQueue" );
       
  1616             }
       
  1617         }
       
  1618     
  1823     
  1619     TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - end" );
  1824     TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - end" );
  1620     }
  1825     }
  1621 	
  1826 	
  1622 // ---------------------------------------------------------------------------
  1827 // ---------------------------------------------------------------------------
  1672     iQueryAllItems->SetResultMode( EQueryResultModeItem );
  1877     iQueryAllItems->SetResultMode( EQueryResultModeItem );
  1673     
  1878     
  1674     CMdELogicCondition& rootCondition = iQueryAllItems->Conditions();
  1879     CMdELogicCondition& rootCondition = iQueryAllItems->Conditions();
  1675     rootCondition.SetOperator( ELogicConditionOperatorOr );
  1880     rootCondition.SetOperator( ELogicConditionOperatorOr );
  1676     
  1881     
  1677     CMdEObjectCondition& imagePHObjectCondition = rootCondition.AddObjectConditionL(imageObjDef);
  1882     CMdEObjectCondition& imageObjectCondition = rootCondition.AddObjectConditionL(imageObjDef);
  1678     
  1883     
  1679     CMdEObjectCondition& videoPHObjectCondition = rootCondition.AddObjectConditionL(videoObjDef);
  1884     CMdEObjectCondition& videoObjectCondition = rootCondition.AddObjectConditionL(videoObjDef);
  1680     
  1885     
  1681     CMdEObjectCondition& audioPHObjectCondition = rootCondition.AddObjectConditionL(audioObjDef);
  1886     CMdEObjectCondition& audioObjectCondition = rootCondition.AddObjectConditionL(audioObjDef);
  1682     
  1887     
  1683     iQueryAllItems->FindL(KMaxTInt, KMaxQueryItems2);  
  1888     iQueryAllItems->FindL(KMaxTInt, KMaxQueryBatchSize);  
  1684     
  1889     
  1685     TN_DEBUG1( "CThumbAGProcessor::QueryAllItemsL - end" );
  1890     TN_DEBUG1( "CThumbAGProcessor::QueryAllItemsL - end" );
  1686     }
  1891     }
  1687 
  1892 
  1688 // -----------------------------------------------------------------------------
  1893 // -----------------------------------------------------------------------------
  1793         }
  1998         }
  1794     else
  1999     else
  1795         {
  2000         {
  1796         iIdle = ETrue; 
  2001         iIdle = ETrue; 
  1797         
  2002         
  1798         if(iAddQueue.Count() + iModifyQueue.Count() + iRemoveQueue.Count() + 
  2003         if(iGenerationQueue.Count() > 0 )
  1799            iQueryQueue.Count() + i2ndRoundGenerateQueue.Count() > 0 )
       
  1800             {
  2004             {
  1801             ActivateAO();
  2005             ActivateAO();
  1802             }
  2006             }
  1803         }
  2007         }
  1804     }
  2008     }
  1846 // ---------------------------------------------------------------------------
  2050 // ---------------------------------------------------------------------------
  1847 // CThumbAGProcessor::UpdateItemsLeft
  2051 // CThumbAGProcessor::UpdateItemsLeft
  1848 // Update KItemsleft PS value if changed
  2052 // Update KItemsleft PS value if changed
  1849 // ---------------------------------------------------------------------------
  2053 // ---------------------------------------------------------------------------
  1850 //
  2054 //
  1851 void CThumbAGProcessor::UpdatePSValues(const TBool aDefine)
  2055 void CThumbAGProcessor::UpdatePSValues(const TBool aDefine, const TBool aForce)
  1852     {
  2056     {
  1853     TInt itemsLeft = iModifyQueue.Count() + iAddQueue.Count();
  2057     TInt itemsLeft(KErrNotReady);
  1854     TBool daemonProcessing = EFalse;
  2058     TBool daemonProcessing = ETrue;
  1855     
  2059     
  1856     if(iShutdown)
  2060     if(iShutdown)
  1857         {
  2061         {
  1858         RProperty::Set(KTAGDPSNotification, KDaemonProcessing, EFalse);
  2062         RProperty::Set(KTAGDPSNotification, KDaemonProcessing, EFalse);
  1859         RProperty::Set(KTAGDPSNotification, KItemsleft, 0 );
  2063         RProperty::Set(KTAGDPSNotification, KItemsleft, 0 );
  1860         return;
  2064         return;
  1861         }
  2065         }
  1862     
  2066    
  1863     if(itemsLeft + i2ndRoundGenerateQueue.Count() + iRemoveQueue.Count() > 0 )
       
  1864         {
       
  1865         daemonProcessing = ETrue;
       
  1866         }
       
  1867     
       
  1868     //adjust items left to containing also items not yet processed but removed from queue under processing
       
  1869     if((iLastQueue == &iModifyQueue || iLastQueue == &iAddQueue) && !i2ndRound)
       
  1870         {
       
  1871         itemsLeft +=iQueryQueue.Count();
       
  1872         }
       
  1873     
       
  1874     //cancel 2nd round generarion when there is items in 1st round queues
       
  1875     if(itemsLeft && i2ndRound)
       
  1876         {
       
  1877         DeleteAndCancelQuery(ETrue);
       
  1878         i2ndRound = EFalse;
       
  1879         }
       
  1880         
       
  1881     TN_DEBUG2( "CThumbAGProcessor::UpdatePSValues() KItemsleft == %d", itemsLeft);
       
  1882     
       
  1883     if(aDefine)
  2067     if(aDefine)
  1884         {
  2068         {
  1885         TN_DEBUG1( "CThumbAGProcessor::UpdatePSValues() define");
  2069         TInt ret = RProperty::Define(KTAGDPSNotification, KDaemonProcessing, RProperty::EInt);
  1886         RProperty::Define(KTAGDPSNotification, KDaemonProcessing, RProperty::EInt);
  2070         
  1887         RProperty::Set(KTAGDPSNotification, KDaemonProcessing, 0);
  2071         if( ret != KErrNone )
  1888         daemonProcessing = EFalse;
  2072             {
  1889         RProperty::Define(KTAGDPSNotification, KItemsleft, RProperty::EInt);
  2073             TN_DEBUG2( "CThumbAGProcessor::UpdatePSValues() define KDaemonProcessing ret = %d", ret);
  1890         RProperty::Set(KTAGDPSNotification, KItemsleft, 0);
  2074             }
  1891         iPreviousItemsLeft = 0;
  2075 
  1892         }
  2076         ret = RProperty::Define(KTAGDPSNotification, KItemsleft, RProperty::EInt);
  1893     
  2077         
  1894     if( daemonProcessing != iPreviousDaemonProcessing)
  2078         if( ret != KErrNone )
  1895         {
  2079             {
  1896         TN_DEBUG2( "CThumbAGProcessor::UpdatePSValues() update KDaemonProcessing == %d", daemonProcessing);
  2080             TN_DEBUG2( "CThumbAGProcessor::UpdatePSValues() define KItemsleft ret = %d", ret);
  1897         iPreviousDaemonProcessing = daemonProcessing;
  2081             }
  1898         RProperty::Set(KTAGDPSNotification, KDaemonProcessing, daemonProcessing);
  2082         }
  1899         }
  2083     
  1900     
  2084         // set itemsleft = KErrNotReady (-18) and daemonProcessing = ETrue if
  1901     if( itemsLeft != iPreviousItemsLeft)
  2085         // - key is initalized
  1902         {
  2086         // - mount timer is pending
  1903         TN_DEBUG2( "CThumbAGProcessor::UpdatePSValues() update KItemsleft == %d", itemsLeft);
  2087         // - harvester observer is not yet activated
  1904         iPreviousItemsLeft = itemsLeft;
  2088         // - single unknown item exists in processing queue
  1905         RProperty::Set(KTAGDPSNotification, KItemsleft, itemsLeft );
  2089         // - forced
  1906         }
  2090        if( iMountTimer->IsActive() || aForce || aDefine  || iUnknownItemCount
       
  2091                || !iHarvesterActivated  )
       
  2092            {
       
  2093            daemonProcessing = ETrue;
       
  2094            itemsLeft = KErrNotReady;
       
  2095            }
       
  2096        else
       
  2097            {
       
  2098            itemsLeft = iAddItemCount + iModifyItemCount;
       
  2099            }
       
  2100        
       
  2101        TN_DEBUG2( "CThumbAGProcessor::UpdatePSValues() KItemsleft == %d", itemsLeft);
       
  2102            
       
  2103        //cancel 2nd round generarion when there is items in 1st round queues
       
  2104        if(iAddItemCount && i2ndRound)
       
  2105            {
       
  2106            DeleteAndCancelQuery(ETrue);
       
  2107            i2ndRound = EFalse;
       
  2108            }
       
  2109     
       
  2110         if( iGenerationQueue.Count() )
       
  2111             {
       
  2112             daemonProcessing = ETrue;
       
  2113             }
       
  2114         else
       
  2115             {
       
  2116             daemonProcessing = EFalse;
       
  2117             }
       
  2118         
       
  2119         if( daemonProcessing != iPreviousDaemonProcessing)
       
  2120             {
       
  2121             TN_DEBUG2( "CThumbAGProcessor::UpdatePSValues() update KDaemonProcessing == %d", daemonProcessing);
       
  2122             iPreviousDaemonProcessing = daemonProcessing;
       
  2123             TInt ret = RProperty::Set(KTAGDPSNotification, KDaemonProcessing, daemonProcessing);
       
  2124             
       
  2125             if(ret != KErrNone )
       
  2126                 {
       
  2127                 TN_DEBUG3( "CThumbAGProcessor::UpdatePSValues() set KDaemonProcessing %d failed %d", daemonProcessing, ret);
       
  2128                 }
       
  2129             }
       
  2130         
       
  2131         if( itemsLeft != iPreviousItemsLeft)
       
  2132             {
       
  2133             TN_DEBUG2( "CThumbAGProcessor::UpdatePSValues() update KItemsleft == %d", itemsLeft);
       
  2134             iPreviousItemsLeft = itemsLeft;
       
  2135             TInt ret = RProperty::Set(KTAGDPSNotification, KItemsleft, itemsLeft );
       
  2136             
       
  2137             if(ret != KErrNone )
       
  2138                 {
       
  2139                 TN_DEBUG3( "CThumbAGProcessor::UpdatePSValues() set KItemsleft %d failed %d", itemsLeft, ret);
       
  2140                 }
       
  2141             }
       
  2142         
  1907     }
  2143     }
  1908 
  2144 
  1909 // ---------------------------------------------------------------------------
  2145 // ---------------------------------------------------------------------------
  1910 // CThumbAGProcessor::Compare
  2146 // CThumbAGProcessor::Compare
  1911 // Comparison function for logaritmic use of queue arrays
  2147 // Comparison function for logaritmic use of queue arrays
  1912 // ---------------------------------------------------------------------------
  2148 // ---------------------------------------------------------------------------
  1913 //
  2149 //
  1914 TInt CThumbAGProcessor::Compare(const TItemId& aLeft, const TItemId& aRight)
  2150 
       
  2151 TInt CThumbAGProcessor::Compare(const TThumbnailGenerationItem& aLeft, const TThumbnailGenerationItem& aRight)
       
  2152     {  
       
  2153     return (aLeft.iItemId - aRight.iItemId);
       
  2154     }
       
  2155 
       
  2156 TInt CThumbAGProcessor::CompareId(const TItemId& aLeft, const TItemId& aRight)
  1915     {  
  2157     {  
  1916     return (aLeft - aRight);
  2158     return (aLeft - aRight);
  1917     }
  2159     }
  1918 
  2160 
       
  2161 void CThumbAGProcessor::UpdateItemCounts()
       
  2162     {
       
  2163     TN_DEBUG1( "CThumbAGProcessor::UpdateItemCounts()");
       
  2164     iModifyItemCount = 0;
       
  2165     iDeleteItemCount = 0;
       
  2166     iAddItemCount = 0;
       
  2167     iUnknownItemCount = 0;
       
  2168     i2ndAddItemCount = 0;
       
  2169     iPlaceholderItemCount=0;
       
  2170     iCameraItemCount =0;
       
  2171     iImageItemCount=0;
       
  2172     iVideoItemCount=0;
       
  2173     iAudioItemCount=0;
       
  2174     
       
  2175     for(TInt i=0; i < iGenerationQueue.Count(); i++)
       
  2176     {
       
  2177         TThumbnailGenerationItem& item = iGenerationQueue[i];
       
  2178     
       
  2179         if(item.iItemAction == EGenerationItemActionModify)
       
  2180             {
       
  2181             iModifyItemCount++;
       
  2182             }
       
  2183         
       
  2184         if(item.iItemAction == EGenerationItemActionDelete)
       
  2185             {
       
  2186             iDeleteItemCount++;
       
  2187             }
       
  2188         
       
  2189         if(item.iItemType == EGenerationItemTypeUnknown)
       
  2190             {
       
  2191             iUnknownItemCount++;
       
  2192             }
       
  2193         if(item.iItemAction == EGenerationItemAction2ndAdd)
       
  2194             {
       
  2195             i2ndAddItemCount++;
       
  2196             }
       
  2197         if(item.iPlaceholder)
       
  2198             {
       
  2199             iPlaceholderItemCount++;
       
  2200             }
       
  2201         if(item.iItemType == EGenerationItemTypeCamera)
       
  2202             {
       
  2203             iCameraItemCount++;
       
  2204             }
       
  2205         if(item.iItemAction == EGenerationItemActionAdd )
       
  2206             {
       
  2207             iAddItemCount++;
       
  2208             }
       
  2209         if(item.iItemType == EGenerationItemTypeAudio)
       
  2210             {
       
  2211             iAudioItemCount++;
       
  2212             }
       
  2213         if(item.iItemType == EGenerationItemTypeVideo)
       
  2214             {
       
  2215             iVideoItemCount++;
       
  2216             }
       
  2217         if(item.iItemType == EGenerationItemTypeImage)
       
  2218             {
       
  2219             iImageItemCount++;
       
  2220             }
       
  2221     }
       
  2222     
       
  2223     TN_DEBUG2( "CThumbAGProcessor::UpdateItemCounts() iActiveCount = %d", 
       
  2224             iActiveCount);
       
  2225     TN_DEBUG2( "CThumbAGProcessor::UpdateItemCounts() iPreviousItemsLeft = %d", 
       
  2226             iPreviousItemsLeft);
       
  2227     TN_DEBUG5( "CThumbAGProcessor::UpdateItemCounts() iHarvesting == %d, iMMCHarvesting == %d, iPHHarvesting == %d, iMPXHarvesting == %d", 
       
  2228             iHarvesting, iMMCHarvesting, iPHHarvesting, iMPXHarvesting);
       
  2229     TN_DEBUG5( "CThumbAGProcessor::UpdateItemCounts() iIdle = %d, iForegroundRun = %d, timer = %d, iForceRun = %d", 
       
  2230             iIdle, iForegroundRun, iPeriodicTimer->IsActive(), iForceRun);
       
  2231     TN_DEBUG4( "CThumbAGProcessor::UpdateItemCounts() iModify = %d, iQueryReady = %d, iProcessingCount = %d", 
       
  2232             iModify, iQueryReady, iProcessingCount);
       
  2233     TN_DEBUG2( "CThumbAGProcessor::UpdateItemCounts() iMountTimer = %d", iMountTimer->IsActive());
       
  2234     TN_DEBUG3( "CThumbAGProcessor::UpdateItemCounts() iGenerationQueue = %d, iQueryQueue = %d", 
       
  2235             iGenerationQueue.Count(), iQueryQueue.Count());
       
  2236     TN_DEBUG5( "CThumbAGProcessor::UpdateItemCounts() iAddItemCount=%d, i2ndAddItemCount=%d, iModifyItemCount=%d, iDeleteItemCount=%d",
       
  2237             iAddItemCount, i2ndAddItemCount, iModifyItemCount, iDeleteItemCount );
       
  2238     TN_DEBUG3( "CThumbAGProcessor::UpdateItemCounts() iUnknownItemCount=%d, iPlaceholderItemCount=%d",
       
  2239             iUnknownItemCount, iPlaceholderItemCount);
       
  2240     TN_DEBUG4( "CThumbAGProcessor::UpdateItemCounts() iAudioItemCount=%d, iVideoItemCount=%d, iImageItemCount=%d",
       
  2241             iAudioItemCount, iVideoItemCount, iImageItemCount);
       
  2242     TN_DEBUG2( "CThumbAGProcessor::UpdateItemCounts() iCameraItemCount=%d", iCameraItemCount);
       
  2243     
       
  2244     //compress queues when empty
       
  2245     if(!iGenerationQueue.Count())
       
  2246         {
       
  2247         iGenerationQueue.Compress();
       
  2248         }
       
  2249     
       
  2250     if(!iQueryQueue.Count())
       
  2251         {
       
  2252         iQueryQueue.Compress();
       
  2253         }
       
  2254     }
       
  2255 
       
  2256 
       
  2257 // ---------------------------------------------------------------------------
       
  2258 // CThumbAGProcessor::MountTimerCallBack()
       
  2259 // ---------------------------------------------------------------------------
       
  2260 //
       
  2261 TInt CThumbAGProcessor::MountTimerCallBack(TAny* aAny)
       
  2262     {
       
  2263     TN_DEBUG1( "CThumbAGProcessor::MountTimerCallBack()");
       
  2264     CThumbAGProcessor* self = static_cast<CThumbAGProcessor*>( aAny );
       
  2265     
       
  2266     self->iMountTimer->Cancel();
       
  2267     
       
  2268     //activate timeout if overall or mmc harvestig is not active
       
  2269     if(!self->iHarvesting && !self->iMMCHarvesting )
       
  2270         {
       
  2271         self->ActivateAO();
       
  2272         }
       
  2273 
       
  2274     return KErrNone; // Return value ignored by CPeriodic
       
  2275     }
       
  2276 
       
  2277 // ---------------------------------------------------------------------------
       
  2278 // CThumbAGProcessor::SetGenerationItemAction()
       
  2279 // ---------------------------------------------------------------------------
       
  2280 //
       
  2281 void CThumbAGProcessor::SetGenerationItemAction( TThumbnailGenerationItem& aGenerationItem, TThumbnailGenerationItemType aItemType )
       
  2282     {
       
  2283     switch( aItemType )
       
  2284         {
       
  2285         case EGenerationItemTypeAudio:
       
  2286             aGenerationItem.iItemAction = EGenerationItemAction2ndAdd;
       
  2287             break;
       
  2288         case EGenerationItemTypeCamera:
       
  2289             aGenerationItem.iItemAction = EGenerationItemAction2ndAdd;
       
  2290             aGenerationItem.iPlaceholder = ETrue;
       
  2291             break;
       
  2292         case EGenerationItemTypeImage:
       
  2293             aGenerationItem.iItemAction = EGenerationItemActionAdd;
       
  2294             break;
       
  2295         case EGenerationItemTypeVideo:
       
  2296             //S^3 EGenerationItemActionAdd
       
  2297             //S^4 EGenerationItemAction2ndAdd
       
  2298             aGenerationItem.iItemAction = EGenerationItemActionAdd;    
       
  2299             break;
       
  2300         default:
       
  2301             aGenerationItem.iItemAction = EGenerationItemActionResolveType;
       
  2302         }
       
  2303     }
       
  2304 
       
  2305 // ---------------------------------------------------------------------------
       
  2306 // CThumbAGProcessor::SetGenerationItemType()
       
  2307 // ---------------------------------------------------------------------------
       
  2308 //
       
  2309 void CThumbAGProcessor::SetGenerationItemType( TThumbnailGenerationItem& aGenerationItem, const TDefId aDefId )
       
  2310     {
       
  2311         if(aDefId == iImageObjectDef->Id())
       
  2312           {
       
  2313             aGenerationItem.iItemType = EGenerationItemTypeImage;
       
  2314           }
       
  2315       else if(aDefId == iAudioObjectDef->Id())
       
  2316           {
       
  2317           aGenerationItem.iItemType = EGenerationItemTypeAudio;
       
  2318           }
       
  2319       else if(aDefId == iVideoObjectDef->Id())
       
  2320           {
       
  2321           aGenerationItem.iItemType = EGenerationItemTypeVideo;
       
  2322           }
       
  2323       else
       
  2324           {
       
  2325           aGenerationItem.iItemType = EGenerationItemTypeUnknown;
       
  2326           }
       
  2327         
       
  2328         SetGenerationItemAction( aGenerationItem, aGenerationItem.iItemType );
       
  2329     }
       
  2330 
       
  2331 
       
  2332 // -----------------------------------------------------------------------------
       
  2333 // CThumbAGProcessor::AppendProcessingQueue()
       
  2334 // -----------------------------------------------------------------------------
       
  2335 //
       
  2336 void CThumbAGProcessor::AppendProcessingQueue( TThumbnailGenerationItem& item )
       
  2337     {
       
  2338 
       
  2339     TInt itemIndex = iGenerationQueue.FindInOrder( item, Compare );
       
  2340            
       
  2341     if(itemIndex >= 0)
       
  2342        {
       
  2343        iGenerationQueue[itemIndex].iPlaceholder = item.iPlaceholder;
       
  2344        iGenerationQueue[itemIndex].iItemType = item.iItemType;
       
  2345        iGenerationQueue[itemIndex].iItemAction = item.iItemAction;
       
  2346        }
       
  2347     else
       
  2348        {
       
  2349        iGenerationQueue.InsertInOrder(item, Compare);
       
  2350        }
       
  2351     }
       
  2352 
  1919 
  2353 
  1920 // End of file
  2354 // End of file