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