|
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 * Generates a unique id using name and coordinates as a seed |
|
24 */ |
|
25 TUint32 GenerateIdL(const CPosLandmark& aLandmark) |
|
26 { |
|
27 TPtrC name; |
|
28 aLandmark.GetLandmarkName(name); |
|
29 |
|
30 TLocality coordinate; |
|
31 aLandmark.GetPosition(coordinate); |
|
32 |
|
33 HBufC8* name8 = HBufC8::NewLC(name.Length()); |
|
34 name8->Des().Copy(name); |
|
35 |
|
36 TRealFormat realFormat; |
|
37 realFormat.iPoint = TChar('.'); // Override TLocale::DecimalSeparator() as separator |
|
38 realFormat.iWidth = 8; // Set max width of number |
|
39 realFormat.iPlaces = 5; // Set max width of decimal portion |
|
40 |
|
41 TBuf8<KDefaultRealWidth> latitude; |
|
42 latitude.Num(coordinate.Latitude(), realFormat); |
|
43 |
|
44 TBuf8<KDefaultRealWidth> longitude; |
|
45 longitude.Num(coordinate.Longitude(), realFormat); |
|
46 |
|
47 CSHA1* hash = CSHA1::NewL(); |
|
48 CleanupStack::PushL(hash); |
|
49 hash->Update(*name8); |
|
50 hash->Update(latitude); |
|
51 TPtrC8 result = hash->Final(longitude); |
|
52 |
|
53 // Use only 32 bits from hash |
|
54 const TUint32* ptr = reinterpret_cast<const TUint32*>(result.Ptr()); |
|
55 TUint32 value = *ptr; |
|
56 |
|
57 CleanupStack::PopAndDestroy(2, name8); // hash, name8 |
|
58 |
|
59 return value; |
|
60 } |
|
61 |
|
62 // Create instance of concrete ECOM interface implementation |
|
63 CProvider* CProvider::NewL() |
|
64 { |
|
65 CProvider* self = new(ELeave) CProvider(); |
|
66 CleanupStack::PushL(self); |
|
67 self->ConstructL(); |
|
68 CleanupStack::Pop(self); |
|
69 |
|
70 return self; |
|
71 } |
|
72 |
|
73 CProvider::~CProvider() |
|
74 { |
|
75 delete iLoader; |
|
76 } |
|
77 |
|
78 CProvider::CProvider() |
|
79 { |
|
80 } |
|
81 |
|
82 void CProvider::ConstructL() |
|
83 { |
|
84 iLoader = CLoader::NewL(*this); |
|
85 } |
|
86 |
|
87 void CProvider::LandmarkLoaderOpenedL(TInt aError) |
|
88 { |
|
89 if (iObserver) |
|
90 iObserver->POIProviderLoadedL(this, aError); |
|
91 } |
|
92 |
|
93 void CProvider::LandmarkLoaderItemCreatedL(const CPosLandmark& aLandmark) |
|
94 { |
|
95 if (iObserver) |
|
96 { |
|
97 TPosLmItemId id = aLandmark.LandmarkId(); |
|
98 |
|
99 if (id == KPosLmNullItemId) |
|
100 id = GenerateIdL(aLandmark); |
|
101 |
|
102 _LIT8(KObject, "geonames"); |
|
103 OpenMAR::CPOIObject* object = OpenMAR::CPOIObject::NewL(KObject, *this); |
|
104 CleanupStack::PushL(object); |
|
105 |
|
106 object->SetIdentifier(id); |
|
107 |
|
108 TLocality locality; |
|
109 aLandmark.GetPosition(locality); |
|
110 object->SetCoordinate(locality); |
|
111 |
|
112 TPtrC name; |
|
113 aLandmark.GetLandmarkName(name); |
|
114 object->SetNameL(name); |
|
115 |
|
116 iObserver->POIObjectCreatedL(object); // Transfers ownership |
|
117 |
|
118 CleanupStack::Pop(object); |
|
119 } |
|
120 } |
|
121 |
|
122 void CProvider::RetrieveL(const TCoordinate& aCoordinate, TReal32 aRadius) |
|
123 { |
|
124 LOGARG("[GEONAMES] Retrieving entries from %f %f %f", aCoordinate.Latitude(), aCoordinate.Longitude(), aCoordinate.Altitude()); |
|
125 |
|
126 iLoader->RequestL(aCoordinate, aRadius); |
|
127 } |