memspyui/ui/avkon/src/MemSpyViewThreadInfoItemList.cpp
branchRCL_3
changeset 22 fad26422216a
parent 21 b3cee849fa46
child 23 f8280f3bfeb7
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 "MemSpyViewThreadInfoItemList.h"
       
    19 
       
    20 // Engine includes
       
    21 #include <memspy/engine/memspyengine.h>
       
    22 #include <memspy/engine/memspyengineobjectprocess.h>
       
    23 #include <memspy/engine/memspyengineobjectthread.h>
       
    24 #include <memspy/engine/memspyengineobjectcontainer.h>
       
    25 #include <memspy/engine/memspyengineobjectthreadinfoobjects.h>
       
    26 #include <memspy/engine/memspyengineobjectthreadinfocontainer.h>
       
    27 #include <memspy/engine/memspyenginehelperprocess.h>
       
    28 #include <memspysession.h>
       
    29 
       
    30 // UI Utils include
       
    31 #include "MemSpyUiUtils.h"
       
    32 
       
    33 // User includes
       
    34 #include "MemSpyContainerObserver.h"
       
    35 #include "MemSpyViewThreads.h"
       
    36 #include "MemSpyViewThreadInfoItemHeap.h"
       
    37 #include "MemSpyViewThreadInfoItemStack.h"
       
    38 #include "MemSpyViewThreadInfoItemChunk.h"
       
    39 #include "MemSpyViewThreadInfoItemCodeSeg.h"
       
    40 #include "MemSpyViewThreadInfoItemServer.h"
       
    41 #include "MemSpyViewThreadInfoItemActiveObject.h"
       
    42 #include "MemSpyViewThreadInfoItemGeneralInfo.h"
       
    43 #include "MemSpyViewThreadInfoItemMemoryTracking.h"
       
    44 
       
    45 // Constants
       
    46 const TInt KMemSpyIdleResetListboxTimerPeriod = 250000;
       
    47 
       
    48 
       
    49 CMemSpyViewThreadInfoItemList::CMemSpyViewThreadInfoItemList( RMemSpySession& aSession, MMemSpyViewObserver& aObserver, TProcessId aProcess, TThreadId aThread )
       
    50 :   CMemSpyViewBase( aSession, aObserver ), iParentProcessId( aProcess ), iThreadId( aThread )
       
    51     {
       
    52     }
       
    53 
       
    54 
       
    55 CMemSpyViewThreadInfoItemList::~CMemSpyViewThreadInfoItemList()
       
    56     {
       
    57 	/* TODO:
       
    58     TRAP_IGNORE( 
       
    59         CMemSpyThreadInfoContainer& container = iThread.InfoContainerL();
       
    60         container.ObserverRemove( *this );
       
    61     );
       
    62 	*/
       
    63     }
       
    64 
       
    65 
       
    66 
       
    67 void CMemSpyViewThreadInfoItemList::ConstructL( const TRect& aRect, CCoeControl& aContainer, TMemSpyThreadInfoItemType aType )
       
    68     {
       
    69     _LIT( KTitle, "Thread Objects" );
       
    70     SetTitleL( KTitle );
       
    71     //
       
    72     //iIdleResetListboxTimer = CPeriodic::NewL( CActive::EPriorityIdle );    
       
    73     /* TODO: to solve observer
       
    74     CMemSpyThreadInfoContainer& container = iThread.InfoContainerL();
       
    75     container.ObserverAddL( *this );
       
    76     */    
       
    77     CMemSpyViewBase::ConstructL( aRect, aContainer );
       
    78     //
       
    79     if( aType > EMemSpyThreadInfoItemTypeFirst || aType < EMemSpyThreadInfoItemTypeLast )
       
    80     	{
       
    81 		TInt index(aType);
       
    82 		if  ( index >= 0 && index < iListBox->Model()->NumberOfItems() )
       
    83 			{
       
    84 			iListBox->SetCurrentItemIndex( index );
       
    85 			HandleListBoxItemSelectedL( index );
       
    86 			}
       
    87     	}
       
    88     else
       
    89     	{
       
    90 		iListBox->SetCurrentItemIndex( 0 );
       
    91         HandleListBoxItemSelectedL( 0 );
       
    92     	}
       
    93     /*if  ( aSelectionRune )
       
    94         {		
       
    95         CMemSpyThreadInfoItemBase* selectedItem = reinterpret_cast< CMemSpyThreadInfoItemBase* >( aSelectionRune );
       
    96         const TInt index = container.InfoItemIndexByType( selectedItem->Type() );
       
    97         if  ( index >= 0 && index < iListBox->Model()->NumberOfItems() )
       
    98             {
       
    99             iListBox->SetCurrentItemIndex( index );
       
   100             HandleListBoxItemSelectedL( index );
       
   101             }
       
   102         }
       
   103     else if ( container.MdcaCount() > 0 )
       
   104         {*/
       
   105         //iListBox->SetCurrentItemIndex( 0 );
       
   106         //HandleListBoxItemSelectedL( 0 );
       
   107         //}
       
   108     }
       
   109 
       
   110 const CMemSpyThreadInfoItemBase& CMemSpyViewThreadInfoItemList::CurrentInfoItem() const
       
   111     {
       
   112     //__ASSERT_ALWAYS( iCurrentInfoItem != NULL, User::Invariant() );
       
   113     return *iCurrentInfoItem;
       
   114     }
       
   115 
       
   116 void CMemSpyViewThreadInfoItemList::RefreshL()
       
   117     {
       
   118     SetListBoxModelL();
       
   119     CMemSpyViewBase::RefreshL();
       
   120     }
       
   121 
       
   122 
       
   123 TMemSpyViewType CMemSpyViewThreadInfoItemList::ViewType() const
       
   124     {
       
   125     return EMemSpyViewTypeThreadInfoItemList;
       
   126     }
       
   127 
       
   128 
       
   129 CMemSpyViewBase* CMemSpyViewThreadInfoItemList::PrepareParentViewL()
       
   130     {
       
   131     CMemSpyViewBase* parent = new(ELeave) CMemSpyViewThreads( iMemSpySession, iObserver, iParentProcessId, iThreadId );
       
   132     CleanupStack::PushL( parent );
       
   133     parent->ConstructL( Rect(), *Parent() );
       
   134     CleanupStack::Pop( parent );
       
   135     return parent;
       
   136     }
       
   137 
       
   138 
       
   139 CMemSpyViewBase* CMemSpyViewThreadInfoItemList::PrepareChildViewL()
       
   140     {
       
   141     CMemSpyViewBase* child = NULL;
       
   142 
       
   143     TMemSpyThreadInfoItemType type;
       
   144     iMemSpySession.GetInfoItemType( iCurrentInfoItemId, iThreadId, type );
       
   145     
       
   146     switch( type )
       
   147         {    	
       
   148     case EMemSpyThreadInfoItemTypeHeap:
       
   149         child = new(ELeave) CMemSpyViewThreadInfoItemHeap( iMemSpySession, iObserver, iParentProcessId, iThreadId, type );
       
   150         break;        
       
   151     case EMemSpyThreadInfoItemTypeStack:
       
   152         child = new(ELeave) CMemSpyViewThreadInfoItemStack( iMemSpySession, iObserver, iParentProcessId, iThreadId, type );
       
   153         break;        
       
   154     case EMemSpyThreadInfoItemTypeChunk:
       
   155         child = new(ELeave) CMemSpyViewThreadInfoItemChunk( iMemSpySession, iObserver, iParentProcessId, iThreadId, type  );
       
   156         break;
       
   157     case EMemSpyThreadInfoItemTypeCodeSeg:
       
   158         child = new(ELeave) CMemSpyViewThreadInfoItemCodeSeg( iMemSpySession, iObserver, iParentProcessId, iThreadId, type  );
       
   159         break;        
       
   160     case EMemSpyThreadInfoItemTypeServer:
       
   161         child = new(ELeave) CMemSpyViewThreadInfoItemServer( iMemSpySession, iObserver, iParentProcessId, iThreadId, type  );
       
   162         break;        
       
   163     case EMemSpyThreadInfoItemTypeActiveObject:
       
   164         child = new(ELeave) CMemSpyViewThreadInfoItemActiveObject( iMemSpySession, iObserver, iParentProcessId, iThreadId, type  );
       
   165         break;             
       
   166     case EMemSpyThreadInfoItemTypeGeneralInfo:
       
   167         child = new(ELeave) CMemSpyViewThreadInfoItemGeneralInfo( iMemSpySession, iObserver, iParentProcessId, iThreadId, type );
       
   168         break;
       
   169     /* 
       
   170      * This subview is permanently removed from Thread Info Item subview.
       
   171      * 
       
   172     case EMemSpyThreadInfoItemTypeMemoryTracking:
       
   173         child = new(ELeave) CMemSpyViewThreadInfoItemMemoryTracking( iEngine, iObserver, iThread.InfoContainerL() );
       
   174         break;
       
   175     */
       
   176     case EMemSpyThreadInfoItemTypeSession:
       
   177     case EMemSpyThreadInfoItemTypeSemaphore:
       
   178     case EMemSpyThreadInfoItemTypeMutex:
       
   179     case EMemSpyThreadInfoItemTypeTimer:
       
   180     case EMemSpyThreadInfoItemTypeLDD:
       
   181     case EMemSpyThreadInfoItemTypePDD:
       
   182     case EMemSpyThreadInfoItemTypeLogicalChannel:
       
   183     case EMemSpyThreadInfoItemTypeChangeNotifier:
       
   184     case EMemSpyThreadInfoItemTypeUndertaker:
       
   185     case EMemSpyThreadInfoItemTypeMessageQueue:
       
   186     case EMemSpyThreadInfoItemTypeConditionalVariable:
       
   187     case EMemSpyThreadInfoItemTypeOpenFiles:
       
   188     case EMemSpyThreadInfoItemTypeOtherThreads:
       
   189     case EMemSpyThreadInfoItemTypeOtherProcesses:
       
   190     case EMemSpyThreadInfoItemTypeOwnedThreadHandles:
       
   191     case EMemSpyThreadInfoItemTypeOwnedProcessHandles:
       
   192         child = new(ELeave) CMemSpyViewThreadInfoItemGeneric( iMemSpySession, iObserver, iParentProcessId, iThreadId, type );
       
   193         break;
       
   194     
       
   195     default:
       
   196        // __ASSERT_ALWAYS( EFalse, User::Panic( _L("MemSpy-View"), 0) );
       
   197         break;        
       
   198         }
       
   199        
       
   200     CleanupStack::PushL( child );
       
   201     child->ConstructL( Rect(), *Parent() );
       
   202     CleanupStack::Pop( child );
       
   203     return child;
       
   204     }
       
   205 
       
   206 
       
   207 TBool CMemSpyViewThreadInfoItemList::HandleCommandL( TInt aCommand )
       
   208     {
       
   209     TBool handled = ETrue;
       
   210     //
       
   211     switch ( aCommand )
       
   212         {
       
   213 	case EMemSpyCmdThreadInfoHandles:
       
   214         OnCmdInfoHandlesL();
       
   215         break;
       
   216 
       
   217     default:
       
   218         handled = CMemSpyViewBase::HandleCommandL( aCommand );
       
   219         break;
       
   220         }
       
   221     //
       
   222     return handled;
       
   223     }
       
   224 
       
   225     
       
   226 void CMemSpyViewThreadInfoItemList::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
       
   227     {
       
   228     if  ( aResourceId == R_MEMSPY_MENUPANE )
       
   229         {
       
   230      //   aMenuPane->SetItemDimmed( EMemSpyCmdThread, iThread.IsDead() ); //TODO
       
   231         }
       
   232     else if ( aResourceId == MenuCascadeResourceId() )
       
   233         {
       
   234         // Always remove these items - they are only shown in the master thread view
       
   235         aMenuPane->SetItemDimmed( EMemSpyCmdThreadSetPriority, ETrue );
       
   236         aMenuPane->SetItemDimmed( EMemSpyCmdThreadEnd, ETrue );
       
   237         }
       
   238     }
       
   239 
       
   240 
       
   241 void CMemSpyViewThreadInfoItemList::OnCmdInfoHandlesL()
       
   242     {
       
   243     iMemSpySession.OutputThreadInfoHandlesL( iThreadId );
       
   244     }
       
   245 
       
   246 
       
   247 void CMemSpyViewThreadInfoItemList::HandleMemSpyEngineInfoContainerEventL( TEvent aEvent, TMemSpyThreadInfoItemType aType )
       
   248     {/*
       
   249     if  ( aEvent == EInfoItemChanged )
       
   250         {
       
   251         }
       
   252     else if ( aEvent == EInfoItemDestroyed )
       
   253         {
       
   254         if  ( iCurrentInfoItem && iCurrentInfoItem->Type() == aType )
       
   255             {
       
   256             iCurrentInfoItem->Close();
       
   257             iCurrentInfoItem = NULL;
       
   258             }
       
   259         }
       
   260 
       
   261     iIdleResetListboxTimer->Cancel();
       
   262     iIdleResetListboxTimer->Start( KMemSpyIdleResetListboxTimerPeriod, KMemSpyIdleResetListboxTimerPeriod, TCallBack( IdleUpdateListBoxModel, this ) );
       
   263     */
       
   264     }
       
   265 
       
   266 
       
   267 void CMemSpyViewThreadInfoItemList::SetListBoxModelL()
       
   268     {	
       
   269 	CDesC16ArrayFlat* iModel = new (ELeave) CDesC16ArrayFlat( 32 );
       
   270 	
       
   271 	HBufC* iItem = HBufC::NewL( 32 );
       
   272 	
       
   273 	iItem = MemSpyUiUtils::FormatItem( KGeneral );
       
   274 	TPtr pItem( iItem->Des() );
       
   275 	iModel->AppendL( pItem );
       
   276 	pItem.Zero();
       
   277 	
       
   278 	iItem = MemSpyUiUtils::FormatItem( KHeap );
       
   279 	pItem = iItem->Des();
       
   280 	iModel->AppendL( pItem );
       
   281 	pItem.Zero();
       
   282 	
       
   283 	iItem = MemSpyUiUtils::FormatItem( KStack );
       
   284 	pItem = iItem->Des();
       
   285 	iModel->AppendL( pItem );
       
   286 	pItem.Zero();
       
   287 	
       
   288 	iItem = MemSpyUiUtils::FormatItem( KChunks );
       
   289 	pItem = iItem->Des();
       
   290 	iModel->AppendL( pItem );
       
   291 	pItem.Zero();
       
   292 	
       
   293 	iItem = MemSpyUiUtils::FormatItem( KCodeSegs );
       
   294 	pItem = iItem->Des();
       
   295 	iModel->AppendL( pItem );
       
   296 	pItem.Zero();
       
   297 	
       
   298 	iItem = MemSpyUiUtils::FormatItem( KOpenFiles );
       
   299 	pItem = iItem->Des();
       
   300 	iModel->AppendL( pItem );
       
   301 	pItem.Zero();
       
   302 	
       
   303 	iItem = MemSpyUiUtils::FormatItem( KActiveObjects );
       
   304 	pItem = iItem->Des();
       
   305 	iModel->AppendL( pItem );
       
   306 	pItem.Zero();
       
   307 	
       
   308 	iItem = MemSpyUiUtils::FormatItem( KThreadHandlers );
       
   309 	pItem = iItem->Des();
       
   310 	iModel->AppendL( pItem );
       
   311 	pItem.Zero();
       
   312 	
       
   313 	iItem = MemSpyUiUtils::FormatItem( KProcessHandlers );
       
   314 	pItem = iItem->Des();
       
   315 	iModel->AppendL( pItem );
       
   316 	pItem.Zero();
       
   317 	
       
   318 	iItem = MemSpyUiUtils::FormatItem( KServers );
       
   319 	pItem = iItem->Des();
       
   320 	iModel->AppendL( pItem );
       
   321 	pItem.Zero();
       
   322 	
       
   323 	iItem = MemSpyUiUtils::FormatItem( KConnections );
       
   324 	pItem = iItem->Des();
       
   325 	iModel->AppendL( pItem );
       
   326 	pItem.Zero();
       
   327 	
       
   328 	iItem = MemSpyUiUtils::FormatItem( KSemaphores );
       
   329 	pItem = iItem->Des();
       
   330 	iModel->AppendL( pItem );
       
   331 	pItem.Zero();
       
   332 	
       
   333 	iItem = MemSpyUiUtils::FormatItem( KThreadReferences );
       
   334 	pItem = iItem->Des();
       
   335 	iModel->AppendL( pItem );
       
   336 	pItem.Zero();
       
   337 	
       
   338 	iItem = MemSpyUiUtils::FormatItem( KProcessReferences );
       
   339 	pItem = iItem->Des();
       
   340 	iModel->AppendL( pItem );
       
   341 	pItem.Zero();
       
   342 	
       
   343 	iItem = MemSpyUiUtils::FormatItem( KMutexes );
       
   344 	pItem = iItem->Des();
       
   345 	iModel->AppendL( pItem );
       
   346 	pItem.Zero();
       
   347 	
       
   348 	iItem = MemSpyUiUtils::FormatItem( KTimers );
       
   349 	pItem = iItem->Des();
       
   350 	iModel->AppendL( pItem );
       
   351 	pItem.Zero();
       
   352 	
       
   353 	iItem = MemSpyUiUtils::FormatItem( KDD );
       
   354 	pItem = iItem->Des();
       
   355 	iModel->AppendL( pItem );
       
   356 	pItem.Zero();
       
   357 	
       
   358 	iItem = MemSpyUiUtils::FormatItem( KChangeNotif );
       
   359 	pItem = iItem->Des();
       
   360 	iModel->AppendL( pItem );
       
   361 	pItem.Zero();
       
   362 	
       
   363 	iItem = MemSpyUiUtils::FormatItem( KUndertakers );
       
   364 	pItem = iItem->Des();
       
   365 	iModel->AppendL( pItem );
       
   366 	pItem.Zero();
       
   367 	
       
   368 	iItem = MemSpyUiUtils::FormatItem( KLogicalDrivers );
       
   369 	pItem = iItem->Des();
       
   370 	iModel->AppendL( pItem );
       
   371 	pItem.Zero();
       
   372 	
       
   373 	iItem = MemSpyUiUtils::FormatItem( KPhysicalDrivers );
       
   374 	pItem = iItem->Des();
       
   375 	iModel->AppendL( pItem );
       
   376 	pItem.Zero();		
       
   377 	
       
   378     CAknSettingStyleListBox* listbox = static_cast< CAknSettingStyleListBox* >( iListBox ); 
       
   379     listbox->Model()->SetItemTextArray( iModel );
       
   380     listbox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   381     }
       
   382 
       
   383 
       
   384 void CMemSpyViewThreadInfoItemList::HandleListBoxItemActionedL( TInt /*aIndex*/ )
       
   385     {
       
   386     // Notify observer about an item being 'fired'
       
   387     ReportEventL( MMemSpyViewObserver::EEventItemActioned );
       
   388     }
       
   389 
       
   390 
       
   391 void CMemSpyViewThreadInfoItemList::HandleListBoxItemSelectedL( TInt aIndex )
       
   392     {
       
   393 	iCurrentInfoItemId = aIndex;
       
   394 	
       
   395     // Notify observer about item selection
       
   396     ReportEventL( MMemSpyViewObserver::EEventItemSelected );
       
   397     }
       
   398 
       
   399 
       
   400 TInt CMemSpyViewThreadInfoItemList::IdleUpdateListBoxModel( TAny* aSelf )
       
   401     {
       
   402     CMemSpyViewThreadInfoItemList* self = reinterpret_cast< CMemSpyViewThreadInfoItemList* >( aSelf );
       
   403     TRAP_IGNORE( self->DoIdleUpdateListBoxModelL() );
       
   404     return EFalse;
       
   405     }
       
   406 
       
   407 
       
   408 void CMemSpyViewThreadInfoItemList::DoIdleUpdateListBoxModelL()
       
   409     {
       
   410 	/*
       
   411     CMemSpyThreadInfoContainer& container = iThread.InfoContainerL();
       
   412 
       
   413     // Try to maintain current item selection if at all possible.
       
   414     TMemSpyThreadInfoItemType type = EMemSpyThreadInfoItemTypeHeap;
       
   415     if  ( iCurrentInfoItem )
       
   416         {
       
   417         type = iCurrentInfoItem->Type();
       
   418         }
       
   419    
       
   420     // Update list box & model
       
   421     SetListBoxModelL();
       
   422     iListBox->HandleItemAdditionL();
       
   423     RefreshL();
       
   424     
       
   425     // Try to select previous item if it is still available
       
   426     const TInt index = container.InfoItemIndexByType( type );
       
   427     if  ( index >= 0 && index < container.MdcaCount() )
       
   428         {
       
   429         iListBox->SetCurrentItemIndex( index );
       
   430         HandleListBoxItemSelectedL( index );
       
   431         }
       
   432 
       
   433     iIdleResetListboxTimer->Cancel();
       
   434     */
       
   435     }