|
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 ssmpolicyplugins 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"[SSMPPS]: " 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*)"[SSMPPS]: " ##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, "ssmpolicyplugins.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 #define INFO_PARAM(_p) _p |
|
231 |
|
232 #else//INFO_TRACE not defined |
|
233 |
|
234 #define INFO( aMsg ) |
|
235 #define INFO_1( aMsg, aP1 ) |
|
236 #define INFO_2( aMsg, aP1, aP2 ) |
|
237 #define INFO_3( aMsg, aP1, aP2, aP3 ) |
|
238 |
|
239 #define INFO_PARAM(_p) |
|
240 |
|
241 #endif//INFO_TRACE |
|
242 |
|
243 //---------------------------------------------------------------------------- |
|
244 // Trace current client thread name and process id |
|
245 //---------------------------------------------------------------------------- |
|
246 // |
|
247 #ifdef CLIENT_TRACE |
|
248 |
|
249 #define CLIENT( aMessage )\ |
|
250 {\ |
|
251 RThread thread;\ |
|
252 TInt err = aMessage.Client( thread );\ |
|
253 if( err == KErrNone )\ |
|
254 {\ |
|
255 RProcess process;\ |
|
256 err = thread.Process( process );\ |
|
257 if( err == KErrNone )\ |
|
258 {\ |
|
259 TPtrC thredName( thread.Name() );\ |
|
260 TUid processUid( process.SecureId() );\ |
|
261 INFO_2( "Current client process UID: [%x], thread name: [%S]",\ |
|
262 processUid,\ |
|
263 &thredName );\ |
|
264 }\ |
|
265 process.Close();\ |
|
266 }\ |
|
267 thread.Close();\ |
|
268 } |
|
269 |
|
270 #else |
|
271 |
|
272 #define CLIENT( aMessage ) |
|
273 |
|
274 #endif |
|
275 |
|
276 //---------------------------------------------------------------------------- |
|
277 // Function trace macros |
|
278 //---------------------------------------------------------------------------- |
|
279 // |
|
280 #ifdef FUNC_TRACE |
|
281 |
|
282 /** |
|
283 * Function logging definitions. |
|
284 */ |
|
285 #ifdef TRACE_INTO_FILE |
|
286 |
|
287 #define FUNC( aMsg, aP1 )\ |
|
288 {\ |
|
289 TPtrC8 trace( _S8( aMsg ) );\ |
|
290 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, trace, aP1 );\ |
|
291 }\ |
|
292 |
|
293 #else//TRACE_INTO_FILE not defined |
|
294 |
|
295 #define FUNC( aMsg, aP1 )\ |
|
296 {\ |
|
297 RDebug::Printf( aMsg, aP1 );\ |
|
298 }\ |
|
299 |
|
300 #endif//TRACE_INTO_FILE |
|
301 |
|
302 /** |
|
303 * Function trace helper class. |
|
304 * |
|
305 * NOTE: |
|
306 * LC -methods cannot be trapped. Therefore if LC -method leaves |
|
307 * END trace is used instead of LEAVE trace. |
|
308 * If you have an idea how to round this problem please tell. |
|
309 */ |
|
310 _LIT8( KFuncNameTerminator, "(" ); |
|
311 _LIT8( KFuncLeavePatternL, "L" ); |
|
312 class TFuncLog |
|
313 { |
|
314 public: |
|
315 static void Cleanup( TAny* aPtr ) |
|
316 { |
|
317 TFuncLog* self = static_cast< TFuncLog* >( aPtr ); |
|
318 self->iLeft = ETrue; |
|
319 FUNC( _PREFIX_CHAR("%S-LEAVE"), &self->iFunc ); // Leave detected |
|
320 } |
|
321 inline TFuncLog( const char* aFunc ) : |
|
322 iFunc( aFunc ? _S8( aFunc ) : _S8("") ), |
|
323 iLeft( EFalse ), |
|
324 iCleanupItem( Cleanup, this ), |
|
325 iCanLeave( EFalse ) |
|
326 { |
|
327 TInt pos( iFunc.Find( KFuncNameTerminator ) ); |
|
328 if( pos != KErrNotFound ) |
|
329 { |
|
330 iFunc.Set( iFunc.Left( pos ) ); |
|
331 iCanLeave = !iFunc.Right( |
|
332 KFuncLeavePatternL().Length() ).Compare( KFuncLeavePatternL ); |
|
333 if ( iCanLeave ) |
|
334 { |
|
335 CleanupStack::PushL( iCleanupItem ); // Ignore warnings |
|
336 } |
|
337 } |
|
338 FUNC( _PREFIX_CHAR("%S-START"), &iFunc ); |
|
339 } |
|
340 |
|
341 inline ~TFuncLog() |
|
342 { |
|
343 if ( !iLeft ) |
|
344 { |
|
345 if ( iCanLeave ) |
|
346 { |
|
347 CleanupStack::Pop( this ); // Pop the cleanup item |
|
348 } |
|
349 FUNC( _PREFIX_CHAR("%S-END"), &iFunc ); // Normally finished |
|
350 } |
|
351 } |
|
352 |
|
353 private: // Data |
|
354 TPtrC8 iFunc; |
|
355 TBool iLeft; |
|
356 TCleanupItem iCleanupItem; |
|
357 TBool iCanLeave; |
|
358 }; |
|
359 #define FUNC_LOG TFuncLog _fl( __PRETTY_FUNCTION__ ); |
|
360 |
|
361 #else//FUNC_TRACE not defined |
|
362 |
|
363 #define FUNC_LOG |
|
364 |
|
365 #endif//FUNC_TRACE |
|
366 |
|
367 //---------------------------------------------------------------------------- |
|
368 // Timestamp trace macros |
|
369 //---------------------------------------------------------------------------- |
|
370 // |
|
371 #ifdef TIMESTAMP_TRACE |
|
372 |
|
373 #ifdef TRACE_INTO_FILE |
|
374 |
|
375 #define TIMESTAMP( aCaption )\ |
|
376 {\ |
|
377 TTime t;\ |
|
378 t.HomeTime();\ |
|
379 TDateTime dt = t.DateTime();\ |
|
380 _LIT( KCaption, aCaption );\ |
|
381 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend,\ |
|
382 _PREFIX_TRACE("[TIMESTAMP] %S %d:%02d:%02d.%d us"),\ |
|
383 &KCaption, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond() );\ |
|
384 } |
|
385 |
|
386 #else//TRACE_INTO_FILE not defined |
|
387 |
|
388 #define TIMESTAMP( aCaption )\ |
|
389 {\ |
|
390 TTime t;\ |
|
391 t.HomeTime();\ |
|
392 TDateTime dt = t.DateTime();\ |
|
393 _LIT( KCaption, aCaption );\ |
|
394 RDebug::Print( _PREFIX_TRACE("[TIMESTAMP] %S %d:%02d:%02d.%d us"),\ |
|
395 &KCaption, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond() );\ |
|
396 } |
|
397 |
|
398 #endif//TRACE_INTO_FILE |
|
399 |
|
400 #else//TIMESTAMP_TRACE not defined |
|
401 |
|
402 #define TIMESTAMP( aCaption ) |
|
403 |
|
404 #endif//TIMESTAMP_TRACE |
|
405 |
|
406 #ifdef _DEBUG |
|
407 |
|
408 static void Panic( const TDesC8& aFileName, const TInt aLineNum ) |
|
409 { |
|
410 TPath name; |
|
411 name.Copy( aFileName ); |
|
412 RDebug::Print( _L( "Assertion failed in file=%S, line=%d" ), &name, aLineNum ); |
|
413 User::Invariant(); |
|
414 } |
|
415 |
|
416 #define ASSERT_ALWAYS_TRACE Panic( _L8(__FILE__), __LINE__ ); |
|
417 #define ASSERT_TRACE( _s ) if ( !( _s ) ) { ASSERT_ALWAYS_TRACE; } |
|
418 |
|
419 #else // _DEBUG |
|
420 |
|
421 #define ASSERT_ALWAYS_TRACE |
|
422 #define ASSERT_TRACE( _s ) |
|
423 |
|
424 #endif // _DEBUG |
|
425 |
|
426 #endif |