harvesterplugins/media/mediautils/src/mdeobjectqueuemanager.cpp
changeset 26 367228f82b66
parent 0 ccd0fd43f247
child 27 7a8855317cbd
equal deleted inserted replaced
24:1abfa342db42 26:367228f82b66
    73 //
    73 //
    74 void CMdeObjectQueueManager::ConstructL()
    74 void CMdeObjectQueueManager::ConstructL()
    75     {
    75     {
    76     CActiveScheduler::Add(this);
    76     CActiveScheduler::Add(this);
    77     User::LeaveIfError(iTimer.CreateLocal());
    77     User::LeaveIfError(iTimer.CreateLocal());
       
    78     iHState = EStateResume;
    78     }
    79     }
    79 
    80 
    80 // -----------------------------------------------------------------------------
    81 // -----------------------------------------------------------------------------
    81 // CCPixIndexerUtils::AddMdeItemToQueueL()
    82 // CCPixIndexerUtils::AddMdeItemToQueueL()
    82 // -----------------------------------------------------------------------------
    83 // -----------------------------------------------------------------------------
    83 //
    84 //
    84 void CMdeObjectQueueManager::AddMdeItemToQueueL( TItemId aMsgId, 
    85 void CMdeObjectQueueManager::AddMdeItemToQueueL( TItemId aMsgId, 
    85                                                  TCPixActionType aActionType)
    86                                                  TCPixActionType aActionType)
    86     {
    87     {
    87     OverWriteOrAddToQueueL(aMsgId,aActionType);
    88     OverWriteOrAddToQueueL(aMsgId,aActionType);    
    88     // Check the size against maximum queue size
    89     ActivateAO();
    89     if (iJobQueue.Count() > INDEXING_QUEUE_MAX)
       
    90         {
       
    91         // Maximum is exceeded, force the write immediately
       
    92         if (iState == EStateWaiting)
       
    93             {
       
    94             iTimer.Cancel(); // RunL will be called with iStatus of KErrCancelled
       
    95             }
       
    96         else if (iState == EStateNone)
       
    97             {
       
    98             SetActive();
       
    99             TRequestStatus* status = &iStatus;
       
   100             User::RequestComplete(status, KErrNone); // RunL will be called with iStatus of KErrNone
       
   101             }
       
   102         }
       
   103         else
       
   104         {
       
   105             // Maximum is not exceeded, keep waiting
       
   106             if (iState == EStateNone)
       
   107             {
       
   108             iState = EStateWaiting;
       
   109             iTimer.After(iStatus, INDEXING_DELAY); // Wait 5 seconds before putting this to index
       
   110             SetActive();
       
   111             }
       
   112         }
       
   113     }
    90     }
   114 
    91 
   115 // -----------------------------------------------------------------------------
    92 // -----------------------------------------------------------------------------
   116 // CCPixIndexerUtils::OverWriteOrAddToQueueL()
    93 // CCPixIndexerUtils::OverWriteOrAddToQueueL()
   117 // -----------------------------------------------------------------------------
    94 // -----------------------------------------------------------------------------
   135     
   112     
   136     // older not found, append
   113     // older not found, append
   137     iJobQueue.AppendL(object);    
   114     iJobQueue.AppendL(object);    
   138     }
   115     }
   139 
   116 
       
   117 void CMdeObjectQueueManager::ActivateAO()
       
   118     {
       
   119     // Proceed only if the plugin is not in pause state 
       
   120     if ( iHState == EStateResume )
       
   121         {
       
   122         // Check the size against maximum queue size
       
   123         if (iJobQueue.Count() > INDEXING_QUEUE_MAX)
       
   124             {
       
   125             // Maximum is exceeded, force the write immediately
       
   126             if (iState == EStateWaiting)
       
   127                 {
       
   128                 iTimer.Cancel(); // RunL will be called with iStatus of KErrCancelled
       
   129                 }
       
   130             else if (iState == EStateNone)
       
   131                 {
       
   132                 SetActive();
       
   133                 TRequestStatus* status = &iStatus;
       
   134                 User::RequestComplete(status, KErrNone); // RunL will be called with iStatus of KErrNone
       
   135                 }
       
   136             }
       
   137         else
       
   138             {
       
   139             // Maximum is not exceeded, keep waiting
       
   140             if (iState == EStateNone)
       
   141                 {
       
   142                 iState = EStateWaiting;
       
   143                 iTimer.After(iStatus, INDEXING_DELAY); // Wait 5 seconds before putting this to index
       
   144                 SetActive();
       
   145                 }
       
   146             }
       
   147         }
       
   148     }
   140 // -----------------------------------------------------------------------------
   149 // -----------------------------------------------------------------------------
   141 // CCPixIndexerUtils::RunL()
   150 // CCPixIndexerUtils::RunL()
   142 // -----------------------------------------------------------------------------
   151 // -----------------------------------------------------------------------------
   143 //
   152 //
   144 void CMdeObjectQueueManager::RunL()
   153 void CMdeObjectQueueManager::RunL()
   145     {
   154     {
   146     CPIXLOGSTRING("START CMdeObjectQueueManager::RunL");
   155     CPIXLOGSTRING("START CMdeObjectQueueManager::RunL");
   147     while (iJobQueue.Count()>0)
   156     
       
   157     if ( iHState == EStatePause )
       
   158         {
       
   159         iState = EStateNone;
       
   160         CPIXLOGSTRING("END CMdeObjectQueueManager::RunL as Harvester in Pause state");  
       
   161         return;          
       
   162         }
       
   163     while (iJobQueue.Count()>0 )
   148         {
   164         {
   149         TMdeActionRecord object = iJobQueue[0];
   165         TMdeActionRecord object = iJobQueue[0];
   150         //iJobQueue.Remove(0);
   166         //iJobQueue.Remove(0);
   151         //Let the indexer handle this object TRAP it as it can leave
   167         //Let the indexer handle this object TRAP it as it can leave
   152         TRAPD(err,iMdeObjectHandler->HandleMdeItemL(object.iObjectId, object.iAction));
   168         TRAPD(err,iMdeObjectHandler->HandleMdeItemL(object.iObjectId, object.iAction));
   192 //
   208 //
   193 TInt CMdeObjectQueueManager::RunError()
   209 TInt CMdeObjectQueueManager::RunError()
   194     {
   210     {
   195     return KErrNone;
   211     return KErrNone;
   196     }
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CCPixIndexerUtils::PauseL()
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 void CMdeObjectQueueManager::PauseL()
       
   219     {
       
   220     iHState = EStatePause;
       
   221     }
       
   222 // -----------------------------------------------------------------------------
       
   223 // CCPixIndexerUtils::ResumeL()
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 void CMdeObjectQueueManager::ResumeL()
       
   227     {
       
   228     iHState = EStateResume;
       
   229     ActivateAO();       
       
   230     }
       
   231 
   197 //End of file
   232 //End of file