|
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 <e32base.h> |
|
22 #include <e32cons.h> |
|
23 #include <e32svr.h> |
|
24 #include <utf.h> |
|
25 #include <apgtask.h> |
|
26 #include "atconsoleui.h" |
|
27 #include "atconsoleviews.h" |
|
28 |
|
29 // LOCAL FUNCTION PROTOTYPES |
|
30 LOCAL_C void LimitedAppend( TDes& aOriginal, const TDesC& aAppend); |
|
31 |
|
32 // FORWARD DECLARATIONS |
|
33 |
|
34 // ==================== LOCAL FUNCTIONS ======================================= |
|
35 // ----------------------------------------------------------------------------- |
|
36 // LimitedAppend() |
|
37 // Appends texts. |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 LOCAL_C void LimitedAppend( TDes& aOriginal, const TDesC& aAppend ) |
|
41 { |
|
42 |
|
43 TInt spaceLeft = aOriginal.MaxLength() - aOriginal.Length(); |
|
44 |
|
45 if ( spaceLeft > aAppend.Length() ) |
|
46 { |
|
47 aOriginal.Append ( aAppend ); |
|
48 } |
|
49 else |
|
50 { |
|
51 aOriginal.Append ( aAppend.Left ( spaceLeft ) ); |
|
52 } |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CView::NewL() |
|
57 // First phase constructor. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CView* CView::NewL( CConsoleMain* aConsole, |
|
61 CView* aParent, |
|
62 const TDesC& aName, |
|
63 TInt64 aProcessId |
|
64 ) |
|
65 { |
|
66 |
|
67 CView* self = new ( ELeave ) CView(); |
|
68 CleanupStack::PushL( self ); |
|
69 self->ConstructL( aConsole, aParent, aName, aProcessId ); |
|
70 CleanupStack::Pop( self ); |
|
71 return self; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CView::ConstructL() |
|
76 // Second phase constructor. |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 void CView::ConstructL( CConsoleMain* aConsole, |
|
80 CView* aParent, |
|
81 const TDesC& aName, TInt64 aProcessId |
|
82 ) |
|
83 { |
|
84 // Store the parameters |
|
85 iMain = aConsole; |
|
86 iConsole = aConsole->GetConsole(); |
|
87 iParent = aParent; |
|
88 iViewName = aName; |
|
89 iProcessId = aProcessId; |
|
90 |
|
91 // Get display size |
|
92 const TInt KOverHead = 5; |
|
93 iSize = iConsole->ScreenSize(); |
|
94 iScreenSize = iSize.iHeight - KOverHead; // Size available for menus |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CView::CView() |
|
99 // C++ default constructor. |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 CView::CView() |
|
103 { |
|
104 iDirection = 1; |
|
105 iPrevPos = -1; // Invalid starting value |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CView::~CView() |
|
110 // Destructor. |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 CView::~CView() |
|
114 { |
|
115 iItems.ResetAndDestroy(); |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CView::TimerUpdate() |
|
120 // Handles screen updates. |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 void CView::TimerUpdate() |
|
124 { |
|
125 RArray<TDesC> texts; |
|
126 if( ItemTexts( texts ) != KErrNone ) |
|
127 { |
|
128 texts.Close(); |
|
129 return; |
|
130 } |
|
131 TInt count = texts.Count(); |
|
132 // If list is empty, do not scroll. |
|
133 if ( count < 1 ) |
|
134 { |
|
135 texts.Close(); |
|
136 return; |
|
137 } |
|
138 else if( iFirstItem + iPositionOnScreen > count ) |
|
139 { |
|
140 iFirstItem = iPositionOnScreen = 0; |
|
141 } |
|
142 |
|
143 // If menu selection is updated, then restart scrolling |
|
144 if (iPrevPos != iFirstItem + iPositionOnScreen) |
|
145 { |
|
146 iPrevPos = iFirstItem + iPositionOnScreen; |
|
147 iStart = 0; |
|
148 iDirection = 1; |
|
149 } |
|
150 |
|
151 // If menu item have not been changed after last timer, then |
|
152 // start scrolling |
|
153 const TDesC& name = texts[ iFirstItem + iPositionOnScreen ]; |
|
154 if ( name.Length() > iSize.iWidth) |
|
155 { |
|
156 TInt y = iConsole->WhereY(); |
|
157 TInt x = iConsole->WhereX(); |
|
158 TBuf<80> iTmp; |
|
159 |
|
160 iStart = iStart + iDirection; |
|
161 |
|
162 // "Right end" |
|
163 if ( iStart + iSize.iWidth > name.Length() + KViewOverhead ) |
|
164 { |
|
165 iStart--; |
|
166 iDirection = -1; |
|
167 } |
|
168 |
|
169 // "Left end" |
|
170 if ( iStart == -1 ) |
|
171 { |
|
172 iStart++; |
|
173 iDirection = 1; |
|
174 } |
|
175 |
|
176 if( iStart > name.Length() ) |
|
177 { |
|
178 iStart = 0; |
|
179 } |
|
180 |
|
181 iTmp=_L(" *"); |
|
182 LimitedAppend( iTmp, name.Mid ( iStart ) ); |
|
183 |
|
184 iConsole->SetPos( 0, iPositionOnScreen + 1 ); |
|
185 iConsole->Printf ( iTmp.Left( iSize.iWidth -2 ) ); |
|
186 |
|
187 iConsole->SetPos(x,y); |
|
188 } |
|
189 texts.Close(); |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CView::AppendBefore() |
|
194 // Appends cursor to the line. |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 void CView::AppendBefore( TInt aLineNum, TDes& aLine ) |
|
198 { |
|
199 if( ( aLine.MaxLength() - aLine.Length() ) < 2 ) |
|
200 { |
|
201 return; |
|
202 } |
|
203 |
|
204 // If printing active line, print the marker |
|
205 if ( aLineNum == iPositionOnScreen + iFirstItem ) |
|
206 { |
|
207 aLine.Append( _L(" *") ); |
|
208 } |
|
209 else |
|
210 { |
|
211 aLine.Append( _L(" ") ); |
|
212 } |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CView::PrintViewL() |
|
217 // Prints view. |
|
218 // ----------------------------------------------------------------------------- |
|
219 // |
|
220 void CView::PrintViewL( TUpdateType aType ) |
|
221 { |
|
222 iUpdateType = aType; |
|
223 TBuf<KMaxLineLength> line; |
|
224 |
|
225 // Clear display |
|
226 iConsole->ClearScreen(); |
|
227 |
|
228 // Print menu title |
|
229 Print( Name() ); |
|
230 |
|
231 RArray<TDesC> texts; |
|
232 if( ItemTexts( texts ) != KErrNone ) |
|
233 { |
|
234 texts.Close(); |
|
235 return; |
|
236 } |
|
237 |
|
238 TInt oldItemCount = iItemCount; |
|
239 |
|
240 iItemCount = texts.Count(); |
|
241 |
|
242 // If first time in menu, update start and end positions |
|
243 if( ( iFirstItem == iLastItem ) || // First time here.. |
|
244 ( iLastItem >= iItemCount ) || |
|
245 ( oldItemCount != iItemCount ) ) // Menu size changed |
|
246 { |
|
247 iLastItem = iItemCount - 1; |
|
248 iPositionOnScreen = 0; |
|
249 |
|
250 // If "overflow", then adjust the end |
|
251 if (iLastItem > iScreenSize ) |
|
252 { |
|
253 iLastItem = iScreenSize; |
|
254 } |
|
255 } |
|
256 |
|
257 // Print items |
|
258 for ( TInt i = iFirstItem; i <= iLastItem; i++ ) |
|
259 { |
|
260 line.Zero(); |
|
261 |
|
262 // Append text before line |
|
263 AppendBefore( i, line ); |
|
264 TBuf<2*KMaxName> temp; |
|
265 if ( i < iItems.Count() ) |
|
266 { |
|
267 temp.Copy( iItems[ i ]->Name() ); |
|
268 TATLogOption loggingMode; |
|
269 iMain->StorageServer().GetLoggingModeL( iMain->Processes()[ i ].iProcessId, loggingMode ); |
|
270 if ( EATLoggingOff != loggingMode ) |
|
271 { |
|
272 if ( iMain->IsSubTestRunning( iMain->Processes()[ i ].iProcessId ) > KErrNotFound ) |
|
273 { |
|
274 temp.Append( _L(": ") ); |
|
275 temp.Append( _L("subtest running") ); |
|
276 } |
|
277 } |
|
278 else |
|
279 { |
|
280 temp.Append( _L(": ") ); |
|
281 temp.Append( _L("logging cancelled") ); |
|
282 } |
|
283 // TEST START |
|
284 /*if ( i == iFirstItem ) |
|
285 { |
|
286 temp.Append( _L(": ") ); |
|
287 temp.Append( _L("subtest running") ); |
|
288 } |
|
289 else if ( i == iFirstItem + 1 ) |
|
290 { |
|
291 temp.Append( _L(": ") ); |
|
292 temp.Append( _L("logging cancelled") ); |
|
293 } |
|
294 else if ( i == iFirstItem + 2 ) |
|
295 { |
|
296 temp.Append( _L(": ") ); |
|
297 temp.Append( _L("subtest running") ); |
|
298 }*/ |
|
299 // TEST END |
|
300 LimitedAppend ( line, temp /*texts[i]*/ ); |
|
301 } |
|
302 else |
|
303 LimitedAppend ( line, KExitTxt ); |
|
304 |
|
305 // Print the line |
|
306 Print(line); |
|
307 } |
|
308 texts.Close(); |
|
309 } |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CView::SelectL() |
|
313 // Handles line selections. |
|
314 // ----------------------------------------------------------------------------- |
|
315 // |
|
316 CView* CView::SelectL( TKeyCode aSelection, TBool& aContinue ) |
|
317 { |
|
318 MapKeyCode( aSelection ); |
|
319 |
|
320 switch ( ( TInt )aSelection ) |
|
321 { |
|
322 // Exit |
|
323 case EKeyEscape: |
|
324 aContinue = EFalse; |
|
325 return this; |
|
326 // SelectL item |
|
327 case EKeyEnter: |
|
328 case EKeyRightArrow: |
|
329 { |
|
330 // Print items |
|
331 for ( TInt i = iFirstItem; i <= iLastItem; i++ ) |
|
332 { |
|
333 if ( i < iItems.Count() ) |
|
334 { |
|
335 TATLogOption loggingMode; |
|
336 TInt processCount ( iMain->Processes().Count() ); |
|
337 if ( i < processCount ) |
|
338 { |
|
339 iMain->StorageServer().GetLoggingModeL( iMain->Processes()[ i ].iProcessId, loggingMode ); |
|
340 if ( EATLoggingOff != loggingMode ) |
|
341 { |
|
342 return iItems[ iPositionOnScreen ]; |
|
343 } |
|
344 else |
|
345 { |
|
346 return this; |
|
347 } |
|
348 } |
|
349 } |
|
350 } |
|
351 //return iItems[ iPositionOnScreen ]; |
|
352 } |
|
353 // Going back |
|
354 case EKeyLeftArrow: |
|
355 { |
|
356 TBool tmp = iShowLibraries | iSetLoggingMode; |
|
357 iShowLibraries = EFalse; |
|
358 iSetLoggingMode = EFalse; |
|
359 if ( tmp ) |
|
360 return this; |
|
361 else |
|
362 return iParent; |
|
363 } |
|
364 // Go down |
|
365 case EKeyDownArrow: |
|
366 { |
|
367 if ( iFirstItem + iPositionOnScreen == iItemCount - 1 ) |
|
368 { |
|
369 // If end of the list, go to beginning |
|
370 iLastItem = iLastItem - iFirstItem; |
|
371 iFirstItem = 0; |
|
372 iPositionOnScreen = 0; |
|
373 } |
|
374 else |
|
375 { |
|
376 if ( iPositionOnScreen == iScreenSize ) |
|
377 { |
|
378 // If in end of screen, update items |
|
379 if ( iLastItem != ( iItemCount - 1 ) ) |
|
380 { |
|
381 // If not end of the list, then update first and last |
|
382 // but do not update position in screen. |
|
383 iLastItem++; |
|
384 iFirstItem++; |
|
385 } |
|
386 } |
|
387 else |
|
388 { |
|
389 // Going down "in-screen", no need to update items |
|
390 iPositionOnScreen++; |
|
391 } |
|
392 } |
|
393 break; |
|
394 } |
|
395 // Go Up |
|
396 case EKeyUpArrow: |
|
397 { |
|
398 if ( iFirstItem + iPositionOnScreen == 0 ) |
|
399 { |
|
400 // If in the beginning of the list |
|
401 |
|
402 if ( iItemCount <= iScreenSize ) |
|
403 { |
|
404 // Wrap around when the list is not full |
|
405 iPositionOnScreen = iItemCount-1; |
|
406 } |
|
407 else |
|
408 { |
|
409 // Wrap around when there are more items than |
|
410 // can be shown at once. |
|
411 iPositionOnScreen = iScreenSize; |
|
412 iLastItem = iItemCount-1; |
|
413 iFirstItem = iItemCount - iPositionOnScreen - 1; |
|
414 } |
|
415 } |
|
416 else if ( iPositionOnScreen == 0 ) |
|
417 { |
|
418 // If not at the beginning of the list, then update first and |
|
419 // last but do not update position in screen. |
|
420 if ( iFirstItem != 0 ) |
|
421 { |
|
422 iLastItem--; |
|
423 iFirstItem--; |
|
424 } |
|
425 } |
|
426 else |
|
427 { |
|
428 // Going up "in-screen", no need to update items |
|
429 iPositionOnScreen--; |
|
430 } |
|
431 |
|
432 break; |
|
433 } |
|
434 |
|
435 // Additional keys |
|
436 case EKeyHome: |
|
437 case '3': |
|
438 iPositionOnScreen = 0; |
|
439 iFirstItem = 0; |
|
440 iLastItem = iScreenSize; |
|
441 |
|
442 if ( iLastItem > iItemCount-1 ) |
|
443 { |
|
444 iLastItem = iItemCount-1; |
|
445 } |
|
446 break; |
|
447 case EKeyEnd: |
|
448 case '9': |
|
449 iPositionOnScreen = iScreenSize; |
|
450 iLastItem = iItemCount-1; |
|
451 iFirstItem = iLastItem - iScreenSize; |
|
452 |
|
453 if ( iFirstItem < 0 ) |
|
454 { |
|
455 iFirstItem = 0; |
|
456 iPositionOnScreen = iLastItem-1; |
|
457 } |
|
458 break; |
|
459 case EKeyPageUp: |
|
460 case '1': |
|
461 |
|
462 iFirstItem = iFirstItem - iScreenSize - 1; |
|
463 iLastItem = iLastItem - iScreenSize - 1; |
|
464 |
|
465 if ( iFirstItem < 0 ) |
|
466 { |
|
467 iFirstItem = 0; |
|
468 iPositionOnScreen = 0; |
|
469 iLastItem = iScreenSize; |
|
470 if ( iLastItem > iItemCount-1 ) |
|
471 { |
|
472 iLastItem = iItemCount-1; |
|
473 } |
|
474 } |
|
475 break; |
|
476 case EKeyPageDown: |
|
477 case '7': |
|
478 iFirstItem = iFirstItem + iScreenSize + 1; |
|
479 iLastItem = iLastItem + iScreenSize + 1; |
|
480 |
|
481 // Going too far |
|
482 if ( iLastItem > iItemCount - 1 ) |
|
483 { |
|
484 iLastItem = iItemCount-1; |
|
485 iFirstItem = iLastItem - iScreenSize; |
|
486 iPositionOnScreen = iScreenSize; |
|
487 } |
|
488 |
|
489 // Ok, list is smaller than screen |
|
490 if ( iFirstItem < 0 ) |
|
491 { |
|
492 iFirstItem = 0; |
|
493 iLastItem = iItemCount-1; |
|
494 iPositionOnScreen = iLastItem; |
|
495 } |
|
496 break; |
|
497 default: // Bypass the keypress |
|
498 break; |
|
499 } |
|
500 |
|
501 // Continue normally and keep in the same menu |
|
502 aContinue = ETrue; |
|
503 return this; |
|
504 |
|
505 } |
|
506 |
|
507 // ----------------------------------------------------------------------------- |
|
508 // CView::ItemTexts() |
|
509 // Formats menu texts |
|
510 // ----------------------------------------------------------------------------- |
|
511 // |
|
512 TInt CView::ItemTexts( RArray<TDesC>& aArray ) |
|
513 { |
|
514 |
|
515 TInt count = iItems.Count(); |
|
516 for( TInt i=0; i<count; i++ ) |
|
517 { |
|
518 TBuf<50> temp; |
|
519 temp.Copy( iItems[i]->Name() ); |
|
520 if( aArray.Append( iItems[i]->Name() ) != KErrNone ) |
|
521 { |
|
522 return KErrNoMemory; |
|
523 } |
|
524 } |
|
525 |
|
526 return KErrNone; |
|
527 |
|
528 } |
|
529 |
|
530 // ----------------------------------------------------------------------------- |
|
531 // CView::SetParent() |
|
532 // Sets menu parent menu |
|
533 // ----------------------------------------------------------------------------- |
|
534 // |
|
535 void CView::SetParent ( CView* aMenu ) |
|
536 { |
|
537 |
|
538 iParent = aMenu; |
|
539 |
|
540 } |
|
541 |
|
542 // ----------------------------------------------------------------------------- |
|
543 // CView::Print() |
|
544 // Prints line to the screen. |
|
545 // ----------------------------------------------------------------------------- |
|
546 // |
|
547 void CView::Print( const TDesC& aPrint ) |
|
548 { |
|
549 iConsole->Printf ( aPrint.Left( iSize.iWidth - KViewOverhead ) ); |
|
550 iConsole->Printf(_L("\n")); |
|
551 } |
|
552 |
|
553 // ----------------------------------------------------------------------------- |
|
554 // CView::AddItemL() |
|
555 // Adds item to the list. |
|
556 // ----------------------------------------------------------------------------- |
|
557 // |
|
558 void CView::AddItemL( CView* aMenu ) |
|
559 { |
|
560 |
|
561 User::LeaveIfError ( iItems.Append( aMenu ) ); |
|
562 |
|
563 } |
|
564 |
|
565 // ----------------------------------------------------------------------------- |
|
566 // CView::ResetItems() |
|
567 // Resets the item list. |
|
568 // ----------------------------------------------------------------------------- |
|
569 // |
|
570 void CView::ResetItems() |
|
571 { |
|
572 iItems.ResetAndDestroy(); |
|
573 } |
|
574 // ----------------------------------------------------------------------------- |
|
575 // CView::Name() |
|
576 // Returns the name of view. |
|
577 // ----------------------------------------------------------------------------- |
|
578 // |
|
579 const TDesC& CView::Name( ) const |
|
580 { |
|
581 |
|
582 return iViewName; |
|
583 |
|
584 } |
|
585 |
|
586 // ----------------------------------------------------------------------------- |
|
587 // CView::MapKeyCode() |
|
588 // Maps numeric keycodes to proper TKeyCode values. |
|
589 // ----------------------------------------------------------------------------- |
|
590 // |
|
591 void CView::MapKeyCode(TKeyCode &aSelection) |
|
592 { |
|
593 |
|
594 TInt asciiCode = (TInt) aSelection; |
|
595 |
|
596 // Handling numeric keys 2,4,6 and 8 |
|
597 |
|
598 if(asciiCode == KMyKeyUpAsciiCode) |
|
599 { |
|
600 aSelection = EKeyUpArrow; |
|
601 } |
|
602 |
|
603 if(asciiCode == KMyKeyLeftAsciiCode) |
|
604 { |
|
605 aSelection = EKeyLeftArrow; |
|
606 } |
|
607 |
|
608 if(asciiCode == KMyKeyRightAsciiCode) |
|
609 { |
|
610 aSelection = EKeyEnter; |
|
611 } |
|
612 |
|
613 if(asciiCode == KMyKeyDownAsciiCode) |
|
614 { |
|
615 aSelection = EKeyDownArrow; |
|
616 } |
|
617 } |
|
618 |
|
619 // ----------------------------------------------------------------------------- |
|
620 // CMainView::NewL() |
|
621 // First phase constructor. |
|
622 // ----------------------------------------------------------------------------- |
|
623 // |
|
624 CMainView* CMainView::NewL( CConsoleMain* aConsole, |
|
625 CView* aParent, |
|
626 const TDesC& aName ) |
|
627 { |
|
628 |
|
629 CMainView* self = new ( ELeave ) CMainView(); |
|
630 CleanupStack::PushL( self ); |
|
631 self->ConstructL( aConsole, aParent, aName ); |
|
632 CleanupStack::Pop( self ); |
|
633 return self; |
|
634 |
|
635 } |
|
636 |
|
637 // ----------------------------------------------------------------------------- |
|
638 // CMainView::ItemTexts() |
|
639 // Format menu texts. |
|
640 // ----------------------------------------------------------------------------- |
|
641 // |
|
642 TInt CMainView::ItemTexts( RArray<TDesC>& aArray ) |
|
643 { |
|
644 |
|
645 CView::ItemTexts( aArray ); |
|
646 // Add Exit to last one in menu |
|
647 if( aArray.Append( KExitTxt ) != KErrNone ) |
|
648 { |
|
649 return KErrNoMemory; |
|
650 } |
|
651 |
|
652 return KErrNone; |
|
653 } |
|
654 |
|
655 // ----------------------------------------------------------------------------- |
|
656 // CMainView::ConstructL() |
|
657 // Second phase constructor. |
|
658 // ----------------------------------------------------------------------------- |
|
659 // |
|
660 void CMainView::ConstructL( CConsoleMain* aConsole, |
|
661 CView* aParent, |
|
662 const TDesC& aName |
|
663 ) |
|
664 { |
|
665 |
|
666 CView::ConstructL( aConsole, aParent, aName, NULL ); |
|
667 |
|
668 } |
|
669 |
|
670 // ----------------------------------------------------------------------------- |
|
671 // CMainView::SelectL() |
|
672 // Process keypresses in menu. |
|
673 // ----------------------------------------------------------------------------- |
|
674 // |
|
675 CView* CMainView::SelectL( TKeyCode aSelection, TBool& aContinue ) |
|
676 { |
|
677 |
|
678 MapKeyCode( aSelection ); |
|
679 |
|
680 // If SelectLion == "exit" and right or enter |
|
681 if ( aSelection == EKeyEnter || aSelection == EKeyRightArrow ) |
|
682 { |
|
683 if ( iPositionOnScreen == iItemCount - 1 ) |
|
684 { |
|
685 // Exit |
|
686 aContinue = EFalse; |
|
687 return this; |
|
688 } |
|
689 } |
|
690 |
|
691 // Normal menu handling |
|
692 CView* tmp = CView::SelectL( aSelection, aContinue ); |
|
693 return tmp; |
|
694 |
|
695 } |
|
696 |
|
697 // ----------------------------------------------------------------------------- |
|
698 // CProcessInfoView::NewL() |
|
699 // First phase constructor. |
|
700 // ----------------------------------------------------------------------------- |
|
701 // |
|
702 CProcessInfoView* CProcessInfoView::NewL( CConsoleMain* aConsole, |
|
703 CView* aParent, |
|
704 const TDesC& aName, TInt64 aProcessId ) |
|
705 { |
|
706 |
|
707 CProcessInfoView* self = new ( ELeave ) CProcessInfoView(); |
|
708 CleanupStack::PushL( self ); |
|
709 self->ConstructL( aConsole, aParent, aName, aProcessId ); |
|
710 CleanupStack::Pop( self ); |
|
711 return self; |
|
712 |
|
713 } |
|
714 |
|
715 // ----------------------------------------------------------------------------- |
|
716 // CProcessInfoView::~CProcessInfoView() |
|
717 // Destructor. |
|
718 // ----------------------------------------------------------------------------- |
|
719 // |
|
720 CProcessInfoView::~CProcessInfoView() |
|
721 { |
|
722 } |
|
723 |
|
724 // ----------------------------------------------------------------------------- |
|
725 // CProcessInfoView::ConstructL() |
|
726 // First phase constructor. |
|
727 // ----------------------------------------------------------------------------- |
|
728 // |
|
729 void CProcessInfoView::ConstructL( CConsoleMain* aConsole, |
|
730 CView* aParent, |
|
731 const TDesC& aName, TInt64 aProcessId |
|
732 ) |
|
733 { |
|
734 CView::ConstructL( aConsole, aParent, aName, aProcessId ); |
|
735 } |
|
736 |
|
737 // ----------------------------------------------------------------------------- |
|
738 // CProcessInfoView::ItemTexts() |
|
739 // Formats menu item texts. |
|
740 // ----------------------------------------------------------------------------- |
|
741 // |
|
742 TInt CProcessInfoView::ItemTexts( RArray<TDesC>& /*aArray*/ ) |
|
743 { |
|
744 return KErrNone; |
|
745 } |
|
746 |
|
747 // ----------------------------------------------------------------------------- |
|
748 // CProcessInfoView::PrintViewL() |
|
749 // Prints process info view. |
|
750 // ----------------------------------------------------------------------------- |
|
751 // |
|
752 void CProcessInfoView::PrintViewL( TUpdateType /*aType*/ ) |
|
753 { |
|
754 if ( !iShowLibraries && !iSetLoggingMode ) |
|
755 { |
|
756 // Get module names |
|
757 RArray<TATProcessInfo> processes; |
|
758 // Clear display |
|
759 iConsole->ClearScreen(); |
|
760 // Print menu title |
|
761 TBuf<2*KMaxName> title; |
|
762 title.Copy( Name() ); |
|
763 TInt subTest = iMain->IsSubTestRunning( iProcessId ); |
|
764 if ( subTest > KErrNotFound ) |
|
765 { |
|
766 // Append subtest running text |
|
767 title.Append( _L(": ") ); |
|
768 title.Append( _L( "subtest running" ) ); |
|
769 } |
|
770 |
|
771 Print( title /*Name()*/ ); |
|
772 // Update positions |
|
773 RArray<TDesC> texts; |
|
774 if( ItemTexts( texts ) != KErrNone ) |
|
775 { |
|
776 return; |
|
777 } |
|
778 |
|
779 TInt oldItemCount = iItemCount; |
|
780 iItemCount = texts.Count(); |
|
781 |
|
782 // If first time in menu, update start and end positions |
|
783 if( ( iFirstItem == iLastItem ) || // First time here.. |
|
784 ( iLastItem >= iItemCount ) || |
|
785 ( oldItemCount != iItemCount ) ) // Menu size changed |
|
786 { |
|
787 iLastItem = iItemCount - 1; |
|
788 iPositionOnScreen = 0; |
|
789 |
|
790 // If "overflow", then adjust the end |
|
791 if ( iLastItem > iScreenSize ) |
|
792 { |
|
793 iLastItem = iScreenSize; |
|
794 } |
|
795 } |
|
796 // Update pos screen |
|
797 if ( iPositionOnScreen > ( TInt )ECancelLoggingTxtItem - 1 ) |
|
798 iPositionOnScreen = 0; |
|
799 else if ( iPositionOnScreen < ( TInt )EStartSubtestTxtItem ) |
|
800 iPositionOnScreen = ( TInt )ECancelLoggingTxtItem - 1; |
|
801 |
|
802 // Get processes |
|
803 processes = iMain->Processes(); |
|
804 // Get current opened process |
|
805 for ( TInt num = 0 ; num < processes.Count() ; num++ ) |
|
806 { |
|
807 TATProcessInfo tmpProcessInfo; |
|
808 tmpProcessInfo = processes[ num ]; |
|
809 if ( tmpProcessInfo.iProcessId == iProcessId ) |
|
810 { |
|
811 iCurrentProcessInfo = tmpProcessInfo; |
|
812 break; |
|
813 } |
|
814 } |
|
815 |
|
816 TBuf<KMaxLineLength> line; |
|
817 // Get curr. and max. allocations |
|
818 TUint32 number( KErrNone ); |
|
819 TUint32 size( KErrNone ); |
|
820 TUint32 maxNumber( KErrNone ); |
|
821 TUint32 maxSize( KErrNone ); |
|
822 TInt currErr = iMain->StorageServer().GetCurrentAllocsL( iProcessId, number, size ); |
|
823 TInt maxErr = iMain->StorageServer().GetMaxAllocsL( iProcessId, maxNumber, maxSize ); |
|
824 // Get logging mode |
|
825 TATLogOption loggingMode; |
|
826 TInt loggingErr = iMain->StorageServer().GetLoggingModeL( iProcessId, loggingMode ); |
|
827 |
|
828 // Print curr. allocations |
|
829 line = _L(" "); |
|
830 LimitedAppend ( line, _L( "Curr. allocations: " ) ); |
|
831 // Append curr. allocs |
|
832 if ( currErr == KErrNone ) |
|
833 line.AppendNum( number ); |
|
834 |
|
835 Print( line ); |
|
836 line = _L(" "); |
|
837 if ( currErr == KErrNone ) |
|
838 { |
|
839 if ( size >= KATThousand && size < KATMillion ) // kiloByte range |
|
840 { |
|
841 TReal value( size ); |
|
842 value = value / KATThousand; |
|
843 line.Format( _L(" %.1f"), value ); |
|
844 line.Append( _L(" ") ); |
|
845 line.Append( KATKB ); |
|
846 } |
|
847 else if ( size >= KATMillion ) // megaByte range |
|
848 { |
|
849 TReal value( size ); |
|
850 value = value / KATMillion; |
|
851 line.Format( _L(" %.1f"), value ); |
|
852 line.Append( _L(" ") ); |
|
853 line.Append( KATMB ); |
|
854 } |
|
855 else |
|
856 { |
|
857 line.Copy( _L(" ") ); |
|
858 line.AppendNum( size ); |
|
859 line.Append( _L(" ") ); |
|
860 line.Append( KATB ); |
|
861 } |
|
862 } |
|
863 else |
|
864 { |
|
865 LimitedAppend ( line, _L( "unavailable" ) ); |
|
866 } |
|
867 Print( line ); |
|
868 |
|
869 // Print max. allocations |
|
870 line = _L(" "); |
|
871 LimitedAppend ( line, _L( "Max. allocations: " ) ); |
|
872 // Append curr. allocs |
|
873 if ( maxErr == KErrNone ) |
|
874 line.AppendNum( maxNumber ); |
|
875 |
|
876 Print( line ); |
|
877 line = _L(" "); |
|
878 if ( maxErr == KErrNone ) |
|
879 { |
|
880 if ( size >= KATThousand && size < KATMillion ) // kiloByte range |
|
881 { |
|
882 TReal value( maxSize ); |
|
883 value = value / KATThousand; |
|
884 line.Format( _L(" %.1f"), value ); |
|
885 line.Append( _L(" ") ); |
|
886 line.Append( KATKB ); |
|
887 } |
|
888 else if ( size >= KATMillion ) // megaByte range |
|
889 { |
|
890 TReal value( maxSize ); |
|
891 value = value / KATMillion; |
|
892 line.Format( _L(" %.1f"), value ); |
|
893 line.Append( _L(" ") ); |
|
894 line.Append( KATMB ); |
|
895 } |
|
896 else |
|
897 { |
|
898 line.Copy( _L(" ") ); |
|
899 line.AppendNum( maxSize ); |
|
900 line.Append( _L(" ") ); |
|
901 line.Append( KATB ); |
|
902 } |
|
903 } |
|
904 else |
|
905 { |
|
906 LimitedAppend ( line, _L( "unavailable") ); |
|
907 } |
|
908 Print( line ); |
|
909 |
|
910 // Print starting time |
|
911 line = _L(" "); |
|
912 LimitedAppend ( line, _L( "Process started:") ); |
|
913 Print( line ); |
|
914 line = _L(" "); |
|
915 TTime time( iCurrentProcessInfo.iStartTime ); |
|
916 TBuf<50> dateString; |
|
917 _LIT( KDateString3,"%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B" ); |
|
918 time.FormatL( dateString, KDateString3 ); |
|
919 LimitedAppend ( line, dateString ); |
|
920 Print( line ); |
|
921 |
|
922 // Print logging mode |
|
923 line = _L(" "); |
|
924 LimitedAppend ( line, _L( "Logging mode:") ); |
|
925 Print( line ); |
|
926 line = _L(" "); |
|
927 if ( KErrNone == loggingErr ) |
|
928 { |
|
929 if ( EATUseDefault == loggingMode ) |
|
930 { |
|
931 LimitedAppend ( line, _L( "External" ) ); |
|
932 } |
|
933 else if ( EATLogToFile == loggingMode ) |
|
934 { |
|
935 LimitedAppend ( line, _L( "Internal" ) ); |
|
936 } |
|
937 else if ( EATLogToXti == loggingMode ) |
|
938 { |
|
939 LimitedAppend ( line, _L( "External" ) ); |
|
940 } |
|
941 else if( EATLoggingOff == loggingMode ) |
|
942 { |
|
943 LimitedAppend ( line, _L( "None" ) ); |
|
944 } |
|
945 } |
|
946 else |
|
947 { |
|
948 LimitedAppend ( line, _L( "unavailable" ) ); |
|
949 } |
|
950 Print(line); |
|
951 |
|
952 // Print mode information (UDEB/UREL) |
|
953 line = _L(" "); |
|
954 LimitedAppend ( line, _L( "Mode:") ); |
|
955 Print( line ); |
|
956 line = _L(" "); |
|
957 TUint32 isUdeb; |
|
958 TInt udebErr = iMain->StorageServer().GetUdebL( iProcessId, isUdeb ); |
|
959 if ( KErrNone == udebErr ) |
|
960 { |
|
961 if ( isUdeb > KErrNone ) |
|
962 { |
|
963 LimitedAppend ( line, _L( "UDEB" ) ); |
|
964 } |
|
965 else |
|
966 { |
|
967 LimitedAppend ( line, _L( "UREL" ) ); |
|
968 } |
|
969 } |
|
970 else |
|
971 { |
|
972 LimitedAppend ( line, _L( "unavailable" ) ); |
|
973 } |
|
974 Print( line ); |
|
975 |
|
976 // Print logging file information |
|
977 line = _L(" "); |
|
978 LimitedAppend ( line, _L( "Logging file:") ); |
|
979 Print( line ); |
|
980 line = _L(" "); |
|
981 TBuf8<KMaxFileName> fileName; |
|
982 TInt fileErr = iMain->StorageServer().GetLoggingFileL( iProcessId, fileName ); |
|
983 if ( KErrNone == fileErr ) |
|
984 { |
|
985 if ( fileName.Length() > KErrNone ) |
|
986 { |
|
987 TBuf<KMaxFileName> unicodeFile; |
|
988 CnvUtfConverter::ConvertToUnicodeFromUtf8( unicodeFile, fileName ); |
|
989 LimitedAppend ( line, unicodeFile ); |
|
990 } |
|
991 else |
|
992 { |
|
993 LimitedAppend ( line, _L( "None" ) ); |
|
994 } |
|
995 } |
|
996 else |
|
997 { |
|
998 LimitedAppend ( line, _L( "unavailable" ) ); |
|
999 } |
|
1000 Print( line ); |
|
1001 |
|
1002 line = _L("\n"); |
|
1003 Print( line ); |
|
1004 |
|
1005 // Print process info menu |
|
1006 TInt cursor( KErrNone ); |
|
1007 while ( cursor <= ( TInt )ECancelLoggingTxtItem - 1 ) // -1, dyninitmenupane |
|
1008 { |
|
1009 line.Zero(); |
|
1010 if ( cursor == 0 && iMain->IsSubTestRunning( iProcessId ) == KErrNotFound ) |
|
1011 { |
|
1012 AppendBefore( cursor, line ); |
|
1013 LimitedAppend ( line, _L( "Start subtest") ); |
|
1014 // Print the line |
|
1015 Print( line ); |
|
1016 } |
|
1017 else if ( cursor == 0 && iMain->IsSubTestRunning( iProcessId ) > KErrNotFound ) |
|
1018 { |
|
1019 AppendBefore( cursor, line ); |
|
1020 LimitedAppend ( line, _L( "Stop subtest") ); |
|
1021 // Print the line |
|
1022 Print( line ); |
|
1023 } |
|
1024 else if ( cursor == 1 ) |
|
1025 { |
|
1026 AppendBefore( cursor, line ); |
|
1027 LimitedAppend ( line, _L( "View libraries") ); |
|
1028 // Print the line |
|
1029 Print( line ); |
|
1030 } |
|
1031 else if ( cursor == 2 ) |
|
1032 { |
|
1033 AppendBefore( cursor, line ); |
|
1034 LimitedAppend ( line, _L( "End process") ); |
|
1035 // Print the line |
|
1036 Print( line ); |
|
1037 } |
|
1038 else if ( cursor == 3 ) |
|
1039 { |
|
1040 AppendBefore( cursor, line ); |
|
1041 LimitedAppend ( line, _L( "Kill process") ); |
|
1042 // Print the line |
|
1043 Print( line ); |
|
1044 } |
|
1045 else if ( cursor == 4 ) |
|
1046 { |
|
1047 AppendBefore( cursor, line ); |
|
1048 LimitedAppend ( line, _L( "Cancel logging") ); |
|
1049 // Print the line |
|
1050 Print( line ); |
|
1051 } |
|
1052 cursor++; |
|
1053 } |
|
1054 texts.Close(); |
|
1055 } |
|
1056 else if ( iShowLibraries && !iSetLoggingMode ) |
|
1057 { |
|
1058 ViewLibrariesL(); |
|
1059 } |
|
1060 else if ( !iShowLibraries && iSetLoggingMode ) |
|
1061 { |
|
1062 SetLoggingModeL(); |
|
1063 } |
|
1064 |
|
1065 } |
|
1066 |
|
1067 // ----------------------------------------------------------------------------- |
|
1068 // CProcessInfoView::SelectL() |
|
1069 // Process keypresses in menu. |
|
1070 // ----------------------------------------------------------------------------- |
|
1071 // |
|
1072 CView* CProcessInfoView::SelectL( TKeyCode aSelection, TBool& aContinue ) |
|
1073 { |
|
1074 MapKeyCode( aSelection ); |
|
1075 |
|
1076 if( ( aSelection == EKeyRightArrow || |
|
1077 aSelection == EKeyEnter ) ) |
|
1078 { |
|
1079 if ( !iSetLoggingMode ) |
|
1080 { |
|
1081 if( iPositionOnScreen == EStartSubtestTxtItem ) |
|
1082 { |
|
1083 if ( iMain->IsSubTestRunning( iProcessId ) == KErrNotFound ) |
|
1084 iMain->SetProcessSubTestStart( iProcessId ); |
|
1085 else |
|
1086 iMain->SetProcessSubTestStop( iProcessId ); |
|
1087 return NULL; |
|
1088 } |
|
1089 else if( iPositionOnScreen == EViewLibrariesTxtItem - 1 ) |
|
1090 { |
|
1091 iShowLibraries = ETrue; |
|
1092 return NULL; |
|
1093 } |
|
1094 else if( iPositionOnScreen == EEndProcessTxtItem - 1 ) |
|
1095 { |
|
1096 EndProcessL( ETryToEnd ); |
|
1097 // Trying to end process -> go processes view |
|
1098 return iParent; |
|
1099 } |
|
1100 else if( iPositionOnScreen == EKillProcessTxtItem - 1 ) |
|
1101 { |
|
1102 EndProcessL( ETryToKill ); |
|
1103 // Trying to kill process -> go processes view |
|
1104 return iParent; |
|
1105 } |
|
1106 else if( iPositionOnScreen == ECancelLoggingTxtItem - 1 ) |
|
1107 { |
|
1108 iMain->StorageServer().CancelLogging( iProcessId ); |
|
1109 return iParent; |
|
1110 } |
|
1111 else |
|
1112 { |
|
1113 return this; |
|
1114 } |
|
1115 } |
|
1116 else if ( iSetLoggingMode ) |
|
1117 { |
|
1118 return NULL; |
|
1119 } |
|
1120 } |
|
1121 |
|
1122 return CView::SelectL( aSelection, aContinue ); |
|
1123 } |
|
1124 |
|
1125 // ----------------------------------------------------------------------------- |
|
1126 // CProcessInfoView::ViewLibrariesL() |
|
1127 // Prints libraries loaded by current process. |
|
1128 // ----------------------------------------------------------------------------- |
|
1129 // |
|
1130 void CProcessInfoView::ViewLibrariesL() |
|
1131 { |
|
1132 // Clear display |
|
1133 iConsole->ClearScreen(); |
|
1134 // Print menu title |
|
1135 Print( _L( "Loaded libraries:") ); |
|
1136 |
|
1137 TBuf<KMaxLineLength> line; |
|
1138 // Loaded libraries for this process |
|
1139 RArray< TBuf8<KMaxLibraryName> > libraries; |
|
1140 iMain->StorageServer().GetLoadedDllsL( iCurrentProcessInfo.iProcessId, libraries ); |
|
1141 TInt lCount = libraries.Count(); |
|
1142 for ( TInt count = 0 ; count < lCount ; count++ ) |
|
1143 { |
|
1144 TBuf<KMaxLibraryName> library; |
|
1145 library.Copy( libraries[ count ] ); |
|
1146 line = _L(" "); |
|
1147 LimitedAppend ( line, library ); |
|
1148 Print(line); |
|
1149 } |
|
1150 libraries.Close(); |
|
1151 } |
|
1152 |
|
1153 |
|
1154 // ----------------------------------------------------------------------------- |
|
1155 // CProcessInfoView::SetLoggingModeL() |
|
1156 // Prints logging modes which user wants to select to current process. |
|
1157 // ----------------------------------------------------------------------------- |
|
1158 // |
|
1159 void CProcessInfoView::SetLoggingModeL() |
|
1160 { |
|
1161 // Clear display |
|
1162 iConsole->ClearScreen(); |
|
1163 // Print menu title |
|
1164 Print( _L( "Logging mode:") ); |
|
1165 |
|
1166 // Update pos screen |
|
1167 if ( iPositionOnScreen > 2 ) |
|
1168 iPositionOnScreen = 0; |
|
1169 else if ( iPositionOnScreen < 0 ) |
|
1170 iPositionOnScreen = 2; |
|
1171 |
|
1172 TBuf<KMaxLineLength> line; |
|
1173 |
|
1174 // Print logging modes |
|
1175 TInt cursor( KErrNone ); |
|
1176 while ( cursor <= 2 ) // Three items |
|
1177 { |
|
1178 line.Zero(); |
|
1179 if ( cursor == 0 ) |
|
1180 { |
|
1181 AppendBefore( cursor, line ); |
|
1182 LimitedAppend ( line, _L( "External") ); |
|
1183 // Print the line |
|
1184 Print( line ); |
|
1185 } |
|
1186 else if ( cursor == 1 ) |
|
1187 { |
|
1188 AppendBefore( cursor, line ); |
|
1189 LimitedAppend ( line, _L( "Internal") ); |
|
1190 // Print the line |
|
1191 Print( line ); |
|
1192 } |
|
1193 else if ( cursor == 2 ) |
|
1194 { |
|
1195 AppendBefore( cursor, line ); |
|
1196 LimitedAppend ( line, _L( "None") ); |
|
1197 // Print the line |
|
1198 Print( line ); |
|
1199 } |
|
1200 cursor++; |
|
1201 } |
|
1202 } |
|
1203 |
|
1204 // ----------------------------------------------------------------------------- |
|
1205 // CProcessInfoView::EndProcessL() |
|
1206 // Ends process with a specific method. |
|
1207 // ----------------------------------------------------------------------------- |
|
1208 // |
|
1209 void CProcessInfoView::EndProcessL( TInt aCommand ) |
|
1210 { |
|
1211 RProcess endProcess; |
|
1212 TUint processId = iProcessId; |
|
1213 TBuf<KMaxProcessName> processName; |
|
1214 processName.Copy( Name() ); |
|
1215 TInt find = processName.Find( _L( "." ) ); |
|
1216 if ( find > KErrNotFound ) |
|
1217 processName.Delete( find, processName.Length() - find ); |
|
1218 |
|
1219 TInt openErr = endProcess.Open( TProcessId( processId ) ); |
|
1220 if ( openErr ==KErrNone ) |
|
1221 { |
|
1222 if ( aCommand == ETryToEnd ) |
|
1223 { |
|
1224 endProcess.Close(); |
|
1225 RWsSession wsSession; |
|
1226 TInt wsErr = wsSession.Connect(); |
|
1227 if ( KErrNone == wsErr ) |
|
1228 { |
|
1229 TApaTaskList apList = TApaTaskList( wsSession ); |
|
1230 TApaTask apTask = apList.FindApp( processName ); |
|
1231 if ( apTask.Exists() ) |
|
1232 { |
|
1233 apTask.EndTask(); |
|
1234 } |
|
1235 wsSession.Close(); |
|
1236 } |
|
1237 |
|
1238 } |
|
1239 else if ( aCommand == ETryToKill ) |
|
1240 { |
|
1241 endProcess.Kill( KErrNone ); |
|
1242 endProcess.Close(); |
|
1243 } |
|
1244 } |
|
1245 } |
|
1246 |
|
1247 // End of file |