memspy/Console/Source/ConsoleMenu.cpp
branchRCL_3
changeset 21 52e343bb8f80
parent 20 ca8a1b6995f6
--- a/memspy/Console/Source/ConsoleMenu.cpp	Tue Aug 31 16:45:49 2010 +0300
+++ b/memspy/Console/Source/ConsoleMenu.cpp	Wed Sep 01 12:37:10 2010 +0100
@@ -39,17 +39,18 @@
 #include "ConsoleDWOperation.h"
 
 
-CMemSpyConsoleMenu::CMemSpyConsoleMenu( RMemSpySession& aSession, CConsoleBase& aConsole )
-:   CActive( EPriorityHigh ), iSession( aSession ), iConsole( aConsole ), iOutputType(EOutputTypeDebug)
+CMemSpyConsoleMenu::CMemSpyConsoleMenu( CMemSpyEngine& aEngine, CConsoleBase& aConsole )
+:   CActive( EPriorityHigh ), iEngine( aEngine ), iConsole( aConsole )
     {
     CActiveScheduler::Add( this );
-    // TODO: iEngine.SetObserver( this );
+    iEngine.SetObserver( this );
     }
 
 
 CMemSpyConsoleMenu::~CMemSpyConsoleMenu()
     {
     Cancel();
+    iEngine.SetObserver( NULL );
     }
 
 
@@ -60,9 +61,9 @@
     }
 
 
-CMemSpyConsoleMenu* CMemSpyConsoleMenu::NewLC( RMemSpySession& aSession, CConsoleBase& aConsole )
+CMemSpyConsoleMenu* CMemSpyConsoleMenu::NewLC( CMemSpyEngine& aEngine, CConsoleBase& aConsole )
     {
-    CMemSpyConsoleMenu* self = new(ELeave) CMemSpyConsoleMenu( aSession, aConsole );
+    CMemSpyConsoleMenu* self = new(ELeave) CMemSpyConsoleMenu( aEngine, aConsole );
     CleanupStack::PushL( self );
     self->ConstructL();
     return self;
@@ -75,7 +76,7 @@
    
     // First line - sink type (defaults to file)
     _LIT( KLine1, "1 or T. Toggle output mode between file or trace [%S]" );
-    if  ( iOutputType == EOutputTypeDebug )
+    if  ( iEngine.SinkType() == ESinkTypeDebug )
         {
         _LIT( KLine1Trace, "Trace" );
         iConsole.Printf( KLine1, &KLine1Trace );
@@ -203,7 +204,14 @@
 
 void CMemSpyConsoleMenu::OnCmdSinkTypeToggleL()
     {
-	iOutputType = iOutputType == EOutputTypeFile ? EOutputTypeDebug : EOutputTypeFile;
+    if  ( iEngine.SinkType() == ESinkTypeDebug )
+        {
+        iEngine.InstallSinkL( ESinkTypeFile );
+        }
+    else
+        {
+        iEngine.InstallSinkL( ESinkTypeDebug );
+        }
     }
 
 
@@ -216,7 +224,7 @@
     _LIT( KMsg, "Ouputting Kernel data..." );
     RedrawStatusMessage( KMsg );
 
-    iSession.OutputKernelHeapDataL( iOutputType );
+    iEngine.HelperHeap().OutputHeapDataKernelL();
 
     RedrawStatusMessage( KNullDesC );
     }
@@ -231,7 +239,14 @@
     _LIT( KMsg, "Ouputting Kernel Object listing..." );
     RedrawStatusMessage( KMsg );
     //
-    iSession.OutputKernelObjectsL( iOutputType );
+    CMemSpyEngineHelperKernelContainers& kernelContainerManager = iEngine.HelperKernelContainers();
+    CMemSpyEngineGenericKernelObjectContainer* model = kernelContainerManager.ObjectsAllL();
+    CleanupStack::PushL( model );
+    //
+    CMemSpyEngineOutputSink& sink = iEngine.Sink();
+    model->OutputL( sink );
+    //
+    CleanupStack::PopAndDestroy( model );
 
     RedrawStatusMessage( KNullDesC );
     }
@@ -243,7 +258,7 @@
     RDebug::Printf( "[MCon] CMemSpyConsoleMenu::OnCmdCSVListingStackL() - START" );
 #endif
 
-    iSession.OutputCompactStackInfoL( iOutputType );
+    iEngine.HelperStack().OutputStackInfoForDeviceL();
     }
 
 
@@ -253,7 +268,7 @@
     RDebug::Printf( "[MCon] CMemSpyConsoleMenu::OnCmdCSVListingHeapL() - START" );
 #endif
 
-    iSession.OutputCompactHeapInfoL( iOutputType );
+    iEngine.HelperHeap().OutputHeapInfoForDeviceL();
     }
 
 
@@ -281,34 +296,44 @@
         TPtr pCmdBuf( cmdBuf->Des() );
         pCmdBuf.Copy( iCommandBuffer );
         pCmdBuf.Append( KMemSpyConsoleWildcardCharacter );
-        
-        TInt err;
-        TProcessId procId;
-        TRAP(err, procId = iSession.GetProcessIdByNameL(pCmdBuf));
+        //
+        CMemSpyEngineObjectContainer& container = iEngine.Container();
+        const TInt count = container.Count();
+        TFullName fullThreadName;
         //
-        if (err == KErrNone) 
-        	{
-        	RArray<CMemSpyApiThread*> threads;
-        	
-        	TRAP(err, iSession.GetThreadsL(procId, threads));
-        	if (err == KErrNone)
-        		{
-				_LIT( KProcessingRequest, "** Dumping Heap Data for thread: %S" );     	
-				TFullName fullThreadName;
-				
-                for( TInt i=0; i<threads.Count(); i++ )
+        TInt index = 0;
+#ifdef _DEBUG
+        RDebug::Printf( "[MCon] CMemSpyConsoleMenu::OnCmdHeapDataUserL() - procCount: %d", count );
+#endif
+
+        while( index < count )
+            {
+            CMemSpyProcess& process = container.At( index );
+            const TPtrC processName( process.Name() );
+#ifdef _DEBUG
+            RDebug::Print( _L("[MCon] CMemSpyConsoleMenu::OnCmdHeapDataUserL() - procName: 0x%08x %S"), &process, &processName );
+#endif
+
+            //
+            if  ( processName.MatchF( pCmdBuf ) >= 0 )
+                {
+                _LIT( KProcessingRequest, "** Dumping Heap Data for thread: %S" );
+                const TInt threadCount = process.Count();
+                for( TInt i=0; i<threadCount; i++ )
                     {
-                    CMemSpyApiThread* thread = threads[i];
+                    CMemSpyThread& thread = process.At( i );
                     //
-                    fullThreadName = thread->Name();
+                    fullThreadName = thread.FullName();
                     iConsole.Printf( KProcessingRequest, &fullThreadName );
                     iConsole.Write( KMemSpyConsoleNewLine );
                     //
-                    TRAP_IGNORE( iSession.OutputThreadHeapDataL(iOutputType, thread->Id()) );
-                    
-                    delete thread;
+                    TRAP_IGNORE( iEngine.HelperHeap().OutputHeapDataUserL( thread ) );
                     }
+
+                break;
                 }
+            
+            ++index;
             }
 
         CleanupStack::PopAndDestroy( cmdBuf );
@@ -344,36 +369,38 @@
         TPtr pCmdBuf( cmdBuf->Des() );
         pCmdBuf.Copy( iCommandBuffer );
         pCmdBuf.Append( KMemSpyConsoleWildcardCharacter );
-        
-        TInt err;
-		TProcessId procId;
-		TRAP(err, procId = iSession.GetProcessIdByNameL(pCmdBuf));
-		//
-		if (err == KErrNone) 
-			{
-			RArray<CMemSpyApiThread*> threads;
-			
-			TRAP(err, iSession.GetThreadsL(procId, threads));
-			if (err == KErrNone)
-				{
-				_LIT( KProcessingRequest, "** Dumping Heap Cell List for thread: %S" );     	
-				TFullName fullThreadName;
-				
-				for( TInt i=0; i<threads.Count(); i++ )
-					{
-					CMemSpyApiThread* thread = threads[i];
-					//
-					fullThreadName = thread->Name();
-					iConsole.Printf( KProcessingRequest, &fullThreadName );
-					iConsole.Write( KMemSpyConsoleNewLine );
-					//
-					TRAP_IGNORE( iSession.OutputThreadCellListL(iOutputType, thread->Id()) );
-					
-					delete thread;
-					}
-				}
-			}
-        
+        //
+        CMemSpyEngineObjectContainer& container = iEngine.Container();
+        const TInt count = container.Count();
+        TFullName fullThreadName;
+        //
+        TInt index = 0;
+        while( index < count )
+            {
+            CMemSpyProcess& process = container.At( index );
+            const TPtrC processName( process.Name() );
+            //
+            if  ( processName.MatchF( pCmdBuf ) >= 0 )
+                {
+                _LIT( KProcessingRequest, "** Dumping Heap Cell List for thread: %S" );
+                const TInt threadCount = process.Count();
+                for( TInt i=0; i<threadCount; i++ )
+                    {
+                    CMemSpyThread& thread = process.At( i );
+                    //
+                    fullThreadName = thread.FullName();
+                    iConsole.Printf( KProcessingRequest, &fullThreadName );
+                    iConsole.Write( KMemSpyConsoleNewLine );
+                    //
+                    TRAP_IGNORE( iEngine.HelperHeap().OutputCellListingUserL( thread ) );
+                    }
+
+                break;
+                }
+            
+            ++index;
+            }
+
         CleanupStack::PopAndDestroy( cmdBuf );
         DrawMenuL();
         }
@@ -577,72 +604,71 @@
 
 void CMemSpyConsoleMenu::InitiateMemSpyClientServerOperationL( TInt aOpCode )
     {
-	// TODO: ....
-//#ifdef _DEBUG
-//    RDebug::Printf( "[MCon] CMemSpyConsoleMenu::InitiateMemSpyClientServerOperationL() - START - aOpCode: %d, iRunningDeviceWideOperation: %d", aOpCode, iRunningDeviceWideOperation );
-//#endif
-//    //
-//    if ( aOpCode == EMemSpyClientServerOpExit )
-//        {
-//        // Exit console app UI
-//        CActiveScheduler::Stop();
-//        }
-//    else
-//        {
-//        CMemSpyDeviceWideOperations::TOperation op = CMemSpyDeviceWideOperations::EPerEntityGeneralSummary;
-//        switch( aOpCode )
-//            {
-//        case EMemSpyClientServerOpSummaryInfo:
-//            op = CMemSpyDeviceWideOperations::EPerEntityGeneralSummary;
-//            break;
-//        case EMemSpyClientServerOpSummaryInfoDetailed:
-//            op = CMemSpyDeviceWideOperations::EPerEntityGeneralDetailed;
-//            break;
-//        //
-//        case EMemSpyClientServerOpHeapInfo:
-//            op = CMemSpyDeviceWideOperations::EPerEntityHeapInfo;
-//            break;
-//        case EMemSpyClientServerOpHeapCellListing:
-//            op = CMemSpyDeviceWideOperations::EPerEntityHeapCellListing;
-//            break;
-//        case EMemSpyClientServerOpHeapData:
-//            op = CMemSpyDeviceWideOperations::EPerEntityHeapData;
-//            break;
-//        //
-//        case EMemSpyClientServerOpStackInfo:
-//            op = CMemSpyDeviceWideOperations::EPerEntityStackInfo;
-//            break;
-//        case EMemSpyClientServerOpStackDataUser:
-//            op = CMemSpyDeviceWideOperations::EPerEntityStackDataUser;
-//            break;
-//        case EMemSpyClientServerOpStackDataKernel:
-//            op = CMemSpyDeviceWideOperations::EPerEntityStackDataKernel;
-//            break;
-//        
-//        // These are not supported by the console UI
-//        default:
-//        case EMemSpyClientServerOpBitmapsSave:
-//        case EMemSpyClientServerOpSendToBackground:
-//        case EMemSpyClientServerOpBringToForeground:
-//            User::Leave( KErrNotSupported );
-//            break;
-//            }
-//
-//        if  ( iRunningDeviceWideOperation )
-//            {
-//            User::Leave( KErrInUse );
-//            }
-//        else
-//            {
-//            iRunningDeviceWideOperation = ETrue;
-//            TRAP_IGNORE( CMemSpyDeviceWideOperationWaiter::ExecuteLD( iEngine, op ) );
-//            iRunningDeviceWideOperation = EFalse;
-//            }
-//        }
-//
-//#ifdef _DEBUG
-//    RDebug::Printf( "[MCon] CMemSpyConsoleMenu::InitiateMemSpyClientServerOperationL() - END - aOpCode: %d", aOpCode );
-//#endif
+#ifdef _DEBUG
+    RDebug::Printf( "[MCon] CMemSpyConsoleMenu::InitiateMemSpyClientServerOperationL() - START - aOpCode: %d, iRunningDeviceWideOperation: %d", aOpCode, iRunningDeviceWideOperation );
+#endif
+    //
+    if ( aOpCode == EMemSpyClientServerOpExit )
+        {
+        // Exit console app UI
+        CActiveScheduler::Stop();
+        }
+    else
+        {
+        CMemSpyDeviceWideOperations::TOperation op = CMemSpyDeviceWideOperations::EPerEntityGeneralSummary;
+        switch( aOpCode )
+            {
+        case EMemSpyClientServerOpSummaryInfo:
+            op = CMemSpyDeviceWideOperations::EPerEntityGeneralSummary;
+            break;
+        case EMemSpyClientServerOpSummaryInfoDetailed:
+            op = CMemSpyDeviceWideOperations::EPerEntityGeneralDetailed;
+            break;
+        //
+        case EMemSpyClientServerOpHeapInfo:
+            op = CMemSpyDeviceWideOperations::EPerEntityHeapInfo;
+            break;
+        case EMemSpyClientServerOpHeapCellListing:
+            op = CMemSpyDeviceWideOperations::EPerEntityHeapCellListing;
+            break;
+        case EMemSpyClientServerOpHeapData:
+            op = CMemSpyDeviceWideOperations::EPerEntityHeapData;
+            break;
+        //
+        case EMemSpyClientServerOpStackInfo:
+            op = CMemSpyDeviceWideOperations::EPerEntityStackInfo;
+            break;
+        case EMemSpyClientServerOpStackDataUser:
+            op = CMemSpyDeviceWideOperations::EPerEntityStackDataUser;
+            break;
+        case EMemSpyClientServerOpStackDataKernel:
+            op = CMemSpyDeviceWideOperations::EPerEntityStackDataKernel;
+            break;
+        
+        // These are not supported by the console UI
+        default:
+        case EMemSpyClientServerOpBitmapsSave:
+        case EMemSpyClientServerOpSendToBackground:
+        case EMemSpyClientServerOpBringToForeground:
+            User::Leave( KErrNotSupported );
+            break;
+            }
+
+        if  ( iRunningDeviceWideOperation )
+            {
+            User::Leave( KErrInUse );
+            }
+        else
+            {
+            iRunningDeviceWideOperation = ETrue;
+            TRAP_IGNORE( CMemSpyDeviceWideOperationWaiter::ExecuteLD( iEngine, op ) );
+            iRunningDeviceWideOperation = EFalse;
+            }
+        }
+
+#ifdef _DEBUG
+    RDebug::Printf( "[MCon] CMemSpyConsoleMenu::InitiateMemSpyClientServerOperationL() - END - aOpCode: %d", aOpCode );
+#endif
     }