perfsrv/memspy/Driver/Kernel/Source/MemSpyDriverLogicalChannel.cpp
changeset 48 516af714ebb4
child 52 c2f44e33b468
equal deleted inserted replaced
45:185201be11b0 48:516af714ebb4
       
     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 "MemSpyDriverLogicalChannel.h"
       
    19 
       
    20 // System includes
       
    21 #include <u32hal.h>
       
    22 #include <e32rom.h>
       
    23 
       
    24 // User includes
       
    25 #include "MemSpyDriverUtils.h"
       
    26 #include "MemSpyDriverDevice.h"
       
    27 #include <memspy/driver/memspydriverconstants.h>
       
    28 #include "MemSpyDriverLogChanChunks.h"
       
    29 #include "MemSpyDriverLogChanClientServer.h"
       
    30 #include "MemSpyDriverLogChanCodeSegs.h"
       
    31 #include "MemSpyDriverLogChanContainers.h"
       
    32 #include "MemSpyDriverLogChanHeapData.h"
       
    33 #include "MemSpyDriverLogChanHeapWalk.h"
       
    34 #include "MemSpyDriverLogChanHeapInfo.h"
       
    35 #include "MemSpyDriverLogChanMisc.h"
       
    36 #include "MemSpyDriverLogChanProcessInspection.h"
       
    37 #include "MemSpyDriverLogChanStack.h"
       
    38 #include "MemSpyDriverLogChanRawMemory.h"
       
    39 #include "MemSpyDriverLogChanUserEventMonitor.h"
       
    40 #include "MemSpyDriverLogChanThreadAndProcess.h"
       
    41 
       
    42 
       
    43 DMemSpyDriverLogicalChannel::DMemSpyDriverLogicalChannel()
       
    44     {
       
    45     }
       
    46 
       
    47 
       
    48 DMemSpyDriverLogicalChannel::~DMemSpyDriverLogicalChannel()
       
    49 	{
       
    50 	TRACE( Kern::Printf("DMemSpyDriverLogicalChannel::~DMemSpyDriverLogicalChannel() - START"));
       
    51 
       
    52     NKern::ThreadEnterCS();
       
    53     SubChannelsDestroy();
       
    54 
       
    55     TRACE( Kern::Printf("DMemSpyDriverLogicalChannel::~DMemSpyDriverLogicalChannel() - closing client thread..."));
       
    56     Kern::SafeClose( (DObject*&) iClientThread, NULL );
       
    57     NKern::ThreadLeaveCS();
       
    58 
       
    59     TRACE( Kern::Printf("DMemSpyDriverLogicalChannel::~DMemSpyDriverLogicalChannel() - calling device to cleanup..."));
       
    60     MemSpyDevice().Cleanup();
       
    61 
       
    62     TRACE( Kern::Printf("DMemSpyDriverLogicalChannel::~DMemSpyDriverLogicalChannel() - END"));
       
    63 	}
       
    64 
       
    65 
       
    66 TInt DMemSpyDriverLogicalChannel::DoCreate( TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& aVer )
       
    67 	{
       
    68 	TRACE( Kern::Printf("DMemSpyDriverLogicalChannel::DoCreate() - START - heldFM: %d, device: 0x%08x", Kern::CurrentThread().iNThread.iHeldFastMutex != NULL, &MemSpyDevice() ) );
       
    69 
       
    70     TInt error = KErrNone;
       
    71     //
       
    72     if  ( !Kern::QueryVersionSupported( KMemSpyDriverVersion(), aVer ) )
       
    73         {
       
    74         error = KErrNotSupported;
       
    75         }
       
    76     else
       
    77         {
       
    78         // Try to get the memory model type
       
    79         
       
    80     	TRACE( Kern::Printf("DMemSpyDriverLogicalChannel::DoCreate - opening client thread..."));
       
    81 
       
    82         iClientThread = &Kern::CurrentThread();
       
    83 	    error = iClientThread->Open();
       
    84         TRACE( Kern::Printf("DMemSpyDriverLogicalChannel::DoCreate - client thread open error: %d", error ));
       
    85 
       
    86         if  ( error == KErrNone )
       
    87             {
       
    88             TRACE( Kern::Printf("DMemSpyDriverLogicalChannel::DoCreate - creating sub channels error: %d", error ));
       
    89             error = SubChannelsRegister();
       
    90             }
       
    91         }
       
    92     //
       
    93 	TRACE( Kern::Printf("DMemSpyDriverLogicalChannel::DoCreate() - END - heldFM: %d", Kern::CurrentThread().iNThread.iHeldFastMutex != NULL ) );
       
    94     return error;
       
    95 	}
       
    96 
       
    97 
       
    98 
       
    99 
       
   100 
       
   101 
       
   102 
       
   103 
       
   104 
       
   105 
       
   106 
       
   107 
       
   108 TInt DMemSpyDriverLogicalChannel::Request( TInt aFunction, TAny* a1, TAny* a2 )
       
   109 	{
       
   110 	TRACE( Kern::Printf(" " ) );
       
   111 	TRACE( Kern::Printf(" " ) );
       
   112 	TRACE( Kern::Printf("--------------------------------------------------------------------------------------------------------------------- " ) );
       
   113 	TRACE_OP( Kern::Printf("DMemSpyDriverLogicalChannel::Request() - START - fn: %3d, a1: 0x%08x, a2: 0x%08x, heldFM: %d", aFunction, a1, a2, iClientThread->iNThread.iHeldFastMutex != NULL ) );
       
   114 	TRACE( Kern::Printf("--------------------------------------------------------------------------------------------------------------------- " ) );
       
   115 	//
       
   116     TInt r = KErrNotSupported;
       
   117     //
       
   118     DMemSpyDriverLogChanBase* handler = SubChannelForFunction( aFunction );
       
   119     if  ( handler )
       
   120         {
       
   121         r = handler->Request( aFunction, a1, a2 );
       
   122         }
       
   123     //
       
   124 #ifdef _DEBUG
       
   125     if  ( r < 0 && r != KErrEof )
       
   126         {
       
   127 	    Kern::Printf( "DMemSpyDriverLogicalChannel::Request() - END - fn: %3d, a1: 0x%08x, a2: 0x%08x, heldFM: %d, r: %d", aFunction, a1, a2, iClientThread->iNThread.iHeldFastMutex != NULL, r );
       
   128         }
       
   129 #endif
       
   130 	TRACE( Kern::Printf(" " ) );
       
   131 	TRACE( Kern::Printf(" " ) );
       
   132     //
       
   133     return r;
       
   134 	}
       
   135 
       
   136 
       
   137 
       
   138 
       
   139 
       
   140 
       
   141 
       
   142 
       
   143 
       
   144 
       
   145 
       
   146 
       
   147 
       
   148 TInt DMemSpyDriverLogicalChannel::SubChannelsRegister()
       
   149     {
       
   150     TInt r = KErrNone;
       
   151     DMemSpyDriverDevice& device = MemSpyDevice();
       
   152     DMemSpyDriverLogChanBase* subChan = NULL;
       
   153     //
       
   154     subChan = new DMemSpyDriverLogChanChunks( device, *iClientThread );
       
   155     r = SubChannelConstructAndSave( subChan );
       
   156     if ( r != KErrNone )
       
   157         {
       
   158         return r;
       
   159         }
       
   160     //
       
   161     subChan = new DMemSpyDriverLogChanClientServer( device, *iClientThread );
       
   162     r = SubChannelConstructAndSave( subChan );
       
   163     if ( r != KErrNone )
       
   164         {
       
   165         return r;
       
   166         }
       
   167     //
       
   168     subChan = new DMemSpyDriverLogChanCodeSegs( device, *iClientThread );
       
   169     r = SubChannelConstructAndSave( subChan );
       
   170     if ( r != KErrNone )
       
   171         {
       
   172         return r;
       
   173         }
       
   174     //
       
   175     subChan = new DMemSpyDriverLogChanContainers( device, *iClientThread );
       
   176     r = SubChannelConstructAndSave( subChan );
       
   177     if ( r != KErrNone )
       
   178         {
       
   179         return r;
       
   180         }
       
   181     //
       
   182     subChan = new DMemSpyDriverLogChanHeapData( device, *iClientThread );
       
   183     r = SubChannelConstructAndSave( subChan );
       
   184     if ( r != KErrNone )
       
   185         {
       
   186         return r;
       
   187         }
       
   188     //
       
   189     subChan = new DMemSpyDriverLogChanHeapInfo( device, *iClientThread );
       
   190     r = SubChannelConstructAndSave( subChan );
       
   191     if ( r != KErrNone )
       
   192         {
       
   193         return r;
       
   194         }
       
   195     //
       
   196     subChan = new DMemSpyDriverLogChanHeapWalk( device, *iClientThread );
       
   197     r = SubChannelConstructAndSave( subChan );
       
   198     if ( r != KErrNone )
       
   199         {
       
   200         return r;
       
   201         }
       
   202     //
       
   203     subChan = new DMemSpyDriverLogChanMisc( device, *iClientThread );
       
   204     r = SubChannelConstructAndSave( subChan );
       
   205     if ( r != KErrNone )
       
   206         {
       
   207         return r;
       
   208         }
       
   209     //
       
   210     subChan = new DMemSpyDriverLogChanProcessInspection( device, *iClientThread );
       
   211     r = SubChannelConstructAndSave( subChan );
       
   212     if ( r != KErrNone )
       
   213         {
       
   214         return r;
       
   215         }
       
   216     //
       
   217     subChan = new DMemSpyDriverLogChanRawMemory( device, *iClientThread );
       
   218     r = SubChannelConstructAndSave( subChan );
       
   219     if ( r != KErrNone )
       
   220         {
       
   221         return r;
       
   222         }
       
   223     //
       
   224     subChan = new DMemSpyDriverLogChanStack( device, *iClientThread );
       
   225     r = SubChannelConstructAndSave( subChan );
       
   226     if ( r != KErrNone )
       
   227         {
       
   228         return r;
       
   229         }
       
   230     //
       
   231     subChan = new DMemSpyDriverLogChanThreadAndProcess( device, *iClientThread );
       
   232     r = SubChannelConstructAndSave( subChan );
       
   233     if ( r != KErrNone )
       
   234         {
       
   235         return r;
       
   236         }
       
   237     //
       
   238     subChan = new DMemSpyDriverLogChanUserEventMonitor( device, *iClientThread );
       
   239     r = SubChannelConstructAndSave( subChan );
       
   240     if ( r != KErrNone )
       
   241         {
       
   242         return r;
       
   243         }
       
   244     //
       
   245     return r;
       
   246     }
       
   247 
       
   248 
       
   249 TInt DMemSpyDriverLogicalChannel::SubChannelConstructAndSave( DMemSpyDriverLogChanBase*& aSubChannel )
       
   250     {
       
   251     TInt r = KErrNoMemory;
       
   252     //
       
   253     if ( aSubChannel )
       
   254         {
       
   255         NKern::ThreadEnterCS();
       
   256         r = aSubChannel->Construct();
       
   257         //
       
   258         if  ( r == KErrNone )
       
   259             {
       
   260             r = iSubChannels.Append( aSubChannel );
       
   261             if  ( r != KErrNone )
       
   262                 {
       
   263                 delete aSubChannel;
       
   264                 }
       
   265             }
       
   266         else
       
   267             {
       
   268             delete aSubChannel;
       
   269             }
       
   270         //
       
   271         NKern::ThreadLeaveCS();
       
   272         }
       
   273     //
       
   274     aSubChannel = NULL;
       
   275     return r;
       
   276     }
       
   277 
       
   278 
       
   279 void DMemSpyDriverLogicalChannel::SubChannelsDestroy()
       
   280     {
       
   281     const TInt count = iSubChannels.Count();
       
   282 	TRACE( Kern::Printf("DMemSpyDriverLogicalChannel::SubChannelsDestroy() - START - count: %d", count ) );
       
   283     //
       
   284     NKern::ThreadEnterCS();
       
   285     for( TInt i=0; i<count; i++ )
       
   286         {
       
   287         DMemSpyDriverLogChanBase* subChan = iSubChannels[ i ];
       
   288 	    TRACE( Kern::Printf("DMemSpyDriverLogicalChannel::SubChannelsDestroy() - deleting subChannel: 0x%08x", subChan ) );
       
   289         delete subChan;
       
   290         }
       
   291     //
       
   292     iSubChannels.Reset();
       
   293     NKern::ThreadLeaveCS();
       
   294     //
       
   295 	TRACE( Kern::Printf("DMemSpyDriverLogicalChannel::SubChannelsDestroy() - END" ) );
       
   296     }
       
   297 
       
   298 
       
   299 DMemSpyDriverLogChanBase* DMemSpyDriverLogicalChannel::SubChannelForFunction( TInt aFunction )
       
   300     {
       
   301 	TRACE( Kern::Printf("DMemSpyDriverLogicalChannel::SubChannelForFunction() - START - aFunction: %d", aFunction ) );
       
   302     //
       
   303     DMemSpyDriverLogChanBase* ret = NULL;
       
   304     const TInt count = iSubChannels.Count();
       
   305     for( TInt i=0; i<count; i++ )
       
   306         {
       
   307         DMemSpyDriverLogChanBase* subChan = iSubChannels[ i ];
       
   308         if  ( subChan->IsHandler( aFunction ) )
       
   309             {
       
   310             ret = subChan;
       
   311             break;
       
   312             }
       
   313         }
       
   314     //
       
   315 	TRACE( Kern::Printf("DMemSpyDriverLogicalChannel::SubChannelForFunction() - END - aFunction: %d, subChannel: 0x%08x", aFunction, ret ) );
       
   316     return ret;
       
   317     }
       
   318 
       
   319 
       
   320 DMemSpyDriverDevice& DMemSpyDriverLogicalChannel::MemSpyDevice()
       
   321     {
       
   322     DMemSpyDriverDevice& device = *((DMemSpyDriverDevice*) iDevice);
       
   323     return device;
       
   324     }
       
   325