45
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2006 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: CMnGeocoder class implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <e32base.h>
|
|
20 |
#include <e32math.h>
|
|
21 |
#include <AknServerApp.h>
|
|
22 |
#include <apaserverapp.h>
|
|
23 |
|
|
24 |
#include <lbsfields.h>
|
|
25 |
#include <lbsfieldids.h>
|
|
26 |
#include <lbsposition.h>
|
|
27 |
|
|
28 |
#include <EPos_CPosLandmark.h>
|
|
29 |
|
|
30 |
#include "mnprovider.h"
|
|
31 |
#include "mngeocodingserviceclient.h"
|
|
32 |
#include "mngeocoder.h"
|
|
33 |
|
|
34 |
// ======== LOCAL FUNCTIONS ========
|
|
35 |
|
|
36 |
// ---------------------------------------------------------------------------
|
|
37 |
// Copies address information (address and building position fields) from
|
|
38 |
// source landmark to target.
|
|
39 |
// ---------------------------------------------------------------------------
|
|
40 |
//
|
|
41 |
void CopyAddressL( CPosLandmark& aSrc, CPosLandmark& aTrg )
|
|
42 |
{
|
|
43 |
// clean address fields (CMnGeocoder says that "all <data> will be updated")
|
|
44 |
for ( TPositionFieldId fieldId = EPositionFieldAddressCapabilitiesBegin + 1;
|
|
45 |
fieldId < EPositionFieldNMEACapabilitiesBegin;
|
|
46 |
fieldId++ )
|
|
47 |
{
|
|
48 |
aTrg.RemovePositionField( fieldId );
|
|
49 |
}
|
|
50 |
|
|
51 |
// copy fields
|
|
52 |
TPositionFieldId fieldId = aSrc.FirstPositionFieldId();
|
|
53 |
while ( fieldId != EPositionFieldNone )
|
|
54 |
{
|
|
55 |
if ( fieldId > EPositionFieldAddressCapabilitiesBegin &&
|
|
56 |
fieldId < EPositionFieldNMEACapabilitiesBegin)
|
|
57 |
{
|
|
58 |
TPtrC field;
|
|
59 |
if ( KErrNone == aSrc.GetPositionField( fieldId, field ) )
|
|
60 |
{
|
|
61 |
aTrg.SetPositionFieldL( fieldId, field );
|
|
62 |
}
|
|
63 |
}
|
|
64 |
fieldId = aSrc.NextPositionFieldId( fieldId );
|
|
65 |
}
|
|
66 |
}
|
|
67 |
|
|
68 |
// ---------------------------------------------------------------------------
|
|
69 |
// Copies coordinate information (locality and coverage) from
|
|
70 |
// source landmark to target. If some fields are empty in source,
|
|
71 |
// they will also be emptied in result.
|
|
72 |
// ---------------------------------------------------------------------------
|
|
73 |
//
|
|
74 |
void CopyCoordinatesL( CPosLandmark& aSrc, CPosLandmark& aTrg )
|
|
75 |
{
|
|
76 |
TLocality loc;
|
|
77 |
TInt posErr = aSrc.GetPosition( loc );
|
|
78 |
if( !posErr )
|
|
79 |
{
|
|
80 |
aTrg.SetPositionL( loc );
|
|
81 |
}
|
|
82 |
|
|
83 |
TRealX nan;
|
|
84 |
nan.SetNaN();
|
|
85 |
TReal32 coverage( nan );
|
|
86 |
|
|
87 |
TInt radiusErr = aSrc.GetCoverageRadius( coverage );
|
|
88 |
if( !radiusErr )
|
|
89 |
{
|
|
90 |
aTrg.SetCoverageRadius( coverage );
|
|
91 |
}
|
|
92 |
|
|
93 |
}
|
|
94 |
|
|
95 |
// ======== MEMBER FUNCTIONS ========
|
|
96 |
|
|
97 |
// ---------------------------------------------------------------------------
|
|
98 |
// ---------------------------------------------------------------------------
|
|
99 |
//
|
|
100 |
CMnGeocoder::CMnGeocoder()
|
|
101 |
{
|
|
102 |
}
|
|
103 |
|
|
104 |
// ---------------------------------------------------------------------------
|
|
105 |
// ---------------------------------------------------------------------------
|
|
106 |
//
|
|
107 |
void CMnGeocoder::ConstructCommonL( CMnProvider& aProvider )
|
|
108 |
{
|
|
109 |
if ( !( aProvider.SupportedServices() & CMnProvider::EServiceGeocoding ) )
|
|
110 |
{
|
|
111 |
User::Leave( KErrNotSupported );
|
|
112 |
}
|
|
113 |
|
|
114 |
iSession = new (ELeave) RMnGeocodingServiceClient;
|
|
115 |
}
|
|
116 |
|
|
117 |
// ---------------------------------------------------------------------------
|
|
118 |
// ---------------------------------------------------------------------------
|
|
119 |
//
|
|
120 |
void CMnGeocoder::ConstructNewL( CMnProvider& aProvider )
|
|
121 |
{
|
|
122 |
ConstructCommonL( aProvider );
|
|
123 |
iSession->ConnectL( aProvider.Uid() );
|
|
124 |
}
|
|
125 |
|
|
126 |
// ---------------------------------------------------------------------------
|
|
127 |
// ---------------------------------------------------------------------------
|
|
128 |
//
|
|
129 |
void CMnGeocoder::ConstructChainedL( CMnProvider& aProvider )
|
|
130 |
{
|
|
131 |
ConstructCommonL( aProvider );
|
|
132 |
iSession->ConnectChainedL( aProvider.Uid() );
|
|
133 |
}
|
|
134 |
|
|
135 |
// ---------------------------------------------------------------------------
|
|
136 |
// ---------------------------------------------------------------------------
|
|
137 |
//
|
|
138 |
EXPORT_C CMnGeocoder* CMnGeocoder::NewL( CMnProvider& aProvider )
|
|
139 |
{
|
|
140 |
CMnGeocoder* self = new (ELeave) CMnGeocoder;
|
|
141 |
CleanupStack::PushL( self );
|
|
142 |
self->ConstructNewL( aProvider );
|
|
143 |
CleanupStack::Pop( self );
|
|
144 |
return self;
|
|
145 |
}
|
|
146 |
|
|
147 |
// ---------------------------------------------------------------------------
|
|
148 |
// ---------------------------------------------------------------------------
|
|
149 |
//
|
|
150 |
EXPORT_C CMnGeocoder* CMnGeocoder::NewChainedL( CMnProvider& aProvider )
|
|
151 |
{
|
|
152 |
CMnGeocoder* self = new (ELeave) CMnGeocoder;
|
|
153 |
CleanupStack::PushL( self );
|
|
154 |
self->ConstructChainedL( aProvider );
|
|
155 |
CleanupStack::Pop( self );
|
|
156 |
return self;
|
|
157 |
}
|
|
158 |
|
|
159 |
// ---------------------------------------------------------------------------
|
|
160 |
// ---------------------------------------------------------------------------
|
|
161 |
//
|
|
162 |
EXPORT_C CMnGeocoder::~CMnGeocoder()
|
|
163 |
{
|
|
164 |
delete iExitMonitor;
|
|
165 |
|
|
166 |
if ( iSession )
|
|
167 |
{
|
|
168 |
iSession->Close();
|
|
169 |
delete iSession;
|
|
170 |
}
|
|
171 |
}
|
|
172 |
|
|
173 |
// ---------------------------------------------------------------------------
|
|
174 |
// ---------------------------------------------------------------------------
|
|
175 |
//
|
|
176 |
EXPORT_C CMnGeocoder::TOptions CMnGeocoder::Options() const
|
|
177 |
{
|
|
178 |
return iOptions;
|
|
179 |
}
|
|
180 |
|
|
181 |
// ---------------------------------------------------------------------------
|
|
182 |
// ---------------------------------------------------------------------------
|
|
183 |
//
|
|
184 |
EXPORT_C void CMnGeocoder::SetOptions( TOptions aOptions )
|
|
185 |
{
|
|
186 |
iOptions = aOptions;
|
|
187 |
}
|
|
188 |
|
|
189 |
// ---------------------------------------------------------------------------
|
|
190 |
// 1. Get result from session in form of landmark
|
|
191 |
// 2. If last request was for address, copy all position fields from
|
|
192 |
// result to target landmark
|
|
193 |
// 3. If last request was for coordinate, copy position data.
|
|
194 |
// ---------------------------------------------------------------------------
|
|
195 |
//
|
|
196 |
EXPORT_C void CMnGeocoder::RetrieveGeocodingResultL( CPosLandmark& aTargetLandmark )
|
|
197 |
{
|
|
198 |
CPosLandmark* lm = NULL;
|
|
199 |
TMnGeocodingResultType resultType;
|
|
200 |
iSession->GetLastResultL( lm, resultType );
|
|
201 |
CleanupStack::PushL( lm );
|
|
202 |
|
|
203 |
switch ( resultType )
|
|
204 |
{
|
|
205 |
case EMnGeoResultAddress:
|
|
206 |
CopyAddressL( *lm, aTargetLandmark );
|
|
207 |
break;
|
|
208 |
case EMnGeoResultCoordinates:
|
|
209 |
CopyCoordinatesL( *lm, aTargetLandmark );
|
|
210 |
break;
|
|
211 |
}
|
|
212 |
CleanupStack::PopAndDestroy( lm );
|
|
213 |
}
|
|
214 |
|
|
215 |
// ---------------------------------------------------------------------------
|
|
216 |
// ---------------------------------------------------------------------------
|
|
217 |
//
|
|
218 |
EXPORT_C void CMnGeocoder::FindCoordinateByAddressL(
|
|
219 |
const CPosLandmark& aLandmark,
|
|
220 |
TRequestStatus& aRequest)
|
|
221 |
{
|
|
222 |
iSession->CoordinateByAddressL( aLandmark, iOptions, aRequest );
|
|
223 |
}
|
|
224 |
|
|
225 |
// ---------------------------------------------------------------------------
|
|
226 |
// ---------------------------------------------------------------------------
|
|
227 |
//
|
|
228 |
EXPORT_C void CMnGeocoder::FindCoordinateByAddressL(
|
|
229 |
const TDesC& aAddress,
|
|
230 |
TRequestStatus& aRequest)
|
|
231 |
{
|
|
232 |
iSession->CoordinateByAddressL( aAddress, iOptions, aRequest );
|
|
233 |
}
|
|
234 |
|
|
235 |
// ---------------------------------------------------------------------------
|
|
236 |
// ---------------------------------------------------------------------------
|
|
237 |
//
|
|
238 |
EXPORT_C void CMnGeocoder::FindAddressByCoordinateL(
|
|
239 |
const CPosLandmark& aLandmark,
|
|
240 |
TRequestStatus& aRequest)
|
|
241 |
{
|
|
242 |
iSession->AddressByCoordinateL( aLandmark, iOptions, aRequest );
|
|
243 |
}
|
|
244 |
|
|
245 |
// ---------------------------------------------------------------------------
|
|
246 |
// ---------------------------------------------------------------------------
|
|
247 |
//
|
|
248 |
EXPORT_C void CMnGeocoder::Cancel()
|
|
249 |
{
|
|
250 |
iSession->Cancel();
|
|
251 |
}
|
|
252 |
// ---------------------------------------------------------------------------
|
|
253 |
// ---------------------------------------------------------------------------
|
|
254 |
//
|
|
255 |
EXPORT_C void CMnGeocoder::SetExitObserverL( MAknServerAppExitObserver& aObserver )
|
|
256 |
{
|
|
257 |
if ( iExitMonitor )
|
|
258 |
{
|
|
259 |
User::Leave( KErrAlreadyExists );
|
|
260 |
}
|
|
261 |
else
|
|
262 |
{
|
|
263 |
iExitMonitor = CApaServerAppExitMonitor::NewL(
|
|
264 |
*iSession, aObserver, CActive::EPriorityStandard );
|
|
265 |
}
|
|
266 |
}
|
|
267 |
|
|
268 |
// ---------------------------------------------------------------------------
|
|
269 |
// ---------------------------------------------------------------------------
|
|
270 |
//
|
|
271 |
EXPORT_C void CMnGeocoder::RemoveExitObserver()
|
|
272 |
{
|
|
273 |
delete iExitMonitor;
|
|
274 |
iExitMonitor = NULL;
|
|
275 |
}
|