memspyui/source/MemSpyViewThreads.cpp
branchRCL_3
changeset 21 b3cee849fa46
parent 20 48060abbbeaf
child 22 fad26422216a
equal deleted inserted replaced
20:48060abbbeaf 21:b3cee849fa46
     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 "MemSpyViewThreads.h"
       
    19 
       
    20 // System includes
       
    21 #include <AknQueryDialog.h>
       
    22 #include <memspyui.rsg>
       
    23 
       
    24 // Engine includes
       
    25 #include <memspy/engine/memspyengine.h>
       
    26 #include <memspy/engine/memspyengineobjectprocess.h>
       
    27 #include <memspy/engine/memspyengineobjectthread.h>
       
    28 #include <memspy/engine/memspyengineobjectcontainer.h>
       
    29 #include <memspy/engine/memspyengineobjectthreadinfoobjects.h>
       
    30 #include <memspy/engine/memspyengineobjectthreadinfocontainer.h>
       
    31 #include <memspy/engine/memspyenginehelperprocess.h>
       
    32 
       
    33 // User includes
       
    34 #include "MemSpyContainerObserver.h"
       
    35 #include "MemSpyViewProcesses.h"
       
    36 #include "MemSpyViewThreadInfoItemList.h"
       
    37 
       
    38 
       
    39 
       
    40 
       
    41 CMemSpyViewThreads::CMemSpyViewThreads( CMemSpyEngine& aEngine, MMemSpyViewObserver& aObserver, CMemSpyProcess& aProcess )
       
    42 :   CMemSpyViewBase( aEngine, aObserver ), iParentProcess( aProcess )
       
    43     {
       
    44     iParentProcess.Open();
       
    45     }
       
    46 
       
    47 
       
    48 CMemSpyViewThreads::~CMemSpyViewThreads()
       
    49     {
       
    50     iParentProcess.Close();
       
    51     if  ( iCurrentThread )
       
    52         {
       
    53         iCurrentThread->Close();
       
    54         }
       
    55     }
       
    56 
       
    57  
       
    58 void CMemSpyViewThreads::ConstructL( const TRect& aRect, CCoeControl& aContainer, TAny* aSelectionRune )
       
    59     {
       
    60     _LIT( KTitle, "Threads" );
       
    61     SetTitleL( KTitle );
       
    62     //
       
    63     CMemSpyViewBase::ConstructL( aRect, aContainer, aSelectionRune );
       
    64     //
       
    65     if  ( aSelectionRune )
       
    66         {
       
    67         CMemSpyThread* selectedItem = reinterpret_cast< CMemSpyThread* >( aSelectionRune );
       
    68         const TInt index = iParentProcess.ThreadIndexById( selectedItem->Id() );
       
    69         if  ( index >= 0 && index < iListBox->Model()->NumberOfItems() )
       
    70             {
       
    71             iListBox->SetCurrentItemIndex( index );
       
    72             HandleListBoxItemSelectedL( index );
       
    73             }
       
    74         }
       
    75     else if ( iParentProcess.Count() > 0 )
       
    76         {
       
    77         iListBox->SetCurrentItemIndex( 0 );
       
    78         HandleListBoxItemSelectedL( 0 );
       
    79         }
       
    80     }
       
    81 
       
    82 
       
    83 const CMemSpyProcess& CMemSpyViewThreads::Process() const
       
    84     {
       
    85     return iParentProcess;
       
    86     }
       
    87 
       
    88 
       
    89 CMemSpyThread& CMemSpyViewThreads::CurrentThread()
       
    90     {
       
    91     __ASSERT_ALWAYS( iCurrentThread != NULL, User::Invariant() );
       
    92     return *iCurrentThread;
       
    93     }
       
    94 
       
    95 
       
    96 void CMemSpyViewThreads::RefreshL()
       
    97     {
       
    98     SetListBoxModelL();
       
    99     CMemSpyViewBase::RefreshL();
       
   100     }
       
   101 
       
   102 
       
   103 TMemSpyViewType CMemSpyViewThreads::ViewType() const
       
   104     {
       
   105     return EMemSpyViewTypeThreads;
       
   106     }
       
   107 
       
   108 
       
   109 CMemSpyViewBase* CMemSpyViewThreads::PrepareParentViewL()
       
   110     {
       
   111     CMemSpyViewProcesses* parent = new(ELeave) CMemSpyViewProcesses( iEngine, iObserver, iParentProcess );
       
   112     CleanupStack::PushL( parent );
       
   113     parent->ConstructL( Rect(), *Parent(), &iParentProcess );
       
   114     CleanupStack::Pop( parent );
       
   115     return parent;
       
   116     }
       
   117 
       
   118 
       
   119 CMemSpyViewBase* CMemSpyViewThreads::PrepareChildViewL()
       
   120     {
       
   121     CMemSpyViewThreadInfoItemList* child = new(ELeave) CMemSpyViewThreadInfoItemList( iEngine, iObserver, *iCurrentThread );
       
   122     CleanupStack::PushL( child );
       
   123     child->ConstructL( Rect(), *Parent() );
       
   124     CleanupStack::Pop( child );
       
   125     return child;
       
   126     }
       
   127 
       
   128 
       
   129 void CMemSpyViewThreads::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
       
   130     {
       
   131     if  ( aResourceId == R_MEMSPY_MENUPANE )
       
   132         {
       
   133         CMemSpyThread& thread = CurrentThread();
       
   134         aMenuPane->SetItemDimmed( EMemSpyCmdThread, thread.IsDead() );
       
   135         }
       
   136     }
       
   137 
       
   138 
       
   139 TBool CMemSpyViewThreads::HandleCommandL( TInt aCommand )
       
   140     {
       
   141     TBool handled = ETrue;
       
   142     //
       
   143     switch ( aCommand )
       
   144         {
       
   145     case EMemSpyCmdThreadEndKill:
       
   146         OnCmdEndKillL();
       
   147 		break;
       
   148     case EMemSpyCmdThreadEndTerminate:
       
   149         OnCmdEndTerminateL();
       
   150 		break;
       
   151     case EMemSpyCmdThreadEndPanic:
       
   152         OnCmdEndPanicL();
       
   153 		break;
       
   154 	case EMemSpyCmdThreadSetPriorityAbsoluteVeryLow:
       
   155 	case EMemSpyCmdThreadSetPriorityAbsoluteLowNormal:
       
   156 	case EMemSpyCmdThreadSetPriorityAbsoluteLow:
       
   157 	case EMemSpyCmdThreadSetPriorityAbsoluteBackgroundNormal:
       
   158 	case EMemSpyCmdThreadSetPriorityAbsoluteBackground:
       
   159 	case EMemSpyCmdThreadSetPriorityAbsoluteForegroundNormal:
       
   160 	case EMemSpyCmdThreadSetPriorityAbsoluteForeground:
       
   161 	case EMemSpyCmdThreadSetPriorityAbsoluteHighNormal:
       
   162 	case EMemSpyCmdThreadSetPriorityAbsoluteHigh:
       
   163 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime1:
       
   164 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime2:
       
   165 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime3:
       
   166 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime4:
       
   167 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime5:
       
   168 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime6:
       
   169 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime7: 
       
   170 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime8:
       
   171         OnCmdSetPriorityL( aCommand );
       
   172         break;
       
   173 
       
   174     case EMemSpyCmdThreadInfoHandles:
       
   175         OnCmdInfoHandlesL();
       
   176         break;
       
   177 
       
   178     default:
       
   179         handled = CMemSpyViewBase::HandleCommandL( aCommand );
       
   180         break;
       
   181         }
       
   182     //
       
   183     return handled;
       
   184     }
       
   185 
       
   186 
       
   187 void CMemSpyViewThreads::OnCmdEndKillL()
       
   188     {
       
   189     TBool doTerminate = ETrue;
       
   190     CMemSpyThread& thread = CurrentThread();
       
   191     //
       
   192     if  ( thread.IsSystemPermanent() )
       
   193         {
       
   194         CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   195         doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   196         }
       
   197     //
       
   198     if  ( doTerminate )
       
   199         {
       
   200         thread.KillL();
       
   201         RefreshL();
       
   202         }
       
   203     }
       
   204 
       
   205 
       
   206 void CMemSpyViewThreads::OnCmdEndTerminateL()
       
   207     {
       
   208     TBool doTerminate = ETrue;
       
   209     CMemSpyThread& thread = CurrentThread();
       
   210     //
       
   211     if  ( thread.IsSystemPermanent() || thread.IsSystemCritical() )
       
   212         {
       
   213         CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   214         doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   215         }
       
   216     //
       
   217     if  ( doTerminate )
       
   218         {
       
   219         thread.TerminateL();
       
   220         RefreshL();
       
   221         }
       
   222     }
       
   223 
       
   224 
       
   225 void CMemSpyViewThreads::OnCmdEndPanicL()
       
   226     {
       
   227     TBool doTerminate = ETrue;
       
   228     CMemSpyThread& thread = CurrentThread();
       
   229     //
       
   230     if  ( thread.IsSystemPermanent() || thread.IsSystemCritical() )
       
   231         {
       
   232         CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   233         doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   234         }
       
   235     //
       
   236     if  ( doTerminate )
       
   237         {
       
   238         thread.PanicL();
       
   239         RefreshL();
       
   240         }
       
   241     }
       
   242 
       
   243 
       
   244 void CMemSpyViewThreads::OnCmdSetPriorityL( TInt aCommand )
       
   245     {
       
   246     TThreadPriority pri = EPriorityAbsoluteBackground;
       
   247     switch( aCommand )
       
   248         {
       
   249 	case EMemSpyCmdThreadSetPriorityAbsoluteVeryLow:
       
   250         pri = EPriorityAbsoluteVeryLow;
       
   251         break;
       
   252 	case EMemSpyCmdThreadSetPriorityAbsoluteLowNormal:
       
   253         pri = EPriorityAbsoluteLowNormal;
       
   254         break;
       
   255 	case EMemSpyCmdThreadSetPriorityAbsoluteLow:
       
   256         pri = EPriorityAbsoluteLow;
       
   257         break;
       
   258 	case EMemSpyCmdThreadSetPriorityAbsoluteBackgroundNormal:
       
   259         pri = EPriorityAbsoluteBackgroundNormal;
       
   260         break;
       
   261 	case EMemSpyCmdThreadSetPriorityAbsoluteBackground:
       
   262         pri = EPriorityAbsoluteBackground;
       
   263         break;
       
   264 	case EMemSpyCmdThreadSetPriorityAbsoluteForegroundNormal:
       
   265         pri = EPriorityAbsoluteForegroundNormal;
       
   266         break;
       
   267 	case EMemSpyCmdThreadSetPriorityAbsoluteForeground:
       
   268         pri = EPriorityAbsoluteForeground;
       
   269         break;
       
   270 	case EMemSpyCmdThreadSetPriorityAbsoluteHighNormal:
       
   271         pri = EPriorityAbsoluteHighNormal;
       
   272         break;
       
   273 	case EMemSpyCmdThreadSetPriorityAbsoluteHigh:
       
   274         pri = EPriorityAbsoluteHigh;
       
   275         break;
       
   276 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime1:
       
   277         pri = EPriorityAbsoluteRealTime1;
       
   278         break;
       
   279 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime2:
       
   280         pri = EPriorityAbsoluteRealTime2;
       
   281         break;
       
   282 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime3:
       
   283         pri = EPriorityAbsoluteRealTime3;
       
   284         break;
       
   285 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime4:
       
   286         pri = EPriorityAbsoluteRealTime4;
       
   287         break;
       
   288 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime5:
       
   289         pri = EPriorityAbsoluteRealTime5;
       
   290         break;
       
   291 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime6:
       
   292         pri = EPriorityAbsoluteRealTime6;
       
   293         break;
       
   294 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime7: 
       
   295         pri = EPriorityAbsoluteRealTime7;
       
   296         break;
       
   297 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime8:
       
   298         pri = EPriorityAbsoluteRealTime8;
       
   299         break;
       
   300         }
       
   301 
       
   302 #ifdef _DEBUG
       
   303     RDebug::Printf( "CMemSpyViewThreads::OnCmdSetPriorityL() - pri: %d", pri );
       
   304 #endif
       
   305 
       
   306     CMemSpyThread& thread = CurrentThread();
       
   307     thread.SetPriorityL( pri );
       
   308     RefreshL();
       
   309 
       
   310 #ifdef _DEBUG
       
   311     RDebug::Printf( "CMemSpyViewThreads::OnCmdSetPriorityL() - END" );
       
   312 #endif
       
   313     }
       
   314 
       
   315 
       
   316 void CMemSpyViewThreads::OnCmdInfoHandlesL()
       
   317     {
       
   318     CMemSpyThread& thread = CurrentThread();
       
   319     thread.InfoContainerForceSyncronousConstructionL().PrintL();
       
   320     }
       
   321 
       
   322 
       
   323 void CMemSpyViewThreads::SetListBoxModelL()
       
   324     {
       
   325     CAknSettingStyleListBox* listbox = static_cast< CAknSettingStyleListBox* >( iListBox );
       
   326     listbox->Model()->SetItemTextArray( &iParentProcess );
       
   327     listbox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   328     }
       
   329 
       
   330 
       
   331 void CMemSpyViewThreads::HandleListBoxItemActionedL( TInt /*aIndex*/ )
       
   332     {
       
   333     // Notify observer about an item being 'fired'
       
   334     ReportEventL( MMemSpyViewObserver::EEventItemActioned );
       
   335     }
       
   336 
       
   337 
       
   338 void CMemSpyViewThreads::HandleListBoxItemSelectedL( TInt aIndex )
       
   339     {
       
   340     if  ( iCurrentThread )
       
   341         {
       
   342         iCurrentThread->Close();
       
   343         }
       
   344 
       
   345     // Obtain the thread that corresponds to the selected item
       
   346     CMemSpyThread& thread = iParentProcess.At( aIndex );
       
   347     iCurrentThread = &thread;
       
   348     iCurrentThread->Open();
       
   349 
       
   350     // Notify observer about item selection
       
   351     ReportEventL( MMemSpyViewObserver::EEventItemSelected );
       
   352     }
       
   353 
       
   354 
       
   355