|
1 /* |
|
2 * Copyright (c) 2005 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: |
|
15 * ?description_line |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #include "FT_CPosTp78.h" |
|
22 #include <Lbs.h> |
|
23 #include <EPos_CPosLandmarkDatabase.h> |
|
24 #include <EPos_CPosLandmarkParser.h> |
|
25 #include <EPos_CPosLandmarkEncoder.h> |
|
26 #include <EPos_CPosLandmark.h> |
|
27 |
|
28 // CONSTANTS |
|
29 const TInt KExectionTimeInMinutes = 60 * 10; // 10 hours |
|
30 |
|
31 // ================= LOCAL FUNCTIONS ======================= |
|
32 |
|
33 // --------------------------------------------------------- |
|
34 // LOCAL_C ThreadFunction |
|
35 // |
|
36 // (other items were commented in a header). |
|
37 // --------------------------------------------------------- |
|
38 // |
|
39 LOCAL_C TInt ThreadFunction(TAny* aData) |
|
40 { |
|
41 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
42 CActiveScheduler* actSch = new (ELeave) CActiveScheduler; |
|
43 CActiveScheduler::Install(actSch); |
|
44 |
|
45 TThreadParam* params = reinterpret_cast<TThreadParam*> (aData); |
|
46 TRAPD(err, (*params->iTestFunction)(params->iMessage)); |
|
47 |
|
48 delete actSch; |
|
49 delete cleanup; |
|
50 return err; |
|
51 } |
|
52 |
|
53 LOCAL_C void AddLandmarksL( |
|
54 TInt aNrOfLmsToAdd, |
|
55 const TDesC& aName, |
|
56 CPosLandmarkDatabase* aDb, |
|
57 RArray<TPosLmItemId>& aIdArray) |
|
58 { |
|
59 for (TInt i = 0; i < aNrOfLmsToAdd; i++) |
|
60 { |
|
61 CPosLandmark* landmark = CPosLandmark::NewLC(); |
|
62 landmark->SetLandmarkNameL(aName); |
|
63 landmark->SetPositionL(TLocality(TCoordinate(64, 85, 20), 25, 53)); |
|
64 landmark->SetCoverageRadius(18); |
|
65 landmark->AddCategoryL(1); |
|
66 landmark->SetIconL(_L("Icon"), 23, KPosLmIconMaskNotUsed); |
|
67 landmark->SetLandmarkDescriptionL(_L("Desc")); |
|
68 User::LeaveIfError(aIdArray.Append(aDb->AddLandmarkL(*landmark))); |
|
69 CleanupStack::PopAndDestroy(landmark); |
|
70 } |
|
71 } |
|
72 |
|
73 LOCAL_C void VerifyErrorL(const TDesC& aFormat, TInt aErr, TDes* aMessage) |
|
74 { |
|
75 if (aErr != KErrNone && aErr != KErrLocked) |
|
76 { |
|
77 aMessage->Format(aFormat, aErr); |
|
78 |
|
79 // Append time |
|
80 _LIT(KTimeFormat, " %F%Y-%M-%D at %H.%T:%S"); |
|
81 TTime now; |
|
82 now.HomeTime(); |
|
83 TBuf<50> time; |
|
84 now.FormatL(time, KTimeFormat); |
|
85 aMessage->Append(time); |
|
86 |
|
87 User::Leave(aErr); |
|
88 } |
|
89 } |
|
90 |
|
91 // ================= MEMBER FUNCTIONS ======================= |
|
92 |
|
93 // --------------------------------------------------------- |
|
94 // CPosTp78::GetName |
|
95 // |
|
96 // (other items were commented in a header). |
|
97 // --------------------------------------------------------- |
|
98 // |
|
99 void CPosTp78::GetName(TDes& aName) const |
|
100 { |
|
101 _LIT(KTestName, "TP78 - CPosLandmarkDatabase duration tests"); |
|
102 aName = KTestName; |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------- |
|
106 // CPosTp78::InitTestL |
|
107 // |
|
108 // (other items were commented in a header). |
|
109 // --------------------------------------------------------- |
|
110 // |
|
111 void CPosTp78::InitTestL() |
|
112 { |
|
113 MakeSurePanicDebugFileExistsL(); |
|
114 InitDbL(); |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------- |
|
118 // CPosTp78::CloseTest |
|
119 // |
|
120 // (other items were commented in a header). |
|
121 // --------------------------------------------------------- |
|
122 // |
|
123 void CPosTp78::CloseTest() |
|
124 { |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------- |
|
128 // CPosTp78::StartL |
|
129 // |
|
130 // (other items were commented in a header). |
|
131 // --------------------------------------------------------- |
|
132 // |
|
133 void CPosTp78::StartL() |
|
134 { |
|
135 // Test Open database duration test |
|
136 ResumeThreadsAndVerifyExitL(); |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------- |
|
140 // CPosTp78::InitDbL |
|
141 // |
|
142 // (other items were commented in a header). |
|
143 // --------------------------------------------------------- |
|
144 // |
|
145 void CPosTp78::InitDbL() |
|
146 { |
|
147 RemoveDefaultDbL(); |
|
148 CPosLandmarkDatabase* database = CPosLandmarkDatabase::OpenL(); |
|
149 CleanupStack::PushL(database); |
|
150 |
|
151 if (database->IsInitializingNeeded()) |
|
152 { |
|
153 ExecuteAndDeleteLD(database->InitializeL()); |
|
154 } |
|
155 |
|
156 CleanupStack::PopAndDestroy(database); |
|
157 |
|
158 // Wait for LM server to die |
|
159 User::After(2000000); |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------- |
|
163 // CPosTp78::ResumeThreadsAndVerifyExitL |
|
164 // |
|
165 // (other items were commented in a header). |
|
166 // --------------------------------------------------------- |
|
167 // |
|
168 void CPosTp78::ResumeThreadsAndVerifyExitL() |
|
169 { |
|
170 _LIT(KCreateThreadErr, "Creating thread failed with %d"); |
|
171 TInt nrOfThreads = 0; |
|
172 RThread openDbThread, addRemoveLmThread, impExpLmThread, dbEventThread, readAndUpdateThread; |
|
173 TThreadParam params1, params2, params3, params4, params5; |
|
174 TBuf<200> threadMsg1, threadMsg2, threadMsg3, threadMsg4, threadMsg5; |
|
175 |
|
176 // Create open database thread |
|
177 _LIT(KOpenDatabase, "TP78 - Open database duration thread"); |
|
178 params1.iMessage = &threadMsg1; |
|
179 params1.iTestFunction = RunOpenDbTestL; |
|
180 TInt err = openDbThread.Create(KOpenDatabase, ThreadFunction, |
|
181 KDefaultStackSize, KMinHeapSize, KDefaultHeapSize, ¶ms1); |
|
182 AssertTrueSecL(err == KErrNone, KCreateThreadErr, err); |
|
183 CleanupClosePushL(openDbThread); |
|
184 nrOfThreads++; |
|
185 |
|
186 // Create add remove LMs thread |
|
187 _LIT(KAddRemoveLandmarks, "TP78 - Add remove landmarks duration thread"); |
|
188 params2.iMessage = &threadMsg2; |
|
189 params2.iTestFunction = RunAddRemoveLmTestL; |
|
190 err = addRemoveLmThread.Create(KAddRemoveLandmarks, ThreadFunction, |
|
191 KDefaultStackSize, KMinHeapSize, 5 * KDefaultHeapSize, ¶ms2); |
|
192 AssertTrueSecL(err == KErrNone, KCreateThreadErr, err); |
|
193 CleanupClosePushL(addRemoveLmThread); |
|
194 nrOfThreads++; |
|
195 |
|
196 // Create import/export LMs thread |
|
197 _LIT(KImpExpLandmarks, "TP78 - Import/Export landmarks duration thread"); |
|
198 params3.iMessage = &threadMsg3; |
|
199 params3.iTestFunction = RunImportExportLmTestL; |
|
200 err = impExpLmThread.Create(KImpExpLandmarks, ThreadFunction, |
|
201 KDefaultStackSize, KMinHeapSize, 5 * KDefaultHeapSize, ¶ms3); |
|
202 AssertTrueSecL(err == KErrNone, KCreateThreadErr, err); |
|
203 CleanupClosePushL(impExpLmThread); |
|
204 nrOfThreads++; |
|
205 |
|
206 // Create db event thread |
|
207 _LIT(KDbEventThread, "TP78 - Database events duration thread"); |
|
208 params4.iMessage = &threadMsg4; |
|
209 params4.iTestFunction = RunDbEventTestL; |
|
210 err = dbEventThread.Create(KDbEventThread, ThreadFunction, |
|
211 KDefaultStackSize, KMinHeapSize, KDefaultHeapSize, ¶ms4); |
|
212 AssertTrueSecL(err == KErrNone, KCreateThreadErr, err); |
|
213 CleanupClosePushL(dbEventThread); |
|
214 nrOfThreads++; |
|
215 |
|
216 // Create read and update thread |
|
217 _LIT(KReadAndUpdateThread, "TP78 - Read and update landmarks duration thread"); |
|
218 params5.iMessage = &threadMsg5; |
|
219 params5.iTestFunction = RunReadAndUpdateTestL; |
|
220 err = readAndUpdateThread.Create(KReadAndUpdateThread, ThreadFunction, |
|
221 KDefaultStackSize, KMinHeapSize, 5 * KDefaultHeapSize, ¶ms5); |
|
222 AssertTrueSecL(err == KErrNone, KCreateThreadErr, err); |
|
223 CleanupClosePushL(readAndUpdateThread); |
|
224 nrOfThreads++; |
|
225 |
|
226 // Start threads. |
|
227 RThread* threads[] = {&openDbThread, &addRemoveLmThread, &impExpLmThread, &dbEventThread, &readAndUpdateThread}; |
|
228 RPointerArray<CThreadMonitor> threadMonitors; |
|
229 for (TInt j = 0; j < nrOfThreads; j++) |
|
230 { |
|
231 threadMonitors.Append(CThreadMonitor::NewL(threads[j])); |
|
232 } |
|
233 |
|
234 // Log time stamp |
|
235 _LIT(KTimeFormat, "Threads started on %F%Y-%M-%D at %H.%T:%S"); |
|
236 TTime now; |
|
237 now.HomeTime(); |
|
238 now.FormatL(iBuf, KTimeFormat); |
|
239 iLog->Put(iBuf); |
|
240 |
|
241 // Wait until any of the threads exits. |
|
242 TDes* messages[] = {&threadMsg1, &threadMsg2, &threadMsg3, &threadMsg4, &threadMsg5}; |
|
243 TInt errors = KErrNone; |
|
244 TBool allThreadsTerminated = EFalse; |
|
245 while (!allThreadsTerminated && errors == KErrNone) |
|
246 { |
|
247 CActiveScheduler::Start(); |
|
248 |
|
249 // Assume all threads are terminated |
|
250 allThreadsTerminated = ETrue; |
|
251 for (TInt i = 0; i < nrOfThreads && errors == KErrNone; i++) |
|
252 { |
|
253 if (threadMonitors[i]->IsActive()) |
|
254 { |
|
255 // Thread is still alive |
|
256 allThreadsTerminated = EFalse; |
|
257 } |
|
258 else |
|
259 { |
|
260 // Thread is terminated, check exit codes |
|
261 if (*messages[i] != KNullDesC) |
|
262 { |
|
263 iLog->Put(*(messages[i])); |
|
264 } |
|
265 if (threads[i]->ExitType() != EExitKill) |
|
266 { |
|
267 iBuf.Format(_L("Thread %i was not killed!"), i); |
|
268 iLog->PutError(iBuf); |
|
269 TExitCategoryName category = threads[i]->ExitCategory(); |
|
270 iBuf.Format(_L("Exit Category = %S %d"), &category, threads[i]->ExitReason()); |
|
271 iLog->Put(iBuf); |
|
272 errors = KErrGeneral; |
|
273 } |
|
274 else |
|
275 { |
|
276 TInt exitReason = threads[i]->ExitReason(); |
|
277 if (exitReason != 0) |
|
278 { |
|
279 iBuf.Format(_L("Thread's exit reason wasn't 0 but %d."), exitReason); |
|
280 iLog->PutError(iBuf); |
|
281 errors = exitReason; |
|
282 } |
|
283 } |
|
284 } |
|
285 } |
|
286 } |
|
287 |
|
288 // Terminate all remaining threads |
|
289 threadMonitors.ResetAndDestroy(); |
|
290 |
|
291 // Log time stamp |
|
292 _LIT(KTimeFormat2, "Threads terminated on %F%Y-%M-%D at %H.%T:%S"); |
|
293 now.HomeTime(); |
|
294 now.FormatL(iBuf, KTimeFormat2); |
|
295 iLog->Put(iBuf); |
|
296 |
|
297 |
|
298 User::LeaveIfError(errors); |
|
299 |
|
300 CleanupStack::PopAndDestroy(nrOfThreads, &openDbThread); |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------- |
|
304 // CPosTp78::RunOpenDbTestL |
|
305 // |
|
306 // (other items were commented in a header). |
|
307 // --------------------------------------------------------- |
|
308 // |
|
309 void CPosTp78::RunOpenDbTestL(TDes* aMessage) |
|
310 { |
|
311 // Execute thread for a number of hours |
|
312 TTime startTime, stopTime; |
|
313 startTime.HomeTime(); |
|
314 stopTime.HomeTime(); |
|
315 TTimeIntervalMinutes executionTime; |
|
316 User::LeaveIfError(stopTime.MinutesFrom(startTime, executionTime)); |
|
317 |
|
318 while (executionTime.Int() < KExectionTimeInMinutes) |
|
319 { |
|
320 CPosLandmarkDatabase* db = NULL; |
|
321 TRAPD(err, db = CPosLandmarkDatabase::OpenL()); |
|
322 CleanupStack::PushL(db); |
|
323 VerifyErrorL(_L("<-- OpenDbThread: CPosLandmarkDatabase::OpenL() left with %d -->"), err, aMessage); |
|
324 if (err == KErrNone) |
|
325 { |
|
326 // Try to initialize the db |
|
327 db->IsInitializingNeeded(); // don't care about the result. Init anyway |
|
328 CPosLmOperation* operation = NULL; |
|
329 TRAP(err, operation = db->InitializeL()); |
|
330 CleanupStack::PushL(operation); |
|
331 VerifyErrorL(_L("<-- OpenDbThread: InitializeL() left with %d -->"), err, aMessage); |
|
332 if (err == KErrNone) |
|
333 { |
|
334 TRAP(err, operation->ExecuteL()); |
|
335 VerifyErrorL(_L("<-- OpenDbThread: ExecuteAndDeleteLD(InitializeL()) left with %d -->"), err, aMessage); |
|
336 } |
|
337 CleanupStack::PopAndDestroy(operation); |
|
338 } |
|
339 CleanupStack::PopAndDestroy(db); |
|
340 |
|
341 // Let other threads get access to the database |
|
342 User::After(10000); |
|
343 |
|
344 stopTime.HomeTime(); |
|
345 User::LeaveIfError(stopTime.MinutesFrom(startTime, executionTime)); |
|
346 } |
|
347 } |
|
348 |
|
349 // --------------------------------------------------------- |
|
350 // CPosTp78::RunAddRemoveLmTestL |
|
351 // |
|
352 // (other items were commented in a header). |
|
353 // --------------------------------------------------------- |
|
354 // |
|
355 void CPosTp78::RunAddRemoveLmTestL(TDes* aMessage) |
|
356 { |
|
357 // Execute thread for a number of hours |
|
358 TTime startTime, stopTime; |
|
359 startTime.HomeTime(); |
|
360 stopTime.HomeTime(); |
|
361 TTimeIntervalMinutes executionTime; |
|
362 User::LeaveIfError(stopTime.MinutesFrom(startTime, executionTime)); |
|
363 |
|
364 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL(); |
|
365 CleanupStack::PushL(db); |
|
366 while (executionTime.Int() < KExectionTimeInMinutes) |
|
367 { |
|
368 RArray<TPosLmItemId> dbItems; |
|
369 CleanupClosePushL(dbItems); |
|
370 |
|
371 // Remove all landmarks |
|
372 CPosLmOperation* operation = NULL; |
|
373 TRAPD(err, operation = db->RemoveAllLandmarksL()); |
|
374 VerifyErrorL(_L("<-- AddRemoveThread: RemoveAllLandmarksL() left with %d -->"), err, aMessage); |
|
375 if (err == KErrNone) |
|
376 { |
|
377 TRAP(err, ExecuteAndDeleteLD(operation)); |
|
378 VerifyErrorL(_L("<-- AddRemoveThread: ExecuteAndDeleteLD(RemoveAllLandmarksL()) left with %d -->"), err, aMessage); |
|
379 } |
|
380 |
|
381 // Add some landmarks |
|
382 const TInt KNrOfLms = 10; |
|
383 TRAP(err, AddLandmarksL(KNrOfLms, _L("AddRemoveThread"), db, dbItems)); |
|
384 VerifyErrorL(_L("<-- AddRemoveThread: AddLandmarksL() left with %d -->"), err, aMessage); |
|
385 if (err == KErrNone) |
|
386 { |
|
387 // Remove some items one by one |
|
388 for (TInt i = 0; i < KNrOfLms / 2; i++) |
|
389 { |
|
390 dbItems.Remove(0); |
|
391 TRAP(err, db->RemoveLandmarkL(dbItems[0])); |
|
392 VerifyErrorL(_L("<-- AddRemoveThread: RemoveLandmarkL(TPosLmItemId) left with %d -->"), err, aMessage); |
|
393 } |
|
394 |
|
395 // Remove 5 items in one step |
|
396 operation = NULL; |
|
397 TRAPD(err, operation = db->RemoveLandmarksL(dbItems)); |
|
398 VerifyErrorL(_L("<-- AddRemoveThread: RemoveLandmarksL(RArray) left with %d -->"), err, aMessage); |
|
399 if (err == KErrNone) |
|
400 { |
|
401 TRAP(err, ExecuteAndDeleteLD(operation)); |
|
402 VerifyErrorL(_L("<-- AddRemoveThread: ExecuteAndDeleteLD(RemoveLandmarksL(dbItems)) left with %d -->"), err, aMessage); |
|
403 } |
|
404 dbItems.Reset(); |
|
405 |
|
406 CPosLandmarkDatabase::TSize dbSize; dbSize.iUsage = 0; |
|
407 TRAP(err, dbSize = db->SizeL()); |
|
408 VerifyErrorL(_L("<-- AddRemoveThread: SizeL() left with %d -->"), err, aMessage); |
|
409 if (dbSize.iUsage < 0.9) |
|
410 { |
|
411 operation = NULL; |
|
412 TRAP(err, operation = db->CompactL()); |
|
413 VerifyErrorL(_L("<-- AddRemoveThread: CompactL() left with %d -->"), err, aMessage); |
|
414 if (err == KErrNone) |
|
415 { |
|
416 CleanupStack::PushL(operation); |
|
417 TRAP(err, operation->ExecuteL()); |
|
418 VerifyErrorL(_L("<-- AddRemoveThread: ExecuteAndDeleteLD(CompactL()) left with %d -->"), err, aMessage); |
|
419 CleanupStack::PopAndDestroy(operation); |
|
420 } |
|
421 } |
|
422 |
|
423 HBufC* dbUri = NULL; |
|
424 TRAP(err, CleanupStack::Pop(dbUri = db->DatabaseUriLC())); |
|
425 CleanupStack::PushL(dbUri); |
|
426 VerifyErrorL(_L("<-- AddRemoveThread: DatabaseUriLC() left with %d -->"), err, aMessage); |
|
427 CleanupStack::PopAndDestroy(dbUri); |
|
428 } |
|
429 |
|
430 dbItems.Reset(); |
|
431 CleanupStack::PopAndDestroy(&dbItems); |
|
432 |
|
433 // Let other threads get access to the database |
|
434 User::After(300000); |
|
435 |
|
436 stopTime.HomeTime(); |
|
437 User::LeaveIfError(stopTime.MinutesFrom(startTime, executionTime)); |
|
438 } |
|
439 |
|
440 CleanupStack::PopAndDestroy(db); |
|
441 } |
|
442 |
|
443 // --------------------------------------------------------- |
|
444 // CPosTp78::RunImportExportLmTestL |
|
445 // |
|
446 // (other items were commented in a header). |
|
447 // --------------------------------------------------------- |
|
448 // |
|
449 void CPosTp78::RunImportExportLmTestL(TDes* aMessage) |
|
450 { |
|
451 // Execute thread for a number of hours |
|
452 TTime startTime, stopTime; |
|
453 startTime.HomeTime(); |
|
454 stopTime.HomeTime(); |
|
455 TTimeIntervalMinutes executionTime; |
|
456 User::LeaveIfError(stopTime.MinutesFrom(startTime, executionTime)); |
|
457 |
|
458 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL(); |
|
459 CleanupStack::PushL(db); |
|
460 while (executionTime.Int() < KExectionTimeInMinutes) |
|
461 { |
|
462 // Export landmarks |
|
463 TBool exportSuccessful = EFalse; |
|
464 CPosLmOperation* operation = NULL; |
|
465 CPosLandmarkEncoder* encoder = NULL; |
|
466 TRAPD(err, encoder = CPosLandmarkEncoder::NewL(KMimeType)); |
|
467 VerifyErrorL(_L("<-- ImportExportThread: CPosLandmarkEncoder::NewL left with %d -->"), err, aMessage); |
|
468 CleanupStack::PushL(encoder); |
|
469 |
|
470 // Use buffer as output |
|
471 CBufBase* outputBuffer = NULL; |
|
472 TRAP(err, outputBuffer = encoder->SetUseOutputBufferL()); |
|
473 VerifyErrorL(_L("<-- ImportExportThread: SetUseOutputBufferL left with %d -->"), err, aMessage); |
|
474 CleanupStack::PushL(outputBuffer); |
|
475 |
|
476 // Add collection data |
|
477 TRAP(err, encoder->AddCollectionDataL(EPosLmCollDataCollectionName, _L("collection Name"))); |
|
478 VerifyErrorL(_L("<-- ImportExportThread: AddCollectionDataL(Name) left with %d -->"), err, aMessage); |
|
479 TRAP(err, encoder->AddCollectionDataL(EPosLmCollDataCollectionDescription, _L("collection Desc"))); |
|
480 VerifyErrorL(_L("<-- ImportExportThread: AddCollectionDataL(Desc) left with %d -->"), err, aMessage); |
|
481 |
|
482 // Export landmarks |
|
483 RArray<TPosLmItemId> lmIdArray; |
|
484 CleanupClosePushL(lmIdArray); |
|
485 TRAP(err, AddLandmarksL(5, _L("ImportExportThread"), db, lmIdArray)); |
|
486 VerifyErrorL(_L("<-- ImportExportThread: AddLandmarksL() left with %d -->"), err, aMessage); |
|
487 if (err == KErrNone) |
|
488 { |
|
489 TRAP(err, operation = db->ExportLandmarksL(*encoder, lmIdArray, |
|
490 CPosLandmarkDatabase::EIncludeCategories | CPosLandmarkDatabase::EIncludeGlobalCategoryNames)); |
|
491 VerifyErrorL(_L("<-- ImportExportThread: ExportLandmarksL left with %d -->"), err, aMessage); |
|
492 if (err == KErrNone) |
|
493 { |
|
494 CleanupStack::PushL(operation); |
|
495 TRAP(err, ExecuteAndDeleteLD(operation)); |
|
496 CleanupStack::Pop(operation); |
|
497 VerifyErrorL(_L("<-- ImportExportThread: ExecuteAndDeleteLD(ExportLandmarksL) left with %d -->"), err, aMessage); |
|
498 |
|
499 // finalize encoding |
|
500 operation = NULL; |
|
501 TRAP(err, operation = encoder->FinalizeEncodingL()); |
|
502 VerifyErrorL(_L("<-- ImportExportThread: FinalizeEncodingL left with %d -->"), err, aMessage); |
|
503 if (err == KErrNone) |
|
504 { |
|
505 CleanupStack::PushL(operation); |
|
506 TRAP(err, ExecuteAndDeleteLD(operation)); |
|
507 CleanupStack::Pop(operation); |
|
508 VerifyErrorL(_L("<-- ImportExportThread: ExecuteAndDeleteLD(FinalizeEncodingL) left with %d -->"), err, aMessage); |
|
509 exportSuccessful = ETrue; |
|
510 } |
|
511 } |
|
512 } |
|
513 CleanupStack::PopAndDestroy(&lmIdArray); |
|
514 |
|
515 // Import landmarks |
|
516 if (exportSuccessful) |
|
517 { |
|
518 CPosLandmarkParser* parser = NULL; |
|
519 TRAP(err, parser = CPosLandmarkParser::NewL(KMimeType)); |
|
520 CleanupStack::PushL(parser); |
|
521 VerifyErrorL(_L("<-- ImportExportThread: CPosLandmarkParser::NewL left with %d -->"), err, aMessage); |
|
522 |
|
523 // Use buffer as input |
|
524 TInt size = outputBuffer->Size(); |
|
525 HBufC8* inputBuffer = HBufC8::New(size); |
|
526 if (!inputBuffer) |
|
527 { |
|
528 aMessage->Copy(_L8("Unable to allocate inputBuffer. Error: KErrNoMemory")); |
|
529 } |
|
530 CleanupStack::PushL(inputBuffer); |
|
531 TPtr8 inputBufferPtr = inputBuffer->Des(); |
|
532 outputBuffer->Read(0, inputBufferPtr, size); |
|
533 parser->SetInputBuffer(inputBufferPtr); |
|
534 |
|
535 // Import landmarks |
|
536 operation = NULL; |
|
537 TRAP(err, operation = db->ImportLandmarksL(*parser, |
|
538 CPosLandmarkDatabase::EDefaultOptions)); |
|
539 CleanupStack::PushL(operation); |
|
540 VerifyErrorL(_L("<-- ImportExportThread: ImportLandmarksL left with %d -->"), err, aMessage); |
|
541 if (err == KErrNone) |
|
542 { |
|
543 TRAP(err, operation->ExecuteL()); |
|
544 VerifyErrorL(_L("<-- ImportExportThread: ExecuteAndDeleteLD(ImportLandmarksL) left with %d -->"), err, aMessage); |
|
545 |
|
546 CPosLmItemIterator* iterator = NULL; |
|
547 TRAP(err, iterator = db->ImportedLandmarksIteratorL(operation)); |
|
548 CleanupStack::PushL(iterator); |
|
549 VerifyErrorL(_L("<-- ImportExportThread: ImportedLandmarksIteratorL() left with %d -->"), err, aMessage); |
|
550 CleanupStack::PopAndDestroy(iterator); |
|
551 } |
|
552 CleanupStack::PopAndDestroy(operation); |
|
553 CleanupStack::PopAndDestroy(inputBuffer); |
|
554 CleanupStack::PopAndDestroy(parser); |
|
555 } |
|
556 CleanupStack::PopAndDestroy(outputBuffer); |
|
557 CleanupStack::PopAndDestroy(encoder); |
|
558 |
|
559 // Let other threads get access to the database |
|
560 User::After(100000); |
|
561 |
|
562 stopTime.HomeTime(); |
|
563 User::LeaveIfError(stopTime.MinutesFrom(startTime, executionTime)); |
|
564 } |
|
565 |
|
566 CleanupStack::PopAndDestroy(db); |
|
567 } |
|
568 |
|
569 // --------------------------------------------------------- |
|
570 // CPosTp78::RunDbEventTestL |
|
571 // |
|
572 // (other items were commented in a header). |
|
573 // --------------------------------------------------------- |
|
574 // |
|
575 void CPosTp78::RunDbEventTestL(TDes* aMessage) |
|
576 { |
|
577 // Execute thread for a number of hours |
|
578 TTime startTime, stopTime; |
|
579 startTime.HomeTime(); |
|
580 stopTime.HomeTime(); |
|
581 TTimeIntervalMinutes executionTime; |
|
582 User::LeaveIfError(stopTime.MinutesFrom(startTime, executionTime)); |
|
583 |
|
584 // Open db |
|
585 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL(); |
|
586 CleanupStack::PushL(db); |
|
587 |
|
588 while (executionTime.Int() < KExectionTimeInMinutes - 1) |
|
589 { |
|
590 TRequestStatus status; |
|
591 TPosLmEvent event; |
|
592 |
|
593 // Listen for events for some time |
|
594 db->NotifyDatabaseEvent(event, status); |
|
595 User::After(100000); |
|
596 |
|
597 // Cancel listening |
|
598 TInt err = db->CancelNotifyDatabaseEvent(); |
|
599 VerifyErrorL(_L("<-- DbEventThread: CancelNotifyDatabaseEvent returned %d -->"), err, aMessage); |
|
600 |
|
601 // Start listening again |
|
602 db->NotifyDatabaseEvent(event, status); |
|
603 User::WaitForRequest(status); |
|
604 VerifyErrorL(_L("<-- DbEventThread: NotifyDatabaseEvent returned %d -->"), status.Int(), aMessage); |
|
605 |
|
606 stopTime.HomeTime(); |
|
607 User::LeaveIfError(stopTime.MinutesFrom(startTime, executionTime)); |
|
608 } |
|
609 |
|
610 CleanupStack::PopAndDestroy(db); |
|
611 } |
|
612 |
|
613 // --------------------------------------------------------- |
|
614 // CPosTp78::UpdateLandmarksL |
|
615 // |
|
616 // (other items were commented in a header). |
|
617 // --------------------------------------------------------- |
|
618 // |
|
619 void CPosTp78::UpdateLandmarksL(CPosLandmarkDatabase* aDb, TPosLmItemId aId, TDes* aMessage) |
|
620 { |
|
621 //CPosLandmark* landmark = NULL; |
|
622 CPosLandmark* landmark = aDb->ReadLandmarkLC(aId); |
|
623 //VerifyErrorL(_L("<-- ReadAndUpdateThread: ReadLandmarkLC() left with %d -->"), err, aMessage); |
|
624 |
|
625 TRAPD(err, landmark->SetLandmarkNameL(_L("UpdatedName"))); |
|
626 VerifyErrorL(_L("<-- ReadAndUpdateThread: SetLandmarkNameL() left with %d -->"), err, aMessage); |
|
627 TRAP(err, aDb->UpdateLandmarkL(*landmark)); |
|
628 VerifyErrorL(_L("<-- ReadAndUpdateThread: UpdateLandmarkL() left with %d -->"), err, aMessage); |
|
629 CleanupStack::PopAndDestroy(landmark); |
|
630 } |
|
631 |
|
632 // --------------------------------------------------------- |
|
633 // CPosTp78::RunReadAndUpdateTestL |
|
634 // |
|
635 // (other items were commented in a header). |
|
636 // --------------------------------------------------------- |
|
637 // |
|
638 void CPosTp78::RunReadAndUpdateTestL(TDes* aMessage) |
|
639 { |
|
640 // Execute thread for a number of hours |
|
641 TTime startTime, stopTime; |
|
642 startTime.HomeTime(); |
|
643 stopTime.HomeTime(); |
|
644 TTimeIntervalMinutes executionTime; |
|
645 User::LeaveIfError(stopTime.MinutesFrom(startTime, executionTime)); |
|
646 |
|
647 // Open db |
|
648 CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL(); |
|
649 CleanupStack::PushL(db); |
|
650 |
|
651 while (executionTime.Int() < KExectionTimeInMinutes) |
|
652 { |
|
653 RArray<TPosLmItemId> dbItems; |
|
654 CleanupClosePushL(dbItems); |
|
655 |
|
656 const TInt KNrOfLms = 3; |
|
657 TRAPD(err, AddLandmarksL(KNrOfLms, _L("ReadAndUpdateThread"), db, dbItems)); |
|
658 VerifyErrorL(_L("<-- ReadAndUpdateThread: AddLandmarksL() left with %d -->"), err, aMessage); |
|
659 |
|
660 if (err == KErrNone) |
|
661 { |
|
662 // Read and update |
|
663 for (TInt i = 0; i < KNrOfLms; i++) |
|
664 { |
|
665 /* |
|
666 CPosLandmark* landmark = NULL; |
|
667 TRAP(err, landmark = db->ReadLandmarkLC(dbItems[i])); |
|
668 VerifyErrorL(_L("<-- ReadAndUpdateThread: ReadLandmarkLC() left with %d -->"), err, aMessage); |
|
669 if (err == KErrNone) |
|
670 { |
|
671 TRAP(err, landmark->SetLandmarkNameL(_L("UpdatedName"))); |
|
672 VerifyErrorL(_L("<-- ReadAndUpdateThread: SetLandmarkNameL() left with %d -->"), err, aMessage); |
|
673 TRAP(err, db->UpdateLandmarkL(*landmark)); |
|
674 VerifyErrorL(_L("<-- ReadAndUpdateThread: UpdateLandmarkL() left with %d -->"), err, aMessage); |
|
675 CleanupStack::PopAndDestroy(landmark); |
|
676 } |
|
677 */ |
|
678 |
|
679 TRAPD(err, UpdateLandmarksL(db,dbItems[i], aMessage)); |
|
680 VerifyErrorL(_L("<-- ReadAndUpdateThread: ReadLandmarkLC() left with %d -->"), err, aMessage); |
|
681 } |
|
682 |
|
683 // Set partial read parameters |
|
684 CPosLmPartialReadParameters* params = NULL; |
|
685 TRAP(err, CleanupStack::Pop(params = db->PartialReadParametersLC())); |
|
686 CleanupStack::PushL(params); |
|
687 VerifyErrorL(_L("<-- ReadAndUpdateThread: PartialReadParametersLC() left with %d -->"), err, aMessage); |
|
688 if (err == KErrNone) |
|
689 { |
|
690 params->SetRequestedAttributes(CPosLandmark::EIcon | CPosLandmark::ECoverageRadius); |
|
691 RArray<TUint> posFields; |
|
692 err = posFields.Append(EPositionFieldStreet); |
|
693 params->SetRequestedPositionFields(posFields); |
|
694 posFields.Close(); |
|
695 VerifyErrorL(_L("<-- ReadAndUpdateThread: Append() returned %d -->"), err, aMessage); |
|
696 TRAP(err, db->SetPartialReadParametersL(*params)); |
|
697 VerifyErrorL(_L("<-- ReadAndUpdateThread: SetPartialReadParametersL() left with %d -->"), err, aMessage); |
|
698 CleanupStack::PopAndDestroy(params); |
|
699 } |
|
700 |
|
701 // Read partial landmarks one by one |
|
702 for (TInt j = 0; j < KNrOfLms; j++) |
|
703 { |
|
704 CPosLandmark* lm = NULL; |
|
705 TRAP(err, CleanupStack::Pop(lm = db->ReadPartialLandmarkLC(dbItems[j]))); |
|
706 CleanupStack::PushL(lm); |
|
707 VerifyErrorL(_L("<-- ReadAndUpdateThread: ReadPartialLandmarkLC() left with %d -->"), err, aMessage); |
|
708 CleanupStack::PopAndDestroy(lm); |
|
709 } |
|
710 |
|
711 // Read several partial landmarks in one chunk |
|
712 CPosLmOperation* operation = NULL; |
|
713 TRAP(err, operation = db->PreparePartialLandmarksL(dbItems)); |
|
714 CleanupStack::PushL(operation); |
|
715 VerifyErrorL(_L("<-- ReadAndUpdateThread: PreparePartialLandmarksL() left with %d -->"), err, aMessage); |
|
716 |
|
717 if (err == KErrNone) |
|
718 { |
|
719 TRAP(err, operation->ExecuteL()); |
|
720 VerifyErrorL(_L("<-- ReadAndUpdateThread: ExecuteAndDeleteLD(PreparePartialLandmarksL()) left with %d -->"), err, aMessage); |
|
721 if (err == KErrNone) |
|
722 { |
|
723 CArrayPtr<CPosLandmark>* landmarks = NULL; |
|
724 TRAP(err, landmarks = db->TakePreparedPartialLandmarksL(operation)); |
|
725 if (landmarks) |
|
726 { |
|
727 landmarks->ResetAndDestroy(); |
|
728 delete landmarks; |
|
729 } |
|
730 VerifyErrorL(_L("<-- ReadAndUpdateThread: PreparePartialLandmarksL() left with %d -->"), err, aMessage); |
|
731 } |
|
732 } |
|
733 CleanupStack::PopAndDestroy(operation); |
|
734 } |
|
735 CleanupStack::PopAndDestroy(&dbItems); |
|
736 |
|
737 // Let other threads get access to the database |
|
738 User::After(110000); |
|
739 |
|
740 stopTime.HomeTime(); |
|
741 User::LeaveIfError(stopTime.MinutesFrom(startTime, executionTime)); |
|
742 } |
|
743 CleanupStack::PopAndDestroy(db); |
|
744 } |
|
745 |
|
746 // --------------------------------------------------------- |
|
747 // CThreadMonitor::NewL |
|
748 // |
|
749 // (other items were commented in a header). |
|
750 // --------------------------------------------------------- |
|
751 // |
|
752 CThreadMonitor* CThreadMonitor::NewL(RThread* aThread) |
|
753 { |
|
754 CThreadMonitor* self = new (ELeave) CThreadMonitor(aThread); |
|
755 CleanupStack::PushL(self); |
|
756 self->ConstructL(); |
|
757 CleanupStack::Pop(self); |
|
758 return self; |
|
759 } |
|
760 |
|
761 // --------------------------------------------------------- |
|
762 // CThreadMonitor::ConstructL |
|
763 // |
|
764 // (other items were commented in a header). |
|
765 // --------------------------------------------------------- |
|
766 // |
|
767 void CThreadMonitor::ConstructL() |
|
768 { |
|
769 iThread->Resume(); |
|
770 iThread->Logon(iStatus); |
|
771 SetActive(); |
|
772 } |
|
773 |
|
774 // Constructor |
|
775 CThreadMonitor::CThreadMonitor(RThread* aThread) |
|
776 : CActive(CActive::EPriorityStandard), iThread(aThread) |
|
777 { |
|
778 CActiveScheduler::Add(this); |
|
779 } |
|
780 |
|
781 // Destructor |
|
782 CThreadMonitor::~CThreadMonitor() |
|
783 { |
|
784 Cancel(); |
|
785 } |
|
786 |
|
787 // --------------------------------------------------------- |
|
788 // CThreadMonitor::DoCancel |
|
789 // |
|
790 // (other items were commented in a header). |
|
791 // --------------------------------------------------------- |
|
792 // |
|
793 void CThreadMonitor::DoCancel() |
|
794 { |
|
795 iThread->LogonCancel(iStatus); |
|
796 |
|
797 // Kill thread |
|
798 TRequestStatus status; |
|
799 iThread->Logon(status); |
|
800 iThread->Kill(KErrCancel); |
|
801 User::WaitForRequest(status); |
|
802 } |
|
803 |
|
804 // --------------------------------------------------------- |
|
805 // CThreadMonitor::RunL |
|
806 // |
|
807 // (other items were commented in a header). |
|
808 // --------------------------------------------------------- |
|
809 // |
|
810 void CThreadMonitor::RunL() |
|
811 { |
|
812 CActiveScheduler::Stop(); |
|
813 } |
|
814 |
|
815 // End of File |