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