perfapps/memspyui/ui/avkon/src/MemSpyViewKernelObjects.cpp
changeset 48 da3ec8478e66
child 53 819e59dfc032
equal deleted inserted replaced
47:11fa016241a4 48:da3ec8478e66
       
     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 "MemSpyViewKernelObjects.h"
       
    19 
       
    20 // System includes
       
    21 #include <eikspane.h>
       
    22 #include <aknnavide.h> 
       
    23 #include <akntabgrp.h>
       
    24 #include <eikclbd.h>
       
    25 #include <AknQueryDialog.h>
       
    26 #include <aknnotewrappers.h>
       
    27 #include <apgwgnam.h>
       
    28 #include <aknmessagequerydialog.h>
       
    29 
       
    30 // Engine includes
       
    31 #include <memspy/engine/memspyengine.h>
       
    32 #include <memspy/engine/memspyengineobjectprocess.h>
       
    33 #include <memspy/engine/memspyengineobjectthread.h>
       
    34 #include <memspy/engine/memspyengineobjectcontainer.h>
       
    35 #include <memspy/engine/memspyengineobjectthreadinfoobjects.h>
       
    36 #include <memspy/engine/memspyengineobjectthreadinfocontainer.h>
       
    37 #include <memspy/engine/memspyenginehelperkernelcontainers.h>
       
    38 #include <memspy/engine/memspyenginehelperserver.h>
       
    39 #include <memspy/engine/memspyenginehelpercondvar.h>
       
    40 
       
    41 #include <memspysession.h>
       
    42 
       
    43 // User includes
       
    44 #include "MemSpyUiUtils.h"
       
    45 #include "MemSpyViewKernel.h"
       
    46 #include "MemSpyContainerObserver.h"
       
    47 #include "MemSpyViewKernelContainers.h"
       
    48 
       
    49 const TInt KMaxInfoLength = 128;
       
    50 
       
    51 /*
       
    52 CMemSpyViewKernelObjects::CMemSpyViewKernelObjects( CMemSpyEngine& aEngine, MMemSpyViewObserver& aObserver, TMemSpyDriverContainerType aObjectType )
       
    53 :   CMemSpyViewBase( aEngine, aObserver ),
       
    54     iObjectType( aObjectType ),
       
    55     iCurrItemIndex( KErrNotFound )
       
    56     {
       
    57     }
       
    58 */
       
    59 CMemSpyViewKernelObjects::CMemSpyViewKernelObjects( RMemSpySession& aSession, MMemSpyViewObserver& aObserver, TMemSpyDriverContainerType aObjectType )
       
    60 :   CMemSpyViewBase( aSession, aObserver ),
       
    61     iObjectType( aObjectType ),
       
    62     iCurrItemIndex( KErrNotFound )
       
    63     {
       
    64     }
       
    65 
       
    66 
       
    67 CMemSpyViewKernelObjects::~CMemSpyViewKernelObjects()
       
    68     {
       
    69     if ( iNavContainer && iNavDecorator )
       
    70         {
       
    71         iNavContainer->Pop( iNavDecorator );
       
    72         delete iNavDecorator;
       
    73         }
       
    74     delete iModel;
       
    75     delete iItems;
       
    76     delete iObjectList;
       
    77     }
       
    78 
       
    79 
       
    80 void CMemSpyViewKernelObjects::ConstructL( const TRect& aRect, CCoeControl& aContainer, TAny* aSelectionRune )
       
    81     {
       
    82     _LIT( KTitle, "Kernel Objects" );
       
    83     SetTitleL( KTitle );
       
    84     iItems = new(ELeave) CDesCArrayFlat(5);
       
    85     //
       
    86     CMemSpyViewBase::ConstructL( aRect, aContainer, aSelectionRune );
       
    87     CreateTabsL();
       
    88     }
       
    89 
       
    90 
       
    91 CEikListBox* CMemSpyViewKernelObjects::ConstructListBoxL()
       
    92     {
       
    93     delete iListBox;
       
    94     iListBox = NULL;
       
    95     CAknSingleStyleListBox* listbox = new (ELeave) CAknSingleStyleListBox();
       
    96     iListBox = listbox;
       
    97     listbox->ConstructL( this, EAknListBoxSelectionList | EAknListBoxLoopScrolling );
       
    98     listbox->SetContainerWindowL( *this );
       
    99     listbox->CreateScrollBarFrameL( ETrue );
       
   100     SetListBoxModelL();
       
   101     listbox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   102     listbox->SetListBoxObserver( this );
       
   103     listbox->ItemDrawer()->ColumnData()->EnableMarqueeL(ETrue);
       
   104     listbox->SetObserver( this );
       
   105     return listbox;
       
   106     }
       
   107 
       
   108 
       
   109 void CMemSpyViewKernelObjects::RefreshL()
       
   110     {
       
   111     SetListBoxModelL();
       
   112     CMemSpyViewBase::RefreshL();
       
   113     }
       
   114 
       
   115 
       
   116 TMemSpyViewType CMemSpyViewKernelObjects::ViewType() const
       
   117     {
       
   118     return EMemSpyViewTypeKernelObjects;
       
   119     }
       
   120 
       
   121 
       
   122 CMemSpyViewBase* CMemSpyViewKernelObjects::PrepareParentViewL()
       
   123     {	
       
   124 	if ( iNaviPane && iNavDecorator )
       
   125 	   {
       
   126 		iNaviPane->Pop( iNavDecorator );
       
   127 		delete iNavDecorator;
       
   128 		iNavDecorator = NULL;
       
   129 	   }	
       
   130     //CMemSpyViewBase* parent = new(ELeave) CMemSpyViewKernelContainers( iEngine, iObserver );
       
   131     CMemSpyViewBase* parent = new(ELeave) CMemSpyViewKernelContainers( iMemSpySession, iObserver );
       
   132     CleanupStack::PushL( parent );
       
   133     parent->ConstructL( Rect(), *Parent(), (TAny*) ViewType() );
       
   134     CleanupStack::Pop( parent );
       
   135     return parent;
       
   136     }
       
   137 
       
   138 
       
   139 CMemSpyViewBase* CMemSpyViewKernelObjects::PrepareChildViewL()
       
   140     {
       
   141     CMemSpyViewBase* child = NULL;
       
   142     if ( iListBox && 
       
   143          iListBox->Model()->NumberOfItems() && 
       
   144          iListBox->CurrentItemIndex() > KErrNotFound )
       
   145         {
       
   146         DetailsL();
       
   147         }
       
   148     return child;
       
   149     }
       
   150 
       
   151 
       
   152 void CMemSpyViewKernelObjects::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
       
   153     {
       
   154     if  ( aResourceId == R_MEMSPY_MENUPANE )
       
   155        {
       
   156        if ( iObjectType > EMemSpyDriverContainerTypeProcess )
       
   157            {
       
   158            // Display Terminate, Switch to, End and Panic
       
   159            // commands only for Threads and processes
       
   160            aMenuPane->SetItemDimmed( EMemSpyCmdKernelObjects, ETrue );
       
   161            }
       
   162         }
       
   163     }
       
   164 
       
   165 
       
   166 void CMemSpyViewKernelObjects::SetListBoxModelL()
       
   167     {
       
   168     //_LIT( KLineFormatSpec, "\t%S" );
       
   169     _LIT( KTab, "\t" );
       
   170        
       
   171     iMemSpySession.GetKernelObjectItems( iKernelObjectItems, iObjectType );    
       
   172     
       
   173     iModel = new (ELeave) CDesC16ArrayFlat( iKernelObjectItems.Count() + 1 ); //array for formated items, +1 added there for 0 case - creating 0-sized array panics
       
   174         
       
   175     for ( TInt i = 0; i < iKernelObjectItems.Count(); i++ )
       
   176         {
       
   177         HBufC* tempName = HBufC::NewL( iKernelObjectItems[i]->Name().Length() + 16 );
       
   178         CleanupStack::PushL( tempName );
       
   179         TPtr tempNamePtr( tempName->Des() );
       
   180         tempNamePtr.Copy( KTab );
       
   181     	
       
   182         TBuf<KMaxName> temp;
       
   183         temp.Copy(iKernelObjectItems[i]->Name());    	
       
   184         tempNamePtr.Append( temp	 );
       
   185         iModel->AppendL( tempNamePtr );
       
   186             
       
   187         CleanupStack::PopAndDestroy( tempName ); 
       
   188         }
       
   189     
       
   190     CAknSettingStyleListBox* listbox = static_cast< CAknSettingStyleListBox* >( iListBox );
       
   191     listbox->Model()->SetItemTextArray( iModel );
       
   192     listbox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );       
       
   193     }
       
   194 
       
   195 
       
   196 TBool CMemSpyViewKernelObjects::HandleCommandL( TInt aCommand )
       
   197     {
       
   198     TBool handled = ETrue;
       
   199     //
       
   200     switch ( aCommand )
       
   201         {
       
   202         case EMemSpyCmdKernelObjectTerminate:
       
   203             {
       
   204             TRAPD( err, OnCmdTerminateL() );
       
   205             if ( err )
       
   206                 {
       
   207                 CAknConfirmationNote* note = new(ELeave) CAknConfirmationNote( ETrue );
       
   208                 note->ExecuteLD( _L("Cannot terminate task") );
       
   209                 }
       
   210             break;
       
   211             }
       
   212         case EMemSpyCmdKernelObjectSwitchTo:
       
   213             {
       
   214             TRAPD( err, OnCmdSwitchToL() );
       
   215             if ( err )
       
   216                 {
       
   217                 CAknConfirmationNote* note = new(ELeave) CAknConfirmationNote( ETrue );
       
   218                 note->ExecuteLD( _L("Cannot bring to foreground") );
       
   219                 }
       
   220             break;
       
   221             }
       
   222         case EMemSpyCmdKernelObjectEnd:
       
   223             {
       
   224             TRAPD( err, OnCmdEndL() );
       
   225             if ( err )
       
   226                 {
       
   227                 CAknConfirmationNote* note = new(ELeave) CAknConfirmationNote( ETrue );
       
   228                 note->ExecuteLD( _L("Cannot end task") );
       
   229                 }
       
   230             break;
       
   231             }
       
   232         case EMemSpyCmdKernelObjectPanic:
       
   233             {
       
   234             TRAPD( err, OnCmdPanicL() );
       
   235             if ( err )
       
   236                 {
       
   237                 CAknConfirmationNote* note = new(ELeave) CAknConfirmationNote( ETrue );
       
   238                 note->ExecuteLD( _L("Cannot panic task") );
       
   239                 }
       
   240             break;
       
   241             }
       
   242         default:
       
   243             {
       
   244             handled = CMemSpyViewBase::HandleCommandL( aCommand );
       
   245             break;        
       
   246             }
       
   247         }
       
   248     //
       
   249     return handled;
       
   250     }
       
   251 
       
   252 
       
   253 TKeyResponse CMemSpyViewKernelObjects::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   254     {	
       
   255     TKeyResponse resp = EKeyWasNotConsumed;
       
   256     resp = CMemSpyViewBase::OfferKeyEventL( aKeyEvent, aType );    
       
   257     //}
       
   258     return resp;
       
   259     }
       
   260 
       
   261 void CMemSpyViewKernelObjects::TabChangedL( TInt /*aIndex*/ )
       
   262     {
       
   263     }
       
   264 
       
   265 
       
   266 void CMemSpyViewKernelObjects::OnCmdTerminateL()
       
   267     {
       
   268     switch ( iObjectType )
       
   269         {
       
   270         case EMemSpyDriverContainerTypeThread:
       
   271             {
       
   272             TBool err = EFalse;
       
   273             TBool doTerminate = ETrue;
       
   274             
       
   275             TThreadId id( iKernelObjectItems[ iListBox->CurrentItemIndex() ]->Id() ); //get id of the current thread
       
   276                         
       
   277             iMemSpySession.ThreadSystemPermanentOrCritical( id, err );
       
   278             
       
   279             if( err )
       
   280             	{
       
   281 				CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   282 				doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   283 				
       
   284 				if ( doTerminate )
       
   285 					{
       
   286 					iMemSpySession.EndThreadL( id, ETerminate );
       
   287 					RefreshL();
       
   288 					}
       
   289             	}                                  
       
   290             break;
       
   291             }        
       
   292         case EMemSpyDriverContainerTypeProcess:
       
   293             {
       
   294             TBool err = EFalse;
       
   295             TBool doTerminate = ETrue;
       
   296             TProcessId id( iKernelObjectItems[ iListBox->CurrentItemIndex() ]->Id() );
       
   297             iMemSpySession.ProcessSystemPermanentOrCritical( id, err );
       
   298             
       
   299             if( err )
       
   300             	{
       
   301 				CAknQueryDialog* importDialog = CAknQueryDialog::NewL();	
       
   302                 doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   303                 
       
   304                 if( doTerminate )
       
   305                 	{
       
   306                     iMemSpySession.EndProcessL( id, ETerminate );     
       
   307                     RefreshL();
       
   308                     }
       
   309             	}                     
       
   310             break;
       
   311             }
       
   312         default:
       
   313             {
       
   314             // Programming error
       
   315             __ASSERT_ALWAYS( EFalse, User::Panic( _L("MemSpy-View"), 0 ) );
       
   316             }
       
   317         }
       
   318     }
       
   319 
       
   320 
       
   321 void CMemSpyViewKernelObjects::OnCmdSwitchToL()
       
   322     {	
       
   323 	TBool brought = EFalse;
       
   324 	/*
       
   325     TInt wgCount;
       
   326     RWsSession wsSession;
       
   327     User::LeaveIfError( wsSession.Connect() );
       
   328     CleanupClosePushL( wsSession );
       
   329     User::LeaveIfError( wgCount = wsSession.NumWindowGroups() );
       
   330     RArray<RWsSession::TWindowGroupChainInfo> wgArray;
       
   331     CleanupClosePushL( wgArray );
       
   332     User::LeaveIfError( wsSession.WindowGroupList( &wgArray ) );
       
   333     TApaTask task( wsSession );
       
   334     TBool brought( EFalse );
       
   335     TInt wgId( KErrNotFound );
       
   336     TThreadId threadId;
       
   337     */
       
   338     switch ( iObjectType )
       
   339         {    	    	    	
       
   340         case EMemSpyDriverContainerTypeThread:
       
   341             {
       
   342             TThreadId currentThreadId( iKernelObjectItems[ iListBox->CurrentItemIndex() ]->Id() );
       
   343             TInt error = iMemSpySession.SwitchToThread( currentThreadId, brought );
       
   344             /*
       
   345             TThreadId currentThreadId( iObjectList->At( iListBox->CurrentItemIndex() ).iId );            
       
   346             
       
   347             // loop trough all window groups and see if a thread id matches
       
   348             while( !brought && wgCount-- )
       
   349                 {
       
   350                 wgId = wgArray[wgCount].iId;
       
   351                 User::LeaveIfError( wsSession.GetWindowGroupClientThreadId( wgId, threadId ) );
       
   352                 if ( threadId == currentThreadId )
       
   353                     {
       
   354                     CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC( wsSession, wgId );
       
   355                     task.SetWgId( wgId );
       
   356                     if ( !wgName->Hidden() && task.Exists() )
       
   357                         {
       
   358                         task.BringToForeground();
       
   359                         brought = ETrue;                        
       
   360                         }
       
   361                     CleanupStack::PopAndDestroy( wgName );
       
   362                     }
       
   363                 }
       
   364                 */                
       
   365             break;
       
   366             }
       
   367         case EMemSpyDriverContainerTypeProcess:
       
   368             {                        
       
   369             TProcessId id( iKernelObjectItems[ iListBox->CurrentItemIndex() ]->Id() );
       
   370             TInt error = iMemSpySession.SwitchToProcess( id, brought  );
       
   371             /*
       
   372             //CMemSpyEngineObjectContainer& container = iEngine.Container();
       
   373             //TProcessId id( iObjectList->At( iListBox->CurrentItemIndex() ).iId );
       
   374             //CMemSpyProcess& process = container.ProcessByIdL( id );
       
   375             
       
   376             TProcessId id( iKernelObjectItems[iListBox->CurrentItemIndex()]->Id() );
       
   377             
       
   378             
       
   379             // loop trough threads in a process
       
   380             for ( TInt i = 0; i < process.MdcaCount(); i++ )
       
   381                 {
       
   382                 TInt wgCountLocal = wgCount;
       
   383                 
       
   384                 // loop trough all window groups and see if a thread id matches
       
   385                 while( !brought && wgCountLocal-- )
       
   386                     {
       
   387                     wgId = wgArray[wgCountLocal].iId;
       
   388                     User::LeaveIfError( wsSession.GetWindowGroupClientThreadId( wgId, threadId ) );
       
   389                     if ( threadId == process.At( i ).Id() )
       
   390                         {
       
   391                         CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC( wsSession, wgId );
       
   392                         task.SetWgId( wgId );
       
   393                         if ( !wgName->Hidden() && task.Exists() )
       
   394                             {
       
   395                             task.BringToForeground();
       
   396                             brought = ETrue;                        
       
   397                             }
       
   398                         CleanupStack::PopAndDestroy( wgName );
       
   399                         }
       
   400                     }
       
   401                 }
       
   402 			*/
       
   403             break;
       
   404             }
       
   405         default:
       
   406             {
       
   407             // Programming error
       
   408             __ASSERT_ALWAYS( EFalse, User::Panic( _L("MemSpy-View"), 0 ) );
       
   409             }
       
   410         }
       
   411     if ( !brought )
       
   412         {
       
   413         // Error handling in HandleCommandL
       
   414         User::Leave( KErrGeneral );
       
   415         }
       
   416     CleanupStack::PopAndDestroy( 2 ); //wgArray,wsSession    
       
   417     }
       
   418 
       
   419 
       
   420 void CMemSpyViewKernelObjects::OnCmdEndL()
       
   421     {
       
   422     switch ( iObjectType )
       
   423         {
       
   424         case EMemSpyDriverContainerTypeThread:
       
   425             {
       
   426             TBool err = EFalse;
       
   427             TBool doTerminate = ETrue;
       
   428             
       
   429             TThreadId id( iKernelObjectItems[ iListBox->CurrentItemIndex() ]->Id() ); //get id of the current thread                                   
       
   430             iMemSpySession.ThreadSystemPermanentOrCritical( id, err );
       
   431             
       
   432             if( err )
       
   433             	{
       
   434 				CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   435 				doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   436                         				
       
   437 				if ( doTerminate )
       
   438 					{
       
   439 					iMemSpySession.EndThreadL( id, EKill );
       
   440 					RefreshL();
       
   441 					}
       
   442             	}            
       
   443 
       
   444             
       
   445             /*
       
   446             CMemSpyEngineObjectContainer& container = iEngine.Container();
       
   447             TThreadId id( iObjectList->At( iListBox->CurrentItemIndex() ).iId );
       
   448             
       
   449             // Try to find the thread in question...
       
   450             CMemSpyProcess* process = NULL;
       
   451             CMemSpyThread* thread = NULL; 
       
   452             User::LeaveIfError( container.ProcessAndThreadByThreadId( id, process, thread ) );
       
   453 
       
   454             if ( thread )
       
   455                 {                
       
   456                 //
       
   457                 if  ( thread->IsSystemPermanent() || thread->IsSystemCritical() )
       
   458                     {
       
   459                     CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   460                     doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   461                     }
       
   462                 //
       
   463                 if  ( doTerminate )
       
   464                     {
       
   465                     thread->KillL();
       
   466                     }                
       
   467                 }
       
   468             
       
   469             RefreshL();
       
   470             */
       
   471             break;
       
   472             }
       
   473         case EMemSpyDriverContainerTypeProcess:
       
   474             {
       
   475             TBool err = EFalse;
       
   476             TBool doTerminate = ETrue;
       
   477             TProcessId id( iKernelObjectItems[ iListBox->CurrentItemIndex() ]->Id() );
       
   478             iMemSpySession.ProcessSystemPermanentOrCritical( id, err );
       
   479             
       
   480             if( err )
       
   481             	{
       
   482 				CAknQueryDialog* importDialog = CAknQueryDialog::NewL();	
       
   483 				doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   484 				
       
   485 				if( doTerminate )
       
   486 					{
       
   487 					iMemSpySession.EndProcessL( id, EKill);     
       
   488 					RefreshL();
       
   489 					}
       
   490             	}
       
   491             
       
   492             /*
       
   493             TBool doTerminate = ETrue;
       
   494             // Obtain the process that corresponds to the selected item
       
   495             CMemSpyEngineObjectContainer& container = iEngine.Container();
       
   496             TProcessId id( iObjectList->At( iListBox->CurrentItemIndex() ).iId );
       
   497             CMemSpyProcess& process = container.ProcessByIdL( id );            
       
   498 
       
   499             if  ( process.IsSystemPermanent() || process.IsSystemCritical() )
       
   500                 {
       
   501                 CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   502                 doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   503                 }
       
   504             if  ( doTerminate )
       
   505                 {
       
   506                 process.KillL();
       
   507                 RefreshL();
       
   508                 }
       
   509 			*/
       
   510             break;
       
   511             }
       
   512         default:
       
   513             {
       
   514             // Programming error
       
   515             __ASSERT_ALWAYS( EFalse, User::Panic( _L("MemSpy-View"), 0 ) );
       
   516             }
       
   517         }    
       
   518     }
       
   519 
       
   520 
       
   521 void CMemSpyViewKernelObjects::OnCmdPanicL()
       
   522     {
       
   523     switch ( iObjectType )
       
   524         {
       
   525         case EMemSpyDriverContainerTypeThread:
       
   526             {
       
   527             TBool err = EFalse;
       
   528             TBool doTerminate = ETrue;
       
   529             
       
   530             TThreadId id( iKernelObjectItems[ iListBox->CurrentItemIndex() ]->Id() ); //get id of the current thread                                   
       
   531             iMemSpySession.ThreadSystemPermanentOrCritical( id, err );
       
   532             
       
   533             if( err )
       
   534             	{
       
   535 				CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   536 				doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   537                         				
       
   538 				if ( doTerminate )
       
   539 					{
       
   540 					iMemSpySession.EndThreadL( id, EPanic );
       
   541 					RefreshL();
       
   542 					}
       
   543             	}
       
   544             
       
   545             break;
       
   546             }
       
   547         case EMemSpyDriverContainerTypeProcess:
       
   548             {
       
   549             TBool err = EFalse;
       
   550             TBool doTerminate = ETrue;
       
   551             TProcessId id( iKernelObjectItems[ iListBox->CurrentItemIndex() ]->Id() );
       
   552             iMemSpySession.ProcessSystemPermanentOrCritical( id, err );
       
   553             
       
   554             if( err )
       
   555             	{
       
   556 				CAknQueryDialog* importDialog = CAknQueryDialog::NewL();	
       
   557 				doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   558                            
       
   559 				if( doTerminate )
       
   560 					{
       
   561 					iMemSpySession.EndProcessL( id, EPanic );     
       
   562 					RefreshL();
       
   563 					}
       
   564             	}
       
   565         
       
   566             break;
       
   567             }
       
   568         default:
       
   569             {
       
   570             // Programming error
       
   571             __ASSERT_ALWAYS( EFalse, User::Panic( _L("MemSpy-View"), 0 ) );
       
   572             }
       
   573         }
       
   574     }
       
   575 
       
   576 
       
   577 void CMemSpyViewKernelObjects::CreateTabsL()
       
   578     {
       
   579 	TMemSpyDriverContainerType type = iObjectType;
       
   580 	const TPtrC pType( MemSpyUiUtils::TypeAsString( type ) );
       
   581 	
       
   582 	CEikStatusPane* statusPane = static_cast<CAknAppUi*> ( iEikonEnv->EikAppUi() )->StatusPane();
       
   583 	TUid uid;
       
   584 	uid.iUid = EEikStatusPaneUidNavi;
       
   585 	iNaviPane = ( CAknNavigationControlContainer * ) statusPane->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) );	
       
   586 	iNavDecorator=iNaviPane->CreateMessageLabelL( pType );
       
   587 	iNaviPane->PushL(*iNavDecorator); 		
       
   588     }
       
   589 
       
   590 
       
   591 void CMemSpyViewKernelObjects::DetailsL()
       
   592     {
       
   593     HBufC* messageBuf = HBufC::NewLC( 40960 );    
       
   594     TPtr messagePtr = messageBuf->Des();
       
   595 
       
   596     //const TMemSpyDriverHandleInfoGeneric& selectedObject = iObjectList->At( iListBox->CurrentItemIndex() );
       
   597     //iKernelObjectItems[iListBox->CurrentItemIndex];
       
   598 
       
   599     // General attributes:
       
   600     TFullName name;
       
   601     name.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->NameDetail() );
       
   602     AppendFormatString( messagePtr, _L("Name: %S\n"), &name );
       
   603     name.Zero();
       
   604     name.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->Name() );
       
   605     AppendFormatString( messagePtr, _L("FullName: %S\n"), &name );
       
   606     name.Zero();
       
   607     AppendFormatString( messagePtr, _L("AccessCount: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AccessCount() );
       
   608     AppendFormatString( messagePtr, _L("UniqueID: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->UniqueID() );
       
   609     AppendFormatString( messagePtr, _L("Protection: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Protection() );
       
   610     AppendFormatString( messagePtr, _L("OwnrAddr: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfKernelOwner() );
       
   611     AppendFormatString( messagePtr, _L("KernelAddr: 0x%08X"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Handle() );
       
   612     
       
   613     // Object type specific attributes:
       
   614     switch ( iKernelObjectItems[iListBox->CurrentItemIndex()]->Type() )
       
   615         {
       
   616         case EMemSpyDriverContainerTypeUnknown:
       
   617             {
       
   618             break;
       
   619             }
       
   620         case EMemSpyDriverContainerTypeThread:
       
   621             {
       
   622             AppendFormatString( messagePtr, _L("\nOwnrPrAddr: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfOwningProcess() );
       
   623             AppendFormatString( messagePtr, _L("ThreadID: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Id() );
       
   624             AppendFormatString( messagePtr, _L("Priority: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Priority() );
       
   625             TFullName procName;
       
   626             procName.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->NameOfOwner() );
       
   627             AppendFormatString( messagePtr, _L("Proc: %S"), &procName );
       
   628             procName.Zero();
       
   629             break;
       
   630             }
       
   631         case EMemSpyDriverContainerTypeProcess:
       
   632             {
       
   633             AppendFormatString( messagePtr, _L("\nOwnrPrAddr: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfOwningProcess() );
       
   634             AppendFormatString( messagePtr, _L("CreatorId: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->CreatorId() );
       
   635             AppendFormatString( messagePtr, _L("Attributes: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Attributes() );
       
   636             AppendFormatString( messagePtr, _L("StckChnk: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfDataBssStackChunk() );
       
   637             AppendFormatString( messagePtr, _L("ProcessID: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Id() );
       
   638             AppendFormatString( messagePtr, _L("Priority: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Priority() );
       
   639             AppendFormatString( messagePtr, _L("SecurityZone: %d"), iKernelObjectItems[iListBox->CurrentItemIndex()]->SecurityZone() );
       
   640             /* TODO: to solve process details
       
   641             CMemSpyEngineObjectContainer& container = iEngine.Container();
       
   642             TProcessId id( iKernelObjectItems[iListBox->CurrentItemIndex().iId );
       
   643             TRAP_IGNORE(
       
   644                 CMemSpyProcess& process = container.ProcessByIdL( id );
       
   645                 AppendFormatString( messagePtr, _L("\nSID: 0x%08X\n"), process.SID() );
       
   646                 AppendFormatString( messagePtr, _L("VID: 0x%08X\n"), process.VID() );
       
   647                 AppendFormatString( messagePtr, _L("UID1: 0x%08X\n"), process.UIDs()[0].iUid  );
       
   648                 AppendFormatString( messagePtr, _L("UID2: 0x%08X\n"), process.UIDs()[1].iUid  );
       
   649                 AppendFormatString( messagePtr, _L("UID3: 0x%08X\n"), process.UIDs()[2].iUid );
       
   650                 AppendFormatString( messagePtr, _L("Caps: 0x%08X%08X"), process.Capabilities().iCaps[0], process.Capabilities().iCaps[1]);
       
   651                 );
       
   652             */
       
   653             break;
       
   654             }
       
   655         case EMemSpyDriverContainerTypeChunk:
       
   656             {
       
   657             AppendFormatString( messagePtr, _L("\nOwnrPrAddr: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfOwningProcess() );
       
   658             AppendFormatString( messagePtr, _L("Size: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Size() );
       
   659             AppendFormatString( messagePtr, _L("MaxSize: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->MaxSize() );
       
   660             AppendFormatString( messagePtr, _L("Bottom: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Bottom() );
       
   661             AppendFormatString( messagePtr, _L("Top: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Top() );
       
   662             AppendFormatString( messagePtr, _L("Attr: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Attributes() );
       
   663             AppendFormatString( messagePtr, _L("Start: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->StartPos() );
       
   664             AppendFormatString( messagePtr, _L("CntrlID: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->ControllingOwner() );
       
   665             AppendFormatString( messagePtr, _L("Restrictions: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Restrictions() );
       
   666             AppendFormatString( messagePtr, _L("MapAttr: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->MapAttr() );
       
   667             AppendFormatString( messagePtr, _L("Type: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->ChunkType() );
       
   668             TFullName procName;
       
   669             procName.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->NameOfOwner() );
       
   670             AppendFormatString( messagePtr, _L("Proc: %S"), &procName );
       
   671             procName.Zero();
       
   672             // OwnerAddr iAddressOfKernelOwner already listed
       
   673             // ProcAddr iAddressOfOwningProcess already listed
       
   674             break;
       
   675             }
       
   676         case EMemSpyDriverContainerTypeLibrary:
       
   677             {
       
   678             AppendFormatString( messagePtr, _L("\nMapCount: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->MapCount() );
       
   679             AppendFormatString( messagePtr, _L("State: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->State() );
       
   680             AppendFormatString( messagePtr, _L("CodeSeg: 0x%08X"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfCodeSeg() );
       
   681             break;
       
   682             }
       
   683         case EMemSpyDriverContainerTypeSemaphore:
       
   684             {
       
   685             AppendFormatString( messagePtr, _L("\nCount: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Count() );
       
   686             AppendFormatString( messagePtr, _L("Resetting: %u"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Resetting() );
       
   687             break;
       
   688             }
       
   689         case EMemSpyDriverContainerTypeMutex:
       
   690             {
       
   691             AppendFormatString( messagePtr, _L("\nHoldCount: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Count() );
       
   692             AppendFormatString( messagePtr, _L("WaitCount: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->WaitCount() );
       
   693             AppendFormatString( messagePtr, _L("Resetting: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Resetting() );
       
   694             AppendFormatString( messagePtr, _L("Order: %u"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Order() );
       
   695             break;
       
   696             }
       
   697         case EMemSpyDriverContainerTypeTimer:
       
   698             {
       
   699             AppendFormatString( messagePtr, _L("\nState: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->TimerState() );
       
   700             AppendFormatString( messagePtr, _L("Type: %d"), iKernelObjectItems[iListBox->CurrentItemIndex()]->TimerType() );
       
   701             break;
       
   702             }
       
   703         case EMemSpyDriverContainerTypeServer:
       
   704             {
       
   705             // Owner == ThrdAddr
       
   706             AppendFormatString( messagePtr, _L("\nThrdAddr: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfOwningThread() );
       
   707             TFullName thrName;
       
   708             thrName.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->NameOfOwner() );
       
   709             AppendFormatString( messagePtr, _L("Thr: %S\n"), &thrName );
       
   710             thrName.Zero();
       
   711             AppendFormatString( messagePtr, _L("Type: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->SessionType() );
       
   712             TBuf8<55>buf;
       
   713             /*
       
   714             RArray<TMemSpyDriverServerSessionInfo> sessions;
       
   715             CleanupClosePushL( sessions );            
       
   716             iEngine.HelperServer().GetServerSessionsL( iKernelObjectItems[iListBox->CurrentItemIndex(), sessions );
       
   717             const TInt count = sessions.Count();
       
   718             for ( TInt i = 0; i < count; i++ )
       
   719                 {
       
   720                 const TMemSpyDriverServerSessionInfo& session = sessions[ i ];
       
   721                 AppendFormatString( messagePtr, _L("SessAddr: 0x%08X\n"), session.iAddress );
       
   722                 TFullName sessName;
       
   723                 sessName.Copy( session.iName );
       
   724                 AppendFormatString( messagePtr, _L("Sess: %S\n"), &sessName );
       
   725                 }
       
   726             CleanupStack::PopAndDestroy( &sessions );
       
   727             */
       
   728             break;
       
   729             }
       
   730         case EMemSpyDriverContainerTypeSession:
       
   731             {
       
   732             // Server == SvrAddr
       
   733             AppendFormatString( messagePtr, _L("\nServer: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfServer() );
       
   734             TFullName srvName;
       
   735             srvName.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->Name() );
       
   736             AppendFormatString( messagePtr, _L("Srv: %S\n"), &srvName );
       
   737             srvName.Zero();
       
   738             // Session: not supported
       
   739             AppendFormatString( messagePtr, _L("AccCount: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->TotalAccessCount() );
       
   740             AppendFormatString( messagePtr, _L("SesType: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->SessionType() );
       
   741             AppendFormatString( messagePtr, _L("SvrType: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->SvrSessionType() );
       
   742             AppendFormatString( messagePtr, _L("MsgCount: %d\n"),  iKernelObjectItems[iListBox->CurrentItemIndex()]->MsgCount() );
       
   743             AppendFormatString( messagePtr, _L("MsgLimit: %d"), iKernelObjectItems[iListBox->CurrentItemIndex()]->MsgLimit() );
       
   744             break;
       
   745             }
       
   746         case EMemSpyDriverContainerTypeLogicalDevice:
       
   747             {
       
   748             AppendFormatString( messagePtr, 
       
   749                                 _L("\nVersion: %d.%d.%d\n"), 
       
   750                                 /*
       
   751                                 iKernelObjectItems[iListBox->CurrentItemIndex()]->Version.iMajor, TODO: To solve this
       
   752                                 iKernelObjectItems[iListBox->CurrentItemIndex()]->Version.iMinor,
       
   753                                 iKernelObjectItems[iListBox->CurrentItemIndex()]->Version.iBuild );
       
   754                                 */
       
   755                                 iKernelObjectItems[iListBox->CurrentItemIndex()]->Version(),
       
   756                                 iKernelObjectItems[iListBox->CurrentItemIndex()]->Version(),
       
   757                                 iKernelObjectItems[iListBox->CurrentItemIndex()]->Version() );
       
   758             AppendFormatString( messagePtr, _L("ParseMask: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->ParseMask() );
       
   759             AppendFormatString( messagePtr, _L("UnitsMask: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->UnitsMask() );
       
   760             AppendFormatString( messagePtr, _L("Open channels: %d"), iKernelObjectItems[iListBox->CurrentItemIndex()]->OpenChannels() );
       
   761             break;
       
   762             }
       
   763         case EMemSpyDriverContainerTypePhysicalDevice:
       
   764             {
       
   765             AppendFormatString( messagePtr, 
       
   766                                 _L("\nVersion: %d.%d.%d\n"), 
       
   767                                 iKernelObjectItems[iListBox->CurrentItemIndex()]->Version(),
       
   768                                 iKernelObjectItems[iListBox->CurrentItemIndex()]->Version(),
       
   769                                 iKernelObjectItems[iListBox->CurrentItemIndex()]->Version() );
       
   770             AppendFormatString( messagePtr, _L("UnitsMask: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->UnitsMask() );
       
   771             AppendFormatString( messagePtr, _L("CodeSeg: 0x%08X"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfCodeSeg() );
       
   772             break;
       
   773             }
       
   774         case EMemSpyDriverContainerTypeLogicalChannel:
       
   775             {
       
   776             // No other details
       
   777             break;
       
   778             }
       
   779         case EMemSpyDriverContainerTypeChangeNotifier:
       
   780             {
       
   781             AppendFormatString( messagePtr, _L("\nChanges: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Changes() );
       
   782             // Thread == ThrdAddr
       
   783             AppendFormatString( messagePtr, _L("ThrdAddr: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfOwningThread() );
       
   784             TFullName thrName;
       
   785             thrName.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->NameOfOwner() );
       
   786             AppendFormatString( messagePtr, _L("Thr: %S"), &thrName );
       
   787             thrName.Zero();
       
   788             break;
       
   789             }
       
   790         case EMemSpyDriverContainerTypeUndertaker:
       
   791             {
       
   792             // Thread == ThrdAddr
       
   793             AppendFormatString( messagePtr, _L("\nThrdAddr: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfOwningThread() );
       
   794             TFullName thrName;
       
   795             thrName.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->NameOfOwner() );
       
   796             AppendFormatString( messagePtr, _L("Thr: %S"), &thrName );
       
   797             thrName.Zero();
       
   798             break;
       
   799             }
       
   800         case EMemSpyDriverContainerTypeMsgQueue:
       
   801             {
       
   802             // No other details
       
   803             break;
       
   804             }
       
   805         case EMemSpyDriverContainerTypePropertyRef:
       
   806             {
       
   807             /*
       
   808             Not listing details here, as propertyRef is not listed in TaskMgr.
       
   809             Following propertyRef attributes are available at engine side. 
       
   810             
       
   811             IsReady
       
   812             Type
       
   813             Category
       
   814             Key
       
   815             RefCount
       
   816             ThreadId
       
   817             CreatorSID
       
   818             */
       
   819             break;
       
   820             }
       
   821         case EMemSpyDriverContainerTypeCondVar:
       
   822             {
       
   823             AppendFormatString( messagePtr, _L("\nResetting: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Resetting() );
       
   824             // Using iAddressOfOwningThread for mutex
       
   825             AppendFormatString( messagePtr, _L("Mutex: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfOwningThread() );
       
   826             // Using iNameOfOwner for mutex
       
   827             TFullName mtxName;
       
   828             mtxName.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->NameOfOwner() );
       
   829             AppendFormatString( messagePtr, _L("Mtx: %S\n"), &mtxName );
       
   830             mtxName.Zero();
       
   831             AppendFormatString( messagePtr, _L("WaitCount: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->WaitCount() );
       
   832             /*
       
   833             RArray<TMemSpyDriverCondVarSuspendedThreadInfo> threads;
       
   834             CleanupClosePushL( threads );            
       
   835             iEngine.HelperCondVar().GetCondVarSuspendedThreadsL( iKernelObjectItems[iListBox->CurrentItemIndex(), threads );
       
   836             const TInt count = threads.Count();
       
   837             for ( TInt i = 0; i < count; i++ )
       
   838                 {
       
   839                 const TMemSpyDriverCondVarSuspendedThreadInfo& thr = threads[ i ];
       
   840                 AppendFormatString( messagePtr, _L("SuspThrdAddr: 0x%08X\n"), thr.iAddress );
       
   841                 TFullName thrName;
       
   842                 thrName.Copy( thr.iName );
       
   843                 AppendFormatString( messagePtr, _L("Thr: %S\n"), &thrName );
       
   844                 }
       
   845             CleanupStack::PopAndDestroy( &threads );
       
   846             */
       
   847             break;
       
   848             }
       
   849         default:
       
   850             {
       
   851             // Programming error
       
   852             __ASSERT_ALWAYS( EFalse, User::Panic( _L("MemSpy-View"), 0 ) );
       
   853             }
       
   854         }
       
   855     
       
   856     CAknMessageQueryDialog* dialog = new(ELeave) CAknMessageQueryDialog( CAknQueryDialog::ENoTone );
       
   857     dialog->PrepareLC( R_MEMSPY_KERNEL_OBJECT_DETAILS_DIALOG );
       
   858     TFileName headerText;
       
   859     headerText.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->Name() );
       
   860     dialog->SetHeaderTextL( headerText );
       
   861     dialog->SetMessageTextL(messagePtr);
       
   862     dialog->RunLD();
       
   863     CleanupStack::PopAndDestroy( messageBuf );
       
   864     }
       
   865 
       
   866 
       
   867 void CMemSpyViewKernelObjects::AppendFormatString( TPtr& aPtr, TRefByValue<const TDesC> aFmt, ... )
       
   868     {
       
   869     TBuf<KMaxInfoLength> infoString;
       
   870     VA_LIST list;
       
   871     VA_START ( list, aFmt );
       
   872     infoString.FormatList( aFmt, list );
       
   873     aPtr.Append( infoString );
       
   874     }
       
   875