memspyui/ui/avkon/src/MemSpyViewThreads.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 "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 #include <memspysession.h>
       
    33 
       
    34 // User includes
       
    35 #include "MemSpyContainerObserver.h"
       
    36 #include "MemSpyViewProcesses.h"
       
    37 #include "MemSpyViewThreadInfoItemList.h"
       
    38 
       
    39 
       
    40 
       
    41 CMemSpyViewThreads::CMemSpyViewThreads( RMemSpySession& aSession, MMemSpyViewObserver& aObserver, TProcessId aId, TThreadId aThreadId )
       
    42 :   CMemSpyViewBase( aSession, aObserver ), iParentProcessId( aId ), iCurrentThreadId( aThreadId )
       
    43     {    
       
    44     }
       
    45 
       
    46 
       
    47 CMemSpyViewThreads::~CMemSpyViewThreads()
       
    48     {
       
    49     }
       
    50 
       
    51  
       
    52 void CMemSpyViewThreads::ConstructL( const TRect& aRect, CCoeControl& aContainer, TAny* aSelectionRune )
       
    53     {
       
    54 	iMemSpySession.GetThreadsL( iParentProcessId, iThreads );
       
    55 	
       
    56     _LIT( KTitle, "Threads" );
       
    57     SetTitleL( KTitle );
       
    58     //
       
    59     CMemSpyViewBase::ConstructL( aRect, aContainer, aSelectionRune );
       
    60     //    
       
    61     if( iCurrentThreadId > 0 )
       
    62         {		
       
    63 		for( TInt i = 0; i < iThreads.Count() ; i++ )
       
    64 			{
       
    65 			if( iThreads[i]->Id() == iCurrentThreadId )
       
    66 				{
       
    67 				const TInt index = i;
       
    68 				if  ( index >= 0 && index < iListBox->Model()->NumberOfItems() )
       
    69 					{
       
    70 					iListBox->SetCurrentItemIndex( index );
       
    71 					HandleListBoxItemSelectedL( index );
       
    72 					}
       
    73 				}			
       
    74 			}
       
    75         }
       
    76     else if( iThreads.Count() > 0 )
       
    77     	{
       
    78 		iListBox->SetCurrentItemIndex( 0 );
       
    79 		HandleListBoxItemSelectedL( 0 );
       
    80     	}		
       
    81     }
       
    82 
       
    83 
       
    84 TProcessId CMemSpyViewThreads::Process() const
       
    85     {
       
    86 	return iParentProcessId;
       
    87     }
       
    88 
       
    89 
       
    90 TThreadId CMemSpyViewThreads::CurrentThread()
       
    91     { 
       
    92 	return iCurrentThreadId;
       
    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( iMemSpySession, iObserver, iParentProcessId );
       
   112     CleanupStack::PushL( parent );
       
   113     //parent->ConstructL( Rect(), *Parent(), &iParentProcessId );
       
   114     parent->ConstructL( Rect(), *Parent() );
       
   115     CleanupStack::Pop( parent );
       
   116     return parent;
       
   117     }
       
   118 
       
   119 
       
   120 CMemSpyViewBase* CMemSpyViewThreads::PrepareChildViewL()
       
   121     {	
       
   122     CMemSpyViewThreadInfoItemList* child = new(ELeave) CMemSpyViewThreadInfoItemList( iMemSpySession, iObserver, iParentProcessId, iCurrentThreadId );
       
   123     CleanupStack::PushL( child );
       
   124     child->ConstructL( Rect(), *Parent(), EMemSpyThreadInfoItemTypeFirst );
       
   125     CleanupStack::Pop( child );
       
   126     return child;    
       
   127     }
       
   128 
       
   129 
       
   130 void CMemSpyViewThreads::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
       
   131     {
       
   132     if  ( aResourceId == R_MEMSPY_MENUPANE )
       
   133         {
       
   134 		/*
       
   135         CMemSpyThread& thread = CurrentThread();
       
   136         aMenuPane->SetItemDimmed( EMemSpyCmdThread, thread.IsDead() );
       
   137         */
       
   138 		aMenuPane->SetItemDimmed( EMemSpyCmdThread, (iThreads[iListBox->CurrentItemIndex()]->ExitType() !=  EExitPending ));
       
   139         }
       
   140     }
       
   141 
       
   142 
       
   143 TBool CMemSpyViewThreads::HandleCommandL( TInt aCommand )
       
   144     {
       
   145     TBool handled = ETrue;
       
   146     //
       
   147     switch ( aCommand )
       
   148         {
       
   149     case EMemSpyCmdThreadEndKill:
       
   150         OnCmdEndKillL();
       
   151 		break;
       
   152     case EMemSpyCmdThreadEndTerminate:
       
   153         OnCmdEndTerminateL();
       
   154 		break;
       
   155     case EMemSpyCmdThreadEndPanic:
       
   156         OnCmdEndPanicL();
       
   157 		break;
       
   158 	case EMemSpyCmdThreadSetPriorityAbsoluteVeryLow:
       
   159 	case EMemSpyCmdThreadSetPriorityAbsoluteLowNormal:
       
   160 	case EMemSpyCmdThreadSetPriorityAbsoluteLow:
       
   161 	case EMemSpyCmdThreadSetPriorityAbsoluteBackgroundNormal:
       
   162 	case EMemSpyCmdThreadSetPriorityAbsoluteBackground:
       
   163 	case EMemSpyCmdThreadSetPriorityAbsoluteForegroundNormal:
       
   164 	case EMemSpyCmdThreadSetPriorityAbsoluteForeground:
       
   165 	case EMemSpyCmdThreadSetPriorityAbsoluteHighNormal:
       
   166 	case EMemSpyCmdThreadSetPriorityAbsoluteHigh:
       
   167 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime1:
       
   168 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime2:
       
   169 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime3:
       
   170 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime4:
       
   171 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime5:
       
   172 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime6:
       
   173 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime7: 
       
   174 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime8:
       
   175         OnCmdSetPriorityL( aCommand );
       
   176         break;
       
   177 
       
   178     case EMemSpyCmdThreadInfoHandles:
       
   179         OnCmdInfoHandlesL();
       
   180         break;
       
   181 
       
   182     default:
       
   183         handled = CMemSpyViewBase::HandleCommandL( aCommand );
       
   184         break;
       
   185         }
       
   186     //
       
   187     return handled;
       
   188     }
       
   189 
       
   190 
       
   191 void CMemSpyViewThreads::OnCmdEndKillL()
       
   192     {
       
   193 	/*
       
   194     TBool doTerminate = ETrue;
       
   195     CMemSpyThread& thread = CurrentThread();
       
   196     //
       
   197     if  ( thread.IsSystemPermanent() )
       
   198         {
       
   199         CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   200         doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   201         }
       
   202     //
       
   203     if  ( doTerminate )
       
   204         {
       
   205         thread.KillL();
       
   206         RefreshL();
       
   207         }
       
   208     */
       
   209     }
       
   210 
       
   211 
       
   212 void CMemSpyViewThreads::OnCmdEndTerminateL()
       
   213     {
       
   214 	/*
       
   215     TBool doTerminate = ETrue;
       
   216     CMemSpyThread& thread = CurrentThread();
       
   217     //
       
   218     if  ( thread.IsSystemPermanent() || thread.IsSystemCritical() )
       
   219         {
       
   220         CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   221         doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   222         }
       
   223     //
       
   224     if  ( doTerminate )
       
   225         {
       
   226         thread.TerminateL();
       
   227         RefreshL();
       
   228         }
       
   229     */
       
   230     }
       
   231 
       
   232 
       
   233 void CMemSpyViewThreads::OnCmdEndPanicL()
       
   234     {
       
   235 	/*
       
   236     TBool doTerminate = ETrue;
       
   237     CMemSpyThread& thread = CurrentThread();
       
   238     //
       
   239     if  ( thread.IsSystemPermanent() || thread.IsSystemCritical() )
       
   240         {
       
   241         CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   242         doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   243         }
       
   244     //
       
   245     if  ( doTerminate )
       
   246         {
       
   247         thread.PanicL();
       
   248         RefreshL();
       
   249         }
       
   250         */
       
   251     }
       
   252 
       
   253 
       
   254 void CMemSpyViewThreads::OnCmdSetPriorityL( TInt aCommand )
       
   255     {
       
   256 	/*
       
   257     TThreadPriority pri = EPriorityAbsoluteBackground;
       
   258     switch( aCommand )
       
   259         {
       
   260 	case EMemSpyCmdThreadSetPriorityAbsoluteVeryLow:
       
   261         pri = EPriorityAbsoluteVeryLow;
       
   262         break;
       
   263 	case EMemSpyCmdThreadSetPriorityAbsoluteLowNormal:
       
   264         pri = EPriorityAbsoluteLowNormal;
       
   265         break;
       
   266 	case EMemSpyCmdThreadSetPriorityAbsoluteLow:
       
   267         pri = EPriorityAbsoluteLow;
       
   268         break;
       
   269 	case EMemSpyCmdThreadSetPriorityAbsoluteBackgroundNormal:
       
   270         pri = EPriorityAbsoluteBackgroundNormal;
       
   271         break;
       
   272 	case EMemSpyCmdThreadSetPriorityAbsoluteBackground:
       
   273         pri = EPriorityAbsoluteBackground;
       
   274         break;
       
   275 	case EMemSpyCmdThreadSetPriorityAbsoluteForegroundNormal:
       
   276         pri = EPriorityAbsoluteForegroundNormal;
       
   277         break;
       
   278 	case EMemSpyCmdThreadSetPriorityAbsoluteForeground:
       
   279         pri = EPriorityAbsoluteForeground;
       
   280         break;
       
   281 	case EMemSpyCmdThreadSetPriorityAbsoluteHighNormal:
       
   282         pri = EPriorityAbsoluteHighNormal;
       
   283         break;
       
   284 	case EMemSpyCmdThreadSetPriorityAbsoluteHigh:
       
   285         pri = EPriorityAbsoluteHigh;
       
   286         break;
       
   287 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime1:
       
   288         pri = EPriorityAbsoluteRealTime1;
       
   289         break;
       
   290 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime2:
       
   291         pri = EPriorityAbsoluteRealTime2;
       
   292         break;
       
   293 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime3:
       
   294         pri = EPriorityAbsoluteRealTime3;
       
   295         break;
       
   296 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime4:
       
   297         pri = EPriorityAbsoluteRealTime4;
       
   298         break;
       
   299 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime5:
       
   300         pri = EPriorityAbsoluteRealTime5;
       
   301         break;
       
   302 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime6:
       
   303         pri = EPriorityAbsoluteRealTime6;
       
   304         break;
       
   305 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime7: 
       
   306         pri = EPriorityAbsoluteRealTime7;
       
   307         break;
       
   308 	case EMemSpyCmdThreadSetPriorityAbsoluteRealTime8:
       
   309         pri = EPriorityAbsoluteRealTime8;
       
   310         break;
       
   311         }
       
   312 
       
   313 #ifdef _DEBUG
       
   314     RDebug::Printf( "CMemSpyViewThreads::OnCmdSetPriorityL() - pri: %d", pri );
       
   315 #endif
       
   316 
       
   317     CMemSpyThread& thread = CurrentThread();
       
   318     thread.SetPriorityL( pri );
       
   319     RefreshL();
       
   320 
       
   321 #ifdef _DEBUG
       
   322     RDebug::Printf( "CMemSpyViewThreads::OnCmdSetPriorityL() - END" );
       
   323 #endif
       
   324 	*/
       
   325     }
       
   326 
       
   327 
       
   328 void CMemSpyViewThreads::OnCmdInfoHandlesL()
       
   329     {
       
   330 	iMemSpySession.OutputThreadInfoHandlesL( iCurrentThreadId );	
       
   331     }
       
   332 
       
   333 
       
   334 void CMemSpyViewThreads::SetListBoxModelL()
       
   335     {
       
   336 	//iMemSpySession.GetThreadsL( iParentProcessId, iThreads );
       
   337 	
       
   338 	iModel = new (ELeave) CDesC16ArrayFlat( iThreads.Count() ); //array for formated items
       
   339 		
       
   340 	_LIT( KTab, "\t" );	
       
   341 		
       
   342 		
       
   343 		for( TInt i=0; i < iThreads.Count(); i++ )
       
   344 			{
       
   345 			HBufC* tempName = HBufC::NewL( iThreads[i]->Name().Length() + 16 );
       
   346 	    	CleanupStack::PushL( tempName );
       
   347 	    	TPtr tempNamePtr( tempName->Des() );
       
   348 	    	tempNamePtr.Copy( KTab );
       
   349 	    	tempNamePtr.Append( iThreads[i]->Name() );
       
   350 	    	iModel->AppendL( tempNamePtr );
       
   351 	    	
       
   352 	    	CleanupStack::PopAndDestroy( tempName ); 
       
   353 			}			
       
   354 	
       
   355     CAknSettingStyleListBox* listbox = static_cast< CAknSettingStyleListBox* >( iListBox );    
       
   356     listbox->Model()->SetItemTextArray( iModel );
       
   357     listbox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   358     }
       
   359 
       
   360 
       
   361 void CMemSpyViewThreads::HandleListBoxItemActionedL( TInt /*aIndex*/ )
       
   362     {
       
   363     // Notify observer about an item being 'fired'
       
   364     ReportEventL( MMemSpyViewObserver::EEventItemActioned );
       
   365     }
       
   366 
       
   367 
       
   368 void CMemSpyViewThreads::HandleListBoxItemSelectedL( TInt aIndex )
       
   369 	{	
       
   370 	iCurrentThreadId = iThreads[ aIndex ]->Id();
       
   371 	
       
   372     // Notify observer about item selection
       
   373     ReportEventL( MMemSpyViewObserver::EEventItemSelected );
       
   374     }
       
   375 
       
   376 
       
   377