memspyui/ui/avkon/src/MemSpyViewKernelObjects.cpp
changeset 17 4f2773374eff
child 19 4b22a598b890
equal deleted inserted replaced
15:e11368ed4880 17:4f2773374eff
       
     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() ); //array for formated items
       
   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     	tempNamePtr.Append( iKernelObjectItems[i]->Name() );
       
   182     	iModel->AppendL( tempNamePtr );
       
   183     	
       
   184     	CleanupStack::PopAndDestroy( tempName ); 
       
   185     	}
       
   186     
       
   187     CAknSettingStyleListBox* listbox = static_cast< CAknSettingStyleListBox* >( iListBox );
       
   188     listbox->Model()->SetItemTextArray( iModel );
       
   189     listbox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );       
       
   190     }
       
   191 
       
   192 
       
   193 TBool CMemSpyViewKernelObjects::HandleCommandL( TInt aCommand )
       
   194     {
       
   195     TBool handled = ETrue;
       
   196     //
       
   197     switch ( aCommand )
       
   198         {
       
   199         case EMemSpyCmdKernelObjectTerminate:
       
   200             {
       
   201             TRAPD( err, OnCmdTerminateL() );
       
   202             if ( err )
       
   203                 {
       
   204                 CAknConfirmationNote* note = new(ELeave) CAknConfirmationNote( ETrue );
       
   205                 note->ExecuteLD( _L("Cannot terminate task") );
       
   206                 }
       
   207             break;
       
   208             }
       
   209         case EMemSpyCmdKernelObjectSwitchTo:
       
   210             {
       
   211             TRAPD( err, OnCmdSwitchToL() );
       
   212             if ( err )
       
   213                 {
       
   214                 CAknConfirmationNote* note = new(ELeave) CAknConfirmationNote( ETrue );
       
   215                 note->ExecuteLD( _L("Cannot bring to foreground") );
       
   216                 }
       
   217             break;
       
   218             }
       
   219         case EMemSpyCmdKernelObjectEnd:
       
   220             {
       
   221             TRAPD( err, OnCmdEndL() );
       
   222             if ( err )
       
   223                 {
       
   224                 CAknConfirmationNote* note = new(ELeave) CAknConfirmationNote( ETrue );
       
   225                 note->ExecuteLD( _L("Cannot end task") );
       
   226                 }
       
   227             break;
       
   228             }
       
   229         case EMemSpyCmdKernelObjectPanic:
       
   230             {
       
   231             TRAPD( err, OnCmdPanicL() );
       
   232             if ( err )
       
   233                 {
       
   234                 CAknConfirmationNote* note = new(ELeave) CAknConfirmationNote( ETrue );
       
   235                 note->ExecuteLD( _L("Cannot panic task") );
       
   236                 }
       
   237             break;
       
   238             }
       
   239         default:
       
   240             {
       
   241             handled = CMemSpyViewBase::HandleCommandL( aCommand );
       
   242             break;        
       
   243             }
       
   244         }
       
   245     //
       
   246     return handled;
       
   247     }
       
   248 
       
   249 
       
   250 TKeyResponse CMemSpyViewKernelObjects::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   251     {
       
   252 	// TODO: to remove support of tabs
       
   253     TKeyResponse resp = EKeyWasNotConsumed;
       
   254     if  ( iTabs && ( aKeyEvent.iScanCode == EStdKeyRightArrow || aKeyEvent.iScanCode == EStdKeyLeftArrow ) )
       
   255         {
       
   256         resp = iTabs->OfferKeyEventL( aKeyEvent, aType );
       
   257         }
       
   258     else
       
   259         {
       
   260         resp = CMemSpyViewBase::OfferKeyEventL( aKeyEvent, aType );    
       
   261         }
       
   262     return resp;
       
   263     }
       
   264 
       
   265 
       
   266 void CMemSpyViewKernelObjects::TabChangedL( TInt /*aIndex*/ )
       
   267     {
       
   268 	/* TODO: tabs removed
       
   269     iObjectType = (TMemSpyDriverContainerType)iTabs->ActiveTabId();
       
   270     RefreshL();
       
   271     */
       
   272     }
       
   273 
       
   274 
       
   275 void CMemSpyViewKernelObjects::OnCmdTerminateL()
       
   276     {
       
   277     switch ( iObjectType )
       
   278         {
       
   279         case EMemSpyDriverContainerTypeThread:
       
   280             {
       
   281             TBool doTerminate = ETrue;
       
   282             
       
   283             //CMemSpyEngineObjectContainer& container = iEngine.Container();
       
   284             //TThreadId id( iObjectList->At( iListBox->CurrentItemIndex() ).iId );
       
   285             TThreadId id( iKernelObjectItems[ iListBox->CurrentItemIndex() ]->Id() ); //get id of the current thread
       
   286             
       
   287             TBool err;
       
   288             iMemSpySession.ThreadSystemPermanentOrCritical( id, err );
       
   289             
       
   290             // Try to find the thread in question...
       
   291             //CMemSpyProcess* process = NULL;
       
   292             //CMemSpyThread* thread = NULL; 
       
   293             //User::LeaveIfError( container.ProcessAndThreadByThreadId( id, process, thread ) ); //
       
   294                         
       
   295             if( err )
       
   296             	{
       
   297 				CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   298 				doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   299 				
       
   300 				if ( doTerminate )
       
   301 					{
       
   302 					iMemSpySession.TerminateThread( id );
       
   303 					}
       
   304             	}            
       
   305             
       
   306             /*
       
   307             if ( thread )
       
   308                 {
       
   309                 thread->Open();
       
   310                 //
       
   311                 if  ( thread->IsSystemPermanent() || thread->IsSystemCritical() )
       
   312                     {
       
   313                     CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   314                     doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   315                     }
       
   316                 //
       
   317                 if  ( doTerminate )
       
   318                     {
       
   319                     thread->TerminateL();
       
   320                     }                
       
   321                 }
       
   322             */
       
   323             RefreshL();
       
   324             break;
       
   325             }        
       
   326         case EMemSpyDriverContainerTypeProcess:
       
   327             {
       
   328             TBool doTerminate = ETrue;
       
   329             // Obtain the process that corresponds to the selected item
       
   330             //CMemSpyEngineObjectContainer& container = iEngine.Container();
       
   331             //TProcessId id( iObjectList->At( iListBox->CurrentItemIndex() ).iId );
       
   332             TProcessId id( iKernelObjectItems[ iListBox->CurrentItemIndex() ]->Id() );
       
   333             
       
   334             CMemSpyProcess& process = container.ProcessByIdL( id );
       
   335             process.Open();
       
   336 
       
   337             if  ( process.IsSystemPermanent() || process.IsSystemCritical() )
       
   338                 {
       
   339                 CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   340                 doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   341                 }
       
   342             //
       
   343             if  ( doTerminate )
       
   344                 {
       
   345                 process.TerminateL();
       
   346                 RefreshL();
       
   347                 }
       
   348             break;
       
   349             }
       
   350         default:
       
   351             {
       
   352             // Programming error
       
   353             __ASSERT_ALWAYS( EFalse, User::Panic( _L("MemSpy-View"), 0 ) );
       
   354             }
       
   355         }
       
   356     }
       
   357 
       
   358 
       
   359 void CMemSpyViewKernelObjects::OnCmdSwitchToL()
       
   360     {/*
       
   361     TInt wgCount;
       
   362     RWsSession wsSession;
       
   363     User::LeaveIfError( wsSession.Connect() );
       
   364     CleanupClosePushL( wsSession );
       
   365     User::LeaveIfError( wgCount = wsSession.NumWindowGroups() );
       
   366     RArray<RWsSession::TWindowGroupChainInfo> wgArray;
       
   367     CleanupClosePushL( wgArray );
       
   368     User::LeaveIfError( wsSession.WindowGroupList( &wgArray ) );
       
   369     TApaTask task( wsSession );
       
   370     TBool brought( EFalse );
       
   371     TInt wgId( KErrNotFound );
       
   372     TThreadId threadId;
       
   373     switch ( iObjectType )
       
   374         {
       
   375         case EMemSpyDriverContainerTypeThread:
       
   376             {
       
   377             TThreadId currentThreadId( iObjectList->At( iListBox->CurrentItemIndex() ).iId );
       
   378             
       
   379             // loop trough all window groups and see if a thread id matches
       
   380             while( !brought && wgCount-- )
       
   381                 {
       
   382                 wgId = wgArray[wgCount].iId;
       
   383                 User::LeaveIfError( wsSession.GetWindowGroupClientThreadId( wgId, threadId ) );
       
   384                 if ( threadId == currentThreadId )
       
   385                     {
       
   386                     CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC( wsSession, wgId );
       
   387                     task.SetWgId( wgId );
       
   388                     if ( !wgName->Hidden() && task.Exists() )
       
   389                         {
       
   390                         task.BringToForeground();
       
   391                         brought = ETrue;                        
       
   392                         }
       
   393                     CleanupStack::PopAndDestroy( wgName );
       
   394                     }
       
   395                 }                
       
   396             break;
       
   397             }
       
   398         case EMemSpyDriverContainerTypeProcess:
       
   399             {
       
   400             CMemSpyEngineObjectContainer& container = iEngine.Container();
       
   401             TProcessId id( iObjectList->At( iListBox->CurrentItemIndex() ).iId );
       
   402             CMemSpyProcess& process = container.ProcessByIdL( id );
       
   403             
       
   404             // loop trough threads in a process
       
   405             for ( TInt i = 0; i < process.MdcaCount(); i++ )
       
   406                 {
       
   407                 TInt wgCountLocal = wgCount;
       
   408                 
       
   409                 // loop trough all window groups and see if a thread id matches
       
   410                 while( !brought && wgCountLocal-- )
       
   411                     {
       
   412                     wgId = wgArray[wgCountLocal].iId;
       
   413                     User::LeaveIfError( wsSession.GetWindowGroupClientThreadId( wgId, threadId ) );
       
   414                     if ( threadId == process.At( i ).Id() )
       
   415                         {
       
   416                         CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC( wsSession, wgId );
       
   417                         task.SetWgId( wgId );
       
   418                         if ( !wgName->Hidden() && task.Exists() )
       
   419                             {
       
   420                             task.BringToForeground();
       
   421                             brought = ETrue;                        
       
   422                             }
       
   423                         CleanupStack::PopAndDestroy( wgName );
       
   424                         }
       
   425                     }
       
   426                 }
       
   427 
       
   428             break;
       
   429             }
       
   430         default:
       
   431             {
       
   432             // Programming error
       
   433             __ASSERT_ALWAYS( EFalse, User::Panic( _L("MemSpy-View"), 0 ) );
       
   434             }
       
   435         }
       
   436     if ( !brought )
       
   437         {
       
   438         // Error handling in HandleCommandL
       
   439         User::Leave( KErrGeneral );
       
   440         }
       
   441     CleanupStack::PopAndDestroy( 2 ); //wgArray,wsSession*/
       
   442     }
       
   443 
       
   444 
       
   445 void CMemSpyViewKernelObjects::OnCmdEndL()
       
   446     {/*
       
   447     switch ( iObjectType )
       
   448         {
       
   449         case EMemSpyDriverContainerTypeThread:
       
   450             {
       
   451             TBool doTerminate = ETrue;
       
   452             
       
   453             CMemSpyEngineObjectContainer& container = iEngine.Container();
       
   454             TThreadId id( iObjectList->At( iListBox->CurrentItemIndex() ).iId );
       
   455             
       
   456             // Try to find the thread in question...
       
   457             CMemSpyProcess* process = NULL;
       
   458             CMemSpyThread* thread = NULL; 
       
   459             User::LeaveIfError( container.ProcessAndThreadByThreadId( id, process, thread ) );
       
   460 
       
   461             if ( thread )
       
   462                 {
       
   463                 thread->Open();
       
   464                 //
       
   465                 if  ( thread->IsSystemPermanent() || thread->IsSystemCritical() )
       
   466                     {
       
   467                     CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   468                     doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   469                     }
       
   470                 //
       
   471                 if  ( doTerminate )
       
   472                     {
       
   473                     thread->KillL();
       
   474                     }                
       
   475                 }
       
   476             RefreshL();
       
   477             break;
       
   478             }
       
   479         case EMemSpyDriverContainerTypeProcess:
       
   480             {
       
   481             TBool doTerminate = ETrue;
       
   482             // Obtain the process that corresponds to the selected item
       
   483             CMemSpyEngineObjectContainer& container = iEngine.Container();
       
   484             TProcessId id( iObjectList->At( iListBox->CurrentItemIndex() ).iId );
       
   485             CMemSpyProcess& process = container.ProcessByIdL( id );
       
   486             process.Open();
       
   487 
       
   488             if  ( process.IsSystemPermanent() || process.IsSystemCritical() )
       
   489                 {
       
   490                 CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   491                 doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   492                 }
       
   493             if  ( doTerminate )
       
   494                 {
       
   495                 process.KillL();
       
   496                 RefreshL();
       
   497                 }
       
   498 
       
   499             break;
       
   500             }
       
   501         default:
       
   502             {
       
   503             // Programming error
       
   504             __ASSERT_ALWAYS( EFalse, User::Panic( _L("MemSpy-View"), 0 ) );
       
   505             }
       
   506         }    */
       
   507     }
       
   508 
       
   509 
       
   510 void CMemSpyViewKernelObjects::OnCmdPanicL()
       
   511     {/*
       
   512     switch ( iObjectType )
       
   513         {
       
   514         case EMemSpyDriverContainerTypeThread:
       
   515             {
       
   516             TBool doTerminate = ETrue;
       
   517             
       
   518             CMemSpyEngineObjectContainer& container = iEngine.Container();
       
   519             TThreadId id( iObjectList->At( iListBox->CurrentItemIndex() ).iId );
       
   520             
       
   521             // Try to find the thread in question...
       
   522             CMemSpyProcess* process = NULL;
       
   523             CMemSpyThread* thread = NULL; 
       
   524             User::LeaveIfError( container.ProcessAndThreadByThreadId( id, process, thread ) );
       
   525 
       
   526             if ( thread )
       
   527                 {
       
   528                 thread->Open();
       
   529                 //
       
   530                 if  ( thread->IsSystemPermanent() || thread->IsSystemCritical() )
       
   531                     {
       
   532                     CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   533                     doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   534                     }
       
   535                 //
       
   536                 if  ( doTerminate )
       
   537                     {
       
   538                     thread->PanicL();
       
   539                     }                
       
   540                 }
       
   541             RefreshL();
       
   542             break;
       
   543             }
       
   544         case EMemSpyDriverContainerTypeProcess:
       
   545             {
       
   546             TBool doTerminate = ETrue;
       
   547             // Obtain the process that corresponds to the selected item
       
   548             CMemSpyEngineObjectContainer& container = iEngine.Container();
       
   549             TProcessId id( iObjectList->At( iListBox->CurrentItemIndex() ).iId );
       
   550             CMemSpyProcess& process = container.ProcessByIdL( id );
       
   551             process.Open();
       
   552 
       
   553             if  ( process.IsSystemPermanent() || process.IsSystemCritical() )
       
   554                 {
       
   555                 CAknQueryDialog* importDialog = CAknQueryDialog::NewL();
       
   556                 doTerminate = ( importDialog->ExecuteLD( R_MEMSPY_PANIC_SYSTEM_CRITICAL_THREAD_OR_PROCESS ) );
       
   557                 }
       
   558             if  ( doTerminate )
       
   559                 {
       
   560                 process.PanicL();
       
   561                 RefreshL();
       
   562                 }
       
   563             break;
       
   564             }
       
   565         default:
       
   566             {
       
   567             // Programming error
       
   568             __ASSERT_ALWAYS( EFalse, User::Panic( _L("MemSpy-View"), 0 ) );
       
   569             }
       
   570         }*/
       
   571     }
       
   572 
       
   573 
       
   574 void CMemSpyViewKernelObjects::CreateTabsL()
       
   575     {
       
   576 	CEikStatusPane* statusPane = static_cast<CAknAppUi*> ( iEikonEnv->EikAppUi() )->StatusPane();
       
   577 	TUid uid;
       
   578 	uid.iUid = EEikStatusPaneUidNavi;
       
   579 	iNaviPane = ( CAknNavigationControlContainer * ) statusPane->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) );	
       
   580 	iNavDecorator=iNaviPane->CreateMessageLabelL(_L("Kernel Object Type")); //TODO: To print there kernel object type
       
   581 	iNaviPane->PushL(*iNavDecorator); 
       
   582 	/*
       
   583     CEikStatusPane* statusPane = static_cast<CAknAppUi*> ( iEikonEnv->EikAppUi() )->StatusPane();
       
   584     TUid uid;
       
   585     uid.iUid = EEikStatusPaneUidNavi;
       
   586     iNavDecorator = ((CAknNavigationControlContainer*)(statusPane->ControlL(uid)))->Top();
       
   587 
       
   588     if ( !iNavDecorator )
       
   589         {
       
   590         iNavContainer = (CAknNavigationControlContainer*)statusPane->ControlL(uid);
       
   591         iNavDecorator = iNavContainer->CreateTabGroupL();
       
   592 
       
   593         iTabs = ( CAknTabGroup* )iNavDecorator->DecoratedControl();
       
   594         iTabs->SetTabFixedWidthL( KTabWidthWithThreeLongTabs );
       
   595     
       
   596         for ( TInt i = 0; i < iModel->Count(); i++ )
       
   597             {
       
   598             const CMemSpyEngineGenericKernelObjectList& item = iModel->At( i );
       
   599             iTabs->AddTabL( item.Type(), item.TypeAsString( item.Type() ) );
       
   600             }
       
   601         iTabs->SetActiveTabById( iObjectType );
       
   602         iTabs->SetObserver( this );
       
   603         iNavContainer->PushL( *iNavDecorator );
       
   604        }
       
   605        */
       
   606     }
       
   607 
       
   608 
       
   609 void CMemSpyViewKernelObjects::DetailsL()
       
   610     {
       
   611     HBufC* messageBuf = HBufC::NewLC( 40960 );
       
   612     TPtr messagePtr = messageBuf->Des();
       
   613 
       
   614     //const TMemSpyDriverHandleInfoGeneric& selectedObject = iObjectList->At( iListBox->CurrentItemIndex() );
       
   615     //iKernelObjectItems[iListBox->CurrentItemIndex];
       
   616 
       
   617     // General attributes:
       
   618     TFullName name;
       
   619     name.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->NameDetail() );
       
   620     AppendFormatString( messagePtr, _L("Name: %S\n"), &name );
       
   621     name.Zero();
       
   622     name.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->Name() );
       
   623     AppendFormatString( messagePtr, _L("FullName: %S\n"), &name );
       
   624     name.Zero();
       
   625     AppendFormatString( messagePtr, _L("AccessCount: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AccessCount() );
       
   626     AppendFormatString( messagePtr, _L("UniqueID: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->UniqueID() );
       
   627     AppendFormatString( messagePtr, _L("Protection: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Protection() );
       
   628     AppendFormatString( messagePtr, _L("OwnrAddr: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfKernelOwner() );
       
   629     AppendFormatString( messagePtr, _L("KernelAddr: 0x%08X"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Handle() );
       
   630     
       
   631     // Object type specific attributes:
       
   632     switch ( iKernelObjectItems[iListBox->CurrentItemIndex()]->Type() )
       
   633         {
       
   634         case EMemSpyDriverContainerTypeUnknown:
       
   635             {
       
   636             break;
       
   637             }
       
   638         case EMemSpyDriverContainerTypeThread:
       
   639             {
       
   640             AppendFormatString( messagePtr, _L("\nOwnrPrAddr: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfOwningProcess() );
       
   641             AppendFormatString( messagePtr, _L("ThreadID: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Id() );
       
   642             AppendFormatString( messagePtr, _L("Priority: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Priority() );
       
   643             TFullName procName;
       
   644             procName.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->NameOfOwner() );
       
   645             AppendFormatString( messagePtr, _L("Proc: %S"), &procName );
       
   646             procName.Zero();
       
   647             break;
       
   648             }
       
   649         case EMemSpyDriverContainerTypeProcess:
       
   650             {
       
   651             AppendFormatString( messagePtr, _L("\nOwnrPrAddr: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfOwningProcess() );
       
   652             AppendFormatString( messagePtr, _L("CreatorId: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->CreatorId() );
       
   653             AppendFormatString( messagePtr, _L("Attributes: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Attributes() );
       
   654             AppendFormatString( messagePtr, _L("StckChnk: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfDataBssStackChunk() );
       
   655             AppendFormatString( messagePtr, _L("ProcessID: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Id() );
       
   656             AppendFormatString( messagePtr, _L("Priority: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Priority() );
       
   657             AppendFormatString( messagePtr, _L("SecurityZone: %d"), iKernelObjectItems[iListBox->CurrentItemIndex()]->SecurityZone() );
       
   658             /* TODO: to solve process details
       
   659             CMemSpyEngineObjectContainer& container = iEngine.Container();
       
   660             TProcessId id( iKernelObjectItems[iListBox->CurrentItemIndex().iId );
       
   661             TRAP_IGNORE(
       
   662                 CMemSpyProcess& process = container.ProcessByIdL( id );
       
   663                 AppendFormatString( messagePtr, _L("\nSID: 0x%08X\n"), process.SID() );
       
   664                 AppendFormatString( messagePtr, _L("VID: 0x%08X\n"), process.VID() );
       
   665                 AppendFormatString( messagePtr, _L("UID1: 0x%08X\n"), process.UIDs()[0].iUid  );
       
   666                 AppendFormatString( messagePtr, _L("UID2: 0x%08X\n"), process.UIDs()[1].iUid  );
       
   667                 AppendFormatString( messagePtr, _L("UID3: 0x%08X\n"), process.UIDs()[2].iUid );
       
   668                 AppendFormatString( messagePtr, _L("Caps: 0x%08X%08X"), process.Capabilities().iCaps[0], process.Capabilities().iCaps[1]);
       
   669                 );
       
   670             */
       
   671             break;
       
   672             }
       
   673         case EMemSpyDriverContainerTypeChunk:
       
   674             {
       
   675             AppendFormatString( messagePtr, _L("\nOwnrPrAddr: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfOwningProcess() );
       
   676             AppendFormatString( messagePtr, _L("Size: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Size() );
       
   677             AppendFormatString( messagePtr, _L("MaxSize: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->MaxSize() );
       
   678             AppendFormatString( messagePtr, _L("Bottom: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Bottom() );
       
   679             AppendFormatString( messagePtr, _L("Top: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Top() );
       
   680             AppendFormatString( messagePtr, _L("Attr: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Attributes() );
       
   681             AppendFormatString( messagePtr, _L("Start: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->StartPos() );
       
   682             AppendFormatString( messagePtr, _L("CntrlID: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->ControllingOwner() );
       
   683             AppendFormatString( messagePtr, _L("Restrictions: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Restrictions() );
       
   684             AppendFormatString( messagePtr, _L("MapAttr: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->MapAttr() );
       
   685             AppendFormatString( messagePtr, _L("Type: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->ChunkType() );
       
   686             TFullName procName;
       
   687             procName.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->NameOfOwner() );
       
   688             AppendFormatString( messagePtr, _L("Proc: %S"), &procName );
       
   689             procName.Zero();
       
   690             // OwnerAddr iAddressOfKernelOwner already listed
       
   691             // ProcAddr iAddressOfOwningProcess already listed
       
   692             break;
       
   693             }
       
   694         case EMemSpyDriverContainerTypeLibrary:
       
   695             {
       
   696             AppendFormatString( messagePtr, _L("\nMapCount: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->MapCount() );
       
   697             AppendFormatString( messagePtr, _L("State: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->State() );
       
   698             AppendFormatString( messagePtr, _L("CodeSeg: 0x%08X"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfCodeSeg() );
       
   699             break;
       
   700             }
       
   701         case EMemSpyDriverContainerTypeSemaphore:
       
   702             {
       
   703             AppendFormatString( messagePtr, _L("\nCount: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Count() );
       
   704             AppendFormatString( messagePtr, _L("Resetting: %u"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Resetting() );
       
   705             break;
       
   706             }
       
   707         case EMemSpyDriverContainerTypeMutex:
       
   708             {
       
   709             AppendFormatString( messagePtr, _L("\nHoldCount: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Count() );
       
   710             AppendFormatString( messagePtr, _L("WaitCount: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->WaitCount() );
       
   711             AppendFormatString( messagePtr, _L("Resetting: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Resetting() );
       
   712             AppendFormatString( messagePtr, _L("Order: %u"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Order() );
       
   713             break;
       
   714             }
       
   715         case EMemSpyDriverContainerTypeTimer:
       
   716             {
       
   717             AppendFormatString( messagePtr, _L("\nState: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->TimerState() );
       
   718             AppendFormatString( messagePtr, _L("Type: %d"), iKernelObjectItems[iListBox->CurrentItemIndex()]->TimerType() );
       
   719             break;
       
   720             }
       
   721         case EMemSpyDriverContainerTypeServer:
       
   722             {
       
   723             // Owner == ThrdAddr
       
   724             AppendFormatString( messagePtr, _L("\nThrdAddr: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfOwningThread() );
       
   725             TFullName thrName;
       
   726             thrName.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->NameOfOwner() );
       
   727             AppendFormatString( messagePtr, _L("Thr: %S\n"), &thrName );
       
   728             thrName.Zero();
       
   729             AppendFormatString( messagePtr, _L("Type: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->SessionType() );
       
   730             TBuf8<55>buf;
       
   731             RArray<TMemSpyDriverServerSessionInfo> sessions;
       
   732             CleanupClosePushL( sessions );
       
   733             /* TODO: to solve server sessions
       
   734             iEngine.HelperServer().GetServerSessionsL( iKernelObjectItems[iListBox->CurrentItemIndex(), sessions );
       
   735             const TInt count = sessions.Count();
       
   736             for ( TInt i = 0; i < count; i++ )
       
   737                 {
       
   738                 const TMemSpyDriverServerSessionInfo& session = sessions[ i ];
       
   739                 AppendFormatString( messagePtr, _L("SessAddr: 0x%08X\n"), session.iAddress );
       
   740                 TFullName sessName;
       
   741                 sessName.Copy( session.iName );
       
   742                 AppendFormatString( messagePtr, _L("Sess: %S\n"), &sessName );
       
   743                 }
       
   744             CleanupStack::PopAndDestroy( &sessions );
       
   745             */
       
   746             break;
       
   747             }
       
   748         case EMemSpyDriverContainerTypeSession:
       
   749             {
       
   750             // Server == SvrAddr
       
   751             AppendFormatString( messagePtr, _L("\nServer: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfServer() );
       
   752             TFullName srvName;
       
   753             srvName.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->Name() );
       
   754             AppendFormatString( messagePtr, _L("Srv: %S\n"), &srvName );
       
   755             srvName.Zero();
       
   756             // Session: not supported
       
   757             AppendFormatString( messagePtr, _L("AccCount: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->TotalAccessCount() );
       
   758             AppendFormatString( messagePtr, _L("SesType: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->SessionType() );
       
   759             AppendFormatString( messagePtr, _L("SvrType: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->SvrSessionType() );
       
   760             AppendFormatString( messagePtr, _L("MsgCount: %d\n"),  iKernelObjectItems[iListBox->CurrentItemIndex()]->MsgCount() );
       
   761             AppendFormatString( messagePtr, _L("MsgLimit: %d"), iKernelObjectItems[iListBox->CurrentItemIndex()]->MsgLimit() );
       
   762             break;
       
   763             }
       
   764         case EMemSpyDriverContainerTypeLogicalDevice:
       
   765             {
       
   766             AppendFormatString( messagePtr, 
       
   767                                 _L("\nVersion: %d.%d.%d\n"), 
       
   768                                 /*
       
   769                                 iKernelObjectItems[iListBox->CurrentItemIndex()]->Version.iMajor, TODO: To solve this
       
   770                                 iKernelObjectItems[iListBox->CurrentItemIndex()]->Version.iMinor,
       
   771                                 iKernelObjectItems[iListBox->CurrentItemIndex()]->Version.iBuild );
       
   772                                 */
       
   773                                 iKernelObjectItems[iListBox->CurrentItemIndex()]->Version(),
       
   774                                 iKernelObjectItems[iListBox->CurrentItemIndex()]->Version(),
       
   775                                 iKernelObjectItems[iListBox->CurrentItemIndex()]->Version() );
       
   776             AppendFormatString( messagePtr, _L("ParseMask: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->ParseMask() );
       
   777             AppendFormatString( messagePtr, _L("UnitsMask: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->UnitsMask() );
       
   778             AppendFormatString( messagePtr, _L("Open channels: %d"), iKernelObjectItems[iListBox->CurrentItemIndex()]->OpenChannels() );
       
   779             break;
       
   780             }
       
   781         case EMemSpyDriverContainerTypePhysicalDevice:
       
   782             {
       
   783             AppendFormatString( messagePtr, 
       
   784                                 _L("\nVersion: %d.%d.%d\n"), 
       
   785                                 iKernelObjectItems[iListBox->CurrentItemIndex()]->Version(),
       
   786                                 iKernelObjectItems[iListBox->CurrentItemIndex()]->Version(),
       
   787                                 iKernelObjectItems[iListBox->CurrentItemIndex()]->Version() );
       
   788             AppendFormatString( messagePtr, _L("UnitsMask: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->UnitsMask() );
       
   789             AppendFormatString( messagePtr, _L("CodeSeg: 0x%08X"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfCodeSeg() );
       
   790             break;
       
   791             }
       
   792         case EMemSpyDriverContainerTypeLogicalChannel:
       
   793             {
       
   794             // No other details
       
   795             break;
       
   796             }
       
   797         case EMemSpyDriverContainerTypeChangeNotifier:
       
   798             {
       
   799             AppendFormatString( messagePtr, _L("\nChanges: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Changes() );
       
   800             // Thread == ThrdAddr
       
   801             AppendFormatString( messagePtr, _L("ThrdAddr: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfOwningThread() );
       
   802             TFullName thrName;
       
   803             thrName.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->NameOfOwner() );
       
   804             AppendFormatString( messagePtr, _L("Thr: %S"), &thrName );
       
   805             thrName.Zero();
       
   806             break;
       
   807             }
       
   808         case EMemSpyDriverContainerTypeUndertaker:
       
   809             {
       
   810             // Thread == ThrdAddr
       
   811             AppendFormatString( messagePtr, _L("\nThrdAddr: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfOwningThread() );
       
   812             TFullName thrName;
       
   813             thrName.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->NameOfOwner() );
       
   814             AppendFormatString( messagePtr, _L("Thr: %S"), &thrName );
       
   815             thrName.Zero();
       
   816             break;
       
   817             }
       
   818         case EMemSpyDriverContainerTypeMsgQueue:
       
   819             {
       
   820             // No other details
       
   821             break;
       
   822             }
       
   823         case EMemSpyDriverContainerTypePropertyRef:
       
   824             {
       
   825             /*
       
   826             Not listing details here, as propertyRef is not listed in TaskMgr.
       
   827             Following propertyRef attributes are available at engine side. 
       
   828             
       
   829             IsReady
       
   830             Type
       
   831             Category
       
   832             Key
       
   833             RefCount
       
   834             ThreadId
       
   835             CreatorSID
       
   836             */
       
   837             break;
       
   838             }
       
   839         case EMemSpyDriverContainerTypeCondVar:
       
   840             {
       
   841             AppendFormatString( messagePtr, _L("\nResetting: %u\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->Resetting() );
       
   842             // Using iAddressOfOwningThread for mutex
       
   843             AppendFormatString( messagePtr, _L("Mutex: 0x%08X\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->AddressOfOwningThread() );
       
   844             // Using iNameOfOwner for mutex
       
   845             TFullName mtxName;
       
   846             mtxName.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->NameOfOwner() );
       
   847             AppendFormatString( messagePtr, _L("Mtx: %S\n"), &mtxName );
       
   848             mtxName.Zero();
       
   849             AppendFormatString( messagePtr, _L("WaitCount: %d\n"), iKernelObjectItems[iListBox->CurrentItemIndex()]->WaitCount() );
       
   850             
       
   851             RArray<TMemSpyDriverCondVarSuspendedThreadInfo> threads;
       
   852             CleanupClosePushL( threads );
       
   853             /* TODO: to solve thread cond. vars.
       
   854             iEngine.HelperCondVar().GetCondVarSuspendedThreadsL( iKernelObjectItems[iListBox->CurrentItemIndex(), threads );
       
   855             const TInt count = threads.Count();
       
   856             for ( TInt i = 0; i < count; i++ )
       
   857                 {
       
   858                 const TMemSpyDriverCondVarSuspendedThreadInfo& thr = threads[ i ];
       
   859                 AppendFormatString( messagePtr, _L("SuspThrdAddr: 0x%08X\n"), thr.iAddress );
       
   860                 TFullName thrName;
       
   861                 thrName.Copy( thr.iName );
       
   862                 AppendFormatString( messagePtr, _L("Thr: %S\n"), &thrName );
       
   863                 }
       
   864             CleanupStack::PopAndDestroy( &threads );
       
   865             */
       
   866             break;
       
   867             }
       
   868         default:
       
   869             {
       
   870             // Programming error
       
   871             __ASSERT_ALWAYS( EFalse, User::Panic( _L("MemSpy-View"), 0 ) );
       
   872             }
       
   873         }
       
   874     
       
   875     CAknMessageQueryDialog* dialog = new(ELeave) CAknMessageQueryDialog( CAknQueryDialog::ENoTone );
       
   876     dialog->PrepareLC( R_MEMSPY_KERNEL_OBJECT_DETAILS_DIALOG );
       
   877     TFileName headerText;
       
   878     headerText.Copy( iKernelObjectItems[iListBox->CurrentItemIndex()]->Name() );
       
   879     dialog->SetHeaderTextL( headerText );
       
   880     dialog->SetMessageTextL(messagePtr);
       
   881     dialog->RunLD();
       
   882     CleanupStack::PopAndDestroy( messageBuf );
       
   883     }
       
   884 
       
   885 
       
   886 void CMemSpyViewKernelObjects::AppendFormatString( TPtr& aPtr, TRefByValue<const TDesC> aFmt, ... )
       
   887     {
       
   888     TBuf<KMaxInfoLength> infoString;
       
   889     VA_LIST list;
       
   890     VA_START ( list, aFmt );
       
   891     infoString.FormatList( aFmt, list );
       
   892     aPtr.Append( infoString );
       
   893     }
       
   894