harvesterplugins/media/mediautils/src/mdeobjectqueuemanager.cpp
changeset 0 ccd0fd43f247
child 26 367228f82b66
equal deleted inserted replaced
-1:000000000000 0:ccd0fd43f247
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  MDE object queuemanager for indexing scheduling
       
    15  *
       
    16 */
       
    17 
       
    18 #include "mdeobjectqueuemanager.h"
       
    19 #include "harvesterserverlogger.h"
       
    20 
       
    21 // DEFINES
       
    22 #define INDEXING_QUEUE_MAX 300 // Maximum number of objects in the queue
       
    23 #define INDEXING_DELAY 3000000 // Nano seconds to delay the monitored object
       
    24 #define MAX_RETRY_COUNT    3   //maximum number of retry on not found object
       
    25 
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CCPixIndexerUtils::NewL()
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 CMdeObjectQueueManager* CMdeObjectQueueManager::NewL(MMediaObjectHandler* aHandler)
       
    32     {
       
    33     CMdeObjectQueueManager* self = CMdeObjectQueueManager::NewLC(aHandler);
       
    34     CleanupStack::Pop();
       
    35     return self;
       
    36     }
       
    37 // -----------------------------------------------------------------------------
       
    38 // CCPixIndexerUtils::NewLC()
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CMdeObjectQueueManager* CMdeObjectQueueManager::NewLC(MMediaObjectHandler* aHandler)
       
    42     {
       
    43     CMdeObjectQueueManager* self = new (ELeave) CMdeObjectQueueManager(aHandler);
       
    44     CleanupStack::PushL(self);
       
    45     self->ConstructL();
       
    46     return self;
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CCPixIndexerUtils::~CMdeObjectQueueManager()
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CMdeObjectQueueManager::~CMdeObjectQueueManager()
       
    54     {
       
    55     Cancel();
       
    56     iTimer.Close();
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CCPixIndexerUtils::CMdeObjectQueueManager()
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CMdeObjectQueueManager::CMdeObjectQueueManager(MMediaObjectHandler* aHandler):
       
    64                         CActive(CActive::EPriorityStandard),
       
    65                         iState(EStateNone),
       
    66                         iMdeObjectHandler(aHandler)
       
    67     {
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CCPixIndexerUtils::ConstructL()
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void CMdeObjectQueueManager::ConstructL()
       
    75     {
       
    76     CActiveScheduler::Add(this);
       
    77     User::LeaveIfError(iTimer.CreateLocal());
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CCPixIndexerUtils::AddMdeItemToQueueL()
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CMdeObjectQueueManager::AddMdeItemToQueueL( TItemId aMsgId, 
       
    85                                                  TCPixActionType aActionType)
       
    86     {
       
    87     OverWriteOrAddToQueueL(aMsgId,aActionType);
       
    88     // Check the size against maximum queue size
       
    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     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CCPixIndexerUtils::OverWriteOrAddToQueueL()
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CMdeObjectQueueManager::OverWriteOrAddToQueueL( TItemId aObjId, 
       
   120                                                      TCPixActionType aActionType)
       
   121     {
       
   122     // Overwrite or add the index to the queue
       
   123     TMdeActionRecord object;
       
   124     object.iObjectId = aObjId;
       
   125     object.iAction = aActionType;
       
   126     for (TInt i=0; i<iJobQueue.Count(); i++)
       
   127     {
       
   128         if (iJobQueue[i].iObjectId ==aObjId)
       
   129         {
       
   130             // Older version found
       
   131             iJobQueue[i] = object;
       
   132             return;
       
   133         }
       
   134     }
       
   135     
       
   136     // older not found, append
       
   137     iJobQueue.AppendL(object);    
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CCPixIndexerUtils::RunL()
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CMdeObjectQueueManager::RunL()
       
   145     {
       
   146     CPIXLOGSTRING("START CMdeObjectQueueManager::RunL");
       
   147     while (iJobQueue.Count()>0)
       
   148         {
       
   149         TMdeActionRecord object = iJobQueue[0];
       
   150         //iJobQueue.Remove(0);
       
   151         //Let the indexer handle this object TRAP it as it can leave
       
   152         TRAPD(err,iMdeObjectHandler->HandleMdeItemL(object.iObjectId, object.iAction));
       
   153         /*Process the Item for three time maximum if in case not able to be found from
       
   154           MDS*/
       
   155         if(KErrNone == err)
       
   156             {
       
   157             iJobQueue.Remove(0);
       
   158             }
       
   159         else if(KErrNotFound == err && object.iRetryCount < MAX_RETRY_COUNT)
       
   160                 {
       
   161                 iJobQueue.Remove(0); //remove existing and add new one 
       
   162                 object.iRetryCount++;
       
   163                 iJobQueue.AppendL(object);
       
   164                 CPIXLOGSTRING3("CMdeObjectQueueManager::RunL HandleMdeItemL Item Not found err = %d, iRetry = %d",err,object.iRetryCount); 
       
   165                 }
       
   166         else
       
   167             {
       
   168             iJobQueue.Remove(0);  //retry count exceeded remove it
       
   169             }
       
   170         }
       
   171 #ifdef __PERFORMANCE_DATA
       
   172         iMdeObjectHandler->UpdateLogL();
       
   173 #endif
       
   174         // Everything is indexed no need to be waiting anymore
       
   175         iState = EStateNone;    
       
   176         CPIXLOGSTRING("END CMdeObjectQueueManager::RunL");    
       
   177     }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CCPixIndexerUtils::DoCancel()
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 void CMdeObjectQueueManager::DoCancel()
       
   184     {
       
   185     iTimer.Cancel();
       
   186     iState = EStateNone; 
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CCPixIndexerUtils::RunError()
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 TInt CMdeObjectQueueManager::RunError()
       
   194     {
       
   195     return KErrNone;
       
   196     }
       
   197 //End of file