|
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 * Tracing definitions for the ssmutilityplugins project. |
|
16 * |
|
17 */ |
|
18 |
|
19 #ifndef TRACE_H |
|
20 #define TRACE_H |
|
21 |
|
22 #include <e32debug.h> // RDebug |
|
23 |
|
24 #include "traceconfiguration.hrh" |
|
25 |
|
26 #ifdef TRACE_INTO_FILE |
|
27 #include <flogger.h> // RFileLogger |
|
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"[SSMUPS]: " 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*)"[SSMUPS]: " ##aMsg |
|
55 |
|
56 /** |
|
57 * Define needed directories if TRACE_INTO_FILE macro in use |
|
58 */ |
|
59 #ifdef TRACE_INTO_FILE |
|
60 |
|
61 _LIT( KDir, "ssm" ); |
|
62 _LIT( KFile, "ssmutilityplugins.txt" ); |
|
63 _LIT( KFullPath, "c:\\logs\\ssm\\" ); |
|
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, \ |
|
83 _PREFIX_ERROR( aMsg ), aErr );\ |
|
84 }\ |
|
85 } |
|
86 #define ERROR_1( aErr, aMsg, aP1 )\ |
|
87 {\ |
|
88 if( aErr < KErrNone )\ |
|
89 {\ |
|
90 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \ |
|
91 _PREFIX_ERROR( aMsg ), aErr, aP1 );\ |
|
92 }\ |
|
93 } |
|
94 #define ERROR_2( aErr, aMsg, aP1, aP2 )\ |
|
95 {\ |
|
96 if( aErr < KErrNone )\ |
|
97 {\ |
|
98 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \ |
|
99 _PREFIX_ERROR( aMsg ), aErr, aP1, aP2 );\ |
|
100 }\ |
|
101 } |
|
102 #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\ |
|
103 {\ |
|
104 if( aErr < KErrNone )\ |
|
105 {\ |
|
106 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \ |
|
107 _PREFIX_ERROR( aMsg ), aErr, aP1, aP2, aP3 );\ |
|
108 }\ |
|
109 } |
|
110 |
|
111 #else//TRACE_INTO_FILE not defined |
|
112 |
|
113 #define ERROR( aErr, aMsg )\ |
|
114 {\ |
|
115 if( aErr < KErrNone )\ |
|
116 {\ |
|
117 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr );\ |
|
118 }\ |
|
119 } |
|
120 #define ERROR_1( aErr, aMsg, aP1 )\ |
|
121 {\ |
|
122 if( aErr < KErrNone )\ |
|
123 {\ |
|
124 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1 );\ |
|
125 }\ |
|
126 } |
|
127 #define ERROR_2( aErr, aMsg, aP1, aP2 )\ |
|
128 {\ |
|
129 if( aErr < KErrNone )\ |
|
130 {\ |
|
131 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1, aP2 );\ |
|
132 }\ |
|
133 } |
|
134 #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\ |
|
135 {\ |
|
136 if( aErr < KErrNone )\ |
|
137 {\ |
|
138 RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1, aP2, aP3 );\ |
|
139 }\ |
|
140 } |
|
141 |
|
142 #endif//TRACE_INTO_FILE |
|
143 |
|
144 #define ERROR_GEN( aMsg ) ERROR( KErrGeneral, aMsg ) |
|
145 #define ERROR_GEN_1( aMsg, aP1 ) ERROR_1( KErrGeneral, aMsg, aP1 ) |
|
146 #define ERROR_GEN_2( aMsg, aP1, aP2 ) ERROR_2( KErrGeneral, aMsg, aP1, aP2 ) |
|
147 #define ERROR_GEN_3( aMsg, aP1, aP2, aP3 ) ERROR_3( KErrGeneral, aMsg, aP1, aP3 ) |
|
148 |
|
149 #define ERROR_PARAM(_p) _p |
|
150 |
|
151 #define TRAPD_ERR( aErr, aStmt ) TRAPD( aErr, aStmt ) |
|
152 #define TRAP_ERR( aErr, aStmt ) TRAP( aErr, aStmt ) |
|
153 |
|
154 #define TRAP_AND_LEAVE(_s,_t) \ |
|
155 { TRAPD(_e,_s); ERROR(_e,_t); User::LeaveIfError(_e); } |
|
156 |
|
157 #else//ERROR_TRACE not defined |
|
158 |
|
159 #define ERROR( aErr, aMsg ) |
|
160 #define ERROR_1( aErr, aMsg, aP1 ) |
|
161 #define ERROR_2( aErr, aMsg, aP1, aP2 ) |
|
162 #define ERROR_3( aErr, aMsg, aP1, aP2, aP3 ) |
|
163 #define ERROR_GEN( aMsg ) |
|
164 #define ERROR_GEN_1( aMsg, aP1 ) |
|
165 #define ERROR_GEN_2( aMsg, aP1, aP2 ) |
|
166 #define ERROR_GEN_3( aMsg, aP1, aP2, aP3 ) |
|
167 |
|
168 #define ERROR_PARAM(_p) |
|
169 |
|
170 #define TRAPD_ERR( aErr, aStmt ) TRAP_IGNORE( aStmt ) |
|
171 #define TRAP_ERR( aErr, aStmt ) TRAP_IGNORE( aStmt ) |
|
172 |
|
173 #define TRAP_AND_LEAVE(_s,_t) { _s; } |
|
174 |
|
175 #endif//ERROR_TRACE |
|
176 |
|
177 //---------------------------------------------------------------------------- |
|
178 // Info trace macros |
|
179 //---------------------------------------------------------------------------- |
|
180 // |
|
181 #ifdef INFO_TRACE |
|
182 |
|
183 /** |
|
184 * Info log message definitions. |
|
185 */ |
|
186 #ifdef TRACE_INTO_FILE |
|
187 |
|
188 #define INFO( aMsg )\ |
|
189 {\ |
|
190 RFileLogger::Write( KDir, KFile, EFileLoggingModeAppend, \ |
|
191 _PREFIX_INFO( aMsg ) );\ |
|
192 } |
|
193 #define INFO_1( aMsg, aP1 )\ |
|
194 {\ |
|
195 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \ |
|
196 _PREFIX_INFO( aMsg ), aP1 );\ |
|
197 } |
|
198 #define INFO_2( aMsg, aP1, aP2 )\ |
|
199 {\ |
|
200 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \ |
|
201 _PREFIX_INFO( aMsg ), aP1, aP2 );\ |
|
202 } |
|
203 #define INFO_3( aMsg, aP1, aP2, aP3 )\ |
|
204 {\ |
|
205 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, \ |
|
206 _PREFIX_INFO( aMsg ), aP1, aP2, aP3 );\ |
|
207 } |
|
208 |
|
209 #else//TRACE_INTO_FILE not defined |
|
210 |
|
211 #define INFO( aMsg )\ |
|
212 {\ |
|
213 RDebug::Print( _PREFIX_INFO( aMsg ) );\ |
|
214 } |
|
215 #define INFO_1( aMsg, aP1 )\ |
|
216 {\ |
|
217 RDebug::Print( _PREFIX_INFO( aMsg ), aP1 );\ |
|
218 } |
|
219 #define INFO_2( aMsg, aP1, aP2 )\ |
|
220 {\ |
|
221 RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2 );\ |
|
222 } |
|
223 #define INFO_3( aMsg, aP1, aP2, aP3 )\ |
|
224 {\ |
|
225 RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2, aP3 );\ |
|
226 } |
|
227 |
|
228 #endif//TRACE_INTO_FILE |
|
229 |
|
230 #else//INFO_TRACE not defined |
|
231 |
|
232 #define INFO( aMsg ) |
|
233 #define INFO_1( aMsg, aP1 ) |
|
234 #define INFO_2( aMsg, aP1, aP2 ) |
|
235 #define INFO_3( aMsg, aP1, aP2, aP3 ) |
|
236 |
|
237 #endif//INFO_TRACE |
|
238 |
|
239 //---------------------------------------------------------------------------- |
|
240 // Trace current client thread name and process id |
|
241 //---------------------------------------------------------------------------- |
|
242 // |
|
243 #ifdef CLIENT_TRACE |
|
244 |
|
245 #define CLIENT( aMessage )\ |
|
246 {\ |
|
247 RThread thread;\ |
|
248 TInt err = aMessage.Client( thread );\ |
|
249 if( err == KErrNone )\ |
|
250 {\ |
|
251 RProcess process;\ |
|
252 err = thread.Process( process );\ |
|
253 if( err == KErrNone )\ |
|
254 {\ |
|
255 TPtrC thredName( thread.Name() );\ |
|
256 TUid processUid( process.SecureId() );\ |
|
257 INFO_2( "Current client process UID: [%x], thread name: [%S]",\ |
|
258 processUid,\ |
|
259 &thredName );\ |
|
260 }\ |
|
261 process.Close();\ |
|
262 }\ |
|
263 thread.Close();\ |
|
264 } |
|
265 |
|
266 #else |
|
267 |
|
268 #define CLIENT( aMessage ) |
|
269 |
|
270 #endif |
|
271 |
|
272 //---------------------------------------------------------------------------- |
|
273 // Function trace macros |
|
274 //---------------------------------------------------------------------------- |
|
275 // |
|
276 #ifdef FUNC_TRACE |
|
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 #ifdef TRACE_INTO_FILE |
|
370 |
|
371 #define TIMESTAMP( aCaption )\ |
|
372 {\ |
|
373 TTime t;\ |
|
374 t.HomeTime();\ |
|
375 TDateTime dt = t.DateTime();\ |
|
376 _LIT( KCaption, aCaption );\ |
|
377 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend,\ |
|
378 _PREFIX_TRACE("[TIMESTAMP] %S %d:%02d:%02d.%d us"),\ |
|
379 &KCaption, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond() );\ |
|
380 } |
|
381 |
|
382 #else//TRACE_INTO_FILE not defined |
|
383 |
|
384 #define TIMESTAMP( aCaption )\ |
|
385 {\ |
|
386 TTime t;\ |
|
387 t.HomeTime();\ |
|
388 TDateTime dt = t.DateTime();\ |
|
389 _LIT( KCaption, aCaption );\ |
|
390 RDebug::Print( _PREFIX_TRACE("[TIMESTAMP] %S %d:%02d:%02d.%d us"),\ |
|
391 &KCaption, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond() );\ |
|
392 } |
|
393 |
|
394 #endif//TRACE_INTO_FILE |
|
395 |
|
396 #else//TIMESTAMP_TRACE not defined |
|
397 |
|
398 #define TIMESTAMP( aCaption ) |
|
399 |
|
400 #endif//TIMESTAMP_TRACE |
|
401 |
|
402 #ifdef _DEBUG |
|
403 |
|
404 static void Panic( const TDesC8& aFileName, const TInt aLineNum ) |
|
405 { |
|
406 TPath name; |
|
407 name.Copy( aFileName ); |
|
408 RDebug::Print( _L( "Assertion failed in file=%S, line=%d" ), &name, aLineNum ); |
|
409 User::Invariant(); |
|
410 } |
|
411 |
|
412 #define ASSERT_ALWAYS_TRACE Panic( _L8(__FILE__), __LINE__ ); |
|
413 #define ASSERT_TRACE( _s ) if ( !( _s ) ) { ASSERT_ALWAYS_TRACE; } |
|
414 |
|
415 #else // _DEBUG |
|
416 |
|
417 #define ASSERT_ALWAYS_TRACE |
|
418 #define ASSERT_TRACE( _s ) |
|
419 |
|
420 #endif // _DEBUG |
|
421 |
|
422 #endif |