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: ÑTestProviderMapViewServiceBase class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <eikenv.h> |
|
21 #include <w32std.h> |
|
22 #include <e32property.h> |
|
23 |
|
24 #include <lbsposition.h> |
|
25 |
|
26 #include <epos_cposlandmark.h> |
|
27 #include <epos_cposlandmarkdatabase.h> |
|
28 |
|
29 #include "debug.h" |
|
30 #include <mnmapviewservicebase.h> |
|
31 |
|
32 #include "testproviderappui.h" |
|
33 #include "testprovidermapview.h" |
|
34 #include "testproviderappserver.h" |
|
35 #include "testproviderdump.h" |
|
36 |
|
37 #include "testprovidermapviewservice.h" |
|
38 |
|
39 const TTimeIntervalMicroSeconds32 KProcessingDelay = 200 * 1000; |
|
40 |
|
41 // ======== MEMBER FUNCTIONS ======== |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CTestProviderMapViewService* CTestProviderMapViewService::NewL() |
|
47 { |
|
48 CTestProviderMapViewService* self = new (ELeave) CTestProviderMapViewService(); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL(); |
|
51 CleanupStack::Pop( self ); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 CTestProviderMapViewService::CTestProviderMapViewService() |
|
59 { |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 CTestProviderMapViewService::~CTestProviderMapViewService() |
|
66 { |
|
67 delete iLandmark; |
|
68 if ( iProcessor ) |
|
69 { |
|
70 iProcessor->Cancel(); |
|
71 delete iProcessor; |
|
72 } |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 void CTestProviderMapViewService::ConstructL() |
|
79 { |
|
80 BaseConstructL(); |
|
81 iProcessor = CPeriodic::NewL( CActive::EPriorityIdle ); |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 void CTestProviderMapViewService::LeaveIfBusyL() |
|
88 { |
|
89 if ( iProcessor->IsActive() ) |
|
90 { |
|
91 LOG("CTestProviderMapViewService::LeaveIfBusyL BUSY"); |
|
92 User::Leave( KErrInUse ); |
|
93 } |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 void CTestProviderMapViewService::LeaveIfInstructedL() |
|
100 { |
|
101 RProperty property; |
|
102 TInt code = KErrNone; |
|
103 TInt err = property.Get( TUid::Uid( KPropCategoryUid ), KPropKeyErrorCode, code ); |
|
104 if ( err == KErrNone ) |
|
105 { |
|
106 User::LeaveIfError( code ); |
|
107 } |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 void CTestProviderMapViewService::StartProcessingL() |
|
114 { |
|
115 iProcessor->Start( KProcessingDelay, KProcessingDelay, |
|
116 TCallBack( CTestProviderMapViewService::SelectionIdleCallBack, this ) ); |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 TInt CTestProviderMapViewService::SelectionIdleCallBack( TAny* aPtr ) |
|
123 { |
|
124 CTestProviderMapViewService* self = |
|
125 static_cast<CTestProviderMapViewService*> ( aPtr ); |
|
126 |
|
127 TRAP_IGNORE( self->HandleSelectionL() ); |
|
128 return EFalse; |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 void CTestProviderMapViewService::HandleSelectionL() |
|
135 { |
|
136 if ( GetTestCommand() != EServerActionDelayCompletion ) |
|
137 { |
|
138 iProcessor->Cancel(); |
|
139 TInt err = KErrNone; |
|
140 TRAP( err, DoSelectionL() ); |
|
141 if ( err ) |
|
142 { |
|
143 CompleteRequest( err ); |
|
144 } |
|
145 } |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // --------------------------------------------------------------------------- |
|
150 // |
|
151 TInt CTestProviderMapViewService::GetTestCommand() |
|
152 { |
|
153 CTestProviderAppServer* server = (CTestProviderAppServer*) Server(); |
|
154 TInt command = server->GetTestCommand(); |
|
155 return command; |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 void CTestProviderMapViewService::HandleTestCommandL( TInt aCommand ) |
|
162 { |
|
163 LOG1("CTestProviderMapViewService::HandleTestCommandL in, %d", aCommand ); |
|
164 switch ( aCommand ) |
|
165 { |
|
166 case EServerActionBaseComplete: |
|
167 CompleteRequest( KErrCompletion ); |
|
168 break; |
|
169 |
|
170 case EServerActionCompleteSelectionFree: |
|
171 { |
|
172 CPosLandmark* lm = CPosLandmark::NewLC(); |
|
173 CompleteSelectionRequestL( *lm ); |
|
174 CleanupStack::PopAndDestroy( lm ); |
|
175 } |
|
176 break; |
|
177 |
|
178 case EServerActionCompleteSelectionIndex: |
|
179 CompleteSelectionRequest( 0 ); |
|
180 break; |
|
181 |
|
182 case EServerActionCompleteSelectionNegativeIndex: |
|
183 CompleteSelectionRequest( -1 ); |
|
184 break; |
|
185 |
|
186 case EServerActionCompleteSelectionLinked: |
|
187 CompleteSelectionRequest( 0, 1 ); |
|
188 break; |
|
189 |
|
190 case EServerActionCompleteSelectionWrongLinked: |
|
191 CompleteSelectionRequest( 0, 1000 ); |
|
192 break; |
|
193 |
|
194 case EServerActionCompleteSelectionNegativeDbIndex: |
|
195 CompleteSelectionRequest( 0, -1 ); |
|
196 break; |
|
197 |
|
198 default: |
|
199 break; |
|
200 } |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------------------------- |
|
204 // --------------------------------------------------------------------------- |
|
205 // |
|
206 void CTestProviderMapViewService::DoSelectionL() |
|
207 { |
|
208 LOG("DoSelectionL in"); |
|
209 |
|
210 HandleTestCommandL( GetTestCommand() ); |
|
211 |
|
212 if ( Options() & CMnMapView::EOptionRestrictSelection ) |
|
213 { |
|
214 LOG("MnTestProvider::HandleSelectFromMapL restricted"); |
|
215 if ( LandmarksToShowDatabases().Count() && |
|
216 LinkedLandmarksToShow( 0 ).Count() ) |
|
217 { |
|
218 LOG("HandleSelectFromMapL taking first linked"); |
|
219 |
|
220 // take first linked landmark from first database |
|
221 TInt dbIndex = 0; |
|
222 TPosLmItemId lmId = LinkedLandmarksToShow( dbIndex )[0]; |
|
223 CompleteSelectionRequest( lmId, dbIndex ); |
|
224 } |
|
225 else if ( LandmarksToShow().Count() ) |
|
226 { |
|
227 LOG("HandleSelectFromMapL taking first not linked"); |
|
228 // take first not linked landmark |
|
229 CompleteSelectionRequest( 0 ); |
|
230 } |
|
231 else |
|
232 { |
|
233 LOG("HandleSelectFromMapL restricted, but no landmarks"); |
|
234 // this shall never happen, because base implementation |
|
235 // will check that landmarks are given if selection is restricted |
|
236 User::Leave( KErrArgument ); |
|
237 } |
|
238 } |
|
239 else |
|
240 { |
|
241 // return random landmark |
|
242 LOG("HandleSelectFromMapL returning random"); |
|
243 CPosLandmark* lm = CPosLandmark::NewLC(); |
|
244 |
|
245 _LIT( KSelected, "RandomLandmark" ); |
|
246 lm->SetLandmarkNameL( KSelected ); |
|
247 |
|
248 // north pole |
|
249 lm->SetPositionL( TLocality( TCoordinate( -90, 0 ), 0 ) ); |
|
250 |
|
251 CompleteSelectionRequestL( *lm ); |
|
252 CleanupStack::PopAndDestroy( lm ); |
|
253 } |
|
254 LOG("DoSelectionL out"); |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // --------------------------------------------------------------------------- |
|
259 // |
|
260 void CTestProviderMapViewService::DumpDataL() |
|
261 { |
|
262 LOG("DumpDataL in"); |
|
263 if ( GetTestCommand() == EServerActionDisableDump ) |
|
264 { |
|
265 LOG("DumpDataL disabled, out"); |
|
266 return; |
|
267 } |
|
268 |
|
269 CTestProviderDump* dump = CTestProviderDump::NewLC(); |
|
270 |
|
271 CTestProviderAppServer* server = ( CTestProviderAppServer* ) Server(); |
|
272 CTestProviderAppUi* ui = server->AppUi(); |
|
273 dump->AddRunModeL( ui->IsChainedMode() ); |
|
274 |
|
275 TCoordinate center; |
|
276 GetAreaCentralPoint( center ); |
|
277 dump->AddMapViewOptionsL( Options(), CurrentLocationOption(), AreaRadius(), center ); |
|
278 |
|
279 dump->AddRequestTextL( SelectionRequestText() ); |
|
280 |
|
281 // free landmarks |
|
282 TArray<const CPosLandmark*> landmarks = LandmarksToShow(); |
|
283 for ( TInt i = 0; i < landmarks.Count(); i++ ) |
|
284 { |
|
285 dump->AddLandmarkL( *(landmarks[i]) ); |
|
286 } |
|
287 |
|
288 // linked landmarks |
|
289 TArray<const HBufC*> lmdbs = LandmarksToShowDatabases(); |
|
290 for ( TInt i = 0; i < lmdbs.Count(); i++ ) |
|
291 { |
|
292 dump->AddLandmarkListL( *( lmdbs[i] ), LinkedLandmarksToShow( i ) ); |
|
293 } |
|
294 |
|
295 dump->CommitL(); |
|
296 CleanupStack::PopAndDestroy( dump ); |
|
297 LOG("DumpDataL out"); |
|
298 } |
|
299 |
|
300 // --------------------------------------------------------------------------- |
|
301 // From class CMnMapViewServiceBase |
|
302 // --------------------------------------------------------------------------- |
|
303 // |
|
304 void CTestProviderMapViewService::HandleShowMapL() |
|
305 { |
|
306 LOG("HandleShowMapL in"); |
|
307 LeaveIfInstructedL(); |
|
308 DumpDataL(); |
|
309 |
|
310 CTestProviderAppServer* server = ( CTestProviderAppServer* ) Server(); |
|
311 CTestProviderAppUi* ui = server->AppUi(); |
|
312 ui->ShowMapViewL(); |
|
313 |
|
314 LOG("HandleShowMapL out"); |
|
315 } |
|
316 |
|
317 // --------------------------------------------------------------------------- |
|
318 // From class CMnMapViewServiceBase |
|
319 // |
|
320 // Implementation differs from HandleShowMapL in a way that central point |
|
321 // setting is ignored and current location is used instead as central point. |
|
322 // --------------------------------------------------------------------------- |
|
323 // |
|
324 void CTestProviderMapViewService::HandleShowCurrentLocationL() |
|
325 { |
|
326 LOG("HandleShowCurrentLocationL in"); |
|
327 LeaveIfInstructedL(); |
|
328 DumpDataL(); |
|
329 LOG("HandleShowCurrentLocationL out"); |
|
330 } |
|
331 |
|
332 // --------------------------------------------------------------------------- |
|
333 // From class CMnMapViewServiceBase |
|
334 // --------------------------------------------------------------------------- |
|
335 // |
|
336 void CTestProviderMapViewService::HandleSelectFromMapL() |
|
337 { |
|
338 LOG("HandleSelectFromMapL in"); |
|
339 LeaveIfInstructedL(); |
|
340 LeaveIfBusyL(); |
|
341 |
|
342 DumpDataL(); |
|
343 |
|
344 StartProcessingL(); |
|
345 LOG("HandleSelectFromMapL out"); |
|
346 } |
|
347 |
|
348 // --------------------------------------------------------------------------- |
|
349 // From class CMnServiceBase |
|
350 // --------------------------------------------------------------------------- |
|
351 // |
|
352 void CTestProviderMapViewService::DoCancel() |
|
353 { |
|
354 iProcessor->Cancel(); |
|
355 } |
|