memspyui/source/MemSpyViewProcesses.cpp
branchRCL_3
changeset 22 fad26422216a
parent 0 d6fe6244b863
equal deleted inserted replaced
21:b3cee849fa46 22: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 "MemSpyViewProcesses.h"
       
    19 
       
    20 // System includes
       
    21 #include <aknsfld.h>
       
    22 #include <AknQueryDialog.h>
       
    23 #include <memspyui.rsg>
       
    24 
       
    25 // Engine includes
       
    26 #include <memspy/engine/memspyengine.h>
       
    27 #include <memspy/engine/memspyengineobjectprocess.h>
       
    28 #include <memspy/engine/memspyengineobjectthread.h>
       
    29 #include <memspy/engine/memspyengineobjectcontainer.h>
       
    30 #include <memspy/engine/memspyengineobjectthreadinfoobjects.h>
       
    31 #include <memspy/engine/memspyengineobjectthreadinfocontainer.h>
       
    32 #include <memspy/engine/memspyenginehelperprocess.h>
       
    33 
       
    34 // User includes
       
    35 #include "MemSpyViewThreads.h"
       
    36 #include "MemSpyViewMainMenu.h"
       
    37 #include "MemSpyContainerObserver.h"
       
    38 
       
    39 // Constants
       
    40 const TInt KMemSpyMaxSearchTextLength = 30;
       
    41 const TInt KMemSpyMaxSearchTextLengthWithWildcards = KMemSpyMaxSearchTextLength + 4;
       
    42 
       
    43 
       
    44 
       
    45 CMemSpyViewProcesses::CMemSpyViewProcesses( CMemSpyEngine& aEngine, MMemSpyViewObserver& aObserver )
       
    46 :   CMemSpyViewBase( aEngine, aObserver )
       
    47     {
       
    48     }
       
    49 
       
    50 
       
    51 CMemSpyViewProcesses::CMemSpyViewProcesses( CMemSpyEngine& aEngine, MMemSpyViewObserver& aObserver, CMemSpyProcess& aProcess )
       
    52 :   CMemSpyViewBase( aEngine, aObserver ), iCurrentProcess( &aProcess )
       
    53     {
       
    54     iCurrentProcess->Open();
       
    55     }
       
    56 
       
    57 
       
    58 CMemSpyViewProcesses::~CMemSpyViewProcesses()
       
    59     {
       
    60     if  ( iCurrentProcess )
       
    61         {
       
    62         iCurrentProcess->Close();
       
    63         }
       
    64     //
       
    65     delete iSearchField;
       
    66     delete iMatcherBuffer;
       
    67     }
       
    68 
       
    69 
       
    70 void CMemSpyViewProcesses::ConstructL( const TRect& aRect, CCoeControl& aContainer, TAny* aSelectionRune )
       
    71     {
       
    72     _LIT( KTitle, "Processes\n& Threads" );
       
    73     SetTitleL( KTitle );
       
    74     //
       
    75     CMemSpyViewBase::ConstructL( aRect, aContainer, aSelectionRune );
       
    76     //
       
    77     iMatcherBuffer = HBufC::NewL( KMemSpyMaxSearchTextLengthWithWildcards );
       
    78     //
       
    79     iSearchField = CAknSearchField::NewL( *this, CAknSearchField::ESearch, NULL, KMemSpyMaxSearchTextLength );
       
    80     iSearchField->SetObserver( this );
       
    81     iSearchField->SetFocus( ETrue );
       
    82     iSearchField->SetComponentsToInheritVisibility( ETrue );
       
    83     //
       
    84     CMemSpyEngineObjectContainer& container = iEngine.Container();
       
    85     if  ( aSelectionRune )
       
    86         {
       
    87         CMemSpyProcess* selectedItem = reinterpret_cast< CMemSpyProcess* >( aSelectionRune );
       
    88         const TInt index = container.ProcessIndexById( selectedItem->Id() );
       
    89         if  ( index >= 0 && index < iListBox->Model()->NumberOfItems() )
       
    90             {
       
    91             iListBox->SetCurrentItemIndex( index );
       
    92             HandleListBoxItemSelectedL( index );
       
    93             }
       
    94         }
       
    95     else if ( container.Count() > 0 )
       
    96         {
       
    97         iListBox->SetCurrentItemIndex( 0 );
       
    98         HandleListBoxItemSelectedL( 0 );
       
    99         }
       
   100     //
       
   101     SizeChanged();
       
   102     ActivateL();
       
   103     }
       
   104 
       
   105 
       
   106 CMemSpyProcess& CMemSpyViewProcesses::CurrentProcess() const
       
   107     {
       
   108     __ASSERT_ALWAYS( iCurrentProcess != NULL, User::Invariant() );
       
   109     return *iCurrentProcess;
       
   110     }
       
   111 
       
   112 
       
   113 void CMemSpyViewProcesses::RefreshL()
       
   114     {
       
   115     SetListBoxModelL();
       
   116     CMemSpyViewBase::RefreshL();
       
   117     }
       
   118 
       
   119 
       
   120 TMemSpyViewType CMemSpyViewProcesses::ViewType() const
       
   121     {
       
   122     return EMemSpyViewTypeProcesses;
       
   123     }
       
   124 
       
   125 
       
   126 CMemSpyViewBase* CMemSpyViewProcesses::PrepareParentViewL()
       
   127     {
       
   128     CMemSpyViewMainMenu* parent = new(ELeave) CMemSpyViewMainMenu( iEngine, iObserver );
       
   129     CleanupStack::PushL( parent );
       
   130     parent->ConstructL( Rect(), *Parent(), (TAny*) ViewType() );
       
   131     CleanupStack::Pop( parent );
       
   132     return parent;
       
   133     }
       
   134 
       
   135 
       
   136 CMemSpyViewBase* CMemSpyViewProcesses::PrepareChildViewL()
       
   137     {
       
   138     CMemSpyViewThreads* child = new(ELeave) CMemSpyViewThreads( iEngine, iObserver, *iCurrentProcess );
       
   139     CleanupStack::PushL( child );
       
   140     child->ConstructL( Rect(), *Parent() );
       
   141     CleanupStack::Pop( child );
       
   142     return child;
       
   143     }
       
   144 
       
   145 
       
   146 void CMemSpyViewProcesses::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
       
   147     {
       
   148     if  ( aResourceId == MenuCascadeResourceId() )
       
   149         {
       
   150         CMemSpyProcess& process = CurrentProcess();
       
   151         const TBool hide = ( iEngine.Container().Count() == 0 ) || process.IsDead();
       
   152         //
       
   153         aMenuPane->SetItemDimmed( EMemSpyCmdProcessInfo, hide );
       
   154         aMenuPane->SetItemDimmed( EMemSpyCmdProcessEnd, hide );
       
   155         }
       
   156     }
       
   157 
       
   158 
       
   159 TBool CMemSpyViewProcesses::HandleCommandL( TInt aCommand )
       
   160     {
       
   161     TBool handled = ETrue;
       
   162     //
       
   163     switch ( aCommand )
       
   164         {
       
   165     // Sorting
       
   166     case EMemSpyCmdProcessSortById:
       
   167         OnCmdSortByIdL();
       
   168 		break;
       
   169     case EMemSpyCmdProcessSortByName:
       
   170         OnCmdSortByNameL();
       
   171 		break;
       
   172     case EMemSpyCmdProcessSortByThreadCount:
       
   173         OnCmdSortByThreadCountL();
       
   174 		break;
       
   175     case EMemSpyCmdProcessSortByCodeSegs:
       
   176         OnCmdSortByCodeSegsL();
       
   177 		break;
       
   178     case EMemSpyCmdProcessSortByHeapUsage:
       
   179         OnCmdSortByHeapUsageL();
       
   180 		break;
       
   181     case EMemSpyCmdProcessSortByStackUsage:
       
   182         OnCmdSortByStackUsageL();
       
   183 		break;
       
   184     // End
       
   185     case EMemSpyCmdProcessEndTerminate:
       
   186         OnCmdEndTerminateL();
       
   187 		break;
       
   188     case EMemSpyCmdProcessEndKill:
       
   189         OnCmdEndKillL();
       
   190 		break;
       
   191     case EMemSpyCmdProcessEndPanic:
       
   192         OnCmdEndPanicL();
       
   193 		break;
       
   194     // Info
       
   195     case EMemSpyCmdProcessInfoSummary:
       
   196         OnCmdInfoSummaryL();
       
   197 		break;
       
   198     case EMemSpyCmdProcessInfoHandles:
       
   199         OnCmdInfoHandlesL();
       
   200         break;
       
   201 
       
   202     default:
       
   203         handled = CMemSpyViewBase::HandleCommandL( aCommand );
       
   204         break;
       
   205         }
       
   206     //
       
   207     return handled;
       
   208     }
       
   209 
       
   210 
       
   211 void CMemSpyViewProcesses::OnCmdSortByIdL()
       
   212     {
       
   213     iEngine.Container().SortById();
       
   214     RefreshL();
       
   215     }
       
   216 
       
   217 
       
   218 void CMemSpyViewProcesses::OnCmdSortByNameL()
       
   219     {
       
   220     iEngine.Container().SortByName();
       
   221     RefreshL();
       
   222     }
       
   223 
       
   224 
       
   225 void CMemSpyViewProcesses::OnCmdSortByThreadCountL()
       
   226     {
       
   227     iEngine.Container().SortByThreadCount();
       
   228     RefreshL();
       
   229     }
       
   230 
       
   231 
       
   232 void CMemSpyViewProcesses::OnCmdSortByCodeSegsL()
       
   233     {
       
   234     iEngine.Container().SortByCodeSegs();
       
   235     RefreshL();
       
   236     }
       
   237 
       
   238 
       
   239 void CMemSpyViewProcesses::OnCmdSortByHeapUsageL()
       
   240     {
       
   241     iEngine.Container().SortByHeapUsage();
       
   242     RefreshL();
       
   243     }
       
   244 
       
   245 
       
   246 void CMemSpyViewProcesses::OnCmdSortByStackUsageL()
       
   247     {
       
   248     iEngine.Container().SortByStackUsage();
       
   249     RefreshL();
       
   250     }
       
   251 
       
   252 
       
   253 void CMemSpyViewProcesses::OnCmdInfoSummaryL()
       
   254     {
       
   255     CMemSpyProcess& process = CurrentProcess();
       
   256     iEngine.HelperProcess().OutputProcessInfoL( process );
       
   257     }
       
   258 
       
   259 
       
   260 void CMemSpyViewProcesses::OnCmdInfoHandlesL()
       
   261     {
       
   262     CMemSpyProcess& process = CurrentProcess();
       
   263     //
       
   264     const TInt threadCount = process.Count();
       
   265     for( TInt i=0; i<threadCount; i++ )
       
   266         {
       
   267         CMemSpyThread& thread = process.At( i );
       
   268         thread.InfoContainerForceSyncronousConstructionL().PrintL();
       
   269         }
       
   270     }
       
   271 
       
   272 
       
   273 void CMemSpyViewProcesses::OnCmdEndTerminateL()
       
   274     {
       
   275     TBool doTerminate = ETrue;
       
   276     CMemSpyProcess& process = CurrentProcess();
       
   277     //
       
   278     if  ( process.IsSystemPermanent() || process.IsSystemCritical() )
       
   279         {
       
   280         CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   281         doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   282         }
       
   283     //
       
   284     if  ( doTerminate )
       
   285         {
       
   286         process.TerminateL();
       
   287         RefreshL();
       
   288         }
       
   289     }
       
   290 
       
   291 
       
   292 void CMemSpyViewProcesses::OnCmdEndPanicL()
       
   293     {
       
   294     TBool doTerminate = ETrue;
       
   295     CMemSpyProcess& process = CurrentProcess();
       
   296     //
       
   297     if  ( process.IsSystemPermanent() || process.IsSystemCritical() )
       
   298         {
       
   299         CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   300         doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   301         }
       
   302     //
       
   303     if  ( doTerminate )
       
   304         {
       
   305         process.PanicL();
       
   306         RefreshL();
       
   307         }
       
   308     }
       
   309 
       
   310 
       
   311 void CMemSpyViewProcesses::OnCmdEndKillL()
       
   312     {
       
   313     TBool doTerminate = ETrue;
       
   314     CMemSpyProcess& process = CurrentProcess();
       
   315     //
       
   316     if  ( process.IsSystemPermanent() || process.IsSystemCritical() )
       
   317         {
       
   318         CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   319         doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   320         }
       
   321     //
       
   322     if  ( doTerminate )
       
   323         {
       
   324         process.KillL();
       
   325         RefreshL();
       
   326         }
       
   327     }
       
   328 
       
   329 
       
   330 
       
   331 
       
   332 void CMemSpyViewProcesses::SetListBoxModelL()
       
   333     {
       
   334     CAknSettingStyleListBox* listbox = static_cast< CAknSettingStyleListBox* >( iListBox );
       
   335     listbox->Model()->SetItemTextArray( &iEngine.Container() );
       
   336     listbox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   337     }
       
   338 
       
   339 
       
   340 void CMemSpyViewProcesses::HandleListBoxItemActionedL( TInt /*aIndex*/ )
       
   341     {
       
   342     // Notify observer about an item being 'fired'
       
   343     ReportEventL( MMemSpyViewObserver::EEventItemActioned );
       
   344     }
       
   345 
       
   346 
       
   347 void CMemSpyViewProcesses::HandleListBoxItemSelectedL( TInt aIndex )
       
   348     {
       
   349     if  ( iCurrentProcess )
       
   350         {
       
   351         iCurrentProcess->Close();
       
   352         }
       
   353 
       
   354     // Obtain the process that corresponds to the selected item
       
   355     CMemSpyEngineObjectContainer& container = iEngine.Container();
       
   356     CMemSpyProcess& process = container.At( aIndex );
       
   357     iCurrentProcess = &process;
       
   358     iCurrentProcess->Open();
       
   359 
       
   360     // Notify observer about item selection
       
   361     ReportEventL( MMemSpyViewObserver::EEventItemSelected );
       
   362     }
       
   363 
       
   364 
       
   365 void CMemSpyViewProcesses::SizeChanged()
       
   366     {
       
   367     const TRect rect( Rect() );
       
   368     
       
   369     if  ( iListBox && iSearchField )
       
   370         {
       
   371         const TInt lafIndex_H = 1;
       
   372         AknLayoutUtils::LayoutControl( iListBox, rect, AknLayout::list_gen_pane( lafIndex_H ) );
       
   373         AknLayoutUtils::LayoutControl( iSearchField, rect, AknLayout::find_pane() );
       
   374         }
       
   375     else
       
   376         {
       
   377         CMemSpyViewBase::SizeChanged();
       
   378         }
       
   379 
       
   380 /*
       
   381     // Search field
       
   382     TSize searchFieldSize( iSearchField->MinimumSize() ); // BALLS: search field doesn't implement minimum size correctly?!?!?
       
   383     searchFieldSize.SetWidth( rect.Width() );
       
   384     const TRect searchFieldRect( TPoint( rect.iTl.iX, rect.iBr.iY ), searchFieldSize );
       
   385     iSearchField->SetRect( searchFieldRect );
       
   386 
       
   387     // Listbox
       
   388     TSize listBoxSize( rect.Size() - TSize( 0, searchFieldSize.iHeight ) );
       
   389     iListBox->SetRect( rect.iTl, listBoxSize );
       
   390 */
       
   391     }
       
   392 
       
   393 
       
   394 TInt CMemSpyViewProcesses::CountComponentControls() const
       
   395     {
       
   396     TInt count = 0;
       
   397     //
       
   398     if  ( iListBox != NULL )
       
   399         {
       
   400         ++count;
       
   401         }
       
   402     if  ( iSearchField != NULL )
       
   403         {
       
   404         ++count;
       
   405         }
       
   406     //
       
   407     return count;
       
   408     }
       
   409 
       
   410 
       
   411 CCoeControl* CMemSpyViewProcesses::ComponentControl( TInt aIndex ) const
       
   412     {
       
   413     CCoeControl* ret = iListBox;
       
   414     //
       
   415     if  ( aIndex == 1 )
       
   416         {
       
   417         ret = iSearchField;
       
   418         }
       
   419     //
       
   420     return ret;
       
   421     }
       
   422 
       
   423 
       
   424 TKeyResponse CMemSpyViewProcesses::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   425     {
       
   426     TKeyResponse resp = EKeyWasNotConsumed;
       
   427     //
       
   428     if  ( aType == EEventKey )
       
   429         {
       
   430         switch( aKeyEvent.iCode )
       
   431             {
       
   432         case EKeyUpArrow:
       
   433         case EKeyDownArrow:
       
   434         case EKeyEnter:
       
   435         case EKeyOK:
       
   436             if  ( iListBox )
       
   437                 {
       
   438                 resp = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   439                 }
       
   440             break;
       
   441         default:
       
   442             break;
       
   443             }
       
   444         //
       
   445         if  ( resp == EKeyWasNotConsumed )
       
   446             {
       
   447             // Do we need to show the find field?
       
   448             resp = iSearchField->OfferKeyEventL( aKeyEvent, aType );
       
   449             }
       
   450         }
       
   451     //
       
   452     return resp;
       
   453     }
       
   454 
       
   455 
       
   456 void CMemSpyViewProcesses::HandleControlEventL( CCoeControl* aControl, TCoeEvent aEventType )
       
   457     {
       
   458     CMemSpyViewBase::HandleControlEventL( aControl, aEventType );
       
   459     //
       
   460     if  ( aEventType == MCoeControlObserver::EEventStateChanged )
       
   461         {
       
   462         if  ( aControl == iSearchField )
       
   463             {
       
   464             SelectListBoxItemByFindTextL();
       
   465             }
       
   466         }
       
   467     }
       
   468 
       
   469 
       
   470 void CMemSpyViewProcesses::FocusChanged( TDrawNow /*aDrawNow*/ )
       
   471     {
       
   472     if  ( iListBox )
       
   473         {
       
   474         iListBox->SetFocus( IsFocused() );
       
   475         }
       
   476     if  ( iSearchField )
       
   477         {
       
   478         iSearchField->SetFocus( IsFocused() );
       
   479         }
       
   480     }
       
   481 
       
   482 
       
   483 void CMemSpyViewProcesses::SelectListBoxItemByFindTextL()
       
   484     {
       
   485     _LIT( KMemSpyWildcardCharacter, "*" );
       
   486     
       
   487     TPtr pBuffer( iMatcherBuffer->Des() );
       
   488     iSearchField->GetSearchText( pBuffer );
       
   489     //pBuffer.Insert( 0, KMemSpyWildcardCharacter );
       
   490     pBuffer.Append( KMemSpyWildcardCharacter );
       
   491     
       
   492     CMemSpyEngineObjectContainer& container = iEngine.Container();
       
   493     const TInt count = container.Count();
       
   494     //
       
   495     TInt index = 0;
       
   496     while( index < count )
       
   497         {
       
   498         CMemSpyProcess& process = container.At( index );
       
   499         const TPtrC processName( process.Name() );
       
   500         //
       
   501         if  ( processName.MatchF( pBuffer ) >= 0 )
       
   502             {
       
   503             HandleListBoxItemSelectedL( index );
       
   504             iListBox->ScrollToMakeItemVisible( index );
       
   505             iListBox->SetCurrentItemIndexAndDraw( index );
       
   506             return;
       
   507             }
       
   508             
       
   509         ++index;
       
   510         }
       
   511     }
       
   512 
       
   513