plugin/poi/landmarks/provider/src/Local.cpp
changeset 0 c316ab048e9d
equal deleted inserted replaced
-1:000000000000 0:c316ab048e9d
       
     1 /*
       
     2  * Name        : Local.cpp
       
     3  * Description : 
       
     4  * Project     : This file is part of OpenMAR, an Open Mobile Augmented Reality browser
       
     5  * Website     : http://OpenMAR.org
       
     6  *
       
     7  * Copyright (c) 2010 David Caabeiro
       
     8  *
       
     9  * All rights reserved. This program and the accompanying materials are made available 
       
    10  * under the terms of the Eclipse Public License v1.0 which accompanies this 
       
    11  * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
       
    12  *
       
    13  */
       
    14 
       
    15 #include "Local.h"
       
    16 
       
    17 #include <EPos_CPosLandmarkDatabase.h>
       
    18 #include <LbsPositionInfo.h>
       
    19 
       
    20 #include "Logger.h"
       
    21 
       
    22 CLocalLoader* CLocalLoader::NewL(MLandmarkLoaderObserver& aObserver, const TDesC8& aProviderUri)
       
    23 {
       
    24     CLocalLoader* self = new(ELeave) CLocalLoader(aObserver);
       
    25     CleanupStack::PushL(self);
       
    26     self->ConstructL(aProviderUri);
       
    27     CleanupStack::Pop(self);
       
    28 
       
    29     return self;
       
    30 }
       
    31 
       
    32 CLocalLoader::~CLocalLoader()
       
    33 {
       
    34     Cancel();
       
    35 
       
    36     delete iLandmarkDb;
       
    37 }
       
    38 
       
    39 CLocalLoader::CLocalLoader(MLandmarkLoaderObserver& aObserver)
       
    40     : CActive(CActive::EPriorityStandard), iObserver(aObserver)
       
    41 {
       
    42     CActiveScheduler::Add(this);
       
    43 }
       
    44 
       
    45 void CLocalLoader::ConstructL(const TDesC8& aProviderUri)
       
    46 {
       
    47     LOGARG("[LANDMARKS] Creating local landmark loader: %S", &aProviderUri);
       
    48 
       
    49     HBufC* uri = HBufC::NewLC(aProviderUri.Length());
       
    50     uri->Des().Copy(aProviderUri);
       
    51 
       
    52 //    iLandmarkDb = CPosLandmarkDatabase::OpenL(*uri);
       
    53     iLandmarkDb = CPosLandmarkDatabase::OpenL();
       
    54 
       
    55     CleanupStack::PopAndDestroy(uri);
       
    56 
       
    57     CPosLmOperation* initialization = iLandmarkDb->InitializeL();
       
    58     ExecuteAndDeleteLD(initialization);
       
    59 
       
    60     iLandmarkDb->NotifyDatabaseEvent(iEvent, iStatus);
       
    61     SetActive();
       
    62 }
       
    63 
       
    64 void CLocalLoader::RunL()
       
    65 {
       
    66     LOGARG("[LANDMARKS] Landmark event %d", iEvent.iEventType);
       
    67 
       
    68     if (iStatus == KErrNone)
       
    69         switch (iEvent.iEventType)
       
    70         {
       
    71             case EPosLmEventLandmarkCreated:
       
    72             {
       
    73                 LOGTXT("[LANDMARKS] Got new landmark. Notifying observer");
       
    74 
       
    75                 CPosLandmark* landmark = iLandmarkDb->ReadLandmarkLC(iEvent.iLandmarkItemId);
       
    76                 iObserver.LandmarkLoaderItemCreatedL(*landmark);
       
    77                 CleanupStack::PopAndDestroy(landmark);
       
    78 
       
    79                 break;
       
    80             }
       
    81 
       
    82             case EPosLmEventLandmarkUpdated:
       
    83             {
       
    84                 LOGTXT("[LANDMARKS] Got updated landmark. Notifying observer");
       
    85 
       
    86                 CPosLandmark* landmark = iLandmarkDb->ReadLandmarkLC(iEvent.iLandmarkItemId);
       
    87                 iObserver.LandmarkLoaderItemUpdatedL(*landmark);
       
    88                 CleanupStack::PopAndDestroy(landmark);
       
    89 
       
    90                 break;
       
    91             }
       
    92 
       
    93             case EPosLmEventLandmarkDeleted:
       
    94             {
       
    95                 LOGTXT("[LANDMARKS] Landmark was deleted. Notifying observer");
       
    96 
       
    97                 CPosLandmark* landmark = CPosLandmark::NewLC();
       
    98 //                landmark->SetLandmarkIdL(iEvent.iLandmarkItemId);
       
    99                 iObserver.LandmarkLoaderItemDeletedL(*landmark);
       
   100                 CleanupStack::PopAndDestroy(landmark);
       
   101 
       
   102                 break;
       
   103             }
       
   104 
       
   105             case EPosLmEventNewDefaultDatabaseLocation:
       
   106             case EPosLmEventMediaRemoved:
       
   107             default:
       
   108                 break;
       
   109         }
       
   110 
       
   111     iLandmarkDb->NotifyDatabaseEvent(iEvent, iStatus);
       
   112     SetActive();
       
   113 }
       
   114 
       
   115 void CLocalLoader::DoCancel()
       
   116 {
       
   117     iLandmarkDb->CancelNotifyDatabaseEvent();
       
   118 }
       
   119 
       
   120 void CLocalLoader::RequestL(const TCoordinate& aCoordinate, TReal32 aRadius)
       
   121 {
       
   122     iObserver.LandmarkLoaderOpenedL(KErrNone);
       
   123 
       
   124     // TODO: Should use CPosLmAreaCriteria to filter
       
   125 
       
   126     CPosLmItemIterator* landmarkIterator = iLandmarkDb->LandmarkIteratorL();
       
   127     CleanupStack::PushL(landmarkIterator);
       
   128 
       
   129     for (TPosLmItemId id = landmarkIterator->NextL();
       
   130             id != KPosLmNullItemId;
       
   131             id = landmarkIterator->NextL())
       
   132     {
       
   133         CPosLandmark* landmark = iLandmarkDb->ReadLandmarkLC(id);
       
   134         iObserver.LandmarkLoaderItemCreatedL(*landmark);
       
   135         CleanupStack::PopAndDestroy(landmark);
       
   136     }
       
   137 
       
   138     CleanupStack::PopAndDestroy(landmarkIterator);
       
   139 }