harvesterplugins/media/mediautils/src/mdsmediamonitor.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 media monitor utility
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "mdsmediamonitor.h"
       
    20 #include <mdesession.h>
       
    21 #include <mdelogiccondition.h>
       
    22 #include <mdeconstants.h>
       
    23 #include "mdeobjectqueuemanager.h"
       
    24 #include "common.h"
       
    25 #include "harvesterserverlogger.h"
       
    26 
       
    27 
       
    28 namespace
       
    29     {
       
    30 // -----------------------------------------------------------------------------
       
    31 // CCPixIndexerUtils::GetCpixAction()
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34     TCPixActionType GetCpixAction(TObserverNotificationType aType)
       
    35         {
       
    36         TCPixActionType action( ECPixAddAction );//Initializing to silence compiler warning. 
       
    37         switch(aType)
       
    38             {
       
    39             case ENotifyAdd:
       
    40                 action = ECPixAddAction;
       
    41                 break;
       
    42             case ENotifyModify:
       
    43                 action = ECPixUpdateAction;
       
    44                 break;
       
    45             case ENotifyRemove:
       
    46                 action = ECPixRemoveAction;
       
    47                 break;
       
    48             default:
       
    49                 break;
       
    50             }
       
    51         return action;
       
    52         }
       
    53     };
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CCPixIndexerUtils::NewL()
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CMdsMediaMonitor* CMdsMediaMonitor::NewL(CMdESession* aSession,CMdeObjectQueueManager* aJobQueue)
       
    60     {
       
    61     CMdsMediaMonitor* self = CMdsMediaMonitor::NewLC(aSession,aJobQueue);
       
    62     CleanupStack::Pop(self);
       
    63     return self;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CCPixIndexerUtils::NewLC()
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CMdsMediaMonitor* CMdsMediaMonitor::NewLC(CMdESession* aSession,CMdeObjectQueueManager* aJobQueue)
       
    71     {
       
    72     CMdsMediaMonitor* self = new (ELeave) CMdsMediaMonitor(aSession,aJobQueue);
       
    73     CleanupStack::PushL(self);
       
    74     self->ConstructL();
       
    75     return self;
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CCPixIndexerUtils::~CMdsMediaMonitor()
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CMdsMediaMonitor::~CMdsMediaMonitor()
       
    83     {
       
    84     
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CCPixIndexerUtils::CMdsMediaMonitor()
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 CMdsMediaMonitor::CMdsMediaMonitor(CMdESession* aSession,
       
    92                                    CMdeObjectQueueManager* aJobQueue):
       
    93                                    iMdsSession(aSession),
       
    94                                    iMdeObjectQueueManager(aJobQueue)
       
    95     {
       
    96     
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CCPixIndexerUtils::ConstructL()
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CMdsMediaMonitor::ConstructL()
       
   104     {
       
   105     
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CCPixIndexerUtils::StartMonitoringL()
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CMdsMediaMonitor::StartMonitoringL(const TDesC& aNameSpaceDef)
       
   113     {
       
   114     CMdELogicCondition* condition = CMdELogicCondition::NewL( ELogicConditionOperatorAnd );
       
   115     CleanupStack::PushL( condition );
       
   116     CMdENamespaceDef& defaultNamespace = iMdsSession->GetDefaultNamespaceDefL();
       
   117     CMdEObjectDef& audioObjDef = defaultNamespace.GetObjectDefL(aNameSpaceDef );
       
   118     condition->AddObjectConditionL( audioObjDef );
       
   119     //Start receiveing events for Audio objects
       
   120     iMdsSession->AddObjectObserverL( *this, condition);
       
   121     iMdsSession->AddObjectPresentObserverL( *this );
       
   122     CleanupStack::Pop(condition);
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CCPixIndexerUtils::StopMonitoringL()
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 void CMdsMediaMonitor::StopMonitoringL()
       
   130     {
       
   131     if(iMdsSession)
       
   132         {
       
   133         iMdsSession->RemoveObjectObserverL(*this,&iMdsSession->GetDefaultNamespaceDefL());
       
   134         }
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CCPixIndexerUtils::HandleObjectNotification()
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CMdsMediaMonitor::HandleObjectNotification(CMdESession& aSession, 
       
   142                             TObserverNotificationType aType,
       
   143                             const RArray<TItemId>& aObjectIdArray)
       
   144     {
       
   145     /*Bhuvi: Observed when MMC card removed and inserted back the Add event
       
   146     Comes we have to reharvest if in case media is MMC card this way the
       
   147     search results are acqurate and also index is synchronized*/
       
   148     CPIXLOGSTRING2("CMdsMediaMonitor::HandleObjectNotification ActionType = %d",aType);
       
   149     TCPixActionType action = GetCpixAction(aType);
       
   150     //handle items here push it to Queue manager
       
   151     for (TInt i=0;i<aObjectIdArray.Count();i++)
       
   152         {
       
   153         TItemId objectId = aObjectIdArray[i];
       
   154         TRAP_IGNORE( iMdeObjectQueueManager->AddMdeItemToQueueL(objectId,action) );
       
   155         }
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CCPixIndexerUtils::HandleObjectPresentNotification()
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 void CMdsMediaMonitor::HandleObjectPresentNotification(CMdESession& aSession, 
       
   163                 TBool aPresent, const RArray<TItemId>& aObjectIdArray)
       
   164     {
       
   165     CPIXLOGSTRING2("CMdsMediaMonitor::HandleObjectPresentNotification aPresent = %d",aPresent);
       
   166     //Handle only Presence true events 
       
   167     if(aPresent)
       
   168         {
       
   169         CPIXLOGSTRING("CMdsMediaMonitor::HandleObjectPresentNotification Add Actions");
       
   170         // Add in the queue for Addition
       
   171         for (TInt i=0;i<aObjectIdArray.Count();i++)
       
   172             {
       
   173             TItemId objectId = aObjectIdArray[i];
       
   174             TRAP_IGNORE( iMdeObjectQueueManager->AddMdeItemToQueueL(objectId,ECPixAddAction) );
       
   175             }
       
   176         }
       
   177     //Dont handle presence false notification for performance as it is only for MMC items
       
   178     /*
       
   179     else
       
   180         {
       
   181         CPIXLOGSTRING("CMdsMediaMonitor::HandleObjectPresentNotification remove Actions");
       
   182         // Add in the queue for removal
       
   183         for (TInt i=0;i<aObjectIdArray.Count();i++)
       
   184             {
       
   185             TItemId objectId = aObjectIdArray[i];
       
   186             iMdeObjectQueueManager->AddMdeItemToQueueL(objectId,ECPixRemoveAction);
       
   187             }
       
   188         }
       
   189     */
       
   190     }
       
   191 
       
   192 //End of File