analyzetool/dynamicmemoryhook/src/analyzetooleventhandler.cpp
changeset 22 a009639409f5
child 49 7fdc9a71d314
equal deleted inserted replaced
17:67c6ff54ec25 22:a009639409f5
       
     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:  Definitions for the class CLibraryEventHandler.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "atlog.h"
       
    21 #include "analyzetooleventhandler.h"
       
    22 #include "analyzetooleventhandlernotifier.h"
       
    23 #include "analyzetoolmemoryallocator.h"
       
    24 #include "analyzetoolfastlog.h"
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CLibraryEventHandler::~CLibraryEventHandler()
       
    28 // Destructor.
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 CLibraryEventHandler::~CLibraryEventHandler()
       
    32     {
       
    33     LOGSTR1( "ATMH CLibraryEventHandler::~CLibraryEventHandler()" );
       
    34     Cancel();
       
    35     }
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CLibraryEventHandler::RunL()
       
    39 // Process active object's task
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 void CLibraryEventHandler::RunL()
       
    43     {
       
    44     LOGSTR1( "ATMH CLibraryEventHandler::RunL()" );
       
    45 
       
    46     if ( KErrNone != iStatus.Int() )
       
    47         {
       
    48         LOGSTR2( "ATMH RunL error: %i",  iStatus.Int() );
       
    49         return;
       
    50         }
       
    51     // Acquire the mutex
       
    52     iMutex.Wait();
       
    53 
       
    54     // Check that this is observed process 
       
    55     if ( iLibraryInfo.iEventType == TLibraryEventInfo::ELibraryAdded )
       
    56         {
       
    57         LOGSTR1( "ATMH CLibraryEventHandler::RunL() - TLibraryEventInfo::ELibraryAdded" );
       
    58         if ( iLibraryInfo.iProcessId == iProcessId )
       
    59             {
       
    60             TInt error( KErrNone );
       
    61 
       
    62             // Log library load event.
       
    63             if ( iLogOption == EATLogToTraceFast )
       
    64                 {
       
    65                 LOGSTR1( "ATMH CLibraryEventHandler::RunL() - ATFastLog.LogDllLoaded() " );
       
    66                 ATFastLogDllLoaded( iProcessId,
       
    67                         iLibraryInfo.iLibraryName, 
       
    68                         iLibraryInfo.iRunAddress,
       
    69                         iLibraryInfo.iRunAddress + iLibraryInfo.iSize );
       
    70                 }
       
    71             else
       
    72                 {
       
    73                 LOGSTR1( "ATMH CLibraryEventHandler::RunL() - iStorageServer.LogDllLoaded() " );
       
    74                 error = iStorageServer.LogDllLoaded( 
       
    75                         iLibraryInfo.iLibraryName, 
       
    76                         iLibraryInfo.iRunAddress,
       
    77                         iLibraryInfo.iRunAddress + iLibraryInfo.iSize );
       
    78                 LOGSTR2( "ATMH StorageServer error: %i",  error );
       
    79                 }
       
    80             if ( KErrNone == error )
       
    81                 {
       
    82                 iCodeblocks.Append( TCodeblock( iLibraryInfo.iRunAddress, 
       
    83                         iLibraryInfo.iSize, 
       
    84                         iLibraryInfo.iLibraryName ) );
       
    85                 }
       
    86             }
       
    87         }
       
    88     else if ( iLibraryInfo.iEventType == TLibraryEventInfo::ELibraryRemoved )
       
    89         {
       
    90         LOGSTR1( "ATMH CLibraryEventHandler::RunL() - TLibraryEventInfo::ELibraryRemoved " );
       
    91         TInt count = iCodeblocks.Count();
       
    92         LOGSTR2( "ATMH count of code blocks: %i",  count );
       
    93         for ( TInt i = 0; i < count; i++ )
       
    94             {
       
    95             if ( iCodeblocks[ i ].Match( iLibraryInfo.iLibraryName ) )
       
    96                 {
       
    97                 TBuf8<KMaxLibraryName> libraryName;
       
    98                 libraryName.Copy( iLibraryInfo.iLibraryName );
       
    99                 
       
   100                 // Log library unloaded event
       
   101                 if ( iLogOption == EATLogToTraceFast )
       
   102                     {
       
   103                     LOGSTR1( "ATMH CLibraryEventHandler::RunL() - ATFastLogDllUnloaded() " );
       
   104                     ATFastLogDllUnloaded( iProcessId,
       
   105                             libraryName,
       
   106                             iLibraryInfo.iRunAddress, 
       
   107                             iLibraryInfo.iRunAddress + iLibraryInfo.iSize );
       
   108                     }
       
   109                 else
       
   110                     {
       
   111                     LOGSTR1( "ATMH CLibraryEventHandler::RunL() - iStorageServer.LogDllUnloaded() " );
       
   112                     #ifdef LOGGING_ENABLED
       
   113                     TInt error = iStorageServer.LogDllUnloaded( 
       
   114                             libraryName/*iLibraryInfo.iLibraryName*/, 
       
   115                             iLibraryInfo.iRunAddress, 
       
   116                             iLibraryInfo.iRunAddress + iLibraryInfo.iSize );
       
   117     
       
   118                     LOGSTR2( "ATMH StorageServer error: %i",  error );
       
   119                     #else
       
   120                     iStorageServer.LogDllUnloaded( 
       
   121                                                 libraryName/*iLibraryInfo.iLibraryName*/, 
       
   122                                                 iLibraryInfo.iRunAddress, 
       
   123                                                 iLibraryInfo.iRunAddress + iLibraryInfo.iSize );
       
   124                     #endif
       
   125                     }
       
   126                 iCodeblocks.Remove( i );
       
   127                 break;
       
   128                 }
       
   129             }
       
   130         }
       
   131     else if ( iLibraryInfo.iEventType == TLibraryEventInfo::EKillThread )
       
   132 		{
       
   133 		LOGSTR1( "ATMH CLibraryEventHandler::RunL() - TLibraryEventInfo::EKillThread" );
       
   134 	  
       
   135 		iNotifier.RemoveKilledThread( iLibraryInfo.iThreadId );
       
   136     	}
       
   137     
       
   138     Start();
       
   139     
       
   140     // Release the mutex
       
   141     iMutex.Signal();
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CLibraryEventHandler::DoCancel()
       
   146 // Cancels active object's task
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void CLibraryEventHandler::DoCancel()
       
   150     {
       
   151     LOGSTR1( "ATMH CLibraryEventHandler::DoCancel()" );
       
   152     // Cancel the subscription of the library events
       
   153     if ( IsActive() )
       
   154         {
       
   155         iStarted = EFalse;
       
   156         
       
   157         iAnalyzeTool.CancelLibraryEvent();
       
   158         }
       
   159     }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CLibraryEventHandler::Start()
       
   163 // Creates CActiveScheduler and variables for the child thread
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 void CLibraryEventHandler::Start()
       
   167     {
       
   168     LOGSTR1( "ATMH CLibraryEventHandler::Start()" );
       
   169     
       
   170     // Acquire the mutex
       
   171     iMutex.Wait();
       
   172 
       
   173     if ( !IsAdded() )
       
   174         {
       
   175         CActiveScheduler::Add( this );
       
   176         }
       
   177 
       
   178     // Cancel current subscribetion
       
   179     if ( IsActive() )
       
   180         {
       
   181         iStarted = EFalse;
       
   182         Cancel();
       
   183         }
       
   184 
       
   185     iStatus = KErrNone;
       
   186     iAnalyzeTool.LibraryEvent( iStatus, iLibraryInfo );
       
   187     SetActive();
       
   188     
       
   189     iStarted = ETrue;
       
   190     // Release the mutex
       
   191     iMutex.Signal();
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CLibraryEventHandler::CLibraryEventHandler()
       
   196 // C++ default constructor can NOT contain any code, that
       
   197 // might leave.
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 CLibraryEventHandler::CLibraryEventHandler( RAnalyzeTool& aAnalyzeTool, 
       
   201 	RArray<TCodeblock>& aCodeblocks, RATStorageServer& aStorageServer, 
       
   202 	TUint aProcessId, RMutex& aMutex, 
       
   203 	MAnalyzeToolEventhandlerNotifier& aNotifier,
       
   204 	TUint32 aLogOption ) 
       
   205  :	CActive( EPriorityNormal ),
       
   206     iAnalyzeTool( aAnalyzeTool ),
       
   207     iCodeblocks( aCodeblocks ),
       
   208     iStorageServer( aStorageServer ),
       
   209     iProcessId( aProcessId ),
       
   210     iMutex( aMutex ),
       
   211     iStarted( EFalse ),
       
   212     iNotifier( aNotifier ),
       
   213     iLogOption( aLogOption )
       
   214     {
       
   215     LOGSTR1( "ATMH CLibraryEventHandler::CLibraryEventHandler()" );
       
   216     }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CLibraryEventHandler::IsStarted()
       
   220 // Returns eventhandler's state.
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 TBool CLibraryEventHandler::IsStarted()
       
   224     {
       
   225     LOGSTR2( "ATMH CLibraryEventHandler::IsStarted(%i)", iStarted );
       
   226     
       
   227     return iStarted;
       
   228     }
       
   229     
       
   230 // End of File