|
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 if( iLogOption == EATLogToFile ) |
|
72 { |
|
73 iLogFile.ATFileLogDllLoaded( iLibraryInfo.iLibraryName, |
|
74 iLibraryInfo.iRunAddress, |
|
75 iLibraryInfo.iRunAddress + iLibraryInfo.iSize ); |
|
76 } |
|
77 |
|
78 if ( KErrNone == error ) |
|
79 { |
|
80 iCodeblocks.Append( TCodeblock( iLibraryInfo.iRunAddress, |
|
81 iLibraryInfo.iSize, |
|
82 iLibraryInfo.iLibraryName ) ); |
|
83 } |
|
84 } |
|
85 } |
|
86 else if ( iLibraryInfo.iEventType == TLibraryEventInfo::ELibraryRemoved ) |
|
87 { |
|
88 LOGSTR1( "ATMH CLibraryEventHandler::RunL() - TLibraryEventInfo::ELibraryRemoved " ); |
|
89 TInt count = iCodeblocks.Count(); |
|
90 LOGSTR2( "ATMH count of code blocks: %i", count ); |
|
91 for ( TInt i = 0; i < count; i++ ) |
|
92 { |
|
93 if ( iCodeblocks[ i ].Match( iLibraryInfo.iLibraryName ) ) |
|
94 { |
|
95 TBuf8<KMaxLibraryName> libraryName; |
|
96 libraryName.Copy( iLibraryInfo.iLibraryName ); |
|
97 |
|
98 // Log library unloaded event |
|
99 if ( iLogOption == EATLogToTraceFast ) |
|
100 { |
|
101 LOGSTR1( "ATMH CLibraryEventHandler::RunL() - ATFastLogDllUnloaded() " ); |
|
102 ATFastLogDllUnloaded( iProcessId, |
|
103 libraryName, |
|
104 iLibraryInfo.iRunAddress, |
|
105 iLibraryInfo.iRunAddress + iLibraryInfo.iSize ); |
|
106 } |
|
107 else if( iLogOption == EATLogToFile ) |
|
108 { |
|
109 iLogFile.ATFileLogDllUnloaded( iLibraryInfo.iLibraryName, |
|
110 iLibraryInfo.iRunAddress, |
|
111 iLibraryInfo.iRunAddress + iLibraryInfo.iSize ); |
|
112 } |
|
113 iCodeblocks.Remove( i ); |
|
114 break; |
|
115 } |
|
116 } |
|
117 } |
|
118 else if ( iLibraryInfo.iEventType == TLibraryEventInfo::EKillThread ) |
|
119 { |
|
120 LOGSTR1( "ATMH CLibraryEventHandler::RunL() - TLibraryEventInfo::EKillThread" ); |
|
121 |
|
122 iNotifier.RemoveKilledThread( iLibraryInfo.iThreadId ); |
|
123 } |
|
124 |
|
125 Start(); |
|
126 |
|
127 // Release the mutex |
|
128 iMutex.Signal(); |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CLibraryEventHandler::DoCancel() |
|
133 // Cancels active object's task |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 void CLibraryEventHandler::DoCancel() |
|
137 { |
|
138 LOGSTR1( "ATMH CLibraryEventHandler::DoCancel()" ); |
|
139 // Cancel the subscription of the library events |
|
140 if ( IsActive() ) |
|
141 { |
|
142 iStarted = EFalse; |
|
143 |
|
144 iAnalyzeTool.CancelLibraryEvent(); |
|
145 } |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CLibraryEventHandler::Start() |
|
150 // Creates CActiveScheduler and variables for the child thread |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 void CLibraryEventHandler::Start() |
|
154 { |
|
155 LOGSTR1( "ATMH CLibraryEventHandler::Start()" ); |
|
156 |
|
157 // Acquire the mutex |
|
158 iMutex.Wait(); |
|
159 |
|
160 if ( !IsAdded() ) |
|
161 { |
|
162 CActiveScheduler::Add( this ); |
|
163 } |
|
164 |
|
165 // Cancel current subscribetion |
|
166 if ( IsActive() ) |
|
167 { |
|
168 iStarted = EFalse; |
|
169 Cancel(); |
|
170 } |
|
171 |
|
172 iStatus = KErrNone; |
|
173 iAnalyzeTool.LibraryEvent( iStatus, iLibraryInfo ); |
|
174 SetActive(); |
|
175 |
|
176 iStarted = ETrue; |
|
177 // Release the mutex |
|
178 iMutex.Signal(); |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CLibraryEventHandler::CLibraryEventHandler() |
|
183 // C++ default constructor can NOT contain any code, that |
|
184 // might leave. |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 CLibraryEventHandler::CLibraryEventHandler( RAnalyzeTool& aAnalyzeTool, |
|
188 RArray<TCodeblock>& aCodeblocks, |
|
189 TUint aProcessId, RMutex& aMutex, |
|
190 MAnalyzeToolEventhandlerNotifier& aNotifier, |
|
191 TUint32 aLogOption, |
|
192 RATFileLog& aFileLog ) |
|
193 : CActive( EPriorityNormal ), |
|
194 iAnalyzeTool( aAnalyzeTool ), |
|
195 iCodeblocks( aCodeblocks ), |
|
196 iProcessId( aProcessId ), |
|
197 iMutex( aMutex ), |
|
198 iStarted( EFalse ), |
|
199 iNotifier( aNotifier ), |
|
200 iLogOption( aLogOption ), |
|
201 iLogFile( aFileLog ) |
|
202 { |
|
203 LOGSTR1( "ATMH CLibraryEventHandler::CLibraryEventHandler()" ); |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // CLibraryEventHandler::IsStarted() |
|
208 // Returns eventhandler's state. |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 TBool CLibraryEventHandler::IsStarted() |
|
212 { |
|
213 LOGSTR2( "ATMH CLibraryEventHandler::IsStarted(%i)", iStarted ); |
|
214 |
|
215 return iStarted; |
|
216 } |
|
217 |
|
218 // End of File |