|
1 /* |
|
2 * Name : Provider.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 "Provider.h" |
|
16 |
|
17 #include <Hash.h> |
|
18 #include <Uri8.h> |
|
19 |
|
20 #include "Logger.h" |
|
21 |
|
22 /* |
|
23 * Generate a unique id using coordinate and name as seeds |
|
24 * |
|
25 */ |
|
26 |
|
27 TUint32 GenerateIdL(const CPosLandmark& aLandmark) |
|
28 { |
|
29 TPtrC name; |
|
30 aLandmark.GetLandmarkName(name); |
|
31 |
|
32 TLocality coordinate; |
|
33 aLandmark.GetPosition(coordinate); |
|
34 |
|
35 HBufC8* name8 = HBufC8::NewLC(name.Length()); |
|
36 name8->Des().Copy(name); |
|
37 |
|
38 TRealFormat realFormat; |
|
39 realFormat.iPoint = TChar('.'); // Override TLocale::DecimalSeparator() as separator |
|
40 realFormat.iWidth = 8; // Set max width of number |
|
41 realFormat.iPlaces = 5; // Set max width of decimal portion |
|
42 |
|
43 TBuf8<KDefaultRealWidth> latitude; |
|
44 latitude.Num(coordinate.Latitude(), realFormat); |
|
45 |
|
46 TBuf8<KDefaultRealWidth> longitude; |
|
47 longitude.Num(coordinate.Longitude(), realFormat); |
|
48 |
|
49 CSHA1* hash = CSHA1::NewL(); |
|
50 CleanupStack::PushL(hash); |
|
51 hash->Update(*name8); |
|
52 hash->Update(latitude); |
|
53 TPtrC8 result = hash->Final(longitude); |
|
54 |
|
55 const TUint32* ptr = reinterpret_cast<const TUint32*>(result.Ptr()); |
|
56 TUint32 value = *ptr; |
|
57 |
|
58 CleanupStack::PopAndDestroy(2, name8); // hash, name8 |
|
59 |
|
60 return value; |
|
61 } |
|
62 |
|
63 |
|
64 CProvider* CProvider::NewL(const TDesC8& aProviderUri) |
|
65 { |
|
66 CProvider* self = new(ELeave) CProvider; |
|
67 CleanupStack::PushL(self); |
|
68 self->ConstructL(aProviderUri); |
|
69 CleanupStack::Pop(self); |
|
70 |
|
71 return self; |
|
72 } |
|
73 |
|
74 CProvider::~CProvider() |
|
75 { |
|
76 delete iLoader; |
|
77 |
|
78 ReleaseLandmarkResources(); |
|
79 } |
|
80 |
|
81 CProvider::CProvider() |
|
82 {} |
|
83 |
|
84 void CProvider::ConstructL(const TDesC8& aProviderUri) |
|
85 { |
|
86 TUriParser8 uri; |
|
87 uri.Parse(aProviderUri); |
|
88 |
|
89 _LIT8(KHttpScheme, "http"); |
|
90 |
|
91 if (uri.IsSchemeValid() && uri.Extract(EUriScheme).Compare(KHttpScheme) == 0) |
|
92 iLoader = CRemoteLoader::NewL(*this, aProviderUri); |
|
93 else |
|
94 iLoader = CLocalLoader::NewL(*this, aProviderUri); |
|
95 } |
|
96 |
|
97 void CProvider::LandmarkLoaderOpenedL(TInt aError) |
|
98 { |
|
99 if (iObserver) |
|
100 iObserver->POIProviderLoadedL(this, aError); |
|
101 } |
|
102 |
|
103 void CProvider::LandmarkLoaderItemCreatedL(const CPosLandmark& aLandmark) |
|
104 { |
|
105 if (iObserver) |
|
106 { |
|
107 TPosLmItemId id = aLandmark.LandmarkId(); |
|
108 |
|
109 if (id == KPosLmNullItemId) |
|
110 id = GenerateIdL(aLandmark); |
|
111 |
|
112 _LIT8(KObject, "lmx"); |
|
113 OpenMAR::CPOIObject* object = OpenMAR::CPOIObject::NewL(KObject, *this); |
|
114 CleanupStack::PushL(object); |
|
115 |
|
116 object->SetIdentifier(id); |
|
117 |
|
118 TLocality locality; |
|
119 aLandmark.GetPosition(locality); |
|
120 object->SetCoordinate(locality); |
|
121 |
|
122 iObserver->POIObjectCreatedL(object); // Transfers ownership |
|
123 |
|
124 CleanupStack::Pop(object); |
|
125 } |
|
126 } |
|
127 |
|
128 void CProvider::LandmarkLoaderItemUpdatedL(const CPosLandmark& aLandmark) |
|
129 { |
|
130 } |
|
131 |
|
132 void CProvider::LandmarkLoaderItemDeletedL(const CPosLandmark& aLandmark) |
|
133 { |
|
134 } |
|
135 |
|
136 void CProvider::RetrieveL(const TCoordinate& aCoordinate, TReal32 aRadius) |
|
137 { |
|
138 LOGARG("[LANDMARKS] Retrieving landmarks from %f %f %f", aCoordinate.Latitude(), aCoordinate.Longitude(), aCoordinate.Altitude()); |
|
139 |
|
140 iLoader->RequestL(aCoordinate, aRadius); |
|
141 } |