memspyui/ui/avkon/src/MemSpyViewWindowGroups.cpp
branchRCL_3
changeset 20 fad26422216a
parent 19 b3cee849fa46
child 21 f8280f3bfeb7
equal deleted inserted replaced
19:b3cee849fa46 20:fad26422216a
     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 #include "MemSpyViewWindowGroups.h"
       
    19 
       
    20 // System includes
       
    21 #include <eikclbd.h>
       
    22 #include <aknmessagequerydialog.h>
       
    23 #include <aknnotewrappers.h>
       
    24 
       
    25 // Engine includes
       
    26 #include <memspy/engine/memspyengine.h>
       
    27 #include <memspy/engine/memspyengineobjectcontainer.h>
       
    28 #include <memspy/engine/memspyengineobjectthread.h>
       
    29 
       
    30 // User includes
       
    31 #include "MemSpyUiUtils.h"
       
    32 #include "MemSpyViewMainMenu.h"
       
    33 #include "MemSpyContainerObserver.h"
       
    34 
       
    35 // Literal constants
       
    36 const TInt KMaxInfoLength = 128;
       
    37 
       
    38 
       
    39 CMemSpyViewWindowGroups::CMemSpyViewWindowGroups( CMemSpyEngine& aEngine, MMemSpyViewObserver& aObserver )
       
    40 :   CMemSpyViewBase( aEngine, aObserver )
       
    41     {
       
    42     }
       
    43 
       
    44 
       
    45 CMemSpyViewWindowGroups::~CMemSpyViewWindowGroups()
       
    46     {
       
    47     delete iWindowGroupList;
       
    48     }
       
    49 
       
    50 
       
    51 void CMemSpyViewWindowGroups::ConstructL( const TRect& aRect, CCoeControl& aContainer, TAny* aSelectionRune )
       
    52     {
       
    53     _LIT( KTitle, "Window Groups" );
       
    54     SetTitleL( KTitle );
       
    55     //
       
    56     CMemSpyViewBase::ConstructL( aRect, aContainer, aSelectionRune );
       
    57     }
       
    58 
       
    59 
       
    60 CEikListBox* CMemSpyViewWindowGroups::ConstructListBoxL()
       
    61     {
       
    62     delete iListBox;
       
    63     iListBox = NULL;
       
    64     CAknSingleNumberStyleListBox* listbox = new (ELeave) CAknSingleNumberStyleListBox();
       
    65     iListBox = listbox;
       
    66     listbox->ConstructL( this, EAknListBoxSelectionList | EAknListBoxLoopScrolling );
       
    67     listbox->SetContainerWindowL( *this );
       
    68     listbox->CreateScrollBarFrameL( ETrue );
       
    69     SetListBoxModelL();
       
    70     listbox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
    71     listbox->SetListBoxObserver( this );
       
    72     listbox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
       
    73     listbox->SetObserver( this );
       
    74     return listbox;
       
    75     }
       
    76 
       
    77 void CMemSpyViewWindowGroups::RefreshL()
       
    78     {
       
    79     SetListBoxModelL();
       
    80     CMemSpyViewBase::RefreshL();
       
    81     }
       
    82 
       
    83 
       
    84 TMemSpyViewType CMemSpyViewWindowGroups::ViewType() const
       
    85     {
       
    86     return EMemSpyViewTypeWindowGroups;
       
    87     }
       
    88 
       
    89 
       
    90 CMemSpyViewBase* CMemSpyViewWindowGroups::PrepareParentViewL()
       
    91     {
       
    92     CMemSpyViewMainMenu* parent = new(ELeave) CMemSpyViewMainMenu( iEngine, iObserver );
       
    93     CleanupStack::PushL( parent );
       
    94     parent->ConstructL( Rect(), *Parent(), (TAny*) ViewType() );
       
    95     CleanupStack::Pop( parent );
       
    96     return parent;
       
    97     }
       
    98 
       
    99 
       
   100 CMemSpyViewBase* CMemSpyViewWindowGroups::PrepareChildViewL()
       
   101     {
       
   102     CMemSpyViewBase* child = NULL;
       
   103     if ( iListBox && 
       
   104          iListBox->Model()->NumberOfItems() && 
       
   105          iListBox->CurrentItemIndex() > KErrNotFound )
       
   106         {
       
   107         DetailsL();
       
   108         }
       
   109     return child;
       
   110     }
       
   111 
       
   112 
       
   113 void CMemSpyViewWindowGroups::SetListBoxModelL()
       
   114     {
       
   115     // Take ownership of new model
       
   116     MMemSpyEngineHelperWindowServer& windowServerManager = iEngine.HelperWindowServer();
       
   117     MMemSpyEngineWindowGroupList* windowGroupList = windowServerManager.WindowGroupListL();
       
   118     delete iWindowGroupList;
       
   119     iWindowGroupList = windowGroupList;
       
   120     
       
   121     // Set up list box
       
   122     CAknSingleNumberStyleListBox* listbox = static_cast< CAknSingleNumberStyleListBox* >( iListBox );
       
   123     listbox->Model()->SetItemTextArray( iWindowGroupList );
       
   124     listbox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   125     }
       
   126 
       
   127 
       
   128 TBool CMemSpyViewWindowGroups::HandleCommandL( TInt aCommand )
       
   129     {
       
   130     TBool handled = ETrue;
       
   131     //
       
   132     switch ( aCommand )
       
   133         {
       
   134         case EMemSpyCmdWindowGroupTerminate:
       
   135             {
       
   136             TRAPD( err, OnCmdEndL( aCommand ) );
       
   137             CAknConfirmationNote* note = new(ELeave) CAknConfirmationNote( ETrue );
       
   138             if ( err )
       
   139                 {
       
   140                 note->ExecuteLD( _L("Cannot terminate task") );
       
   141                 }
       
   142             else
       
   143                 {
       
   144                 note->ExecuteLD( _L("Task terminated") );
       
   145                 }
       
   146             break;
       
   147             }
       
   148         case EMemSpyCmdWindowGroupSwitchTo:
       
   149             {
       
   150             TRAPD( err, OnCmdSwitchToL() );
       
   151             if ( err )
       
   152                 {
       
   153                 CAknConfirmationNote* note = new(ELeave) CAknConfirmationNote( ETrue );
       
   154                 note->ExecuteLD( _L("Cannot bring to foreground") );
       
   155                 }
       
   156             break;
       
   157             }
       
   158         case EMemSpyCmdWindowGroupEnd:
       
   159             {
       
   160             TRAPD( err, OnCmdEndL( aCommand ) );
       
   161             CAknConfirmationNote* note = new(ELeave) CAknConfirmationNote( ETrue );
       
   162             if ( err )
       
   163                 {
       
   164                 note->ExecuteLD( _L("Cannot end task") );
       
   165                 }
       
   166             else
       
   167                 {
       
   168                 note->ExecuteLD( _L("Task exited") );
       
   169                 }
       
   170             break;
       
   171             }
       
   172         case EMemSpyCmdWindowGroupPanic:
       
   173             {
       
   174             TRAPD( err, OnCmdEndL( aCommand ) );
       
   175             CAknConfirmationNote* note = new(ELeave) CAknConfirmationNote( ETrue );
       
   176             if ( err )
       
   177                 {
       
   178                 note->ExecuteLD( _L("Cannot panic task") );
       
   179                 }
       
   180             else
       
   181                 {
       
   182                 note->ExecuteLD( _L("Task panic'ed") );
       
   183                 }
       
   184             break;
       
   185             }
       
   186         default:
       
   187             {
       
   188             handled = CMemSpyViewBase::HandleCommandL( aCommand );
       
   189             break;        
       
   190             }
       
   191         }
       
   192     //
       
   193     return handled;
       
   194     }
       
   195 
       
   196 
       
   197 void CMemSpyViewWindowGroups::OnCmdSwitchToL()
       
   198     {
       
   199     MMemSpyEngineHelperWindowServer& windowServerManager = iEngine.HelperWindowServer();
       
   200     TInt id = iWindowGroupList->At( iListBox->CurrentItemIndex() ).iId;
       
   201     windowServerManager.SwitchToL( id );
       
   202     }
       
   203 
       
   204 
       
   205 void CMemSpyViewWindowGroups::OnCmdEndL( TInt aCommand )
       
   206     {
       
   207 	/*
       
   208     TBool doTerminate = ETrue;
       
   209     
       
   210     CMemSpyEngineObjectContainer& container = iEngine.Container();
       
   211     TThreadId id = iWindowGroupList->At( iListBox->CurrentItemIndex() ).iThreadId;
       
   212     
       
   213     // Try to find the thread in question...
       
   214     CMemSpyProcess* process = NULL;
       
   215     CMemSpyThread* thread = NULL; 
       
   216     User::LeaveIfError( container.ProcessAndThreadByThreadId( id, process, thread ) );
       
   217 
       
   218     if ( thread )
       
   219         {
       
   220         thread->Open();
       
   221         //
       
   222         if  ( thread->IsSystemPermanent() || thread->IsSystemCritical() )
       
   223             {
       
   224             CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   225             doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   226             }
       
   227         //
       
   228         if  ( doTerminate )
       
   229             {
       
   230             switch ( aCommand )
       
   231                 {
       
   232                 case EMemSpyCmdWindowGroupTerminate:
       
   233                     {
       
   234                     thread->TerminateL();
       
   235                     break;
       
   236                     }
       
   237                 case EMemSpyCmdWindowGroupEnd:
       
   238                     {
       
   239                     thread->KillL();
       
   240                     break;
       
   241                     }
       
   242                 case EMemSpyCmdWindowGroupPanic:
       
   243                     {
       
   244                     thread->PanicL();
       
   245                     break;
       
   246                     }
       
   247                 default:
       
   248                     {
       
   249                     // Programming error
       
   250                     __ASSERT_ALWAYS( EFalse, User::Panic( _L("MemSpy-View"), 0 ) );
       
   251                     }                
       
   252                 }
       
   253             }                
       
   254         }
       
   255     RefreshL();
       
   256     */
       
   257     }
       
   258 
       
   259 
       
   260 void CMemSpyViewWindowGroups::DetailsL()
       
   261     {
       
   262     HBufC* messageBuf = HBufC::NewLC( 4096 );
       
   263     TPtr messagePtr = messageBuf->Des();
       
   264 
       
   265     // Fetch data from helper
       
   266     TMemSpyEngineWindowGroupDetails selectedObject;
       
   267     MMemSpyEngineHelperWindowServer& windowServerManager = iEngine.HelperWindowServer();
       
   268     TInt id = iWindowGroupList->At( iListBox->CurrentItemIndex() ).iId;
       
   269     windowServerManager.GetWindowGroupDetailsL( id, selectedObject );
       
   270     
       
   271     // Append info to string buffer
       
   272     AppendFormatString( messagePtr, _L("WG ID: %d\n"), selectedObject.iId );
       
   273     AppendFormatString( messagePtr, _L("Client ThreadId: %Lu\n"), selectedObject.iThreadId.Id() );
       
   274     TFullName name;
       
   275     name.Copy( selectedObject.iFullName );
       
   276     AppendFormatString( messagePtr, _L("Thr: %S\n"), &name );
       
   277     name.Zero();
       
   278     AppendFormatString( messagePtr, _L("Priority: %d\n"), selectedObject.iPriority );
       
   279     AppendFormatString( messagePtr, _L("Handle: 0x%08X\n"), selectedObject.iWindowGroupHandle );
       
   280     name.Copy( selectedObject.iName );
       
   281     AppendFormatString( messagePtr, _L("Name: %S\n"), &name );
       
   282     name.Zero();
       
   283     AppendFormatString( messagePtr, _L("UID: 0x%08X\n"), selectedObject.iUID );
       
   284     AppendFormatString( messagePtr, _L("IsBusy: %d\n"), selectedObject.iIsBusy );
       
   285     AppendFormatString( messagePtr, _L("IsSystem: %d\n"), selectedObject.iIsSystem );
       
   286     AppendFormatString( messagePtr, _L("IsHidden: %d\n"), selectedObject.iIsHidden );
       
   287     name.Copy( selectedObject.iCaption );
       
   288     AppendFormatString( messagePtr, _L("Caption: %S\n"), &name );
       
   289     name.Zero();
       
   290     name.Copy( selectedObject.iDocName );
       
   291     AppendFormatString( messagePtr, _L("Docname: %S"), &name );
       
   292     name.Zero();
       
   293 
       
   294     // Display the buffer on a dialog
       
   295     CAknMessageQueryDialog* dialog = new(ELeave) CAknMessageQueryDialog( CAknQueryDialog::ENoTone );
       
   296     dialog->PrepareLC( R_MEMSPY_KERNEL_OBJECT_DETAILS_DIALOG );
       
   297     TFileName headerText;
       
   298     headerText.Copy( selectedObject.iFullName );
       
   299     dialog->SetHeaderTextL( headerText );
       
   300     dialog->SetMessageTextL( messagePtr );
       
   301     dialog->RunLD();
       
   302    
       
   303     CleanupStack::PopAndDestroy( messageBuf );
       
   304     }
       
   305 
       
   306 
       
   307 void CMemSpyViewWindowGroups::AppendFormatString( TPtr& aPtr, TRefByValue<const TDesC> aFmt, ... )
       
   308     {
       
   309     TBuf<KMaxInfoLength> infoString;
       
   310     VA_LIST list;
       
   311     VA_START ( list, aFmt );
       
   312     infoString.FormatList( aFmt, list );
       
   313     aPtr.Append( infoString );
       
   314     }
       
   315 
       
   316