|
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 "traceconfiguration.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"[DisplaySource]: " 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*)"[DisplaySource]: " ##aMsg |
|
55 |
|
56 /** |
|
57 * Define needed directories if TRACE_INTO_FILE macro in use |
|
58 */ |
|
59 #ifdef TRACE_INTO_FILE |
|
60 |
|
61 _LIT( KDir, "DisplaySource" ); |
|
62 _LIT( KFile, "DisplaySource.log" ); |
|
63 _LIT( KFullPath, "c:\\logs\\DisplaySource\\" ); |
|
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 RFileLogger::Write( KDir, KFile, EFileLoggingModeAppend, _PREFIX_INFO( aMsg ) );\ |
|
172 } |
|
173 #define INFO_1( aMsg, aP1 )\ |
|
174 {\ |
|
175 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_INFO( aMsg ), aP1 );\ |
|
176 } |
|
177 #define INFO_2( aMsg, aP1, aP2 )\ |
|
178 {\ |
|
179 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_INFO( aMsg ), aP1, aP2 );\ |
|
180 } |
|
181 #define INFO_3( aMsg, aP1, aP2, aP3 )\ |
|
182 {\ |
|
183 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_INFO( aMsg ), aP1, aP2, aP3 );\ |
|
184 } |
|
185 |
|
186 #else//TRACE_INTO_FILE not defined |
|
187 |
|
188 #define INFO( aMsg )\ |
|
189 {\ |
|
190 RDebug::Print( _PREFIX_INFO( aMsg ) );\ |
|
191 } |
|
192 #define INFO_1( aMsg, aP1 )\ |
|
193 {\ |
|
194 RDebug::Print( _PREFIX_INFO( aMsg ), aP1 );\ |
|
195 } |
|
196 #define INFO_2( aMsg, aP1, aP2 )\ |
|
197 {\ |
|
198 RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2 );\ |
|
199 } |
|
200 #define INFO_3( aMsg, aP1, aP2, aP3 )\ |
|
201 {\ |
|
202 RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2, aP3 );\ |
|
203 } |
|
204 |
|
205 #endif//TRACE_INTO_FILE |
|
206 |
|
207 #else//INFO_TRACE not defined |
|
208 |
|
209 #define INFO( aMsg ) |
|
210 #define INFO_1( aMsg, aP1 ) |
|
211 #define INFO_2( aMsg, aP1, aP2 ) |
|
212 #define INFO_3( aMsg, aP1, aP2, aP3 ) |
|
213 |
|
214 #endif//INFO_TRACE |
|
215 |
|
216 //----------------------------------------------------------------------------- |
|
217 // Function trace macros |
|
218 //----------------------------------------------------------------------------- |
|
219 // |
|
220 #ifdef FUNC_TRACE |
|
221 |
|
222 /** |
|
223 * Function logging definitions. |
|
224 */ |
|
225 #ifdef TRACE_INTO_FILE |
|
226 |
|
227 #define FUNC( aMsg, aP1 )\ |
|
228 {\ |
|
229 TPtrC8 trace( _S8( aMsg ) );\ |
|
230 RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, trace, aP1 );\ |
|
231 }\ |
|
232 |
|
233 #else//TRACE_INTO_FILE not defined |
|
234 |
|
235 #define FUNC( aMsg, aP1 )\ |
|
236 {\ |
|
237 RDebug::Printf( aMsg, aP1 );\ |
|
238 }\ |
|
239 |
|
240 #endif//TRACE_INTO_FILE |
|
241 |
|
242 /** |
|
243 * Function trace helper class. |
|
244 * |
|
245 * NOTE: |
|
246 * LC -methods cannot be trapped. Therefore if LC -method leaves |
|
247 * END trace is used instead of LEAVE trace. |
|
248 * If you have an idea how to round this problem please tell. |
|
249 */ |
|
250 _LIT8( KFuncNameTerminator, "(" ); |
|
251 _LIT8( KFuncLeavePatternL, "L" ); |
|
252 class TFuncLog |
|
253 { |
|
254 public: |
|
255 static void Cleanup( TAny* aPtr ) |
|
256 { |
|
257 TFuncLog* self = static_cast< TFuncLog* >( aPtr ); |
|
258 self->iLeft = ETrue; |
|
259 FUNC( _PREFIX_CHAR("%S-LEAVE"), &self->iFunc ); // Leave detected |
|
260 } |
|
261 inline TFuncLog( const char* aFunc ) : |
|
262 iFunc( aFunc ? _S8( aFunc ) : _S8("") ), |
|
263 iLeft( EFalse ), |
|
264 iCleanupItem( Cleanup, this ), |
|
265 iCanLeave( EFalse ) |
|
266 { |
|
267 TInt pos( iFunc.Find( KFuncNameTerminator ) ); |
|
268 if( pos != KErrNotFound ) |
|
269 { |
|
270 iFunc.Set( iFunc.Left( pos ) ); |
|
271 iCanLeave = !iFunc.Right( KFuncLeavePatternL().Length() ).Compare( KFuncLeavePatternL ); |
|
272 if ( iCanLeave ) |
|
273 { |
|
274 CleanupStack::PushL( iCleanupItem ); // Ignore warnings |
|
275 } |
|
276 } |
|
277 FUNC( _PREFIX_CHAR("%S-START"), &iFunc ); |
|
278 } |
|
279 |
|
280 inline ~TFuncLog() |
|
281 { |
|
282 if ( !iLeft ) |
|
283 { |
|
284 if ( iCanLeave ) |
|
285 { |
|
286 CleanupStack::Pop( this ); // Pop the cleanup item |
|
287 } |
|
288 FUNC( _PREFIX_CHAR("%S-END"), &iFunc ); // Normally finished |
|
289 } |
|
290 } |
|
291 |
|
292 private: // Data |
|
293 TPtrC8 iFunc; |
|
294 TBool iLeft; |
|
295 TCleanupItem iCleanupItem; |
|
296 TBool iCanLeave; |
|
297 }; |
|
298 #define FUNC_LOG TFuncLog _fl( __PRETTY_FUNCTION__ ); |
|
299 |
|
300 #else//FUNC_TRACE not defined |
|
301 |
|
302 #define FUNC_LOG |
|
303 |
|
304 #endif//FUNC_TRACE |
|
305 |
|
306 #endif |