1 /* |
|
2 * Copyright (c) 2009 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 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "loadgen_cpuload.h" |
|
21 #include "loadgen_memoryeat.h" |
|
22 #include "loadgen_phonecall.h" |
|
23 #include "loadgen_netconn.h" |
|
24 #include "loadgen_keypress.h" |
|
25 #include "loadgen_pointerevent.h" |
|
26 #include "loadgen_messages.h" |
|
27 #include "loadgen_applications.h" |
|
28 #include "loadgen_photocapture.h" |
|
29 #include "loadgen_bluetooth.h" |
|
30 |
|
31 #include "loadgen_traces.h" |
|
32 #include "loadgen_editors.h" |
|
33 #include "loadgen_loadattributes.h" |
|
34 #include "loadgen_model.h" |
|
35 #include "loadgen_app.h" |
|
36 #include "loadgen_settingsviewdlg.h" |
|
37 #include "loadgen_maincontainer.h" |
|
38 #include "loadgen.hrh" |
|
39 #include <loadgen.rsg> |
|
40 |
|
41 #include <coeutils.h> |
|
42 #include <bautils.h> |
|
43 #include <eikenv.h> |
|
44 #include <AknQueryDialog.h> |
|
45 #include <e32math.h> |
|
46 #include <u32hal.h> |
|
47 #include <hal.h> |
|
48 #include <hal_data.h> |
|
49 |
|
50 #include <ecam.h> |
|
51 #include <aknnotewrappers.h> |
|
52 #include <featdiscovery.h> |
|
53 |
|
54 inline TInt64 INIT_SEED() |
|
55 { |
|
56 TTime now; |
|
57 now.HomeTime(); |
|
58 return now.Int64(); |
|
59 } |
|
60 |
|
61 TInt64 CLoadGenModel::iRandomNumberSeed = INIT_SEED(); |
|
62 |
|
63 // ===================================== MEMBER FUNCTIONS ===================================== |
|
64 |
|
65 CLoadGenModel* CLoadGenModel::NewL() |
|
66 { |
|
67 CLoadGenModel* self = new(ELeave) CLoadGenModel; |
|
68 CleanupStack::PushL(self); |
|
69 self->ConstructL(); |
|
70 CleanupStack::Pop(); |
|
71 return self; |
|
72 } |
|
73 |
|
74 // -------------------------------------------------------------------------------------------- |
|
75 |
|
76 CLoadGenModel::CLoadGenModel() : CActive(EPriorityStandard) |
|
77 { |
|
78 } |
|
79 |
|
80 // -------------------------------------------------------------------------------------------- |
|
81 |
|
82 void CLoadGenModel::ConstructL() |
|
83 { |
|
84 iDrawState = EDrawStateInvalid; |
|
85 iReferenceNumber = 0; |
|
86 |
|
87 iEnv = CEikonEnv::Static(); |
|
88 User::LeaveIfError(iLs.Connect()); |
|
89 |
|
90 iLoadItemList = new(ELeave) CLoadItemList(64); |
|
91 |
|
92 User::LeaveIfError(iTimer.CreateLocal()); |
|
93 CActiveScheduler::Add(this); |
|
94 } |
|
95 |
|
96 // -------------------------------------------------------------------------------------------- |
|
97 |
|
98 void CLoadGenModel::ActivateModelL() |
|
99 { |
|
100 // load settings |
|
101 //TRAP_IGNORE(LoadSettingsL()); |
|
102 |
|
103 // set defaults to attributes |
|
104 iCpuLoadAttributes.iId = 0; |
|
105 iCpuLoadAttributes.iPriority = EThreadPriorityTypeNormal; |
|
106 iCpuLoadAttributes.iMode = ECpuLoadModeYielding; |
|
107 iCpuLoadAttributes.iType = ECpuLoadTypePeriodic; |
|
108 iCpuLoadAttributes.iLength = 4000; |
|
109 iCpuLoadAttributes.iIdle = 2000; |
|
110 iCpuLoadAttributes.iRandomVariance = 0; |
|
111 iCpuLoadAttributes.iCpu = KCPUSelection_FreeScheduling; // set CPU as "undefined" (can be >= 0 only in SMP environments) |
|
112 iCpuLoadAttributes.iCpuCount = UserSvr::HalFunction(EHalGroupKernel, KHalFunction_EKernelHalNumLogicalCpus, 0, 0); |
|
113 if( iCpuLoadAttributes.iCpuCount < 1 || iCpuLoadAttributes.iCpuCount > KMaxCPUs ) |
|
114 { |
|
115 // HAL may not support this function, so let's use CPU count 1: |
|
116 iCpuLoadAttributes.iCpuCount = 1; |
|
117 } |
|
118 iMemoryEatAttributes.iId = 0; |
|
119 iMemoryEatAttributes.iPriority = EThreadPriorityTypeNormal; |
|
120 iMemoryEatAttributes.iSource = 0; |
|
121 iMemoryEatAttributes.iType = EMemoryEatTypeMemoryToBeLeft; |
|
122 iMemoryEatAttributes.iBuffer = 16*1024; |
|
123 iMemoryEatAttributes.iIdle = 0; |
|
124 iMemoryEatAttributes.iAmount = 0; |
|
125 iMemoryEatAttributes.iRandomMin = 1000000; |
|
126 iMemoryEatAttributes.iRandomMax = 1500000; |
|
127 iMemoryEatAttributes.iAmountDes.Copy(KNullDesC); |
|
128 iMemoryEatAttributes.iRandomMinDes.Copy(KNullDesC); |
|
129 iMemoryEatAttributes.iRandomMaxDes.Copy(KNullDesC); |
|
130 iMemoryEatAttributes.iRandomVariance = 0; |
|
131 |
|
132 iPhoneCallAttributes.iId = 0; |
|
133 iPhoneCallAttributes.iPriority = EThreadPriorityTypeNormal; |
|
134 iPhoneCallAttributes.iDestination.Copy(_L("+358")); |
|
135 iPhoneCallAttributes.iLength = 60000; |
|
136 iPhoneCallAttributes.iIdle = 10000; |
|
137 iPhoneCallAttributes.iRandomVariance = 0; |
|
138 |
|
139 iNetConnAttributes.iId = 0; |
|
140 iNetConnAttributes.iPriority = EThreadPriorityTypeNormal; |
|
141 iNetConnAttributes.iDestination.Copy(_L("http://www.nokia.com")); |
|
142 iNetConnAttributes.iIdle = 10000; |
|
143 iNetConnAttributes.iRandomVariance = 0; |
|
144 |
|
145 iKeyPressAttributes.iId = 0; |
|
146 iKeyPressAttributes.iPriority = EThreadPriorityTypeNormal; |
|
147 iKeyPressAttributes.iHeartBeat = 100; |
|
148 iKeyPressAttributes.iRandomVariance = 0; |
|
149 |
|
150 iPointerEventAttributes.iId = 0; |
|
151 iPointerEventAttributes.iPriority = EThreadPriorityTypeNormal; |
|
152 iPointerEventAttributes.iHeartBeat = 1000; |
|
153 iPointerEventAttributes.iRandomVariance = 0; |
|
154 |
|
155 iMessageAttributes.iId = 0; |
|
156 iMessageAttributes.iPriority = EThreadPriorityTypeNormal; |
|
157 iMessageAttributes.iMessageType = EMessageTypeSMS; |
|
158 iMessageAttributes.iDestination.Copy(_L("+358")); |
|
159 iMessageAttributes.iAmount = 5; |
|
160 iMessageAttributes.iLength = 160; |
|
161 iMessageAttributes.iIdle = 15000; |
|
162 iMessageAttributes.iRandomVariance = 0; |
|
163 |
|
164 iApplicationsAttributes.iId = 0; |
|
165 iApplicationsAttributes.iLaunchingInterval = 2000; |
|
166 iApplicationsAttributes.iPriority = EThreadPriorityTypeNormal; |
|
167 iApplicationsAttributes.iKeyPressType = EApplicationsKeyPressTypeNone; |
|
168 iApplicationsAttributes.iMaxOpen = 20; |
|
169 iApplicationsAttributes.iHeartBeat = 50; |
|
170 iApplicationsAttributes.iRandomVariance = 0; |
|
171 |
|
172 iPhotoCaptureAttributes.iId = 0; |
|
173 iPhotoCaptureAttributes.iPriority = EThreadPriorityTypeNormal; |
|
174 iPhotoCaptureAttributes.iIdle = 10000; |
|
175 iPhotoCaptureAttributes.iRandomVariance = 0; |
|
176 iPhotoCaptureAttributes.iCameraCount = CCamera::CamerasAvailable(); |
|
177 if(iPhotoCaptureAttributes.iCameraCount > 0) |
|
178 { |
|
179 iPhotoCaptureAttributes.iCamera = 0; // Main camera |
|
180 } |
|
181 else |
|
182 { |
|
183 iPhotoCaptureAttributes.iCamera = -1; |
|
184 } |
|
185 |
|
186 iBluetoothAttributes.iId = 0; |
|
187 iBluetoothAttributes.iPriority = EThreadPriorityTypeNormal; |
|
188 iBluetoothAttributes.iIdle = 10000; |
|
189 iBluetoothAttributes.iRandomVariance = 0; |
|
190 iBluetoothAttributes.iBluetoothSupported = CFeatureDiscovery::IsFeatureSupportedL(KFeatureIdBt); |
|
191 } |
|
192 |
|
193 // -------------------------------------------------------------------------------------------- |
|
194 |
|
195 void CLoadGenModel::DeActivateModelL() |
|
196 { |
|
197 Cancel(); |
|
198 |
|
199 // for a faster exit, send the application to background |
|
200 TApaTask selfTask(iEnv->WsSession()); |
|
201 selfTask.SetWgId(iEnv->RootWin().Identifier()); |
|
202 selfTask.SendToBackground(); |
|
203 } |
|
204 |
|
205 // -------------------------------------------------------------------------------------------- |
|
206 |
|
207 CLoadGenModel::~CLoadGenModel() |
|
208 { |
|
209 if (iLoadItemList) |
|
210 { |
|
211 DeleteAllLoadItems(); |
|
212 delete iLoadItemList; |
|
213 } |
|
214 if ( iApplicationsAttributes.iAppsArray ) |
|
215 { |
|
216 delete iApplicationsAttributes.iAppsArray; |
|
217 } |
|
218 iTimer.Close(); |
|
219 iLs.Close(); |
|
220 } |
|
221 |
|
222 // -------------------------------------------------------------------------------------------- |
|
223 |
|
224 void CLoadGenModel::DoCancel() |
|
225 { |
|
226 iTimer.Cancel(); |
|
227 } |
|
228 |
|
229 // -------------------------------------------------------------------------------------------- |
|
230 |
|
231 void CLoadGenModel::RunL() |
|
232 { |
|
233 // continue |
|
234 //iTimer.After(iStatus, 400000); |
|
235 //SetActive(); |
|
236 } |
|
237 |
|
238 // -------------------------------------------------------------------------------------------- |
|
239 |
|
240 void CLoadGenModel::SetMainContainer(CLoadGenMainContainer* aContainer) |
|
241 { |
|
242 iMainContainer = aContainer; |
|
243 iDrawState = EDrawStateMain; |
|
244 } |
|
245 |
|
246 // -------------------------------------------------------------------------------------------- |
|
247 |
|
248 void CLoadGenModel::StartNewLoadL(TInt aCommand) |
|
249 { |
|
250 // show new load query |
|
251 CLoadGenLoadTypeEditorBase* dlg = NULL; |
|
252 |
|
253 switch ( aCommand ) |
|
254 { |
|
255 case ELoadGenCmdNewLoadCPULoad: |
|
256 { |
|
257 dlg = CLoadGenCPULoadEditor::NewL(iCpuLoadAttributes); |
|
258 break; |
|
259 } |
|
260 case ELoadGenCmdNewLoadEatMemory: |
|
261 { |
|
262 dlg = CLoadGenMemoryEatEditor::NewL(iMemoryEatAttributes); |
|
263 break; |
|
264 } |
|
265 case ELoadGenCmdNewLoadPhoneCall: |
|
266 { |
|
267 dlg = CLoadGenPhoneCallEditor::NewL(iPhoneCallAttributes); |
|
268 break; |
|
269 } |
|
270 case ELoadGenCmdNewLoadNetConn: |
|
271 { |
|
272 dlg = CLoadGenNetConnEditor::NewL(iNetConnAttributes); |
|
273 break; |
|
274 } |
|
275 case ELoadGenCmdNewLoadKeyPress: |
|
276 { |
|
277 dlg = CLoadGenKeyPressEditor::NewL(iKeyPressAttributes); |
|
278 break; |
|
279 } |
|
280 case ELoadGenCmdNewLoadMessages: |
|
281 { |
|
282 dlg = CLoadGenMessagesEditor::NewL( iMessageAttributes ); |
|
283 break; |
|
284 } |
|
285 case ELoadGenCmdNewLoadApplications: |
|
286 { |
|
287 dlg = CLoadGenApplicationsEditor::NewL( iApplicationsAttributes ); |
|
288 break; |
|
289 } |
|
290 case ELoadGenCmdNewLoadPhotoCaptures: |
|
291 { |
|
292 if( iPhotoCaptureAttributes.iCameraCount > 0 ) |
|
293 { |
|
294 dlg = CLoadGenPhotoCaptureEditor::NewL( iPhotoCaptureAttributes ); |
|
295 } |
|
296 else |
|
297 { |
|
298 _LIT(message, "Cameras not available"); |
|
299 CAknErrorNote* errorNote = new(ELeave) CAknErrorNote; |
|
300 errorNote->ExecuteLD(message); |
|
301 return; |
|
302 } |
|
303 break; |
|
304 } |
|
305 case ELoadGenCmdNewLoadBluetooth: |
|
306 { |
|
307 if( iBluetoothAttributes.iBluetoothSupported ) |
|
308 { |
|
309 dlg = CLoadGenBluetoothEditor::NewL(iBluetoothAttributes); |
|
310 } |
|
311 else |
|
312 { |
|
313 _LIT(message, "Bluetooth device not available"); |
|
314 CAknErrorNote* errorNote = new(ELeave) CAknErrorNote; |
|
315 errorNote->ExecuteLD(message); |
|
316 return; |
|
317 } |
|
318 break; |
|
319 } |
|
320 case ELoadGenCmdNewLoadPointerEvent: |
|
321 { |
|
322 dlg = CLoadGenPointerEventEditor::NewL(iPointerEventAttributes); |
|
323 break; |
|
324 } |
|
325 |
|
326 default: |
|
327 { |
|
328 User::Panic(_L("Wrong new load"), 111); |
|
329 break; |
|
330 } |
|
331 } |
|
332 |
|
333 TBool dlgResult = dlg->RunQueryLD(); |
|
334 |
|
335 // set back title |
|
336 if (iMainContainer) |
|
337 iMainContainer->SetDefaultTitlePaneTextL(); |
|
338 |
|
339 // start creating new load if dialog accepted |
|
340 if (dlgResult) |
|
341 { |
|
342 DoStartNewLoadL(aCommand); |
|
343 } |
|
344 |
|
345 } |
|
346 |
|
347 // -------------------------------------------------------------------------------------------- |
|
348 |
|
349 void CLoadGenModel::EditLoadL(CLoadBase* aItem) |
|
350 { |
|
351 // suspend current |
|
352 aItem->Suspend(); |
|
353 |
|
354 // show new load query |
|
355 CLoadGenLoadTypeEditorBase* dlg = NULL; |
|
356 |
|
357 switch ( aItem->Type() ) |
|
358 { |
|
359 case ELoadGenCmdNewLoadCPULoad: |
|
360 { |
|
361 dlg = CLoadGenCPULoadEditor::NewL(static_cast<CCPULoad*>(aItem)->Attributes(), ETrue); |
|
362 break; |
|
363 } |
|
364 case ELoadGenCmdNewLoadEatMemory: |
|
365 { |
|
366 dlg = CLoadGenMemoryEatEditor::NewL(static_cast<CMemoryEat*>(aItem)->Attributes(), ETrue); |
|
367 break; |
|
368 } |
|
369 case ELoadGenCmdNewLoadPhoneCall: |
|
370 { |
|
371 dlg = CLoadGenPhoneCallEditor::NewL(static_cast<CPhoneCall*>(aItem)->Attributes(), ETrue); |
|
372 break; |
|
373 } |
|
374 case ELoadGenCmdNewLoadNetConn: |
|
375 { |
|
376 dlg = CLoadGenNetConnEditor::NewL(static_cast<CNetConn*>(aItem)->Attributes(), ETrue); |
|
377 break; |
|
378 } |
|
379 case ELoadGenCmdNewLoadKeyPress: |
|
380 { |
|
381 dlg = CLoadGenKeyPressEditor::NewL(static_cast<CKeyPress*>(aItem)->Attributes(), ETrue); |
|
382 break; |
|
383 } |
|
384 case ELoadGenCmdNewLoadMessages: |
|
385 { |
|
386 dlg = CLoadGenMessagesEditor::NewL(static_cast<CMessages*>(aItem)->Attributes(), ETrue); |
|
387 break; |
|
388 } |
|
389 case ELoadGenCmdNewLoadApplications: |
|
390 { |
|
391 dlg = CLoadGenApplicationsEditor::NewL( static_cast<CAppLauncher*>(aItem)->Attributes(), ETrue ); |
|
392 break; |
|
393 } |
|
394 case ELoadGenCmdNewLoadPhotoCaptures: |
|
395 { |
|
396 dlg = CLoadGenPhotoCaptureEditor::NewL( static_cast<CPhotoCapture*>(aItem)->Attributes(), ETrue ); |
|
397 break; |
|
398 } |
|
399 case ELoadGenCmdNewLoadBluetooth: |
|
400 { |
|
401 dlg = CLoadGenBluetoothEditor::NewL( static_cast<CBluetooth*>(aItem)->Attributes(), ETrue ); |
|
402 break; |
|
403 } |
|
404 case ELoadGenCmdNewLoadPointerEvent: |
|
405 { |
|
406 dlg = CLoadGenPointerEventEditor::NewL(static_cast<CPointerEvent*>(aItem)->Attributes(), ETrue); |
|
407 break; |
|
408 } |
|
409 default: |
|
410 { |
|
411 User::Panic(_L("Wrong edit load"), 114); |
|
412 break; |
|
413 } |
|
414 } |
|
415 |
|
416 TBool dlgResult = dlg->RunQueryLD(); |
|
417 |
|
418 // set back title |
|
419 if (iMainContainer) |
|
420 iMainContainer->SetDefaultTitlePaneTextL(); |
|
421 |
|
422 // change priority of the load item |
|
423 aItem->SetPriority(); |
|
424 |
|
425 // resume execution the item |
|
426 aItem->Resume(); |
|
427 |
|
428 if (dlgResult) |
|
429 RefreshViewL(EFalse); |
|
430 } |
|
431 |
|
432 // -------------------------------------------------------------------------------------------- |
|
433 |
|
434 void CLoadGenModel::DoStartNewLoadL(TInt aCommand) |
|
435 { |
|
436 CLoadBase* item = NULL; |
|
437 |
|
438 switch ( aCommand ) |
|
439 { |
|
440 case ELoadGenCmdNewLoadCPULoad: |
|
441 { |
|
442 if( iCpuLoadAttributes.iCpu == KCPUSelection_AllCPUs ) |
|
443 { |
|
444 // Call this function recursively for all CPUs: |
|
445 for( TUint i = 0; i < iCpuLoadAttributes.iCpuCount; ++i ) |
|
446 { |
|
447 iCpuLoadAttributes.iCpu = i; |
|
448 DoStartNewLoadL(aCommand); |
|
449 } |
|
450 // And finally set user selection back to "All CPUs" |
|
451 iCpuLoadAttributes.iCpu = KCPUSelection_AllCPUs; |
|
452 return; |
|
453 } |
|
454 else |
|
455 { |
|
456 item = CCPULoad::NewL(iCpuLoadAttributes, iReferenceNumber); |
|
457 } |
|
458 break; |
|
459 } |
|
460 case ELoadGenCmdNewLoadEatMemory: |
|
461 { |
|
462 item = CMemoryEat::NewL(iMemoryEatAttributes, iReferenceNumber); |
|
463 break; |
|
464 } |
|
465 case ELoadGenCmdNewLoadPhoneCall: |
|
466 { |
|
467 item = CPhoneCall::NewL(iPhoneCallAttributes, iReferenceNumber); |
|
468 break; |
|
469 } |
|
470 case ELoadGenCmdNewLoadNetConn: |
|
471 { |
|
472 item = CNetConn::NewL(iNetConnAttributes, iReferenceNumber); |
|
473 break; |
|
474 } |
|
475 case ELoadGenCmdNewLoadKeyPress: |
|
476 { |
|
477 item = CKeyPress::NewL(iKeyPressAttributes, iReferenceNumber); |
|
478 break; |
|
479 } |
|
480 case ELoadGenCmdNewLoadMessages: |
|
481 { |
|
482 item = CMessages::NewL( iMessageAttributes, iReferenceNumber ); |
|
483 break; |
|
484 } |
|
485 case ELoadGenCmdNewLoadApplications: |
|
486 { |
|
487 iApplicationsAttributes.iAppsArray = ListOfAllAppsL(); |
|
488 item = CAppLauncher::NewL( iApplicationsAttributes, iReferenceNumber ); |
|
489 break; |
|
490 } |
|
491 case ELoadGenCmdNewLoadPhotoCaptures: |
|
492 { |
|
493 item = CPhotoCapture::NewL( iPhotoCaptureAttributes, iReferenceNumber); |
|
494 break; |
|
495 } |
|
496 case ELoadGenCmdNewLoadBluetooth: |
|
497 { |
|
498 item = CBluetooth::NewL( iBluetoothAttributes, iReferenceNumber); |
|
499 break; |
|
500 } |
|
501 case ELoadGenCmdNewLoadPointerEvent: |
|
502 { |
|
503 item = CPointerEvent::NewL(iPointerEventAttributes, iReferenceNumber); |
|
504 break; |
|
505 } |
|
506 |
|
507 default: |
|
508 { |
|
509 User::Panic(_L("Wrong new load"), 112); |
|
510 break; |
|
511 } |
|
512 } |
|
513 |
|
514 iReferenceNumber++; |
|
515 |
|
516 // add item to the array |
|
517 AppendToLoadItemListL(item); |
|
518 |
|
519 // update the listbox |
|
520 RefreshViewL(EFalse); |
|
521 |
|
522 // set item index to the end |
|
523 iMainContainer->ListBox()->SetCurrentItemIndexAndDraw( iMainContainer->ListBox()->Model()->NumberOfItems()-1 ); |
|
524 |
|
525 // start the load |
|
526 item->Resume(); |
|
527 |
|
528 // refresh again |
|
529 RefreshViewL(EFalse); |
|
530 } |
|
531 |
|
532 // -------------------------------------------------------------------------------------------- |
|
533 |
|
534 |
|
535 void CLoadGenModel::StopAllLoadItemsL() |
|
536 { |
|
537 DeleteAllLoadItems(); |
|
538 |
|
539 RefreshViewL(); |
|
540 } |
|
541 |
|
542 // -------------------------------------------------------------------------------------------- |
|
543 |
|
544 void CLoadGenModel::SuspendAllLoadItemsL() |
|
545 { |
|
546 for (TInt i=0; i<LoadItemCount(); i++) |
|
547 { |
|
548 if ( iLoadItemList->At(i) ) |
|
549 { |
|
550 iLoadItemList->At(i)->Suspend(); |
|
551 } |
|
552 } |
|
553 |
|
554 RefreshViewL(); |
|
555 } |
|
556 // -------------------------------------------------------------------------------------------- |
|
557 |
|
558 void CLoadGenModel::ResumeAllLoadItemsL() |
|
559 { |
|
560 for (TInt i=0; i<LoadItemCount(); i++) |
|
561 { |
|
562 if ( iLoadItemList->At(i) ) |
|
563 { |
|
564 iLoadItemList->At(i)->Resume(); |
|
565 } |
|
566 } |
|
567 |
|
568 RefreshViewL(); |
|
569 } |
|
570 |
|
571 // -------------------------------------------------------------------------------------------- |
|
572 |
|
573 void CLoadGenModel::RefreshViewL(TBool aClearSelection) |
|
574 { |
|
575 if (iMainContainer && iDrawState == EDrawStateMain && iMainContainer->ListBox()) |
|
576 { |
|
577 // clear selections if any |
|
578 iMainContainer->ListBox()->ClearSelection(); |
|
579 |
|
580 // set item index to 0 |
|
581 if (aClearSelection) |
|
582 iMainContainer->ListBox()->SetCurrentItemIndex(0); |
|
583 |
|
584 // set text items |
|
585 iMainContainer->SetListBoxTextArrayL(GenerateListBoxItemTextArrayL()); |
|
586 } |
|
587 } |
|
588 |
|
589 // -------------------------------------------------------------------------------------------- |
|
590 |
|
591 void CLoadGenModel::AppendToLoadItemListL(CLoadBase* aItem) |
|
592 { |
|
593 if (iLoadItemList) |
|
594 iLoadItemList->AppendL( aItem ); |
|
595 else |
|
596 User::Leave(KErrNotReady); |
|
597 } |
|
598 |
|
599 // -------------------------------------------------------------------------------------------- |
|
600 |
|
601 void CLoadGenModel::DeleteFromLoadItemListL(TInt aIndex) |
|
602 { |
|
603 if (iLoadItemList) |
|
604 { |
|
605 if (iLoadItemList->Count() > aIndex && aIndex >= 0) |
|
606 { |
|
607 // first call delete on the item |
|
608 if (iLoadItemList->At(aIndex)) |
|
609 { |
|
610 delete iLoadItemList->At(aIndex); |
|
611 iLoadItemList->At(aIndex) = NULL; |
|
612 } |
|
613 |
|
614 // and them remove the array entry |
|
615 iLoadItemList->Delete(aIndex); |
|
616 iLoadItemList->Compress(); |
|
617 } |
|
618 else |
|
619 User::Leave(KErrNotFound); |
|
620 } |
|
621 else |
|
622 User::Leave(KErrNotReady); |
|
623 } |
|
624 |
|
625 // -------------------------------------------------------------------------------------------- |
|
626 |
|
627 void CLoadGenModel::SuspendOrResumeFromLoadItemListL(TInt aIndex) |
|
628 { |
|
629 if (iLoadItemList) |
|
630 { |
|
631 if (iLoadItemList->Count() > aIndex && aIndex >= 0) |
|
632 { |
|
633 if (iLoadItemList->At(aIndex)) |
|
634 { |
|
635 if (iLoadItemList->At(aIndex)->State() == CLoadBase::ELoadStateRunning) |
|
636 { |
|
637 iLoadItemList->At(aIndex)->Suspend(); |
|
638 } |
|
639 else if (iLoadItemList->At(aIndex)->State() == CLoadBase::ELoadStateSuspended) |
|
640 { |
|
641 iLoadItemList->At(aIndex)->Resume(); |
|
642 } |
|
643 } |
|
644 } |
|
645 else |
|
646 User::Leave(KErrNotFound); |
|
647 } |
|
648 else |
|
649 User::Leave(KErrNotReady); |
|
650 } |
|
651 |
|
652 // -------------------------------------------------------------------------------------------- |
|
653 |
|
654 TInt CLoadGenModel::LoadItemCount() const |
|
655 { |
|
656 TInt count(0); |
|
657 |
|
658 if (iLoadItemList) |
|
659 count = iLoadItemList->Count(); |
|
660 |
|
661 return count; |
|
662 } |
|
663 |
|
664 // -------------------------------------------------------------------------------------------- |
|
665 |
|
666 void CLoadGenModel::DeleteAllLoadItems() |
|
667 { |
|
668 // call delete for each entry and free memory allocated for the array |
|
669 for (TInt i=0; i<LoadItemCount(); i++) |
|
670 { |
|
671 if ( iLoadItemList->At(i) ) |
|
672 { |
|
673 delete iLoadItemList->At(i); |
|
674 iLoadItemList->At(i) = NULL; |
|
675 } |
|
676 } |
|
677 |
|
678 iLoadItemList->Reset(); |
|
679 } |
|
680 |
|
681 // -------------------------------------------------------------------------------------------- |
|
682 |
|
683 CDesCArray* CLoadGenModel::GenerateListBoxItemTextArrayL() |
|
684 { |
|
685 CDesCArray* textArray = new(ELeave) CDesCArrayFlat(64); |
|
686 CleanupStack::PushL(textArray); |
|
687 |
|
688 _LIT(KEntryTemplateRedIcon, "1\t%S\t\t"); |
|
689 _LIT(KEntryTemplateGreenIcon, "2\t%S\t\t"); |
|
690 |
|
691 for (TInt i=0; i<LoadItemCount(); i++) |
|
692 { |
|
693 // add description from each entry |
|
694 TBuf<256> textEntry; |
|
695 TBuf<256> description = iLoadItemList->At(i)->Description(); |
|
696 |
|
697 if (iLoadItemList->At(i)->State() == CLoadBase::ELoadStateRunning) |
|
698 textEntry.Format(KEntryTemplateGreenIcon, &description); |
|
699 else |
|
700 textEntry.Format(KEntryTemplateRedIcon, &description); |
|
701 |
|
702 textArray->AppendL(textEntry); |
|
703 } |
|
704 |
|
705 CleanupStack::Pop(); //textArray |
|
706 return textArray; |
|
707 } |
|
708 |
|
709 // -------------------------------------------------------------------------------------------- |
|
710 |
|
711 void CLoadGenModel::ShowItemActionMenuL() |
|
712 { |
|
713 TInt currentItemIndex = iMainContainer->CurrentListBoxItemIndex(); |
|
714 |
|
715 if (LoadItemCount() > currentItemIndex && currentItemIndex >= 0) |
|
716 { |
|
717 // show a query dialog |
|
718 TInt queryIndex(0); |
|
719 CAknListQueryDialog* listQueryDlg = new(ELeave) CAknListQueryDialog(&queryIndex); |
|
720 |
|
721 if (listQueryDlg->ExecuteLD(R_ITEM_ACTION_QUERY)) |
|
722 { |
|
723 // stop |
|
724 if (queryIndex == EItemActionMenuTypeStop) |
|
725 { |
|
726 StopSelectedOrHighlightedItemsL(); |
|
727 } |
|
728 |
|
729 // suspend or resume |
|
730 else if (queryIndex == EItemActionMenuTypeSuspendResume) |
|
731 { |
|
732 SuspendOrResumeSelectedOrHighlightedItemsL(); |
|
733 } |
|
734 |
|
735 // edit |
|
736 else if (queryIndex == EItemActionMenuTypeEdit) |
|
737 { |
|
738 EditLoadL(iLoadItemList->At(currentItemIndex)); |
|
739 } |
|
740 } |
|
741 } |
|
742 } |
|
743 |
|
744 // -------------------------------------------------------------------------------------------- |
|
745 |
|
746 void CLoadGenModel::StopSelectedOrHighlightedItemsL() |
|
747 { |
|
748 const CArrayFix<TInt>* selectionIndexes = iMainContainer->ListBoxSelectionIndexes(); |
|
749 |
|
750 TInt err(KErrNone); |
|
751 |
|
752 // by default use selected items |
|
753 if (selectionIndexes && selectionIndexes->Count() > 0) |
|
754 { |
|
755 CAknQueryDialog* query = CAknQueryDialog::NewL(); |
|
756 _LIT(KQueryMessage, "Stop %d selections?"); |
|
757 TFileName queryMsg; |
|
758 queryMsg.Format(KQueryMessage, selectionIndexes->Count()); |
|
759 |
|
760 |
|
761 if (query->ExecuteLD(R_GENERAL_CONFIRMATION_QUERY, queryMsg)) |
|
762 { |
|
763 TInt deleteIndexCounter(0); |
|
764 TInt ref(0); |
|
765 TKeyArrayFix key(0, ECmpTUint16); |
|
766 TInt index(0); |
|
767 |
|
768 TInt loadCount = LoadItemCount(); |
|
769 |
|
770 for (TInt i=0; i<loadCount; i++) |
|
771 { |
|
772 ref = i; |
|
773 |
|
774 if (selectionIndexes->Find(ref, key, index) == 0) |
|
775 { |
|
776 TRAP(err, DeleteFromLoadItemListL(i-deleteIndexCounter)); |
|
777 deleteIndexCounter++; // amount of indexes decreases after each delete |
|
778 } |
|
779 } |
|
780 |
|
781 RefreshViewL(); |
|
782 User::LeaveIfError(err); |
|
783 } |
|
784 } |
|
785 |
|
786 // or if none selected, use the current item index |
|
787 else |
|
788 { |
|
789 TInt currentItemIndex = iMainContainer->CurrentListBoxItemIndex(); |
|
790 |
|
791 if (LoadItemCount() > currentItemIndex && currentItemIndex >= 0) |
|
792 { |
|
793 CAknQueryDialog* query = CAknQueryDialog::NewL(); |
|
794 _LIT(KQueryMessage, "Stop hightlighted item?"); |
|
795 |
|
796 if (query->ExecuteLD(R_GENERAL_CONFIRMATION_QUERY, KQueryMessage)) |
|
797 { |
|
798 TRAP(err, DeleteFromLoadItemListL(currentItemIndex)); |
|
799 |
|
800 RefreshViewL(); |
|
801 User::LeaveIfError(err); |
|
802 } |
|
803 } |
|
804 } |
|
805 } |
|
806 |
|
807 // -------------------------------------------------------------------------------------------- |
|
808 |
|
809 void CLoadGenModel::SuspendOrResumeSelectedOrHighlightedItemsL() |
|
810 { |
|
811 const CArrayFix<TInt>* selectionIndexes = iMainContainer->ListBoxSelectionIndexes(); |
|
812 |
|
813 // by default use selected items |
|
814 if (selectionIndexes && selectionIndexes->Count() > 0) |
|
815 { |
|
816 TInt ref(0); |
|
817 TKeyArrayFix key(0, ECmpTUint16); |
|
818 TInt index(0); |
|
819 |
|
820 for (TInt i=0; i<LoadItemCount(); i++) |
|
821 { |
|
822 ref = i; |
|
823 |
|
824 if (selectionIndexes->Find(ref, key, index) == 0) |
|
825 { |
|
826 SuspendOrResumeFromLoadItemListL(i); |
|
827 } |
|
828 } |
|
829 |
|
830 RefreshViewL(EFalse); |
|
831 } |
|
832 |
|
833 // or if none selected, use the current item index |
|
834 else |
|
835 { |
|
836 TInt currentItemIndex = iMainContainer->CurrentListBoxItemIndex(); |
|
837 |
|
838 if (LoadItemCount() > currentItemIndex && currentItemIndex >= 0) |
|
839 { |
|
840 SuspendOrResumeFromLoadItemListL(currentItemIndex); |
|
841 |
|
842 RefreshViewL(EFalse); |
|
843 } |
|
844 } |
|
845 } |
|
846 // -------------------------------------------------------------------------------------------- |
|
847 |
|
848 void CLoadGenModel::LoadSettingsL() |
|
849 { |
|
850 } |
|
851 |
|
852 // -------------------------------------------------------------------------------------------- |
|
853 |
|
854 void CLoadGenModel::SaveSettingsL() |
|
855 { |
|
856 } |
|
857 |
|
858 // -------------------------------------------------------------------------------------------- |
|
859 |
|
860 TInt CLoadGenModel::LaunchSettingsDialogL() |
|
861 { |
|
862 return 0; |
|
863 } |
|
864 |
|
865 // -------------------------------------------------------------------------------------------- |
|
866 |
|
867 TThreadPriority CLoadGenModel::SettingItemToThreadPriority(TInt aIndex) |
|
868 { |
|
869 TThreadPriority threadPriority = EPriorityNull; |
|
870 |
|
871 switch ( aIndex ) |
|
872 { |
|
873 case EThreadPriorityTypeMuchLess: |
|
874 { |
|
875 threadPriority = EPriorityMuchLess; break; |
|
876 } |
|
877 case EThreadPriorityTypeLess: |
|
878 { |
|
879 threadPriority = EPriorityLess; break; |
|
880 } |
|
881 case EThreadPriorityTypeNormal: |
|
882 { |
|
883 threadPriority = EPriorityNormal; break; |
|
884 } |
|
885 case EThreadPriorityTypeMore: |
|
886 { |
|
887 threadPriority = EPriorityMore; break; |
|
888 } |
|
889 case EThreadPriorityTypeMuchMore: |
|
890 { |
|
891 threadPriority = EPriorityMuchMore; break; |
|
892 } |
|
893 case EThreadPriorityTypeRealTime: |
|
894 { |
|
895 threadPriority = EPriorityRealTime; break; |
|
896 } |
|
897 case EThreadPriorityTypeAbsoluteVeryLow: |
|
898 { |
|
899 threadPriority = EPriorityAbsoluteVeryLow; break; |
|
900 } |
|
901 case EThreadPriorityTypeAbsoluteLow: |
|
902 { |
|
903 threadPriority = EPriorityAbsoluteLow; break; |
|
904 } |
|
905 case EThreadPriorityTypeAbsoluteBackground: |
|
906 { |
|
907 threadPriority = EPriorityAbsoluteBackground; break; |
|
908 } |
|
909 case EThreadPriorityTypeAbsoluteForeground: |
|
910 { |
|
911 threadPriority = EPriorityAbsoluteForeground; break; |
|
912 } |
|
913 case EThreadPriorityTypeAbsoluteHigh: |
|
914 { |
|
915 threadPriority = EPriorityAbsoluteHigh; break; |
|
916 } |
|
917 |
|
918 default: |
|
919 { |
|
920 User::Panic(_L("Wrong tp index"), 276); |
|
921 break; |
|
922 } |
|
923 } |
|
924 |
|
925 return threadPriority; |
|
926 } |
|
927 |
|
928 // -------------------------------------------------------------------------------------------- |
|
929 |
|
930 void CLoadGenModel::SettingItemToThreadDescription(TInt aIndex, TDes& aBuf) |
|
931 { |
|
932 switch ( aIndex ) |
|
933 { |
|
934 case EThreadPriorityTypeMuchLess: |
|
935 { |
|
936 aBuf.Append(_L("ML(-20)")); break; |
|
937 } |
|
938 case EThreadPriorityTypeLess: |
|
939 { |
|
940 aBuf.Append(_L("L(-10)")); break; |
|
941 } |
|
942 case EThreadPriorityTypeNormal: |
|
943 { |
|
944 aBuf.Append(_L("NO(0)")); break; |
|
945 } |
|
946 case EThreadPriorityTypeMore: |
|
947 { |
|
948 aBuf.Append(_L("M(10)")); break; |
|
949 } |
|
950 case EThreadPriorityTypeMuchMore: |
|
951 { |
|
952 aBuf.Append(_L("MM(20)")); break; |
|
953 } |
|
954 case EThreadPriorityTypeRealTime: |
|
955 { |
|
956 aBuf.Append(_L("RL(30)")); break; |
|
957 } |
|
958 case EThreadPriorityTypeAbsoluteVeryLow: |
|
959 { |
|
960 aBuf.Append(_L("AVL(100)")); break; |
|
961 } |
|
962 case EThreadPriorityTypeAbsoluteLow: |
|
963 { |
|
964 aBuf.Append(_L("AL(200)")); break; |
|
965 } |
|
966 case EThreadPriorityTypeAbsoluteBackground: |
|
967 { |
|
968 aBuf.Append(_L("ABG(300)")); break; |
|
969 } |
|
970 case EThreadPriorityTypeAbsoluteForeground: |
|
971 { |
|
972 aBuf.Append(_L("AFG(400)")); break; |
|
973 } |
|
974 case EThreadPriorityTypeAbsoluteHigh: |
|
975 { |
|
976 aBuf.Append(_L("AH(500)")); break; |
|
977 } |
|
978 |
|
979 default: |
|
980 { |
|
981 User::Panic(_L("Wrong td index"), 277); |
|
982 break; |
|
983 } |
|
984 } |
|
985 } |
|
986 |
|
987 // -------------------------------------------------------------------------------------------- |
|
988 |
|
989 void CLoadGenModel::SettingItemToSourceDescription(TInt aIndex, TDes& aBuf) |
|
990 { |
|
991 switch ( aIndex ) |
|
992 { |
|
993 case EMemoryEatSourceTypeRAM: |
|
994 { |
|
995 aBuf.Append(_L("RAM")); break; |
|
996 } |
|
997 case EMemoryEatSourceTypeDriveC: |
|
998 { |
|
999 aBuf.Append(_L("C:")); break; |
|
1000 } |
|
1001 case EMemoryEatSourceTypeDriveD: |
|
1002 { |
|
1003 aBuf.Append(_L("D:")); break; |
|
1004 } |
|
1005 case EMemoryEatSourceTypeDriveE: |
|
1006 { |
|
1007 aBuf.Append(_L("E:")); break; |
|
1008 } |
|
1009 case EMemoryEatSourceTypeDriveF: |
|
1010 { |
|
1011 aBuf.Append(_L("F:")); break; |
|
1012 } |
|
1013 case EMemoryEatSourceTypeDriveG: |
|
1014 { |
|
1015 aBuf.Append(_L("G:")); break; |
|
1016 } |
|
1017 case EMemoryEatSourceTypeDriveH: |
|
1018 { |
|
1019 aBuf.Append(_L("H:")); break; |
|
1020 } |
|
1021 case EMemoryEatSourceTypeDriveI: |
|
1022 { |
|
1023 aBuf.Append(_L("I:")); break; |
|
1024 } |
|
1025 case EMemoryEatSourceTypeDriveJ: |
|
1026 { |
|
1027 aBuf.Append(_L("J:")); break; |
|
1028 } |
|
1029 case EMemoryEatSourceTypeDriveK: |
|
1030 { |
|
1031 aBuf.Append(_L("K:")); break; |
|
1032 } |
|
1033 case EMemoryEatSourceTypeDriveL: |
|
1034 { |
|
1035 aBuf.Append(_L("L:")); break; |
|
1036 } |
|
1037 case EMemoryEatSourceTypeDriveM: |
|
1038 { |
|
1039 aBuf.Append(_L("M:")); break; |
|
1040 } |
|
1041 case EMemoryEatSourceTypeDriveN: |
|
1042 { |
|
1043 aBuf.Append(_L("N:")); break; |
|
1044 } |
|
1045 |
|
1046 default: |
|
1047 { |
|
1048 User::Panic(_L("Wrong src index"), 278); |
|
1049 break; |
|
1050 } |
|
1051 } |
|
1052 } |
|
1053 |
|
1054 // -------------------------------------------------------------------------------------------- |
|
1055 |
|
1056 TInt CLoadGenModel::MilliSecondsToMicroSeconds(TInt aMilliSeconds, TInt aRandomVariance) |
|
1057 { |
|
1058 __ASSERT_ALWAYS(aRandomVariance >= 0 && aRandomVariance <= 100, User::Panic(_L("Inv.var."), 180)); |
|
1059 __ASSERT_ALWAYS(aMilliSeconds >=0, User::Panic(_L("Inv.ms."), 181)); |
|
1060 |
|
1061 // if no variance defined, just do a quick conversion |
|
1062 if (aRandomVariance == 0 || aMilliSeconds == 0) |
|
1063 return aMilliSeconds * 1000; |
|
1064 |
|
1065 // otherwise calculate difference |
|
1066 TInt diff = 1000 * aMilliSeconds / 2 * aRandomVariance / 100; |
|
1067 |
|
1068 return RandomNumber(aMilliSeconds*1000-diff, aMilliSeconds*1000+diff); |
|
1069 } |
|
1070 |
|
1071 // -------------------------------------------------------------------------------------------- |
|
1072 |
|
1073 TInt CLoadGenModel::RandomNumber(TInt aMin, TInt aMax) |
|
1074 { |
|
1075 TInt range = (aMax > aMin ? aMax - aMin : aMin - aMax) + 1; |
|
1076 TInt random = (TInt) (range * Math::FRand(iRandomNumberSeed)); |
|
1077 |
|
1078 random = (random % range) + aMin; |
|
1079 |
|
1080 if (random > aMax) |
|
1081 random = aMax; |
|
1082 else if (random < aMin) |
|
1083 random = aMin; |
|
1084 |
|
1085 return random; |
|
1086 } |
|
1087 |
|
1088 // -------------------------------------------------------------------------------------------- |
|
1089 CDesCArray* CLoadGenModel::ListOfAllAppsL() |
|
1090 { |
|
1091 const TInt KMaxAppsArraySize=250; |
|
1092 RApaLsSession ls; |
|
1093 CleanupClosePushL(ls); |
|
1094 |
|
1095 User::LeaveIfError( ls.Connect() ); |
|
1096 CDesCArray* allAppsArray = new(ELeave) CDesCArrayFlat( KMaxAppsArraySize ); |
|
1097 CleanupStack::PushL( allAppsArray ); |
|
1098 // reset the apps list |
|
1099 allAppsArray->Reset(); |
|
1100 |
|
1101 // search all apps |
|
1102 TApaAppInfo appInfo; |
|
1103 User::LeaveIfError(ls.GetAllApps()); |
|
1104 |
|
1105 |
|
1106 while ( ls.GetNextApp( appInfo ) == KErrNone ) |
|
1107 { |
|
1108 allAppsArray->AppendL( appInfo.iFullName ); |
|
1109 } |
|
1110 CleanupStack::Pop( allAppsArray ); |
|
1111 CleanupStack::PopAndDestroy( &ls ); |
|
1112 |
|
1113 |
|
1114 // remove loadgen.* from the list |
|
1115 for ( TInt i = 0; i < allAppsArray->MdcaCount(); i++ ) |
|
1116 { |
|
1117 if ( allAppsArray->MdcaPoint(i).FindF( _L("\\loadgen.") ) != KErrNotFound ) |
|
1118 { |
|
1119 allAppsArray->Delete(i); |
|
1120 allAppsArray->Compress(); |
|
1121 break; |
|
1122 } |
|
1123 } |
|
1124 |
|
1125 // sort the elements |
|
1126 allAppsArray->Sort(); |
|
1127 |
|
1128 return allAppsArray; // ownership transferred |
|
1129 } |
|
1130 |
|
1131 TSize CLoadGenModel::ScreenSize() |
|
1132 { |
|
1133 TInt x = 0; |
|
1134 TInt y = 0; |
|
1135 HAL::Get(HALData::EDisplayXPixels, x); |
|
1136 HAL::Get(HALData::EDisplayYPixels, y); |
|
1137 return TSize(x, y); |
|
1138 } |
|
1139 |
|
1140 // End of File |
|