harvesterplugins/media/mediautils/src/mdeharvester.cpp
changeset 0 ccd0fd43f247
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 harvester utility class
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "mdeharvester.h"
       
    20 
       
    21 // -----------------------------------------------------------------------------
       
    22 // CCPixIndexerUtils::NewL()
       
    23 // -----------------------------------------------------------------------------
       
    24 //
       
    25 CMdeHarvester* CMdeHarvester::NewL(CMdESession* aSession,
       
    26                                    MdeMEdiaObserver* aObserver,
       
    27                                    CMdeObjectQueueManager* aObjJobQueue)
       
    28     {
       
    29     CMdeHarvester* self = CMdeHarvester::NewLC(aSession,aObserver,aObjJobQueue);
       
    30     CleanupStack::Pop(self);
       
    31     return self;
       
    32     }
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CCPixIndexerUtils::NewLC()
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CMdeHarvester* CMdeHarvester::NewLC(CMdESession* aSession,
       
    39                                     MdeMEdiaObserver* aObserver,
       
    40                                     CMdeObjectQueueManager* aObjJobQueue)
       
    41     {
       
    42     CMdeHarvester* self = new (ELeave) CMdeHarvester();
       
    43     CleanupStack::PushL(self);
       
    44     self->ConstructL(aSession,aObserver,aObjJobQueue);
       
    45     return self;
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CCPixIndexerUtils::~CMdeHarvester()
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CMdeHarvester::~CMdeHarvester()
       
    53    {
       
    54    Cancel();
       
    55    delete iWait;
       
    56    delete iQuery;
       
    57    }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CCPixIndexerUtils::ConstructL()
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 void CMdeHarvester::ConstructL(CMdESession* aSession,
       
    64                                MdeMEdiaObserver* aObserver,
       
    65                                CMdeObjectQueueManager* aObjJobQueue)
       
    66     {
       
    67     iSession = aSession;
       
    68     iObserver = aObserver;
       
    69     iJobQueue = aObjJobQueue;
       
    70     iWait = new (ELeave) CActiveSchedulerWait;
       
    71     CActiveScheduler::Add(this);
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CCPixIndexerUtils::CMdeHarvester()
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CMdeHarvester::CMdeHarvester():CActive(CActive::EPriorityStandard)
       
    79     {
       
    80     iCurrentIndex = 0;
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CCPixIndexerUtils::RunL()
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 //from CActive
       
    88 void CMdeHarvester::RunL()
       
    89     {
       
    90     if(KErrNone == iStatus.Int())
       
    91       {
       
    92       HandleNextRequestL();
       
    93       }
       
    94     else
       
    95       {
       
    96       iObserver->HarvestingCompletedL(/*iStatus.Int()*/);//Introduce Error
       
    97       }
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CCPixIndexerUtils::DoCancel()
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 void CMdeHarvester::DoCancel()
       
   105     {
       
   106     
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CCPixIndexerUtils::RunError()
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 TInt CMdeHarvester::RunError()
       
   114     {
       
   115     //@TODO: handle next items here incrementing count index 
       
   116     return KErrNone;
       
   117     }
       
   118    
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CCPixIndexerUtils::handleQueryNewResults()
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void CMdeHarvester::HandleQueryNewResults(CMdEQuery& aQuery,
       
   125                                           TInt aFirstNewItemIndex,
       
   126                                           TInt aNewItemCount)
       
   127     {
       
   128     
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CCPixIndexerUtils::HandleQueryCOmpleted()
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 void CMdeHarvester::HandleQueryCompleted(CMdEQuery& aQuery, TInt aError)
       
   136     {
       
   137     if(aError !=KErrNone)
       
   138         {
       
   139         TInt count = aQuery.Count();
       
   140         }
       
   141     if(iWait->IsStarted()) //Complete in Handle
       
   142         iWait->AsyncStop();
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CCPixIndexerUtils::DoHarvestL()
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void CMdeHarvester::DoHarvesetL(const TDesC& aNameSpaceDef)
       
   150     {
       
   151     iCurrentIndex = 0;
       
   152     QueryAllMediaObjectsL(aNameSpaceDef);
       
   153     }
       
   154    
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CCPixIndexerUtils::QueryAllMediaObjectsL()
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 void CMdeHarvester::QueryAllMediaObjectsL(const TDesC& aNameSpaceDef)
       
   161     {
       
   162     //delete iQuery;
       
   163 	iQuery->Delete(iQuery);
       
   164 	iQuery = NULL;
       
   165     CMdENamespaceDef& defaultNamespaceDef = iSession->GetDefaultNamespaceDefL();
       
   166     CMdEObjectDef& audioObjDef = defaultNamespaceDef.GetObjectDefL(aNameSpaceDef);    
       
   167     // query objects with object definition "Audio" "video" "images" etc..
       
   168     iQuery = iSession->NewObjectQueryL( defaultNamespaceDef, audioObjDef, this );
       
   169     iQuery->FindL();
       
   170     iWait->Start();  //Complete in Handle
       
   171     TInt count = iQuery->Count();
       
   172     CompleteSelf();    
       
   173     }
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // CCPixIndexerUtils::HandleNextRequestL()
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 void CMdeHarvester::HandleNextRequestL()
       
   180     {
       
   181     if(iCurrentIndex < iQuery->Count())
       
   182         {
       
   183         //Get the Object ID and pass to ObjectQueue manager
       
   184         CMdEObject& object = static_cast<CMdEObject&>( iQuery->ResultItem( iCurrentIndex ) );
       
   185         //@TODO: ResultId does'nt work need to check with MDS 
       
   186         //iJobQueue->AddMdeItemToQueueL(iQuery->ResultId(iCurrentIndex),ECPixAddAction);
       
   187         iJobQueue->AddMdeItemToQueueL(object.Id(),ECPixAddAction);
       
   188         iCurrentIndex++;
       
   189         CompleteSelf();
       
   190         }
       
   191     else
       
   192         {
       
   193         iObserver->HarvestingCompletedL();
       
   194         }
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CCPixIndexerUtils::CompleteSelf()
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 void CMdeHarvester::CompleteSelf()
       
   202     {
       
   203     // trigger our RunL
       
   204     TRequestStatus*  caller;
       
   205     caller = &iStatus;
       
   206     iStatus = KRequestPending;
       
   207     User::RequestComplete(caller, KErrNone);
       
   208     SetActive();    
       
   209     }
       
   210 
       
   211 //End of life