|
1 /* |
|
2 * Copyright (c) 2007 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: Trace macro support for lockapp |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef LOCKAPPTRACE_H |
|
20 #define LOCKAPPTRACE_H |
|
21 |
|
22 #include "lockapptraceconfiguration.hrh" |
|
23 |
|
24 #ifdef TRACE_INTO_FILE |
|
25 #include <flogger.h> // RFileLogger |
|
26 #else |
|
27 #include <e32debug.h> // RDebug |
|
28 #endif |
|
29 |
|
30 //----------------------------------------------------------------------------- |
|
31 // Constants |
|
32 //----------------------------------------------------------------------------- |
|
33 // |
|
34 |
|
35 /** |
|
36 * Prefix trace macro to complete tracing with component name. |
|
37 * Returns TDesC which can be used directly with RDebug or RFileLogger. |
|
38 */ |
|
39 #define _PREFIX_TRACE( aMsg ) TPtrC( (const TText*)L"[LockApp]: " L##aMsg ) |
|
40 |
|
41 /** |
|
42 * Prefix error trace |
|
43 */ |
|
44 #define _PREFIX_ERROR( aMsg ) _PREFIX_TRACE( "[ERROR: %d]: " L##aMsg ) |
|
45 |
|
46 /** |
|
47 * Prefix info trace. |
|
48 */ |
|
49 #define _PREFIX_INFO( aMsg ) _PREFIX_TRACE( "[INFO]: " L##aMsg ) |
|
50 |
|
51 /** |
|
52 * Prefix macro for strings |
|
53 */ |
|
54 #define _PREFIX_CHAR( aMsg ) (const char*)"[LockApp]: " ##aMsg |
|
55 |
|
56 /** |
|
57 * Define needed directories if TRACE_INTO_FILE macro in use |
|
58 */ |
|
59 #ifdef TRACE_INTO_FILE |
|
60 |
|
61 _LIT( KDir, "lockapp" ); |
|
62 _LIT( KFile, "lockapp_log.txt" ); |
|
63 _LIT( KFullPath, "c:\\logs\\lockapp\\" ); |
|
64 |
|
65 #endif |
|
66 |
|
67 //----------------------------------------------------------------------------- |
|
68 // Error trace macros |
|
69 //----------------------------------------------------------------------------- |
|
70 // |
|
71 #ifdef ERROR_TRACE |
|
72 |
|
73 /** |
|
74 * Error trace definitions. |
|
75 */ |
|
76 #ifdef TRACE_INTO_FILE |
|
77 |
|
78 #define ERROR( aErr, aMsg )\ |
|
79 {\ |
|
80 if( aErr < KErrNone )\ |
|
81 {\ |
|
82 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_ERROR( aMsg ), aErr );\ |
|
83 }\ |
|
84 } |
|
85 #define ERROR_1( aErr, aMsg, aP1 )\ |
|
86 {\ |
|
87 if( aErr < KErrNone )\ |
|
88 {\ |
|
89 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_ERROR( aMsg ), aErr, aP1 );\ |
|
90 }\ |
|
91 } |
|
92 #define ERROR_2( aErr, aMsg, aP1, aP2 )\ |
|
93 {\ |
|
94 if( aErr < KErrNone )\ |
|
95 {\ |
|
96 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_ERROR( aMsg ), aErr, aP1, aP2 );\ |
|
97 }\ |
|
98 } |
|
99 #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\ |
|
100 {\ |
|
101 if( aErr < KErrNone )\ |
|
102 {\ |
|
103 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_ERROR( aMsg ), aErr, aP1, aP2, aP3 );\ |
|
104 }\ |
|
105 } |
|
106 |
|
107 #else//TRACE_INTO_FILE not defined |
|
108 |
|
109 #define ERROR( aErr, aMsg )\ |
|
110 {\ |
|
111 if( aErr < KErrNone )\ |
|
112 {\ |
|
113 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr );\ |
|
114 }\ |
|
115 } |
|
116 #define ERROR_1( aErr, aMsg, aP1 )\ |
|
117 {\ |
|
118 if( aErr < KErrNone )\ |
|
119 {\ |
|
120 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1 );\ |
|
121 }\ |
|
122 } |
|
123 #define ERROR_2( aErr, aMsg, aP1, aP2 )\ |
|
124 {\ |
|
125 if( aErr < KErrNone )\ |
|
126 {\ |
|
127 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1, aP2 );\ |
|
128 }\ |
|
129 } |
|
130 #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\ |
|
131 {\ |
|
132 if( aErr < KErrNone )\ |
|
133 {\ |
|
134 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1, aP2, aP3 );\ |
|
135 }\ |
|
136 } |
|
137 |
|
138 #endif//TRACE_INTO_FILE |
|
139 |
|
140 #define ERROR_GEN( aMsg ) ERROR( KErrGeneral, aMsg ) |
|
141 #define ERROR_GEN_1( aMsg, aP1 ) ERROR_1( KErrGeneral, aMsg, aP1 ) |
|
142 #define ERROR_GEN_2( aMsg, aP1, aP2 ) ERROR_2( KErrGeneral, aMsg, aP1, aP2 ) |
|
143 #define ERROR_GEN_3( aMsg, aP1, aP2, aP3 ) ERROR_3( KErrGeneral, aMsg, aP1, aP3 ) |
|
144 |
|
145 #else//ERROR_TRACE not defined |
|
146 |
|
147 #define ERROR( aErr, aMsg ) |
|
148 #define ERROR_1( aErr, aMsg, aP1 ) |
|
149 #define ERROR_2( aErr, aMsg, aP1, aP2 ) |
|
150 #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 ) |
|
151 #define ERROR_GEN( aMsg ) |
|
152 #define ERROR_GEN_1( aMsg, aP1 ) |
|
153 #define ERROR_GEN_2( aMsg, aP1, aP2 ) |
|
154 #define ERROR_GEN_3( aMsg, aP1, aP2, aP3 ) |
|
155 |
|
156 #endif//ERROR_TRACE |
|
157 |
|
158 //----------------------------------------------------------------------------- |
|
159 // Info trace macros |
|
160 //----------------------------------------------------------------------------- |
|
161 // |
|
162 #ifdef INFO_TRACE |
|
163 |
|
164 /** |
|
165 * Info log message definitions. |
|
166 */ |
|
167 #ifdef TRACE_INTO_FILE |
|
168 |
|
169 #define INFO( aMsg )\ |
|
170 {\ |
|
171 RDebug::Print( _PREFIX_INFO( aMsg ) );\ |
|
172 RFileLogger::Write( KDir, KFile, EFileLoggingModeAppend, _PREFIX_INFO( aMsg ) );\ |
|
173 } |
|
174 #define INFO_1( aMsg, aP1 )\ |
|
175 {\ |
|
176 RDebug::Print( _PREFIX_INFO( aMsg ), aP1 );\ |
|
177 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_INFO( aMsg ), aP1 );\ |
|
178 } |
|
179 #define INFO_2( aMsg, aP1, aP2 )\ |
|
180 {\ |
|
181 RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2 );\ |
|
182 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_INFO( aMsg ), aP1, aP2 );\ |
|
183 } |
|
184 #define INFO_3( aMsg, aP1, aP2, aP3 )\ |
|
185 {\ |
|
186 RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2, aP3 );\ |
|
187 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_INFO( aMsg ), aP1, aP2, aP3 );\ |
|
188 } |
|
189 #define INFO_4( aMsg, aP1, aP2, aP3, aP4 )\ |
|
190 {\ |
|
191 RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2, aP3, aP4 );\ |
|
192 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_INFO( aMsg ), aP1, aP2, aP3, aP4 );\ |
|
193 } |
|
194 |
|
195 #else//TRACE_INTO_FILE not defined |
|
196 |
|
197 #define INFO( aMsg )\ |
|
198 {\ |
|
199 RDebug::Print( _PREFIX_INFO( aMsg ) );\ |
|
200 } |
|
201 #define INFO_1( aMsg, aP1 )\ |
|
202 {\ |
|
203 RDebug::Print( _PREFIX_INFO( aMsg ), aP1 );\ |
|
204 } |
|
205 #define INFO_2( aMsg, aP1, aP2 )\ |
|
206 {\ |
|
207 RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2 );\ |
|
208 } |
|
209 #define INFO_3( aMsg, aP1, aP2, aP3 )\ |
|
210 {\ |
|
211 RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2, aP3 );\ |
|
212 } |
|
213 #define INFO_4( aMsg, aP1, aP2, aP3, aP4 )\ |
|
214 {\ |
|
215 RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2, aP3, aP4 );\ |
|
216 } |
|
217 |
|
218 #endif//TRACE_INTO_FILE |
|
219 |
|
220 #else//INFO_TRACE not defined |
|
221 |
|
222 #define INFO( aMsg ) |
|
223 #define INFO_1( aMsg, aP1 ) |
|
224 #define INFO_2( aMsg, aP1, aP2 ) |
|
225 #define INFO_3( aMsg, aP1, aP2, aP3 ) |
|
226 #define INFO_4( aMsg, aP1, aP2, aP3, aP4 ) |
|
227 |
|
228 #endif//INFO_TRACE |
|
229 |
|
230 //----------------------------------------------------------------------------- |
|
231 // Trace current client thread name and process id |
|
232 //----------------------------------------------------------------------------- |
|
233 // |
|
234 #ifdef CLIENT_TRACE |
|
235 |
|
236 #define CLIENT( aMessage )\ |
|
237 {\ |
|
238 RThread thread;\ |
|
239 TInt err = aMessage.Client( thread );\ |
|
240 if( err == KErrNone )\ |
|
241 {\ |
|
242 RProcess process;\ |
|
243 err = thread.Process( process );\ |
|
244 if( err == KErrNone )\ |
|
245 {\ |
|
246 TPtrC thredName( thread.Name() );\ |
|
247 TUid processUid( process.SecureId() );\ |
|
248 INFO_2( "Current client process UID: [%x], thread name: [%S]",\ |
|
249 processUid,\ |
|
250 &thredName );\ |
|
251 }\ |
|
252 process.Close();\ |
|
253 }\ |
|
254 thread.Close();\ |
|
255 } |
|
256 |
|
257 #else |
|
258 |
|
259 #define CLIENT( aMessage ) |
|
260 |
|
261 #endif |
|
262 |
|
263 //----------------------------------------------------------------------------- |
|
264 // Function trace macros |
|
265 //----------------------------------------------------------------------------- |
|
266 // |
|
267 #ifdef FUNC_TRACE |
|
268 |
|
269 /** |
|
270 * Function logging definitions. |
|
271 */ |
|
272 #ifdef TRACE_INTO_FILE |
|
273 |
|
274 #define FUNC( aMsg, aP1 )\ |
|
275 {\ |
|
276 TPtrC8 trace( _S8( aMsg ) );\ |
|
277 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, trace, aP1 );\ |
|
278 }\ |
|
279 |
|
280 #else//TRACE_INTO_FILE not defined |
|
281 |
|
282 #define FUNC( aMsg, aP1 )\ |
|
283 {\ |
|
284 RDebug::Printf( aMsg, aP1 );\ |
|
285 }\ |
|
286 |
|
287 #endif//TRACE_INTO_FILE |
|
288 |
|
289 /** |
|
290 * Function trace helper class. |
|
291 * |
|
292 * NOTE: |
|
293 * LC -methods cannot be trapped. Therefore if LC -method leaves |
|
294 * END trace is used instead of LEAVE trace. |
|
295 * If you have an idea how to round this problem please tell. |
|
296 */ |
|
297 _LIT8( KFuncNameTerminator, "(" ); |
|
298 _LIT8( KFuncLeavePatternL, "L" ); |
|
299 class TFuncLog |
|
300 { |
|
301 public: |
|
302 static void Cleanup( TAny* aPtr ) |
|
303 { |
|
304 TFuncLog* self = static_cast< TFuncLog* >( aPtr ); |
|
305 self->iLeft = ETrue; |
|
306 FUNC( _PREFIX_CHAR("%S-LEAVE"), &self->iFunc ); // Leave detected |
|
307 } |
|
308 inline TFuncLog( const char* aFunc ) : |
|
309 iFunc( aFunc ? _S8( aFunc ) : _S8("") ), |
|
310 iLeft( EFalse ), |
|
311 iCleanupItem( Cleanup, this ), |
|
312 iCanLeave( EFalse ) |
|
313 { |
|
314 TInt pos( iFunc.Find( KFuncNameTerminator ) ); |
|
315 if( pos != KErrNotFound ) |
|
316 { |
|
317 iFunc.Set( iFunc.Left( pos ) ); |
|
318 iCanLeave = !iFunc.Right( KFuncLeavePatternL().Length() ).Compare( KFuncLeavePatternL ); |
|
319 if ( iCanLeave ) |
|
320 { |
|
321 CleanupStack::PushL( iCleanupItem ); // Ignore warnings |
|
322 } |
|
323 } |
|
324 FUNC( _PREFIX_CHAR("%S-START"), &iFunc ); |
|
325 } |
|
326 |
|
327 inline ~TFuncLog() |
|
328 { |
|
329 if ( !iLeft ) |
|
330 { |
|
331 if ( iCanLeave ) |
|
332 { |
|
333 CleanupStack::Pop( this ); // Pop the cleanup item |
|
334 } |
|
335 FUNC( _PREFIX_CHAR("%S-END"), &iFunc ); // Normally finished |
|
336 } |
|
337 } |
|
338 |
|
339 private: // Data |
|
340 TPtrC8 iFunc; |
|
341 TBool iLeft; |
|
342 TCleanupItem iCleanupItem; |
|
343 TBool iCanLeave; |
|
344 }; |
|
345 #define FUNC_LOG TFuncLog _fl( __PRETTY_FUNCTION__ ); |
|
346 |
|
347 #else//FUNC_TRACE not defined |
|
348 |
|
349 #define FUNC_LOG |
|
350 |
|
351 #endif//FUNC_TRACE |
|
352 |
|
353 //----------------------------------------------------------------------------- |
|
354 // Timestamp trace macros |
|
355 //----------------------------------------------------------------------------- |
|
356 // |
|
357 #ifdef TIMESTAMP_TRACE |
|
358 |
|
359 #ifdef TRACE_INTO_FILE |
|
360 |
|
361 #define TIMESTAMP( aCaption )\ |
|
362 {\ |
|
363 TTime t;\ |
|
364 t.HomeTime();\ |
|
365 TDateTime dt = t.DateTime();\ |
|
366 _LIT( KCaption, aCaption );\ |
|
367 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend,\ |
|
368 _PREFIX_TRACE("[TIMESTAMP] %S %d:%02d:%02d.%d us"),\ |
|
369 &KCaption, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond() );\ |
|
370 } |
|
371 |
|
372 #else//TRACE_INTO_FILE not defined |
|
373 |
|
374 #define TIMESTAMP( aCaption )\ |
|
375 {\ |
|
376 TTime t;\ |
|
377 t.HomeTime();\ |
|
378 TDateTime dt = t.DateTime();\ |
|
379 _LIT( KCaption, aCaption );\ |
|
380 RDebug::Print( _PREFIX_TRACE("[TIMESTAMP] %S %d:%02d:%02d.%d us"),\ |
|
381 &KCaption, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond() );\ |
|
382 } |
|
383 |
|
384 #endif//TRACE_INTO_FILE |
|
385 |
|
386 #else//TIMESTAMP_TRACE not defined |
|
387 |
|
388 #define TIMESTAMP( aCaption ) |
|
389 |
|
390 #endif//TIMESTAMP_TRACE |
|
391 |
|
392 #endif |