memspy/Driver/Kernel/Source/MemSpyDriverDevice.cpp
changeset 0 a03f92240627
equal deleted inserted replaced
-1:000000000000 0:a03f92240627
       
     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 "MemSpyDriverDevice.h"
       
    19 
       
    20 // System includes
       
    21 #include <memspy/driver/memspydriverconstants.h>
       
    22 
       
    23 // User includes
       
    24 #include "MemSpyDriverUtils.h"
       
    25 #include "MemSpyDriverOSAdaption.h"
       
    26 #include "MemSpyDriverEventMonitor.h"
       
    27 #include "MemSpyDriverLogicalChannel.h"
       
    28 #include "MemSpyDriverSuspensionManager.h"
       
    29 #include "MemSpyDriverInspectedProcessManager.h"
       
    30 
       
    31 
       
    32 
       
    33 DMemSpyDriverDevice::DMemSpyDriverDevice()
       
    34 	{
       
    35 	iVersion = KMemSpyDriverVersion();
       
    36 	}
       
    37 
       
    38 
       
    39 DMemSpyDriverDevice::~DMemSpyDriverDevice()
       
    40     {
       
    41 	TRACE( Kern::Printf("DMemSpyDriverDevice::~DMemSpyDriverDevice() - START"));
       
    42 
       
    43     Cleanup();
       
    44     
       
    45     TRACE( Kern::Printf("DMemSpyDriverDevice::~DMemSpyDriverDevice() - END"));
       
    46     }
       
    47 
       
    48 
       
    49 TInt DMemSpyDriverDevice::Install()
       
    50 	{
       
    51 	TRACE( Kern::Printf("DMemSpyDriverDevice::Install() - START"));
       
    52     TInt error = KErrNone;
       
    53     //
       
    54 	TRACE( Kern::Printf("DMemSpyDriverDevice::Install() - creating event monitor..."));
       
    55 	iEventMonitor = new DMemSpyEventMonitor();
       
    56 	//
       
    57 	if	( iEventMonitor != NULL )
       
    58     	{
       
    59 	    TRACE( Kern::Printf("DMemSpyDriverDevice::Install() - constructing event monitor..."));
       
    60 		error = iEventMonitor->Create( this );
       
    61 		//
       
    62 		if	( error == KErrNone )
       
    63 			{
       
    64 	        TRACE( Kern::Printf("DMemSpyDriverDevice::Install() - starting event monitor..."));
       
    65 			error = iEventMonitor->Start();
       
    66 			//
       
    67 			if	( error == KErrNone )
       
    68 				{
       
    69 	            TRACE( Kern::Printf("DMemSpyDriverDevice::Install() - creating process manager..."));
       
    70                 iProcessManager = new DMemSpyInspectedProcessManager();
       
    71                 //
       
    72                 if  ( iProcessManager != NULL )
       
    73                     {
       
    74 	                TRACE( Kern::Printf("DMemSpyDriverDevice::Install() - constructing process manager..."));
       
    75                     error = iProcessManager->Create( this );
       
    76                     //
       
    77                     if  ( error == KErrNone )
       
    78                         {
       
    79 	                    TRACE( Kern::Printf("DMemSpyDriverDevice::Install() - creating process manager..."));
       
    80                         iSuspensionManager = new DMemSpySuspensionManager( *this );
       
    81                         //
       
    82                         if  ( iSuspensionManager != NULL )
       
    83                             {
       
    84 	                        TRACE( Kern::Printf("DMemSpyDriverDevice::Install() - constructing process manager..."));
       
    85                             error = iSuspensionManager->Construct();
       
    86                             //
       
    87                             if  ( error == KErrNone )
       
    88                                 {
       
    89 	                            TRACE( Kern::Printf("DMemSpyDriverDevice::Install() - creating os adaption..."));
       
    90                                 iOSAdaption = new DMemSpyDriverOSAdaption( *this );
       
    91                                 //
       
    92                                 if  ( iOSAdaption != NULL )
       
    93                                     {
       
    94 	                                TRACE( Kern::Printf("DMemSpyDriverDevice::Install() - constructing os adaption..."));
       
    95                                     error = iOSAdaption->Construct();
       
    96                                     //
       
    97                                     if  ( error == KErrNone )
       
    98                                         {
       
    99                                         TRACE( Kern::Printf("DMemSpyDriverDevice::Install() - setting name..."));
       
   100 				                        error = SetName( &KMemSpyDriverDeviceName );
       
   101                                         }
       
   102                                     }
       
   103                                 }
       
   104                             }
       
   105                         }
       
   106                     }
       
   107 				}
       
   108 			}
       
   109         }
       
   110     
       
   111     // Handle errors
       
   112     if  ( error != KErrNone )
       
   113         {
       
   114 	    TRACE( Kern::Printf("DMemSpyDriverDevice::Install() - error: %d", error ));
       
   115         if  ( iProcessManager )
       
   116             {
       
   117 	        TRACE( Kern::Printf("DMemSpyDriverDevice::Install() - closing PM" ));
       
   118             iProcessManager->Close( NULL );
       
   119             iProcessManager = NULL;
       
   120             }
       
   121         if  ( iEventMonitor )
       
   122             {
       
   123 	        TRACE( Kern::Printf("DMemSpyDriverDevice::Install() - stopping EM" ));
       
   124             iEventMonitor->Stop();
       
   125 	        TRACE( Kern::Printf("DMemSpyDriverDevice::Install() - closing EM" ));
       
   126             iEventMonitor->Close();
       
   127 	        TRACE( Kern::Printf("DMemSpyDriverDevice::Install() - deleting EM" ));
       
   128             iEventMonitor = NULL;
       
   129             }
       
   130         if  ( iSuspensionManager )
       
   131             {
       
   132 	        TRACE( Kern::Printf("DMemSpyDriverDevice::Install() - deleting SM" ));
       
   133             delete iSuspensionManager;
       
   134             iSuspensionManager = NULL;
       
   135             }
       
   136         }
       
   137     //
       
   138 	TRACE( Kern::Printf("DMemSpyDriverDevice::Install() - END - error: %d", error ));
       
   139 	return error;
       
   140 	}
       
   141 
       
   142 
       
   143 void DMemSpyDriverDevice::GetCaps( TDes8& /*aDes*/ ) const
       
   144 	{
       
   145 	}
       
   146 
       
   147 
       
   148 TInt DMemSpyDriverDevice::Create( DLogicalChannelBase*& aChannel )
       
   149 	{
       
   150     TRACE( Kern::Printf("DMemSpyDriverDevice::Create() - START"));
       
   151     TInt r = KErrNoMemory;
       
   152     //
       
   153 	aChannel = new DMemSpyDriverLogicalChannel;
       
   154     //
       
   155     if  ( aChannel )
       
   156         {
       
   157         if  ( iProcessManager == NULL && iEventMonitor == NULL && iSuspensionManager == NULL )
       
   158             {
       
   159             TRACE( Kern::Printf("DMemSpyDriverDevice::Create() - need to re-create objects, calling Install()"));
       
   160             r = Install();
       
   161             TRACE( Kern::Printf("DMemSpyDriverDevice::Create() - called Install()"));
       
   162             }
       
   163         else
       
   164             {
       
   165             r = KErrNone;
       
   166             }
       
   167         }
       
   168     //
       
   169     TRACE( Kern::Printf("DMemSpyDriverDevice::Create() - END - r: %d", r ));
       
   170 	return r;
       
   171 	}
       
   172 
       
   173 
       
   174 void DMemSpyDriverDevice::Cleanup()
       
   175     {
       
   176 
       
   177     NKern::ThreadEnterCS();
       
   178     if  ( iProcessManager )
       
   179         {
       
   180 	    TRACE( Kern::Printf("DMemSpyDriverDevice::Cleanup() - destroying process manager..."));
       
   181         iProcessManager->Close( NULL );
       
   182 	    TRACE( Kern::Printf("DMemSpyDriverDevice::Cleanup() - process manager destroyed"));
       
   183         iProcessManager = NULL;
       
   184         }
       
   185     
       
   186     if  ( iEventMonitor )
       
   187         {
       
   188 	    TRACE( Kern::Printf("DMemSpyDriverDevice::Cleanup() - destroying event monitor..."));
       
   189         iEventMonitor->Stop();
       
   190 	    TRACE( Kern::Printf("DMemSpyDriverDevice::Cleanup() - stopped event monitor..."));
       
   191         iEventMonitor->Close();
       
   192 	    TRACE( Kern::Printf("DMemSpyDriverDevice::Cleanup() - closed event monitor..."));
       
   193         iEventMonitor = NULL;
       
   194 	    TRACE( Kern::Printf("DMemSpyDriverDevice::Cleanup() - event monitor destroyed"));
       
   195         }
       
   196     
       
   197     if  ( iSuspensionManager )
       
   198         {
       
   199 	    TRACE( Kern::Printf("DMemSpyDriverDevice::Cleanup() - destroying suspension manager..."));
       
   200         delete iSuspensionManager;
       
   201 	    TRACE( Kern::Printf("DMemSpyDriverDevice::Cleanup() - suspension manager destroyed"));
       
   202         iSuspensionManager = NULL;
       
   203         }
       
   204 
       
   205     if  ( iOSAdaption )
       
   206         {
       
   207 	    TRACE( Kern::Printf("DMemSpyDriverDevice::Cleanup() - destroying os adaption..."));
       
   208         delete iOSAdaption;
       
   209 	    TRACE( Kern::Printf("DMemSpyDriverDevice::Cleanup() - suspension os adaption destroyed"));
       
   210         iOSAdaption = NULL;
       
   211         }
       
   212 
       
   213     NKern::ThreadLeaveCS();
       
   214 
       
   215     TRACE( Kern::Printf("DMemSpyDriverDevice::Cleanup() - END"));
       
   216     }
       
   217 
       
   218 
       
   219 
       
   220