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