memspyui/source/MemSpyViewHeapTrackingSettings.cpp
branchRCL_3
changeset 60 6646c35e558c
parent 0 d6fe6244b863
equal deleted inserted replaced
50:9b2cffad4b5e 60:6646c35e558c
       
     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 "MemSpyViewHeapTrackingSettings.h"
       
    19 
       
    20 // System includes
       
    21 #include <hal.h>
       
    22 #ifdef __EPOC32__
       
    23 #include <e32rom.h>
       
    24 #endif
       
    25 #include <AknQueryDialog.h>
       
    26 
       
    27 // Engine includes
       
    28 #include <memspy/engine/memspyengine.h>
       
    29 #include <memspy/engine/memspyengineobjectprocess.h>
       
    30 #include <memspy/engine/memspyengineobjectthread.h>
       
    31 #include <memspy/engine/memspyengineobjectcontainer.h>
       
    32 #include <memspy/engine/memspyengineobjectthreadinfoobjects.h>
       
    33 #include <memspy/engine/memspyengineobjectthreadinfocontainer.h>
       
    34 #include <memspy/engine/memspyenginehelpersysmemtracker.h>
       
    35 #include <memspy/engine/memspyenginehelpersysmemtrackerconfig.h>
       
    36 #include <memspyui.rsg>
       
    37 
       
    38 // User includes
       
    39 #include "MemSpyUiUtils.h"
       
    40 #include "MemSpySettings.h"
       
    41 #include "MemSpyViewHeapTracking.h"
       
    42 #include "MemSpyContainerObserver.h"
       
    43 
       
    44 
       
    45 CMemSpyViewHeapTrackingSettings::CMemSpyViewHeapTrackingSettings( CMemSpyEngine& aEngine, MMemSpyViewObserver& aObserver )
       
    46 :   CMemSpyViewBase( aEngine, aObserver )
       
    47     {
       
    48     }
       
    49 
       
    50 
       
    51 CMemSpyViewHeapTrackingSettings::~CMemSpyViewHeapTrackingSettings()
       
    52     {
       
    53     }
       
    54 
       
    55 
       
    56 void CMemSpyViewHeapTrackingSettings::ConstructL( const TRect& aRect, CCoeControl& aContainer, TAny* aSelectionRune )
       
    57     {
       
    58     _LIT( KTitle, "Settings" );
       
    59     SetTitleL( KTitle );
       
    60     //
       
    61     CMemSpyViewBase::ConstructL( aRect, aContainer, aSelectionRune );
       
    62     }
       
    63 
       
    64 
       
    65 void CMemSpyViewHeapTrackingSettings::RefreshL()
       
    66     {
       
    67     SetListBoxModelL();
       
    68     CMemSpyViewBase::RefreshL();
       
    69     }
       
    70 
       
    71 
       
    72 TMemSpyViewType CMemSpyViewHeapTrackingSettings::ViewType() const
       
    73     {
       
    74     return EMemSpyViewTypeHeapTrackingSettings;
       
    75     }
       
    76 
       
    77 
       
    78 CMemSpyViewBase* CMemSpyViewHeapTrackingSettings::PrepareParentViewL()
       
    79     {
       
    80     CMemSpyViewHeapTracking* parent = new(ELeave) CMemSpyViewHeapTracking( iEngine, iObserver );
       
    81     CleanupStack::PushL( parent );
       
    82     parent->ConstructL( Rect(), *Parent(), (TAny*) ViewType() );
       
    83     CleanupStack::Pop( parent );
       
    84     return parent;
       
    85     }
       
    86 
       
    87 
       
    88 CMemSpyViewBase* CMemSpyViewHeapTrackingSettings::PrepareChildViewL()
       
    89     {
       
    90     const TInt index = iListBox->CurrentItemIndex();
       
    91 
       
    92     // Get current config
       
    93     CMemSpyEngineHelperSysMemTracker& swmt = iEngine.HelperSysMemTracker();
       
    94     TMemSpyEngineHelperSysMemTrackerConfig config;
       
    95     swmt.GetConfig( config );
       
    96 
       
    97     // This view abuses the child view callback to toggle field values and/or
       
    98     // display settings dialogs.
       
    99     if  ( index == 0 )
       
   100         {
       
   101         TInt period = config.iTimerPeriod.Int() / 1000000;
       
   102         CAknNumberQueryDialog* dialog = new(ELeave) CAknNumberQueryDialog( period );
       
   103         if  ( dialog->ExecuteLD( R_MEMSPY_HEAP_TRACKER_TIMER_PERIOD ) )
       
   104             {
       
   105             config.iTimerPeriod = period * 1000000;
       
   106             }
       
   107         }
       
   108     else if ( index == 1 )
       
   109         {
       
   110         TInt categories( config.iEnabledCategories );
       
   111         CSWMTCategorySelectionCheckBoxSettingItem* settingItem = new (ELeave) CSWMTCategorySelectionCheckBoxSettingItem( 0, categories );
       
   112         CleanupStack::PushL( settingItem );
       
   113         settingItem->ConstructL( EFalse,
       
   114                                  0,
       
   115                                  _L("SWMT Categories"),
       
   116                                  NULL,
       
   117                                  R_MEMSPYUI_SWMT_CATEGORIES_SETTING_PAGE,
       
   118                                  EAknCtPopupSettingList,
       
   119                                  NULL,
       
   120                                  NULL );
       
   121         
       
   122         CMemSpySWMTCategorySelectionCheckBoxSettingPage* dlg = new(ELeave) CMemSpySWMTCategorySelectionCheckBoxSettingPage( R_MEMSPYUI_SWMT_CATEGORIES_SETTING_PAGE, settingItem->ItemArray() );
       
   123         dlg->SetSettingPageObserver( settingItem );
       
   124         if  ( dlg->ExecuteLD( CAknSettingPage::EUpdateWhenChanged ) )
       
   125             {
       
   126             config.iEnabledCategories = categories;
       
   127             }
       
   128         CleanupStack::PopAndDestroy( settingItem );
       
   129         }
       
   130     else if ( index == 2 )
       
   131         {
       
   132         config.iDumpData = !config.iDumpData;
       
   133         }
       
   134     else if  ( index == 3 )
       
   135         {
       
   136         TName nameFilter;
       
   137         nameFilter.Copy( config.iThreadNameFilter );
       
   138         CMemSpyAllowEmptyDataDialog* dialog = new (ELeave) CMemSpyAllowEmptyDataDialog( nameFilter );
       
   139         if  ( dialog->ExecuteLD( R_MEMSPY_HEAP_TRACKER_NAME_FILTER ) )
       
   140             {
       
   141             config.iThreadNameFilter = nameFilter;
       
   142             }
       
   143         }
       
   144     
       
   145     // Push changes to SWMT
       
   146     swmt.SetConfigL( config );
       
   147     Settings().StoreSettingsL();
       
   148 
       
   149     RefreshL();
       
   150     return NULL;
       
   151     }
       
   152 
       
   153 
       
   154 void CMemSpyViewHeapTrackingSettings::SetListBoxModelL()
       
   155     {
       
   156     CDesCArrayFlat* model = new(ELeave) CDesCArrayFlat(5);
       
   157     CleanupStack::PushL( model );
       
   158 
       
   159     TBuf<KMaxFullName + 1> item;
       
   160 
       
   161     // Get current config
       
   162     CMemSpyEngineHelperSysMemTracker& swmt = iEngine.HelperSysMemTracker();
       
   163     TMemSpyEngineHelperSysMemTrackerConfig config;
       
   164     swmt.GetConfig( config );
       
   165 
       
   166     // 1st item
       
   167     _LIT( KItem1Format, "\tTracking timer period\t\t%d (sec)" );
       
   168     item.Format( KItem1Format, config.iTimerPeriod.Int() / 1000000 );
       
   169     model->AppendL( item );
       
   170     
       
   171     // 2nd item
       
   172     _LIT( KItem3Format, "\tCategories\t\t%d selected" );
       
   173     item.Format( KItem3Format, config.EnabledCategoryCount() );
       
   174     model->AppendL( item );
       
   175 
       
   176     // following items are related only to User Heap category, 
       
   177     // so hide them if User Heap is not selected
       
   178     if ( config.iEnabledCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryUserHeap )
       
   179         {
       
   180         // 3th item
       
   181         _LIT( KItem2Format, "\tDump data" );
       
   182         PrepareItemBufL( item, KItem2Format, config.iDumpData, config.iEnabledCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryUserHeap && config.iThreadNameFilter.Length() > 0 );
       
   183         model->AppendL( item );
       
   184         
       
   185         // 4th item
       
   186         if ( config.iDumpData )
       
   187             {
       
   188             _LIT( KItem4Format, "\tHeap data thread filter\t\t%S" );
       
   189             if ( config.iThreadNameFilter.Length() > 0 )
       
   190                 {
       
   191                 item.Format( KItem4Format, &config.iThreadNameFilter );
       
   192                 }
       
   193             else
       
   194                 {
       
   195                 item.Format( KItem4Format, &_L("No filtering") );
       
   196                 }
       
   197             model->AppendL( item );        
       
   198             }        
       
   199         }
       
   200     
       
   201     // Set up list box
       
   202     CAknSettingStyleListBox* listbox = static_cast< CAknSettingStyleListBox* >( iListBox );
       
   203     listbox->Model()->SetItemTextArray( model );
       
   204     listbox->Model()->SetOwnershipType( ELbmOwnsItemArray );
       
   205     CleanupStack::Pop( model );
       
   206     }
       
   207 
       
   208 
       
   209 void CMemSpyViewHeapTrackingSettings::PrepareItemBufL( TDes& aBuf, const TDesC& aCaption, TBool aStatus, TBool aHeapCategorySelected )
       
   210     {
       
   211     aBuf.Copy( aCaption ); 
       
   212     //
       
   213     if  ( aStatus )
       
   214         {
       
   215         if ( aHeapCategorySelected )
       
   216             {
       
   217             _LIT( KItemEnabled, "\t\tCustom" );
       
   218             aBuf.Append( KItemEnabled );            
       
   219             }
       
   220         else
       
   221             {
       
   222             _LIT( KItemEnabled, "\t\tAll user heaps" );
       
   223             aBuf.Append( KItemEnabled );   
       
   224             }
       
   225         }
       
   226     else
       
   227         {
       
   228         _LIT( KItemDisabled, "\t\tDisabled" );
       
   229         aBuf.Append( KItemDisabled );
       
   230         }
       
   231     }
       
   232 
       
   233 
       
   234 
       
   235 
       
   236 
       
   237 
       
   238 
       
   239 
       
   240 
       
   241 // --------------------------------------------------------------------------------------------
       
   242 
       
   243 CSWMTCategorySelectionCheckBoxSettingItem::CSWMTCategorySelectionCheckBoxSettingItem( TInt aIdentifier, TInt& aCategories ): 
       
   244     CAknSettingItem(aIdentifier), iExtCategories( aCategories ) 
       
   245     {
       
   246     }   
       
   247 
       
   248 
       
   249 CSWMTCategorySelectionCheckBoxSettingItem::~CSWMTCategorySelectionCheckBoxSettingItem()
       
   250     {
       
   251     delete iSettingText;
       
   252     if( iItemArray )
       
   253         {
       
   254         iItemArray->ResetAndDestroy();
       
   255         delete iItemArray;
       
   256         }
       
   257     }
       
   258 
       
   259 
       
   260 CSelectionItemList* CSWMTCategorySelectionCheckBoxSettingItem::ItemArray() const
       
   261     {
       
   262     return iItemArray;
       
   263     }
       
   264 
       
   265 
       
   266 void CSWMTCategorySelectionCheckBoxSettingItem::AddNewItemToArrayL(const TDesC& aLabel)
       
   267     {
       
   268     TBuf<64> buf;
       
   269     buf.Copy( aLabel );    
       
   270     CSelectableItem* item = new (ELeave) CSelectableItem( buf, EFalse );
       
   271     CleanupStack::PushL( item );
       
   272     item->ConstructL();
       
   273     iItemArray->AppendL( item ); // Ownership is transferred
       
   274     CleanupStack::Pop(); // item    
       
   275     }
       
   276     
       
   277 
       
   278 void CSWMTCategorySelectionCheckBoxSettingItem::CompleteConstructionL()
       
   279     {
       
   280     SetEmptyItemTextL(_L("Nothing selected"));
       
   281     iItemArray = new(ELeave) CSelectionItemList(16);
       
   282     AddNewItemToArrayL( _L("User Heap") );       // 0
       
   283     AddNewItemToArrayL( _L("Kernel Heap") );     // 1
       
   284     AddNewItemToArrayL( _L("User Stacks") );     // 2
       
   285     AddNewItemToArrayL( _L("Global Data") );     // 3
       
   286     AddNewItemToArrayL( _L("Disk Usage") );      // 4
       
   287     AddNewItemToArrayL( _L("Open Files") );      // 5
       
   288     AddNewItemToArrayL( _L("RAM-loaded Code") ); // 6
       
   289     AddNewItemToArrayL( _L("System Memory") );   // 7
       
   290     AddNewItemToArrayL( _L("Local Chunks") );    // 8
       
   291     AddNewItemToArrayL( _L("Global Chunks") );   // 9
       
   292     AddNewItemToArrayL( _L("RAM Drive") );       // 10
       
   293     AddNewItemToArrayL( _L("FileServer Cache") );// 11
       
   294     AddNewItemToArrayL( _L("Kernel Handles") );  // 12
       
   295     AddNewItemToArrayL( _L("Bitmap Handles") );  // 13
       
   296     AddNewItemToArrayL( _L("Window Groups") );   // 14
       
   297     }
       
   298 
       
   299 
       
   300 void CSWMTCategorySelectionCheckBoxSettingItem::StoreL()
       
   301     {
       
   302     iExtCategories = 0;
       
   303     if ( iItemArray->At( 11 )->SelectionStatus() )
       
   304         iExtCategories |= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryFileServerCache; 
       
   305     if ( iItemArray->At( 13 )->SelectionStatus() )
       
   306         iExtCategories |= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryBitmapHandles; 
       
   307     if ( iItemArray->At( 0 )->SelectionStatus() )
       
   308         iExtCategories |= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryUserHeap; 
       
   309     if ( iItemArray->At( 1 )->SelectionStatus() )
       
   310         iExtCategories |= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryKernelHeap; 
       
   311     if ( iItemArray->At( 8 )->SelectionStatus() )
       
   312         iExtCategories |= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryLocalChunks; 
       
   313     if ( iItemArray->At( 9 )->SelectionStatus() )
       
   314         iExtCategories |= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryGlobalChunks; 
       
   315     if ( iItemArray->At( 10 )->SelectionStatus() )
       
   316         iExtCategories |= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryRAMDrive; 
       
   317     if ( iItemArray->At( 2 )->SelectionStatus() )
       
   318         iExtCategories |= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryUserStacks; 
       
   319     if ( iItemArray->At( 3 )->SelectionStatus() )
       
   320         iExtCategories |= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryGlobalData; 
       
   321     if ( iItemArray->At( 6 )->SelectionStatus() )
       
   322         iExtCategories |= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryRAMLoadedCode; 
       
   323     if ( iItemArray->At( 12 )->SelectionStatus() )
       
   324         iExtCategories |= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryKernelHandles; 
       
   325     if ( iItemArray->At( 5 )->SelectionStatus() )
       
   326         iExtCategories |= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryOpenFiles; 
       
   327     if ( iItemArray->At( 4 )->SelectionStatus() )
       
   328         iExtCategories |= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryDiskusage; 
       
   329     if ( iItemArray->At( 7 )->SelectionStatus() )
       
   330         iExtCategories |= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategorySystemMemory; 
       
   331     if ( iItemArray->At( 14 )->SelectionStatus() )
       
   332         iExtCategories |= TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryWindowGroups; 
       
   333     }
       
   334 
       
   335 
       
   336 void CSWMTCategorySelectionCheckBoxSettingItem::LoadL()
       
   337     {
       
   338     iItemArray->At( 11 )->SetSelectionStatus( iExtCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryFileServerCache );
       
   339     iItemArray->At( 13 )->SetSelectionStatus( iExtCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryBitmapHandles );
       
   340     iItemArray->At( 0 )->SetSelectionStatus( iExtCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryUserHeap );
       
   341     iItemArray->At( 1 )->SetSelectionStatus( iExtCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryKernelHeap );
       
   342     iItemArray->At( 8 )->SetSelectionStatus( iExtCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryLocalChunks );
       
   343     iItemArray->At( 9 )->SetSelectionStatus( iExtCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryGlobalChunks );
       
   344     iItemArray->At( 10 )->SetSelectionStatus( iExtCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryRAMDrive );
       
   345     iItemArray->At( 2 )->SetSelectionStatus( iExtCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryUserStacks );
       
   346     iItemArray->At( 3 )->SetSelectionStatus( iExtCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryGlobalData );
       
   347     iItemArray->At( 6 )->SetSelectionStatus( iExtCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryRAMLoadedCode );
       
   348     iItemArray->At( 12 )->SetSelectionStatus( iExtCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryKernelHandles );
       
   349     iItemArray->At( 5 )->SetSelectionStatus( iExtCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryOpenFiles );
       
   350     iItemArray->At( 4 )->SetSelectionStatus( iExtCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryDiskusage );
       
   351     iItemArray->At( 7 )->SetSelectionStatus( iExtCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategorySystemMemory );
       
   352     iItemArray->At( 14 )->SetSelectionStatus( iExtCategories & TMemSpyEngineHelperSysMemTrackerConfig::EMemSpyEngineSysMemTrackerCategoryWindowGroups );
       
   353     }
       
   354 
       
   355 
       
   356 void CSWMTCategorySelectionCheckBoxSettingItem::HandleSettingPageEventL( CAknSettingPage* aSettingPage, TAknSettingPageEvent aEventType )
       
   357     {
       
   358     switch( aEventType )
       
   359         {
       
   360         case EEventSettingOked:
       
   361             {
       
   362             // If settings oked, save new values
       
   363             StoreL();
       
   364             break;
       
   365             }
       
   366         case EEventSettingCancelled:
       
   367             {
       
   368             // If setting is cancelled, load old values
       
   369             LoadL();
       
   370             break;
       
   371             }
       
   372         case EEventSettingChanged:
       
   373             {
       
   374             // If setting has changed, update CBA visibility
       
   375             static_cast<CMemSpySWMTCategorySelectionCheckBoxSettingPage*>( aSettingPage )->UpdateCba();
       
   376             break;
       
   377             }
       
   378         default:
       
   379             {
       
   380             break;
       
   381             }
       
   382         }
       
   383     CAknSettingItem::HandleSettingPageEventL( aSettingPage, aEventType );
       
   384     }
       
   385 
       
   386 
       
   387 CMemSpySWMTCategorySelectionCheckBoxSettingPage::CMemSpySWMTCategorySelectionCheckBoxSettingPage(TInt aResourceID, CSelectionItemList* aItemArray )
       
   388     : CAknCheckBoxSettingPage( aResourceID, aItemArray )
       
   389     {
       
   390     }
       
   391 
       
   392 
       
   393 void CMemSpySWMTCategorySelectionCheckBoxSettingPage::UpdateCba()
       
   394     {
       
   395     // Cache the pointer to button group container
       
   396     CEikButtonGroupContainer* cba = Cba();
       
   397     // Left softkey should be visible if there are items selected,
       
   398     // i.e. the selection index array has items.
       
   399     TBool visible( ListBoxControl()->View()->SelectionIndexes()->Count() > 0 );
       
   400     // Resolve left softkey command id
       
   401     TInt leftId( cba->ButtonGroup()->CommandId( 0 ) );
       
   402     // Check if left softkey visibility has changed
       
   403     if( visible != cba->IsCommandVisible( leftId ) )
       
   404         {
       
   405         // Left softkey visibility has changed, update it
       
   406         cba->MakeCommandVisible( leftId, visible );
       
   407         }
       
   408     }
       
   409 
       
   410 
       
   411 
       
   412 
       
   413 CMemSpyAllowEmptyDataDialog::CMemSpyAllowEmptyDataDialog( TDes& aText, const TTone& aTone )
       
   414     : CAknTextQueryDialog( aText, aTone )
       
   415     {
       
   416     }
       
   417  
       
   418 
       
   419 void CMemSpyAllowEmptyDataDialog::UpdateLeftSoftKeyL()
       
   420     {
       
   421     MakeLeftSoftkeyVisible( ETrue );
       
   422     }