|
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 |
|
22 #include "FT_CPosTp39.h" |
|
23 #include <EPos_CPosLandmarkDatabase.h> |
|
24 #include <EPos_CPosLandmark.h> |
|
25 #include <EPos_CPosLMCategoryManager.h> |
|
26 #include <EPos_CPosLandmarkCategory.h> |
|
27 #include <e32std.h> |
|
28 #include <ss_std.h> |
|
29 #include <bautils.h> |
|
30 #include "FT_LandmarkConstants.h" |
|
31 |
|
32 // CONSTANTS |
|
33 const TInt KNoListeners=5; |
|
34 const TInt KMaxQueueSize = 5; |
|
35 const TInt KLmServerMaxHeapSize = 40000; |
|
36 |
|
37 _LIT(KLandmarkServerName, "eposlmserver*"); |
|
38 |
|
39 |
|
40 // ================= MEMBER FUNCTIONS ======================= |
|
41 |
|
42 // --------------------------------------------------------- |
|
43 // CPosTp39::GetName |
|
44 // |
|
45 // (other items were commented in a header). |
|
46 // --------------------------------------------------------- |
|
47 // |
|
48 void CPosTp39::GetName(TDes& aName) const |
|
49 { |
|
50 _LIT(KTestName, "TP39 - Heap Usage (Goofy)"); |
|
51 aName = KTestName; |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------- |
|
55 // CPosTp39::StartL |
|
56 // |
|
57 // (other items were commented in a header). |
|
58 // --------------------------------------------------------- |
|
59 // |
|
60 void CPosTp39::StartL() |
|
61 { |
|
62 _LIT(KMultipleErr, "Error %d when multiple clients listen for events"); |
|
63 _LIT(KEventErr, "%d Error(s) when multiple clients listen for events"); |
|
64 MakeSurePanicDebugFileExistsL(); |
|
65 iUseLogFromThreadIsDisabled = ETrue; |
|
66 |
|
67 _LIT(KCanceledErr, "Test canceled"); |
|
68 _LIT(KStartGoofy, "Start up Goofy and start a test (Options->Test->Start)."); |
|
69 |
|
70 RemoveDefaultDbL(); |
|
71 |
|
72 #ifndef __WINS__ |
|
73 TUtfwUserAnswer answer; |
|
74 answer = iUserInfo->ShowDialog(KStartGoofy, EUtfwDialogTypeOkCancel, EFalse); |
|
75 AssertTrueSecL(answer == EUtfwUserAnswerOk, KCanceledErr, KErrCancel); |
|
76 #endif |
|
77 |
|
78 RemoveDefaultDbL(); |
|
79 |
|
80 SetupGlobalCategoriesL(); |
|
81 |
|
82 CPosLandmarkDatabase* database = CPosLandmarkDatabase::OpenL(); |
|
83 delete database; |
|
84 |
|
85 TFixedArray<TRequestStatus, KNoListeners+1> statuses; |
|
86 |
|
87 CreateThreadsL(); |
|
88 |
|
89 for (TInt i=0; i<iThreads.Count(); i++) |
|
90 { |
|
91 iThreads[i].Logon(statuses[i]); |
|
92 iThreads[i].Resume(); |
|
93 } |
|
94 for (TInt j=0; j<iThreads.Count(); j++) |
|
95 { |
|
96 User::WaitForRequest(statuses[j]); |
|
97 } |
|
98 |
|
99 for (TInt t=0; t<iThreads.Count(); t++) |
|
100 { |
|
101 TInt exitReason = iThreads[t].ExitReason(); |
|
102 |
|
103 AssertTrueSecL(exitReason == KErrNone, KMultipleErr, exitReason); |
|
104 } |
|
105 |
|
106 if (iErrors > 0) |
|
107 { |
|
108 TBuf<100> info; |
|
109 info.Format(KEventErr, iErrors); |
|
110 LogErrorAndLeave(iErrorLog); |
|
111 } |
|
112 |
|
113 |
|
114 #ifndef __WINS__ |
|
115 |
|
116 TInt heapSize, stackSize=0; |
|
117 |
|
118 TBuf<127> info; |
|
119 TInt err = GetHeapSizeL(KLandmarkServerName, heapSize, stackSize); |
|
120 if (err) |
|
121 { |
|
122 info.Format(_L("GetHeapSizeL error, %d"), err); |
|
123 LogErrorAndLeave(info); |
|
124 } |
|
125 |
|
126 info.Format(_L("LandmarkServer Heap: %d LandmarkServer Stack:"), heapSize, stackSize); |
|
127 iLog->Put(info); |
|
128 |
|
129 if (heapSize > KLmServerMaxHeapSize) |
|
130 { |
|
131 LogErrorAndLeave(_L("The memory consumption for the LandmarkServer is too high!")); |
|
132 } |
|
133 #endif |
|
134 |
|
135 /* |
|
136 _LIT(KCatId, "category_id = %d;"); |
|
137 _LIT(KCatName, "category_name = \"%S\";"); |
|
138 |
|
139 // 201-300 |
|
140 _LIT(KName, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901%d"); |
|
141 |
|
142 for (TInt i=201; i<=300; i++) |
|
143 { |
|
144 iLog->Put(_L("POS_LM_CATEGORY_INFO")); |
|
145 iLog->Put(_L("{")); |
|
146 |
|
147 TBuf<150> info; |
|
148 |
|
149 info.Format(KCatId, (i+1)); |
|
150 |
|
151 iLog->Put(info); |
|
152 |
|
153 info.Format(KName, i); |
|
154 |
|
155 HBufC* name = info.Alloc(); |
|
156 |
|
157 info.Format(KCatName, name); |
|
158 iLog->Put(info); |
|
159 iLog->Put(_L("},")); |
|
160 } |
|
161 */ |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------- |
|
165 // CPosTp39::CloseTest |
|
166 // |
|
167 // (other items were commented in a header). |
|
168 // --------------------------------------------------------- |
|
169 // |
|
170 void CPosTp39::CloseTest() |
|
171 { |
|
172 for (TInt i=0; i<iThreads.Count(); i++) |
|
173 { |
|
174 iThreads[i].Close(); |
|
175 } |
|
176 |
|
177 iThreads.Close(); |
|
178 iUseLogFromThreadIsDisabled = EFalse; |
|
179 |
|
180 RemoveGlobalCategoriesL(); |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------- |
|
184 // CPosTp39::SetupGlobalCategoriesL |
|
185 // |
|
186 // (other items were commented in a header). |
|
187 // --------------------------------------------------------- |
|
188 // |
|
189 void CPosTp39::SetupGlobalCategoriesL() |
|
190 { |
|
191 #ifdef __WINS__ |
|
192 _LIT(KGlobalCategoryResFile, "z:\\system\\test\\testdata\\EPOSLMGLOBALCATEGORIES.R03"); |
|
193 #else |
|
194 _LIT(KGlobalCategoryResFile, "c:\\system\\test\\testdata\\EPOSLMGLOBALCATEGORIES.R03"); |
|
195 #endif |
|
196 //_LIT(KGlobalCategoryResPath, "c:\\system\\data\\"); |
|
197 //_LIT(KGlobalCategoryResFileOld, "c:\\system\\data\\EPOSLMGLOBALCATEGORIES.R03"); |
|
198 //_LIT(KGlobalCategoryResFileNew, "c:\\system\\data\\EPOSLMGLOBALCATEGORIES.R01"); |
|
199 |
|
200 _LIT(KGlobalCategoryResFileOld, "c:\\resource\\EPOSLMGLOBALCATEGORIES.R03"); |
|
201 _LIT(KGlobalCategoryResFileNew, "c:\\resource\\EPOSLMGLOBALCATEGORIES.R01"); |
|
202 _LIT(KGlobalCategoryResPath, "c:\\resource\\"); |
|
203 |
|
204 RFs fs; |
|
205 User::LeaveIfError(fs.Connect()); |
|
206 CleanupClosePushL(fs); |
|
207 |
|
208 CFileMan* fileMan = CFileMan::NewL(fs); |
|
209 CleanupStack::PushL(fileMan); |
|
210 |
|
211 //check if landmark is flashed |
|
212 if (!BaflUtils::FileExists(fs, KGlobalCategoryResFileROM)) |
|
213 { |
|
214 iLog->Put(_L("Landmark is NOT flashed, rename global categories")); |
|
215 //Landmark is not flashed rename the file before copy a own defiend file. |
|
216 //since landmark is not flashed the file should exist hence leaving if it is not found! |
|
217 User::LeaveIfError(fileMan->Rename(KGlobalCategoryResFileWINS, KGlobalCategoryResFileCOPY, CFileMan::EOverWrite)); |
|
218 } |
|
219 else |
|
220 { |
|
221 iLog->Put(_L("Landmark is flashed, copy global categories")); |
|
222 } |
|
223 |
|
224 User::LeaveIfError(fileMan->Copy(KGlobalCategoryResFile, KGlobalCategoryResPath, CFileMan::EOverWrite)); |
|
225 User::LeaveIfError(fileMan->Rename(KGlobalCategoryResFileOld, KGlobalCategoryResFileNew, CFileMan::EOverWrite)); |
|
226 |
|
227 CleanupStack::PopAndDestroy(2, &fs); |
|
228 |
|
229 } |
|
230 |
|
231 // --------------------------------------------------------- |
|
232 // CPosTp39::RunReceiveEventTestL |
|
233 // |
|
234 // (other items were commented in a header). |
|
235 // --------------------------------------------------------- |
|
236 // |
|
237 void CPosTp39::RunEventsListenerL(TAny* aData) |
|
238 { |
|
239 CPosTp39* self = reinterpret_cast<CPosTp39*>(aData); |
|
240 |
|
241 CEventObserverTp39* eventObserver = CEventObserverTp39::NewL(self, ++self->iThreadIndex); |
|
242 CleanupStack::PushL(eventObserver); |
|
243 eventObserver->Start(); |
|
244 |
|
245 eventObserver->StartTimer(); |
|
246 CActiveScheduler::Start(); |
|
247 |
|
248 CleanupStack::PopAndDestroy(eventObserver); |
|
249 } |
|
250 |
|
251 LOCAL_C TInt ReceiveEventsThreadFunction(TAny* aData) |
|
252 { |
|
253 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
254 |
|
255 CActiveScheduler* actSch = new (ELeave) CActiveScheduler; |
|
256 CActiveScheduler::Install(actSch); |
|
257 |
|
258 TRAPD(err, CPosTp39::RunEventsListenerL(aData)); |
|
259 |
|
260 delete actSch; |
|
261 delete cleanup; |
|
262 return err; |
|
263 } |
|
264 |
|
265 // --------------------------------------------------------- |
|
266 // CPosTp39::CreateEventsTestL |
|
267 // |
|
268 // (other items were commented in a header). |
|
269 // --------------------------------------------------------- |
|
270 // |
|
271 void CPosTp39::RunEventsGeneratorL(TAny* /*aData*/) |
|
272 { |
|
273 //CPosTp39* self = reinterpret_cast<CPosTp39*>(aData); |
|
274 |
|
275 CPosLandmarkDatabase* lmd = CPosLandmarkDatabase::OpenL(); |
|
276 CleanupStack::PushL(lmd); |
|
277 |
|
278 if (lmd->IsInitializingNeeded()) |
|
279 { |
|
280 ExecuteAndDeleteLD(lmd->InitializeL()); |
|
281 } |
|
282 |
|
283 CPosLmCategoryManager* cm = CPosLmCategoryManager::NewL(*lmd); |
|
284 CleanupStack::PushL(cm); |
|
285 |
|
286 ///////////////////////////////////////////// |
|
287 // Add one landmark #1 |
|
288 ////////////////////////////////////////////// |
|
289 CPosLandmark* landmark = CPosLandmark::NewLC(); |
|
290 landmark->SetLandmarkNameL(_L("TP39")); |
|
291 lmd->AddLandmarkL(*landmark); |
|
292 CleanupStack::PopAndDestroy(landmark); |
|
293 |
|
294 ///////////////////////////////////////////// |
|
295 // Add 5 categories #2 |
|
296 ///////////////////////////////////////////// |
|
297 |
|
298 _LIT(KCategoryName, "TP39 Category %d"); |
|
299 for (TInt j =0; j < KMaxQueueSize; j++) |
|
300 { |
|
301 TBuf<100> name; |
|
302 name.Format(KCategoryName, j); |
|
303 CPosLandmarkCategory* category = CPosLandmarkCategory::NewLC(); |
|
304 category->SetCategoryNameL(name); |
|
305 cm->AddCategoryL(*category); |
|
306 CleanupStack::PopAndDestroy(category); |
|
307 } |
|
308 |
|
309 CleanupStack::PopAndDestroy(2, lmd); |
|
310 } |
|
311 |
|
312 LOCAL_C TInt CreateEventsThreadFunction(TAny* aData) |
|
313 { |
|
314 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
315 |
|
316 CActiveScheduler* actSch = new (ELeave) CActiveScheduler; |
|
317 CActiveScheduler::Install(actSch); |
|
318 |
|
319 TRAPD(err, CPosTp39::RunEventsGeneratorL(aData)); |
|
320 |
|
321 delete actSch; |
|
322 delete cleanup; |
|
323 return err; |
|
324 } |
|
325 |
|
326 // --------------------------------------------------------- |
|
327 // CPosTp39::CreateThreadsL |
|
328 // |
|
329 // (other items were commented in a header). |
|
330 // --------------------------------------------------------- |
|
331 // |
|
332 void CPosTp39::CreateThreadsL() |
|
333 { |
|
334 _LIT(KThreadName, "TP39 thread%d"); |
|
335 _LIT(KCreateThreadErr, "Create thread failed with %d"); |
|
336 |
|
337 for (TInt i=0; i<=KNoListeners; i++) |
|
338 { |
|
339 RThread thread; |
|
340 TBuf<32> name; |
|
341 name.Format(KThreadName, 1+iThreads.Count()); |
|
342 |
|
343 TInt err; |
|
344 if (i==KNoListeners) |
|
345 { |
|
346 err = thread.Create(name, CreateEventsThreadFunction, KDefaultStackSize, KMinHeapSize, KMaxHeapSize, reinterpret_cast<TAny*>(this)); |
|
347 } |
|
348 else |
|
349 { |
|
350 err = thread.Create(name, ReceiveEventsThreadFunction, KDefaultStackSize, KMinHeapSize, KMaxHeapSize, reinterpret_cast<TAny*>(this)); |
|
351 } |
|
352 |
|
353 AssertTrueSecL(err == KErrNone, KCreateThreadErr, err); |
|
354 |
|
355 iThreads.Append(thread); |
|
356 } |
|
357 } |
|
358 |
|
359 // --------------------------------------------------------- |
|
360 // CPosTp39::LogError |
|
361 // |
|
362 // (other items were commented in a header). |
|
363 // --------------------------------------------------------- |
|
364 // |
|
365 void CPosTp39::LogError(const TDesC& aError) |
|
366 { |
|
367 iErrorLog.Append(aError); |
|
368 iErrors++; |
|
369 } |
|
370 |
|
371 // --------------------------------------------------------- |
|
372 // CEventObserverTp39::CheckEventL |
|
373 // |
|
374 // (other items were commented in a header). |
|
375 // --------------------------------------------------------- |
|
376 // |
|
377 void CPosTp39::CheckEvent(const TInt aThreadIndex, |
|
378 const TPosLmEventType aExpectedEventType, |
|
379 const TPosLmEventType aEventType, |
|
380 const TPosLmItemId aExpectedItemId, |
|
381 const TPosLmItemId aItemId) |
|
382 { |
|
383 if (aExpectedEventType != aEventType) |
|
384 { |
|
385 _LIT(KError,"Thread %d received an unexpected eventtype. Excpected %d got %d\r\n"); |
|
386 TBuf<200> error; |
|
387 error.Format(KError, aThreadIndex, aExpectedEventType, aEventType); |
|
388 LogError(error); |
|
389 } |
|
390 if (aExpectedItemId != aItemId) |
|
391 { |
|
392 _LIT(KError,"Thread %d received an unexpected item id. Excpected %d got %d\r\n"); |
|
393 TBuf<200> error; |
|
394 error.Format(KError, aThreadIndex, aExpectedItemId, aItemId); |
|
395 LogError(error); |
|
396 } |
|
397 } |
|
398 |
|
399 // --------------------------------------------------------- |
|
400 // CPosTp39::GetHeapSizeL |
|
401 // |
|
402 // (other items were commented in a header). |
|
403 // --------------------------------------------------------- |
|
404 // |
|
405 TInt CPosTp39::GetHeapSizeL(const TDesC& aThreadName, TInt& aHeapSize, TInt& aStackSize) |
|
406 { |
|
407 RThread thread; |
|
408 TFindThread findThread(aThreadName); |
|
409 |
|
410 TFullName fullName; |
|
411 |
|
412 TInt err = findThread.Next(fullName); |
|
413 |
|
414 if (err) |
|
415 { |
|
416 iLog->Put(_L("Thread not found")); |
|
417 return err; |
|
418 } |
|
419 err = thread.Open(fullName); |
|
420 if (err) |
|
421 { |
|
422 iLog->Put(_L("Thread could not be opened")); |
|
423 return err; |
|
424 } |
|
425 |
|
426 // FrBo Commented since not supported on ARMV5 (on SDK Series60_30_2005_wk02_incl_LBSpre4) |
|
427 //err = thread.GetRamSizes(aHeapSize, aStackSize); |
|
428 // Use below for now |
|
429 err =KErrNone;aHeapSize=-1;aStackSize=-1; |
|
430 |
|
431 if (err) |
|
432 { |
|
433 iLog->Put(_L("GetRameSize fails")); |
|
434 thread.Close(); |
|
435 return err; |
|
436 } |
|
437 |
|
438 return KErrNone; |
|
439 } |
|
440 |
|
441 // ----------------------------------------------------------------------------- |
|
442 // CEventObserverTp39::NewL |
|
443 // |
|
444 //(other items were commented in a header). |
|
445 // ----------------------------------------------------------------------------- |
|
446 // |
|
447 CEventObserverTp39* CEventObserverTp39::NewL(CPosTp39* aTp39, TInt aThreadIndex) |
|
448 { |
|
449 CEventObserverTp39* self = new(ELeave) CEventObserverTp39(aTp39, aThreadIndex); |
|
450 CleanupStack::PushL(self); |
|
451 self->ConstructL(); |
|
452 CleanupStack::Pop(); |
|
453 return self; |
|
454 } |
|
455 |
|
456 // ----------------------------------------------------------------------------- |
|
457 // CEventObserverTp39::ConstructL |
|
458 // |
|
459 //(other items were commented in a header). |
|
460 // ----------------------------------------------------------------------------- |
|
461 // |
|
462 void CEventObserverTp39::ConstructL() |
|
463 { |
|
464 iDatabase = CPosLandmarkDatabase::OpenL(); |
|
465 iPeriodicTimer = CPeriodic::NewL(EPriorityNormal); |
|
466 |
|
467 if (iDatabase->IsInitializingNeeded()) |
|
468 { |
|
469 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
470 } |
|
471 } |
|
472 |
|
473 // C++ Constructor |
|
474 CEventObserverTp39::CEventObserverTp39(CPosTp39* aTp39, TInt aThreadIndex) : |
|
475 CActive(EPriorityNormal), |
|
476 iTp39(aTp39), |
|
477 iThreadIndex(aThreadIndex), |
|
478 iCallback(StopEventNotification, this) |
|
479 { |
|
480 CActiveScheduler::Add(this); |
|
481 } |
|
482 |
|
483 // C++ destructor |
|
484 CEventObserverTp39::~CEventObserverTp39() |
|
485 { |
|
486 Cancel(); |
|
487 delete iDatabase; |
|
488 iDatabase = NULL; |
|
489 if (iPeriodicTimer) |
|
490 { |
|
491 iPeriodicTimer->Cancel(); |
|
492 } |
|
493 delete iPeriodicTimer; |
|
494 iPeriodicTimer = NULL; |
|
495 } |
|
496 |
|
497 // --------------------------------------------------------- |
|
498 // CEventObserverTp39::StartL |
|
499 // |
|
500 // (other items were commented in a header). |
|
501 // --------------------------------------------------------- |
|
502 // |
|
503 void CEventObserverTp39::Start() |
|
504 { |
|
505 iDatabase->NotifyDatabaseEvent(iEvent, iStatus); |
|
506 SetActive(); |
|
507 } |
|
508 |
|
509 //--------------------------------------------------------- |
|
510 // CEventObserverTp39::DoCancel |
|
511 // |
|
512 // (other items were commented in a header). |
|
513 // --------------------------------------------------------- |
|
514 // |
|
515 void CEventObserverTp39::DoCancel() |
|
516 { |
|
517 iDatabase->CancelNotifyDatabaseEvent(); |
|
518 } |
|
519 |
|
520 //--------------------------------------------------------- |
|
521 // CEventObserverTp39::StartTimer |
|
522 // |
|
523 // (other items were commented in a header). |
|
524 // --------------------------------------------------------- |
|
525 // |
|
526 void CEventObserverTp39::StartTimer() |
|
527 { |
|
528 iPeriodicTimer->Start(10000000, 10000000, TCallBack(StopEventNotification, this)); |
|
529 } |
|
530 |
|
531 //--------------------------------------------------------- |
|
532 // CPosEventObserverTp39::TimeoutCheck |
|
533 // |
|
534 // (other items were commented in a header). |
|
535 // --------------------------------------------------------- |
|
536 // |
|
537 TInt CEventObserverTp39::StopEventNotification(TAny* aSelf) |
|
538 { |
|
539 CEventObserverTp39* self = reinterpret_cast<CEventObserverTp39*>(aSelf); |
|
540 |
|
541 self->Cancel(); |
|
542 self->iPeriodicTimer->Cancel(); |
|
543 CActiveScheduler::Stop(); |
|
544 |
|
545 return 0; |
|
546 } |
|
547 |
|
548 // --------------------------------------------------------- |
|
549 // CPosEventObserver::RunL |
|
550 // |
|
551 // (other items were commented in a header). |
|
552 // --------------------------------------------------------- |
|
553 // |
|
554 void CEventObserverTp39::RunL() |
|
555 { |
|
556 iEventNumber++; |
|
557 |
|
558 switch (iEventNumber) |
|
559 { |
|
560 case 1: |
|
561 iTp39->CheckEvent(iThreadIndex, |
|
562 EPosLmEventLandmarkCreated, |
|
563 iEvent.iEventType, |
|
564 iEventNumber, |
|
565 iEvent.iLandmarkItemId); |
|
566 // Don't renew the event notification so the server will have to start queueing the events |
|
567 break; |
|
568 default: |
|
569 iTp39->LogError(_L("Test logic error, no more events should be received since the queue on the server should be filled")); |
|
570 iPeriodicTimer->Cancel(); |
|
571 Cancel(); |
|
572 CActiveScheduler::Stop(); |
|
573 break; |
|
574 } |
|
575 //iDatabase->NotifyDatabaseEvent(iEvent, iStatus); |
|
576 //SetActive(); |
|
577 } |
|
578 |
|
579 // End of File |