|
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 |
|
20 // INCLUDE FILES |
|
21 #include "profiler_gui_samplersettingsviewdlg.h" |
|
22 #include "profiler_gui_model.h" |
|
23 #include "profiler_gui_app.h" |
|
24 #include "profiler_gui_settingsviewdlg.h" |
|
25 #include "profiler_gui_maincontainer.h" |
|
26 #include "profiler_gui.hrh" |
|
27 #include <piprofilerui.rsg> |
|
28 |
|
29 #include <coeutils.h> |
|
30 #include <bautils.h> |
|
31 #include <eikenv.h> |
|
32 #include <aknquerydialog.h> |
|
33 #include <aknmessagequerydialog.h> |
|
34 #include <e32math.h> |
|
35 #include <akntitle.h> |
|
36 #include <s32file.h> |
|
37 #include <aknnotewrappers.h> |
|
38 |
|
39 |
|
40 // UIDs |
|
41 #include <piprofiler/EngineUIDs.h> |
|
42 |
|
43 #include <piprofiler/ProfilerTraces.h> |
|
44 #include <piprofiler/ProfilerSession.h> |
|
45 |
|
46 // LITERALS |
|
47 _LIT(KAppName, "PIProfiler"); |
|
48 _LIT(KWarningNote, "NOTE: output changed!\n"); |
|
49 _LIT(KProfilerEngineExe, "PIProfilerEngine.exe"); |
|
50 |
|
51 // literals for default general setting values |
|
52 _LIT8(KTraceOutput, "file_system"); |
|
53 _LIT8(KTraceDebugOutput, "debug_output"); |
|
54 _LIT8(KProfilerDefaultDrive, "E:\\data"); |
|
55 _LIT8(KProfilerDefaultPrefix, "Profiler_#"); |
|
56 |
|
57 |
|
58 // ===================================== MEMBER FUNCTIONS ===================================== |
|
59 |
|
60 CProfilerGuiModel* CProfilerGuiModel::NewL() |
|
61 { |
|
62 CProfilerGuiModel* self = new(ELeave) CProfilerGuiModel; |
|
63 CleanupStack::PushL(self); |
|
64 self->ConstructL(); |
|
65 CleanupStack::Pop(); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // -------------------------------------------------------------------------------------------- |
|
70 |
|
71 CProfilerGuiModel::CProfilerGuiModel() : CActive(EPriorityStandard) |
|
72 { |
|
73 } |
|
74 |
|
75 // -------------------------------------------------------------------------------------------- |
|
76 |
|
77 void CProfilerGuiModel::ConstructL() |
|
78 { |
|
79 // initialize basic settings |
|
80 iDrawState = EDrawStateInvalid; |
|
81 iReferenceNumber = 0; |
|
82 iState = MProfilerStatusObserver::EIdle; |
|
83 |
|
84 iEnv = CEikonEnv::Static(); |
|
85 |
|
86 // profiler engine specific initialization |
|
87 LaunchProfilerEngineL(); |
|
88 |
|
89 // max sampler item list length is 64, i.e. max 64 sampler plugins loaded |
|
90 iSamplerItemList = new(ELeave) CSamplerItemList(64); |
|
91 |
|
92 // initialize attribute arrays |
|
93 iSamplerAttributes = new(ELeave) CArrayFixFlat<TSamplerAttributes>(20); // max sampler count is 20 |
|
94 |
|
95 // engine status checker |
|
96 iStatusChecker = CProfilerEngineStatusChecker::NewL(); |
|
97 iStatusChecker->SetObserver(this); |
|
98 |
|
99 CActiveScheduler::Add(this); |
|
100 } |
|
101 |
|
102 void CProfilerGuiModel::UpdateUIRunningStateL() |
|
103 { |
|
104 // prevent the control of sampler specific settings during the trace |
|
105 iMainContainer->SetDimmed(ETrue); |
|
106 |
|
107 // update status pane |
|
108 iMainView->UpdateStatusPaneL(iState); |
|
109 |
|
110 // show an info popup showing the logging method |
|
111 iMainContainer->ShowWriterInfoPopupL(KNullDesC); |
|
112 |
|
113 // refresh view |
|
114 RefreshViewL(); |
|
115 } |
|
116 |
|
117 // -------------------------------------------------------------------------------------------- |
|
118 void CProfilerGuiModel::NotifyContainerReadyL() |
|
119 { |
|
120 // load initial plugins |
|
121 LoadPluginsL(); |
|
122 |
|
123 // get the initial state |
|
124 if( iStatusChecker->GetInitialState() == MProfilerStatusObserver::ERunning ) |
|
125 { |
|
126 // set model state to restarting and grabbing an existing profiler process |
|
127 iState = MProfilerStatusObserver::ERestarting; |
|
128 |
|
129 // update status pane to correspond the running mode |
|
130 UpdateUIRunningStateL(); |
|
131 |
|
132 // set model state to running |
|
133 iState = MProfilerStatusObserver::ERunning; |
|
134 |
|
135 } |
|
136 } |
|
137 |
|
138 // -------------------------------------------------------------------------------------------- |
|
139 |
|
140 void CProfilerGuiModel::ActivateModelL() |
|
141 { |
|
142 // load general settings |
|
143 if( LoadGeneralSettingsL() != KErrNone ) |
|
144 { |
|
145 LOGTEXT(_L("ProfilerGuiAppUi::ActivateModelL - could not connect profiler engine")); |
|
146 } |
|
147 } |
|
148 |
|
149 // -------------------------------------------------------------------------------------------- |
|
150 |
|
151 void CProfilerGuiModel::DeActivateModelL() |
|
152 { |
|
153 Cancel(); |
|
154 |
|
155 // for a faster exit, send the application to background |
|
156 TApaTask selfTask(iEnv->WsSession()); |
|
157 selfTask.SetWgId(iEnv->RootWin().Identifier()); |
|
158 selfTask.SendToBackground(); |
|
159 } |
|
160 |
|
161 // -------------------------------------------------------------------------------------------- |
|
162 |
|
163 CProfilerGuiModel::~CProfilerGuiModel() |
|
164 { |
|
165 if (iSamplerItemList) |
|
166 { |
|
167 DeleteAllSamplerItems(); |
|
168 delete iSamplerItemList; |
|
169 iSamplerItemList = NULL; |
|
170 } |
|
171 |
|
172 if(iStatusChecker) |
|
173 { |
|
174 iStatusChecker->Cancel(); |
|
175 delete iStatusChecker; |
|
176 iStatusChecker = NULL; |
|
177 } |
|
178 |
|
179 |
|
180 if(iSamplerAttributes) |
|
181 { |
|
182 iSamplerAttributes->Reset(); |
|
183 delete iSamplerAttributes; |
|
184 iSamplerAttributes = NULL; |
|
185 } |
|
186 |
|
187 } |
|
188 |
|
189 // -------------------------------------------------------------------------------------------- |
|
190 |
|
191 void CProfilerGuiModel::DoCancel() |
|
192 { |
|
193 |
|
194 } |
|
195 |
|
196 // -------------------------------------------------------------------------------------------- |
|
197 |
|
198 void CProfilerGuiModel::RunL() |
|
199 { |
|
200 |
|
201 } |
|
202 |
|
203 // -------------------------------------------------------------------------------------------- |
|
204 |
|
205 void CProfilerGuiModel::SetMainContainer(CProfilerGuiMainContainer* aContainer) |
|
206 { |
|
207 iMainContainer = aContainer; |
|
208 iDrawState = EDrawStateMain; |
|
209 } |
|
210 |
|
211 void CProfilerGuiModel::UpdateState(TInt aState) |
|
212 { |
|
213 iState = aState; |
|
214 } |
|
215 |
|
216 TInt CProfilerGuiModel::FindProcessL(RProcess& aProc) |
|
217 { |
|
218 TProcessId engId; |
|
219 TFindProcess procName; |
|
220 procName.Find(_L("PIProfilerEngine.exe*")); |
|
221 TFullName aResult; |
|
222 TFullName aResult2; |
|
223 TInt err(KErrNone); |
|
224 |
|
225 // find the first appearance |
|
226 err = procName.Next(aResult); |
|
227 if(err != KErrNone) |
|
228 { |
|
229 // did not find any engine process |
|
230 return err; |
|
231 } |
|
232 else |
|
233 { |
|
234 err = aProc.Open(procName); |
|
235 if(err == KErrNone) |
|
236 { |
|
237 if(aProc.ExitCategory().Length() > 0) |
|
238 { |
|
239 aProc.Close(); |
|
240 // process already exited => create a new one |
|
241 return KErrNotFound; |
|
242 } |
|
243 aProc.Close(); |
|
244 } |
|
245 } |
|
246 |
|
247 // // check now if a second appearance exists in process list, |
|
248 // // i.e. engine started from eshell => two engine processes appear in normal case |
|
249 // procName.Next(aResult2); |
|
250 // |
|
251 // // check if aResult2 contained the second appearance of profiler engine |
|
252 // if(aResult2.CompareF(aResult) > 0) |
|
253 // { |
|
254 // // other process found, i.e. right process to communicate with, in case started from eshell |
|
255 // err = aProc.Open(procName); |
|
256 // if(err == KErrNone) |
|
257 // { |
|
258 // if(aProc.ExitCategory().Length() > 0) |
|
259 // { |
|
260 // // process already exited => create a new one |
|
261 // return KErrNotFound; |
|
262 // } |
|
263 // aProc.Close(); |
|
264 // } |
|
265 // } |
|
266 |
|
267 return err; |
|
268 } |
|
269 |
|
270 void CProfilerGuiModel::LaunchProfilerEngineL() |
|
271 { |
|
272 LOGTEXT(_L("CProfilerGuiModel::LaunchProfilerEngineL - start")); |
|
273 |
|
274 TRequestStatus stat = KRequestPending; |
|
275 RProcess proc; |
|
276 |
|
277 TInt err(KErrNone); |
|
278 |
|
279 // check if process exists |
|
280 err = FindProcessL(proc); |
|
281 |
|
282 // check if already exists and don't start a new eshell profiling |
|
283 if( err == KErrNotFound ) |
|
284 { |
|
285 // try create new process |
|
286 err = proc.Create(KProfilerEngineExe, _L("")); |
|
287 |
|
288 // check if RProcess::Create() succeeded |
|
289 if( err == KErrNone ) |
|
290 { |
|
291 // kick off the engine process |
|
292 proc.Resume(); |
|
293 |
|
294 // wait for the constructor to complete |
|
295 proc.Rendezvous(stat); // Trigger rendezvous on the supplied TRequestStatus object |
|
296 User::WaitForRequest(stat); |
|
297 |
|
298 // just lose the handle |
|
299 proc.Close(); |
|
300 } |
|
301 } |
|
302 } |
|
303 |
|
304 //----------------------------------------------------------------------------- |
|
305 // CProfilerGuiModel::TerminateProfilerL() |
|
306 // Stops Profiler Engine if it has been launched by this launcher. |
|
307 //----------------------------------------------------------------------------- |
|
308 |
|
309 void CProfilerGuiModel::TerminateProfilerL() |
|
310 { |
|
311 LOGTEXT(_L("CProfilerGuiModel::TerminateProfiler - entry")); |
|
312 |
|
313 // exit profiler engine |
|
314 RProfiler::ExitProfiler(); |
|
315 |
|
316 LOGTEXT(_L("CProfilerGuiModel::TerminateProfiler - exit")); |
|
317 |
|
318 } |
|
319 |
|
320 void CProfilerGuiModel::AddNewSamplersL(CArrayFixFlat<TSamplerAttributes>& aAttributes) |
|
321 { |
|
322 TSamplerAttributes item; |
|
323 |
|
324 TInt count(aAttributes.Count()); |
|
325 |
|
326 // loop the attribute array and insert them into view list |
|
327 for (TInt i(0);i<count;i++) |
|
328 { |
|
329 // get a TSamplerAttributes from list at a time |
|
330 item = aAttributes.At(i); |
|
331 |
|
332 iReferenceNumber++; |
|
333 |
|
334 // add item to the array |
|
335 AppendToSamplerItemListL(item); |
|
336 |
|
337 // update the listbox |
|
338 RefreshViewL(EFalse); |
|
339 |
|
340 // set item index to the begin |
|
341 iMainContainer->ListBox()->SetCurrentItemIndexAndDraw(iMainContainer->ListBox()->Model()->NumberOfItems()-1); |
|
342 |
|
343 } |
|
344 // refresh again |
|
345 if(iReferenceNumber > 0) |
|
346 { |
|
347 RefreshViewL(ETrue); |
|
348 } |
|
349 } |
|
350 |
|
351 TBool CProfilerGuiModel::CheckTraceLocationSanityL(TGeneralAttributes& aAttr, TBool aQuietCheck) |
|
352 { |
|
353 RFs fs; |
|
354 User::LeaveIfError(fs.Connect()); |
|
355 |
|
356 TBuf<32> drive; |
|
357 |
|
358 CnvUtfConverter::ConvertToUnicodeFromUtf8(drive, aAttr.iSaveFileDrive); |
|
359 |
|
360 TBool ret(EFalse); |
|
361 |
|
362 if(aAttr.iSaveFileDrive.Find(_L8("C:\\")) != KErrNotFound && BaflUtils::CheckFolder(fs, drive) == KErrNone) |
|
363 ret = ETrue; |
|
364 else if(aAttr.iSaveFileDrive.Find(_L8("D:\\")) != KErrNotFound && BaflUtils::CheckFolder(fs, drive) == KErrNone) |
|
365 ret = ETrue; |
|
366 else if(aAttr.iSaveFileDrive.Find(_L8("E:\\")) != KErrNotFound && BaflUtils::CheckFolder(fs, drive) == KErrNone) |
|
367 ret = ETrue; |
|
368 else if(aAttr.iSaveFileDrive.Find(_L8("F:\\")) != KErrNotFound && BaflUtils::CheckFolder(fs, drive) == KErrNone) |
|
369 ret = ETrue; |
|
370 else if(aAttr.iSaveFileDrive.Find(_L8("G:\\")) != KErrNotFound && BaflUtils::CheckFolder(fs, drive) == KErrNone) |
|
371 ret = ETrue; |
|
372 else if(aAttr.iSaveFileDrive.Find(_L8("H:\\")) != KErrNotFound && BaflUtils::CheckFolder(fs, drive) == KErrNone) |
|
373 ret = ETrue; |
|
374 else if(aAttr.iSaveFileDrive.Find(_L8("I:\\")) != KErrNotFound && BaflUtils::CheckFolder(fs, drive) == KErrNone) |
|
375 ret = ETrue; |
|
376 else |
|
377 { |
|
378 // show error |
|
379 if(aQuietCheck == EFalse) |
|
380 { |
|
381 CAknErrorNote* note = new(ELeave) CAknErrorNote(); |
|
382 note->ExecuteLD(_L("Unable to find drive, check settings!")); |
|
383 ret = EFalse; |
|
384 } |
|
385 } |
|
386 |
|
387 return ret; |
|
388 } |
|
389 |
|
390 // -------------------------------------------------------------------------------------------- |
|
391 |
|
392 TInt CProfilerGuiModel::LaunchSettingsDialogL() |
|
393 { |
|
394 // launch the settings dialog |
|
395 TGeneralAttributes newSettings = iGeneralAttributes; |
|
396 TBool quietCheck(EFalse); |
|
397 |
|
398 CProfilerGuiSettingsViewDlg* dlg = CProfilerGuiSettingsViewDlg::NewL(newSettings); |
|
399 TInt returnValue = dlg->ExecuteLD(R_PROFILER_GUI_SETTINGS_DIALOG); |
|
400 |
|
401 // check if exit command => no error note to user |
|
402 if(returnValue == EAknCmdExit) |
|
403 quietCheck = ETrue; |
|
404 |
|
405 // always save settings since the settings dialog does not provide a possibility to cancel |
|
406 iGeneralAttributes.iTraceOutput.Copy(newSettings.iTraceOutput); |
|
407 iGeneralAttributes.iTraceFilePrefix.Copy(newSettings.iTraceFilePrefix); |
|
408 |
|
409 // check if debug output selected no check of |
|
410 if(newSettings.iTraceOutput.CompareF(KTraceDebugOutput) != 0) |
|
411 { |
|
412 // Check save file drive sanity |
|
413 if(CheckTraceLocationSanityL(newSettings, quietCheck)) |
|
414 { |
|
415 // save the new location |
|
416 iGeneralAttributes.iSaveFileDrive.Copy(newSettings.iSaveFileDrive); |
|
417 } |
|
418 } |
|
419 // saves the general settings to profiler engine |
|
420 SaveGeneralSettingsL(); |
|
421 |
|
422 // make sure that the title of the application is correct |
|
423 CEikStatusPane* sp = iEnv->AppUiFactory()->StatusPane(); |
|
424 CAknTitlePane* tp = static_cast<CAknTitlePane*>( sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) ); |
|
425 tp->SetTextL(KAppName); |
|
426 |
|
427 return returnValue; |
|
428 } |
|
429 |
|
430 |
|
431 TPtrC CProfilerGuiModel::GetWriterInfoNoteL(const TDesC& aNote) |
|
432 { |
|
433 TBuf<256> buf; |
|
434 TBuf<128> descBuf; |
|
435 |
|
436 buf.Zero(); |
|
437 |
|
438 // get active profiler since it |
|
439 RProfiler::GetActiveWriter(buf); |
|
440 |
|
441 if(iGeneralAttributes.iTraceOutput.CompareF(KTraceOutput) == 0) |
|
442 { |
|
443 if(iState == MProfilerStatusObserver::EInitializing || |
|
444 iState == MProfilerStatusObserver::ERestarting ) |
|
445 { |
|
446 descBuf.Zero(); |
|
447 // set the additional note if available |
|
448 buf.Copy(aNote); |
|
449 RProfiler::GetFileName(descBuf); |
|
450 buf.Append(_L("Writing to ")); |
|
451 buf.Append(descBuf); |
|
452 } |
|
453 else if(iState == MProfilerStatusObserver::EIdle || |
|
454 iState == MProfilerStatusObserver::EStopping || |
|
455 iState == MProfilerStatusObserver::ERunning ) |
|
456 { |
|
457 descBuf.Zero(); |
|
458 // set the additional note if available |
|
459 buf.Copy(aNote); |
|
460 RProfiler::GetFileName(descBuf); |
|
461 buf.Append(_L("Wrote trace data to ")); |
|
462 buf.Append(descBuf); |
|
463 } |
|
464 else |
|
465 { |
|
466 buf.Copy(KNullDesC); |
|
467 } |
|
468 } |
|
469 else if(iGeneralAttributes.iTraceOutput.CompareF(KTraceDebugOutput) == 0) |
|
470 { |
|
471 if(iState == MProfilerStatusObserver::EInitializing || |
|
472 iState == MProfilerStatusObserver::ERestarting ) |
|
473 { |
|
474 buf.Copy(_L("Writing to debug output...")); |
|
475 } |
|
476 else if( iState == MProfilerStatusObserver::EIdle || |
|
477 iState == MProfilerStatusObserver::EStopping || |
|
478 iState == MProfilerStatusObserver::ERunning ) |
|
479 { |
|
480 buf.Copy(_L("Wrote trace data to debug output")); |
|
481 } |
|
482 else |
|
483 { |
|
484 buf.Copy(KNullDesC); |
|
485 } |
|
486 } |
|
487 else |
|
488 { |
|
489 // should not reach this point |
|
490 buf.Copy(KNullDesC); |
|
491 } |
|
492 |
|
493 return TPtrC(buf); |
|
494 } |
|
495 |
|
496 // -------------------------------------------------------------------------------------------- |
|
497 |
|
498 TInt CProfilerGuiModel::EditSamplerL(TSamplerAttributes& aItem) |
|
499 { |
|
500 // edit sampler specific settings i.e. attributes |
|
501 TSamplerAttributes& newSettings = aItem; |
|
502 TInt indexToReplace(iMainContainer->CurrentListBoxItemIndex()); |
|
503 |
|
504 // create a new settings editor dialog |
|
505 CProfilerSamplerSettingsViewDlg* dlg = CProfilerSamplerSettingsViewDlg::NewL(newSettings); |
|
506 TInt returnValue = dlg->ExecuteLD(R_PROFILER_SAMPLER_SETTINGS_DIALOG); |
|
507 |
|
508 // save settings |
|
509 aItem = newSettings; |
|
510 |
|
511 // replace the old attribute container with saved values |
|
512 iSamplerItemList->Delete(indexToReplace); |
|
513 iSamplerItemList->InsertL(indexToReplace, newSettings); |
|
514 |
|
515 // save the settings to sampler item |
|
516 RProfiler::SetSamplerAttributes(newSettings); |
|
517 |
|
518 // make sure that the title of the application is correct |
|
519 CEikStatusPane* sp = iEnv->AppUiFactory()->StatusPane(); |
|
520 CAknTitlePane* tp = static_cast<CAknTitlePane*>( sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) ); |
|
521 tp->SetTextL(KAppName); |
|
522 |
|
523 return returnValue; |
|
524 } |
|
525 |
|
526 |
|
527 void CProfilerGuiModel::SamplerInfoL(TSamplerAttributes& aItem) |
|
528 { |
|
529 TBuf<64> header; |
|
530 TBuf<256> info; |
|
531 |
|
532 _LIT(KSamplerStr, "Sampler Info"); |
|
533 |
|
534 // CnvUtfConverter::ConvertToUnicodeFromUtf8(header, aItem.iName); |
|
535 |
|
536 header.Append(KSamplerStr); |
|
537 |
|
538 CnvUtfConverter::ConvertToUnicodeFromUtf8(info, aItem.iDescription); |
|
539 |
|
540 CAknMessageQueryDialog* dialog = new(ELeave) CAknMessageQueryDialog; |
|
541 //dialog->ExecuteLD(info); |
|
542 dialog->PrepareLC( R_PROFILER_GUI_EMPTY_ABOUT_DIALOG ); |
|
543 dialog->SetHeaderText(header); |
|
544 dialog->SetMessageTextL(info); |
|
545 dialog->RunLD(); |
|
546 |
|
547 RefreshViewL(EFalse); |
|
548 } |
|
549 |
|
550 // -------------------------------------------------------------------------------------------- |
|
551 |
|
552 void CProfilerGuiModel::StartAllSamplerItemsL() |
|
553 { |
|
554 TBuf<256> activeWriterDes; |
|
555 TBuf8<256> writer8; |
|
556 |
|
557 // try to start profiling process through client-server interface |
|
558 if(RProfiler::StartSampling() == KErrNotFound) |
|
559 { |
|
560 // profiler stopped (e.g. from eshell) and must be restarted |
|
561 LaunchProfilerEngineL(); |
|
562 |
|
563 // set general attributes |
|
564 SaveGeneralSettingsL(); |
|
565 |
|
566 // set sampler attributes |
|
567 for(TInt i(0);i<iSamplerAttributes->Count();i++) |
|
568 { |
|
569 // set the attributes for each sampler loaded in the UI |
|
570 RProfiler::SetSamplerAttributes(iSamplerAttributes->At(i)); |
|
571 } |
|
572 |
|
573 // try to launch sampling again |
|
574 RProfiler::StartSampling(); |
|
575 } |
|
576 |
|
577 // get selected writer |
|
578 RProfiler::GetActiveWriter(activeWriterDes); |
|
579 CnvUtfConverter::ConvertFromUnicodeToUtf8(writer8, activeWriterDes); |
|
580 |
|
581 // check that output mode has not changed for a problem with trace file name |
|
582 // problem cases: |
|
583 // - trace file name and/or path false |
|
584 // - disk full, cannot write to given location |
|
585 // - false drive, e.g. x: |
|
586 if(writer8.CompareF(iGeneralAttributes.iTraceOutput) != 0) |
|
587 { |
|
588 // save change also to general attributes |
|
589 iGeneralAttributes.iTraceOutput.Copy(writer8); |
|
590 // show an info popup showing the logging method |
|
591 iMainContainer->ShowWriterInfoPopupL(KWarningNote); |
|
592 } |
|
593 else |
|
594 { |
|
595 // show an info popup showing the logging method |
|
596 iMainContainer->ShowWriterInfoPopupL(KNullDesC); |
|
597 } |
|
598 |
|
599 // update the view |
|
600 RefreshViewL(); |
|
601 } |
|
602 // -------------------------------------------------------------------------------------------- |
|
603 |
|
604 void CProfilerGuiModel::DeleteAllSamplerItemsL() |
|
605 { |
|
606 DeleteAllSamplerItems(); |
|
607 |
|
608 RefreshViewL(); |
|
609 } |
|
610 |
|
611 |
|
612 void CProfilerGuiModel::StopAllSamplerItemsL() |
|
613 { |
|
614 // show an info popup showing the logging method |
|
615 iMainContainer->ShowWriterInfoPopupL(KNullDesC); |
|
616 |
|
617 // Stop profiling process through CS session |
|
618 RProfiler::StopSampling(); |
|
619 |
|
620 RefreshViewL(); |
|
621 } |
|
622 |
|
623 // -------------------------------------------------------------------------------------------- |
|
624 |
|
625 void CProfilerGuiModel::RefreshViewL(TBool aClearSelection) |
|
626 { |
|
627 // refresh the main list view |
|
628 if (iMainContainer && iDrawState == EDrawStateMain && iMainContainer->ListBox()) |
|
629 { |
|
630 // clear selections if any |
|
631 iMainContainer->ListBox()->ClearSelection(); |
|
632 |
|
633 // set item index to 0 |
|
634 if (aClearSelection) |
|
635 iMainContainer->ListBox()->SetCurrentItemIndex(0); |
|
636 |
|
637 // set text items |
|
638 iMainContainer->SetListBoxTextArrayL(GenerateListBoxItemTextArrayL()); |
|
639 } |
|
640 } |
|
641 |
|
642 // -------------------------------------------------------------------------------------------- |
|
643 |
|
644 void CProfilerGuiModel::AppendToSamplerItemListL(TSamplerAttributes& aItem) |
|
645 { |
|
646 // append single sampler item into sampler item list |
|
647 if (iSamplerItemList) |
|
648 iSamplerItemList->AppendL( aItem ); |
|
649 else |
|
650 User::Leave(KErrNotReady); |
|
651 } |
|
652 |
|
653 // -------------------------------------------------------------------------------------------- |
|
654 |
|
655 void CProfilerGuiModel::DisableOrEnableFromSamplerItemListL(TInt aIndex) |
|
656 { |
|
657 if (iSamplerItemList) |
|
658 { |
|
659 if (iSamplerItemList->Count() > aIndex && aIndex >= 0) |
|
660 { |
|
661 TSamplerAttributes& attr = iSamplerItemList->At(aIndex); |
|
662 if (attr.iEnabled) |
|
663 { |
|
664 attr.iEnabled = EFalse; |
|
665 } |
|
666 else if (!attr.iEnabled) |
|
667 { |
|
668 attr.iEnabled = ETrue; |
|
669 } |
|
670 // save settings to engine |
|
671 RProfiler::SetSamplerAttributes(attr); |
|
672 } |
|
673 else |
|
674 User::Leave(KErrNotFound); |
|
675 } |
|
676 else |
|
677 { |
|
678 User::Leave(KErrNotReady); |
|
679 } |
|
680 |
|
681 } |
|
682 |
|
683 // -------------------------------------------------------------------------------------------- |
|
684 |
|
685 TInt CProfilerGuiModel::SamplerItemCount() const |
|
686 { |
|
687 TInt count(0); |
|
688 |
|
689 if (iSamplerItemList) |
|
690 count = iSamplerItemList->Count(); |
|
691 |
|
692 return count; |
|
693 } |
|
694 |
|
695 // -------------------------------------------------------------------------------------------- |
|
696 |
|
697 void CProfilerGuiModel::DeleteAllSamplerItems() |
|
698 { |
|
699 // reset sampler array |
|
700 iSamplerItemList->Reset(); |
|
701 } |
|
702 |
|
703 // -------------------------------------------------------------------------------------------- |
|
704 |
|
705 CDesCArray* CProfilerGuiModel::GenerateListBoxItemTextArrayL() |
|
706 { |
|
707 CDesCArray* textArray = new(ELeave) CDesCArrayFlat(64); |
|
708 CleanupStack::PushL(textArray); |
|
709 |
|
710 _LIT(KEntryTemplateRedIcon, "1\t%S\t\t"); |
|
711 _LIT(KEntryTemplateGreenIcon, "2\t%S\t\t"); |
|
712 |
|
713 TSamplerAttributes attr; |
|
714 TInt itemCount(SamplerItemCount()); |
|
715 for (TInt i(0); i<itemCount; i++) |
|
716 { |
|
717 // add description from each entry |
|
718 TBuf<512> textEntry; |
|
719 TBuf<512> description; |
|
720 |
|
721 attr = iSamplerItemList->At(i); |
|
722 |
|
723 description.Copy(attr.iName); |
|
724 |
|
725 if (attr.iEnabled) |
|
726 textEntry.Format(KEntryTemplateGreenIcon, &description); |
|
727 else |
|
728 textEntry.Format(KEntryTemplateRedIcon, &description); |
|
729 |
|
730 textArray->AppendL(textEntry); |
|
731 } |
|
732 |
|
733 CleanupStack::Pop(); //textArray |
|
734 return textArray; |
|
735 } |
|
736 |
|
737 // -------------------------------------------------------------------------------------------- |
|
738 |
|
739 TBool CProfilerGuiModel::GetSelectedItemEnabled() |
|
740 { |
|
741 TInt currentItemIndex = iMainContainer->CurrentListBoxItemIndex(); |
|
742 |
|
743 if (SamplerItemCount() > currentItemIndex && currentItemIndex >= 0) |
|
744 { |
|
745 return iSamplerItemList->At(currentItemIndex).iEnabled; |
|
746 } |
|
747 return EFalse; |
|
748 } |
|
749 |
|
750 // -------------------------------------------------------------------------------------------- |
|
751 |
|
752 TBool CProfilerGuiModel::GetSelectedItemHasSettings() |
|
753 { |
|
754 TInt currentItemIndex = iMainContainer->CurrentListBoxItemIndex(); |
|
755 |
|
756 if (SamplerItemCount() > currentItemIndex && currentItemIndex >= 0) |
|
757 { |
|
758 if(iSamplerItemList->At(currentItemIndex).iItemCount != 0 || |
|
759 iSamplerItemList->At(currentItemIndex).iSampleRate != KErrNotFound) |
|
760 { |
|
761 return ETrue; |
|
762 } |
|
763 else |
|
764 { |
|
765 return EFalse; |
|
766 } |
|
767 } |
|
768 return EFalse; |
|
769 } |
|
770 |
|
771 // -------------------------------------------------------------------------------------------- |
|
772 |
|
773 TBool CProfilerGuiModel::GetSelectedItemHidden() |
|
774 { |
|
775 TInt currentItemIndex = iMainContainer->CurrentListBoxItemIndex(); |
|
776 |
|
777 if (SamplerItemCount() > currentItemIndex && currentItemIndex >= 0) |
|
778 { |
|
779 if(iSamplerItemList->At(currentItemIndex).iIsHidden) |
|
780 { |
|
781 return ETrue; |
|
782 } |
|
783 else |
|
784 { |
|
785 return EFalse; |
|
786 } |
|
787 } |
|
788 return EFalse; |
|
789 } |
|
790 |
|
791 // -------------------------------------------------------------------------------------------- |
|
792 |
|
793 TInt CProfilerGuiModel::EditSelectedSamplerL(TInt index) |
|
794 { |
|
795 TSamplerAttributes sampler; |
|
796 if(SamplerItemCount() > index && index >= 0) |
|
797 { |
|
798 sampler = iSamplerItemList->At(index); |
|
799 return EditSamplerL(sampler); |
|
800 } |
|
801 return KErrNone; |
|
802 } |
|
803 |
|
804 // -------------------------------------------------------------------------------------------- |
|
805 |
|
806 void CProfilerGuiModel::SelectedSamplerInfoL(TInt index) |
|
807 { |
|
808 if(SamplerItemCount() > index && index >= 0) |
|
809 { |
|
810 SamplerInfoL(iSamplerItemList->At(index)); |
|
811 } |
|
812 } |
|
813 |
|
814 // -------------------------------------------------------------------------------------------- |
|
815 |
|
816 void CProfilerGuiModel::ShowItemActionMenuL() |
|
817 { |
|
818 TInt currentItemIndex = iMainContainer->CurrentListBoxItemIndex(); |
|
819 |
|
820 if (SamplerItemCount() > currentItemIndex && currentItemIndex >= 0) |
|
821 { |
|
822 // show a query dialog |
|
823 TInt queryIndex(0); |
|
824 CAknListQueryDialog* listQueryDlg = new(ELeave) CAknListQueryDialog(&queryIndex); |
|
825 TInt resource = 0; |
|
826 TSamplerAttributes sampler = iSamplerItemList->At(currentItemIndex); |
|
827 |
|
828 // check if sampler enabled |
|
829 if(sampler.iEnabled) |
|
830 { |
|
831 resource = R_ITEM_ACTION_QUERY_ENABLED; |
|
832 } |
|
833 else |
|
834 { |
|
835 resource = R_ITEM_ACTION_QUERY_DISABLED; |
|
836 } |
|
837 |
|
838 // check if sampler plugin hidden => don't allow starting and stopping of sampling |
|
839 if(sampler.iIsHidden) |
|
840 { |
|
841 resource = R_ITEM_ACTION_QUERY_HIDDEN_START_STOP; |
|
842 } |
|
843 else if(( sampler.iItemCount == 0 && |
|
844 sampler.iSampleRate == KErrNotFound ) && |
|
845 sampler.iEnabled ) |
|
846 { |
|
847 resource = R_ITEM_ACTION_QUERY_HIDDEN_SETTINGS_ENABLED; |
|
848 } |
|
849 else if(( sampler.iItemCount == 0 && |
|
850 sampler.iSampleRate == KErrNotFound ) && |
|
851 !sampler.iEnabled ) |
|
852 { |
|
853 resource = R_ITEM_ACTION_QUERY_HIDDEN_SETTINGS_DISABLED; |
|
854 } |
|
855 |
|
856 // execute query dialog with the given resource |
|
857 if (listQueryDlg->ExecuteLD(resource)) |
|
858 { |
|
859 if(!sampler.iIsHidden) |
|
860 { |
|
861 if(sampler.iItemCount != 0 || |
|
862 sampler.iSampleRate != KErrNotFound ) |
|
863 { |
|
864 // enable/disable sampler |
|
865 if (queryIndex == EItemActionMenuTypeEnable) |
|
866 { |
|
867 DisableOrEnableSelectedOrHighlightedItemsL(); |
|
868 } |
|
869 // edit sampler settings |
|
870 else if (queryIndex == EItemActionMenuTypeEditSettings - 1) |
|
871 { |
|
872 EditSamplerL(sampler); |
|
873 } |
|
874 // info |
|
875 else if (queryIndex == EItemActionMenuTypeInfo - 1) |
|
876 { |
|
877 SamplerInfoL(sampler); |
|
878 } |
|
879 } |
|
880 else |
|
881 { |
|
882 // special case, use raw query indexes |
|
883 if (queryIndex == 0) |
|
884 { |
|
885 DisableOrEnableSelectedOrHighlightedItemsL(); |
|
886 } |
|
887 else if (queryIndex == 1) |
|
888 { |
|
889 SamplerInfoL(sampler); |
|
890 } |
|
891 } |
|
892 } |
|
893 else |
|
894 { |
|
895 if(sampler.iItemCount != 0 || |
|
896 sampler.iSampleRate != KErrNotFound) |
|
897 { |
|
898 // special case, use raw query indexes |
|
899 // edit sampler settings |
|
900 if (queryIndex == 0) |
|
901 { |
|
902 EditSamplerL(sampler); |
|
903 } |
|
904 // sampler info |
|
905 else if (queryIndex == 1) |
|
906 { |
|
907 SamplerInfoL(sampler); |
|
908 } |
|
909 } |
|
910 else |
|
911 { |
|
912 // only sampler info available if hidden and no setting items to be set |
|
913 if (queryIndex == 0) |
|
914 { |
|
915 SamplerInfoL(sampler); |
|
916 } |
|
917 |
|
918 } |
|
919 } |
|
920 } |
|
921 } |
|
922 } |
|
923 |
|
924 void CProfilerGuiModel::DisableOrEnableSelectedOrHighlightedItemsL() |
|
925 { |
|
926 const CArrayFix<TInt>* selectionIndexes = iMainContainer->ListBoxSelectionIndexes(); |
|
927 |
|
928 // by default use selected items |
|
929 if (selectionIndexes && selectionIndexes->Count() > 0) |
|
930 { |
|
931 TInt ref(0); |
|
932 TKeyArrayFix key(0, ECmpTUint16); |
|
933 TInt index(0); |
|
934 |
|
935 for (TInt i=0; i<SamplerItemCount(); i++) |
|
936 { |
|
937 ref = i; |
|
938 |
|
939 if (selectionIndexes->Find(ref, key, index) == 0) |
|
940 { |
|
941 DisableOrEnableFromSamplerItemListL(i); |
|
942 } |
|
943 } |
|
944 |
|
945 RefreshViewL(EFalse); |
|
946 } |
|
947 |
|
948 // or if none selected, use the current item index |
|
949 else |
|
950 { |
|
951 TInt currentItemIndex = iMainContainer->CurrentListBoxItemIndex(); |
|
952 |
|
953 if (SamplerItemCount() > currentItemIndex && currentItemIndex >= 0) |
|
954 { |
|
955 DisableOrEnableFromSamplerItemListL(currentItemIndex); |
|
956 |
|
957 RefreshViewL(EFalse); |
|
958 } |
|
959 } |
|
960 } |
|
961 |
|
962 void CProfilerGuiModel::LoadPluginsL() |
|
963 { |
|
964 // get samplers from Profiler Engine (client-server session) |
|
965 // and add the to the samplers list for the first time |
|
966 LOGTEXT(_L("CProfilerGuiModel::LoadPlugins - get sampler plugins")); |
|
967 TInt err = RProfiler::GetSamplerAttributes(*iSamplerAttributes); |
|
968 |
|
969 // check if engine provided a list of samplers |
|
970 if( err != KErrNone ) |
|
971 { |
|
972 // could not get samplers from engine |
|
973 LOGTEXT(_L("CProfilerGuiModel::LoadPlugins - failed to connect engine")); |
|
974 } |
|
975 else |
|
976 { |
|
977 LOGTEXT(_L("CProfilerGuiModel::LoadPlugins - adding new samplers into view")); |
|
978 AddNewSamplersL(*iSamplerAttributes); |
|
979 } |
|
980 |
|
981 LOGTEXT(_L("CProfilerGuiModel::LoadPlugins - exit")); |
|
982 } |
|
983 |
|
984 // -------------------------------------------------------------------------------------------- |
|
985 |
|
986 TInt CProfilerGuiModel::LoadGeneralSettingsL() |
|
987 { |
|
988 // local variable for getting saved settings from profiler engine |
|
989 TGeneralAttributes generalAttr; |
|
990 TInt err(KErrNone); |
|
991 |
|
992 // before loading saved settings (from settings file) set the default values |
|
993 iGeneralAttributes.iTraceOutput.Copy(KTraceOutput); |
|
994 iGeneralAttributes.iTraceFilePrefix.Copy(KProfilerDefaultPrefix); |
|
995 iGeneralAttributes.iSaveFileDrive.Copy(KProfilerDefaultDrive); |
|
996 |
|
997 // request to |
|
998 err = RProfiler::GetGeneralAttributes(generalAttr); |
|
999 |
|
1000 // check that request succesfull |
|
1001 if( err != KErrNone ) |
|
1002 { |
|
1003 // could not connect profiler engine, use |
|
1004 return err; |
|
1005 } |
|
1006 |
|
1007 // check if saved settings different than the default |
|
1008 if(generalAttr.iTraceOutput.MatchF(iGeneralAttributes.iTraceOutput) == KErrNotFound) |
|
1009 { |
|
1010 iGeneralAttributes.iTraceOutput.Copy(generalAttr.iTraceOutput); |
|
1011 } |
|
1012 |
|
1013 if(generalAttr.iTraceFilePrefix.MatchF(iGeneralAttributes.iTraceFilePrefix) == KErrNotFound) |
|
1014 { |
|
1015 iGeneralAttributes.iTraceFilePrefix.Copy(generalAttr.iTraceFilePrefix); |
|
1016 } |
|
1017 |
|
1018 if(generalAttr.iSaveFileDrive.MatchF(iGeneralAttributes.iSaveFileDrive) == KErrNotFound) |
|
1019 { |
|
1020 iGeneralAttributes.iSaveFileDrive.Copy(generalAttr.iSaveFileDrive); |
|
1021 } |
|
1022 return err; |
|
1023 } |
|
1024 |
|
1025 // -------------------------------------------------------------------------------------------- |
|
1026 |
|
1027 void CProfilerGuiModel::SaveGeneralSettingsL() |
|
1028 { |
|
1029 TInt err(KErrNone); |
|
1030 |
|
1031 // save general attributes to Profiler Engine |
|
1032 err = RProfiler::SetGeneralAttributes(iGeneralAttributes); |
|
1033 |
|
1034 // check if save failed |
|
1035 if(err == KErrNotFound) |
|
1036 { |
|
1037 // profiler stopped (e.g. from eshell) and must be restarted |
|
1038 LaunchProfilerEngineL(); |
|
1039 |
|
1040 err = RProfiler::SetGeneralAttributes(iGeneralAttributes); |
|
1041 if(err != KErrNone) |
|
1042 { |
|
1043 // leave no use to continue |
|
1044 User::Leave(err); |
|
1045 } |
|
1046 } |
|
1047 } |
|
1048 |
|
1049 void CProfilerGuiModel::SetMainView(CProfilerGuiMainView* aMainView) |
|
1050 { |
|
1051 iMainView = aMainView; |
|
1052 } |
|
1053 |
|
1054 // -------------------------------------------------------------------------------------------- |
|
1055 |
|
1056 void CProfilerGuiModel::HandleProfilerStatusChange( KProfilerStatus aStatus ) |
|
1057 { |
|
1058 iState = aStatus; |
|
1059 TRAP_IGNORE(iMainView->UpdateStatusPaneL(aStatus)); |
|
1060 } |
|
1061 |
|
1062 void CProfilerGuiModel::HandleProfilerErrorL( TInt aError ) |
|
1063 { |
|
1064 TBuf<64> errorMsg; |
|
1065 _LIT(KErrorMessage, "Error: "); |
|
1066 _LIT(KNoMemory, "Cannot write to file, check settings"); |
|
1067 |
|
1068 errorMsg.Copy(KErrorMessage); |
|
1069 // message from pwr sampler |
|
1070 if( aError < -1000 ) |
|
1071 { |
|
1072 errorMsg.Append(_L("Stop other power measurement tools!")); |
|
1073 } |
|
1074 else if( aError == KErrAlreadyExists || aError == 11 ) |
|
1075 { |
|
1076 errorMsg.Append(_L("Close old Profiler before launching!")); |
|
1077 } |
|
1078 else if( aError == KErrNotReady ) |
|
1079 { |
|
1080 errorMsg.Append(_L("Memory card removed, failed to write!")); |
|
1081 } |
|
1082 else if( aError == KErrPathNotFound ) |
|
1083 { |
|
1084 errorMsg.Append(_L("Given trace data location does not exist")); |
|
1085 } |
|
1086 else |
|
1087 { |
|
1088 if( aError == KErrNoMemory || |
|
1089 aError == KErrOverflow || |
|
1090 aError == KErrDirFull || |
|
1091 aError == KErrDiskFull || |
|
1092 aError == KErrNotReady ) |
|
1093 { |
|
1094 errorMsg.Append(KNoMemory); |
|
1095 } |
|
1096 else |
|
1097 { |
|
1098 errorMsg.Append(_L("code: ")); |
|
1099 errorMsg.AppendNum(aError); |
|
1100 } |
|
1101 } |
|
1102 // simply show an error note |
|
1103 CAknErrorNote* note = new(ELeave) CAknErrorNote(); |
|
1104 note->ExecuteLD(errorMsg); |
|
1105 |
|
1106 // set state idle in all error cases |
|
1107 iState = MProfilerStatusObserver::EIdle; |
|
1108 |
|
1109 // update status pane |
|
1110 iMainView->UpdateStatusPaneL(iState); |
|
1111 |
|
1112 // set plugin list back to enabled |
|
1113 iMainContainer->SetDimmed(EFalse); |
|
1114 |
|
1115 // refresh and set menus etc. in correct state |
|
1116 RefreshViewL(); |
|
1117 } |
|
1118 |
|
1119 // End of File |