63
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 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: Battery Popup Control trace definitions.
|
|
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"[BatteryPopupControl]: " 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*)"[BatteryPopupControl]: " aMsg
|
|
55 |
|
|
56 |
|
|
57 |
/**
|
|
58 |
* Define needed directories if TRACE_INTO_FILE macro in use
|
|
59 |
*/
|
|
60 |
#ifdef TRACE_INTO_FILE
|
|
61 |
|
|
62 |
_LIT( KDir, "BatteryPopupControl" );
|
|
63 |
_LIT( KFile, "BatteryPopupControl_log.txt" );
|
|
64 |
_LIT( KFullPath, "c:\\logs\\BatteryPopupControl\\" );
|
|
65 |
|
|
66 |
#endif
|
|
67 |
|
|
68 |
//-----------------------------------------------------------------------------
|
|
69 |
// Error trace macros
|
|
70 |
//-----------------------------------------------------------------------------
|
|
71 |
//
|
|
72 |
#ifdef ERROR_TRACE
|
|
73 |
|
|
74 |
/**
|
|
75 |
* Error trace definitions.
|
|
76 |
*/
|
|
77 |
#ifdef TRACE_INTO_FILE
|
|
78 |
|
|
79 |
#define ERROR( aErr, aMsg )\
|
|
80 |
{\
|
|
81 |
if( aErr < KErrNone )\
|
|
82 |
{\
|
|
83 |
RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _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, _PREFIX_ERROR( aMsg ), aErr, aP1 );\
|
|
91 |
}\
|
|
92 |
}
|
|
93 |
#define ERROR_2( aErr, aMsg, aP1, aP2 )\
|
|
94 |
{\
|
|
95 |
if( aErr < KErrNone )\
|
|
96 |
{\
|
|
97 |
RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_ERROR( aMsg ), aErr, aP1, aP2 );\
|
|
98 |
}\
|
|
99 |
}
|
|
100 |
#define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\
|
|
101 |
{\
|
|
102 |
if( aErr < KErrNone )\
|
|
103 |
{\
|
|
104 |
RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_ERROR( aMsg ), aErr, aP1, aP2, aP3 );\
|
|
105 |
}\
|
|
106 |
}
|
|
107 |
|
|
108 |
#else//TRACE_INTO_FILE not defined
|
|
109 |
|
|
110 |
#define ERROR( aErr, aMsg )\
|
|
111 |
{\
|
|
112 |
if( aErr < KErrNone )\
|
|
113 |
{\
|
|
114 |
RDebug::Print( _PREFIX_ERROR( aMsg ), aErr );\
|
|
115 |
}\
|
|
116 |
}
|
|
117 |
#define ERROR_1( aErr, aMsg, aP1 )\
|
|
118 |
{\
|
|
119 |
if( aErr < KErrNone )\
|
|
120 |
{\
|
|
121 |
RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1 );\
|
|
122 |
}\
|
|
123 |
}
|
|
124 |
#define ERROR_2( aErr, aMsg, aP1, aP2 )\
|
|
125 |
{\
|
|
126 |
if( aErr < KErrNone )\
|
|
127 |
{\
|
|
128 |
RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1, aP2 );\
|
|
129 |
}\
|
|
130 |
}
|
|
131 |
#define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )\
|
|
132 |
{\
|
|
133 |
if( aErr < KErrNone )\
|
|
134 |
{\
|
|
135 |
RDebug::Print( _PREFIX_ERROR( aMsg ), aErr, aP1, aP2, aP3 );\
|
|
136 |
}\
|
|
137 |
}
|
|
138 |
|
|
139 |
#endif//TRACE_INTO_FILE
|
|
140 |
|
|
141 |
#define ERROR_GEN( aMsg ) ERROR( KErrGeneral, aMsg )
|
|
142 |
#define ERROR_GEN_1( aMsg, aP1 ) ERROR_1( KErrGeneral, aMsg, aP1 )
|
|
143 |
#define ERROR_GEN_2( aMsg, aP1, aP2 ) ERROR_2( KErrGeneral, aMsg, aP1, aP2 )
|
|
144 |
#define ERROR_GEN_3( aMsg, aP1, aP2, aP3 ) ERROR_3( KErrGeneral, aMsg, aP1, aP3 )
|
|
145 |
|
|
146 |
#else//ERROR_TRACE not defined
|
|
147 |
|
|
148 |
#define ERROR( aErr, aMsg )
|
|
149 |
#define ERROR_1( aErr, aMsg, aP1 )
|
|
150 |
#define ERROR_2( aErr, aMsg, aP1, aP2 )
|
|
151 |
#define ERROR_3( aErr, aMsg, aP1, aP2, aP3 )
|
|
152 |
#define ERROR_GEN( aMsg )
|
|
153 |
#define ERROR_GEN_1( aMsg, aP1 )
|
|
154 |
#define ERROR_GEN_2( aMsg, aP1, aP2 )
|
|
155 |
#define ERROR_GEN_3( aMsg, aP1, aP2, aP3 )
|
|
156 |
|
|
157 |
#endif//ERROR_TRACE
|
|
158 |
|
|
159 |
//-----------------------------------------------------------------------------
|
|
160 |
// Info trace macros
|
|
161 |
//-----------------------------------------------------------------------------
|
|
162 |
//
|
|
163 |
#ifdef INFO_TRACE
|
|
164 |
|
|
165 |
/**
|
|
166 |
* Info log message definitions.
|
|
167 |
*/
|
|
168 |
#ifdef TRACE_INTO_FILE
|
|
169 |
|
|
170 |
#define INFO( aMsg )\
|
|
171 |
{\
|
|
172 |
RFileLogger::Write( KDir, KFile, EFileLoggingModeAppend, _PREFIX_INFO( aMsg ) );\
|
|
173 |
}
|
|
174 |
#define INFO_1( aMsg, aP1 )\
|
|
175 |
{\
|
|
176 |
RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_INFO( aMsg ), aP1 );\
|
|
177 |
}
|
|
178 |
#define INFO_2( aMsg, aP1, aP2 )\
|
|
179 |
{\
|
|
180 |
RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_INFO( aMsg ), aP1, aP2 );\
|
|
181 |
}
|
|
182 |
#define INFO_3( aMsg, aP1, aP2, aP3 )\
|
|
183 |
{\
|
|
184 |
RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, _PREFIX_INFO( aMsg ), aP1, aP2, aP3 );\
|
|
185 |
}
|
|
186 |
|
|
187 |
#else//TRACE_INTO_FILE not defined
|
|
188 |
|
|
189 |
#define INFO( aMsg )\
|
|
190 |
{\
|
|
191 |
RDebug::Print( _PREFIX_INFO( aMsg ) );\
|
|
192 |
}
|
|
193 |
#define INFO_1( aMsg, aP1 )\
|
|
194 |
{\
|
|
195 |
RDebug::Print( _PREFIX_INFO( aMsg ), aP1 );\
|
|
196 |
}
|
|
197 |
#define INFO_2( aMsg, aP1, aP2 )\
|
|
198 |
{\
|
|
199 |
RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2 );\
|
|
200 |
}
|
|
201 |
#define INFO_3( aMsg, aP1, aP2, aP3 )\
|
|
202 |
{\
|
|
203 |
RDebug::Print( _PREFIX_INFO( aMsg ), aP1, aP2, aP3 );\
|
|
204 |
}
|
|
205 |
|
|
206 |
#endif//TRACE_INTO_FILE
|
|
207 |
|
|
208 |
#else//INFO_TRACE not defined
|
|
209 |
|
|
210 |
#define INFO( aMsg )
|
|
211 |
#define INFO_1( aMsg, aP1 )
|
|
212 |
#define INFO_2( aMsg, aP1, aP2 )
|
|
213 |
#define INFO_3( aMsg, aP1, aP2, aP3 )
|
|
214 |
|
|
215 |
#endif//INFO_TRACE
|
|
216 |
|
|
217 |
//-----------------------------------------------------------------------------
|
|
218 |
// Trace current client thread name and process id
|
|
219 |
//-----------------------------------------------------------------------------
|
|
220 |
//
|
|
221 |
#ifdef CLIENT_TRACE
|
|
222 |
|
|
223 |
#define CLIENT( aMessage )\
|
|
224 |
{\
|
|
225 |
RThread thread;\
|
|
226 |
TInt err = aMessage.Client( thread );\
|
|
227 |
if( err == KErrNone )\
|
|
228 |
{\
|
|
229 |
RProcess process;\
|
|
230 |
err = thread.Process( process );\
|
|
231 |
if( err == KErrNone )\
|
|
232 |
{\
|
|
233 |
TPtrC thredName( thread.Name() );\
|
|
234 |
TUid processUid( process.SecureId() );\
|
|
235 |
INFO_2( "Current client process UID: [%x], thread name: [%S]",\
|
|
236 |
processUid,\
|
|
237 |
&thredName );\
|
|
238 |
}\
|
|
239 |
process.Close();\
|
|
240 |
}\
|
|
241 |
thread.Close();\
|
|
242 |
}
|
|
243 |
|
|
244 |
#else
|
|
245 |
|
|
246 |
#define CLIENT( aMessage )
|
|
247 |
|
|
248 |
#endif
|
|
249 |
|
|
250 |
//-----------------------------------------------------------------------------
|
|
251 |
// Function trace macros
|
|
252 |
//-----------------------------------------------------------------------------
|
|
253 |
//
|
|
254 |
#ifdef FUNC_TRACE
|
|
255 |
|
|
256 |
/**
|
|
257 |
* Function logging definitions.
|
|
258 |
*/
|
|
259 |
#ifdef TRACE_INTO_FILE
|
|
260 |
|
|
261 |
#define FUNC( aMsg, aP1 )\
|
|
262 |
{\
|
|
263 |
TPtrC8 trace( _S8( aMsg ) );\
|
|
264 |
RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend, trace, aP1 );\
|
|
265 |
}\
|
|
266 |
|
|
267 |
#else//TRACE_INTO_FILE not defined
|
|
268 |
|
|
269 |
#define FUNC( aMsg, aP1 )\
|
|
270 |
{\
|
|
271 |
RDebug::Printf( aMsg, aP1 );\
|
|
272 |
}\
|
|
273 |
|
|
274 |
#endif//TRACE_INTO_FILE
|
|
275 |
|
|
276 |
/**
|
|
277 |
* Function trace helper class.
|
|
278 |
*
|
|
279 |
* NOTE:
|
|
280 |
* LC -methods cannot be trapped. Therefore if LC -method leaves
|
|
281 |
* END trace is used instead of LEAVE trace.
|
|
282 |
* If you have an idea how to round this problem please tell.
|
|
283 |
*/
|
|
284 |
_LIT8( KFuncNameTerminator, "(" );
|
|
285 |
_LIT8( KFuncLeavePatternL, "L" );
|
|
286 |
class TFuncLog
|
|
287 |
{
|
|
288 |
public:
|
|
289 |
static void Cleanup( TAny* aPtr )
|
|
290 |
{
|
|
291 |
TFuncLog* self = static_cast< TFuncLog* >( aPtr );
|
|
292 |
self->iLeft = ETrue;
|
|
293 |
FUNC( _PREFIX_CHAR("%S-LEAVE"), &self->iFunc ); // Leave detected
|
|
294 |
}
|
|
295 |
inline TFuncLog( const char* aFunc ) :
|
|
296 |
iFunc( aFunc ? _S8( aFunc ) : _S8("") ),
|
|
297 |
iLeft( EFalse ),
|
|
298 |
iCleanupItem( Cleanup, this ),
|
|
299 |
iCanLeave( EFalse )
|
|
300 |
{
|
|
301 |
TInt pos( iFunc.Find( KFuncNameTerminator ) );
|
|
302 |
if( pos != KErrNotFound )
|
|
303 |
{
|
|
304 |
iFunc.Set( iFunc.Left( pos ) );
|
|
305 |
iCanLeave = !iFunc.Right( KFuncLeavePatternL().Length() ).Compare( KFuncLeavePatternL );
|
|
306 |
if ( iCanLeave )
|
|
307 |
{
|
|
308 |
CleanupStack::PushL( iCleanupItem ); // Ignore warnings
|
|
309 |
}
|
|
310 |
}
|
|
311 |
FUNC( _PREFIX_CHAR("%S-START"), &iFunc );
|
|
312 |
}
|
|
313 |
|
|
314 |
inline ~TFuncLog()
|
|
315 |
{
|
|
316 |
if ( !iLeft )
|
|
317 |
{
|
|
318 |
if ( iCanLeave )
|
|
319 |
{
|
|
320 |
CleanupStack::Pop( this ); // Pop the cleanup item
|
|
321 |
}
|
|
322 |
FUNC( _PREFIX_CHAR("%S-END"), &iFunc ); // Normally finished
|
|
323 |
}
|
|
324 |
}
|
|
325 |
|
|
326 |
private: // Data
|
|
327 |
TPtrC8 iFunc;
|
|
328 |
TBool iLeft;
|
|
329 |
TCleanupItem iCleanupItem;
|
|
330 |
TBool iCanLeave;
|
|
331 |
};
|
|
332 |
#define FUNC_LOG TFuncLog _fl( __PRETTY_FUNCTION__ );
|
|
333 |
|
|
334 |
#else//FUNC_TRACE not defined
|
|
335 |
|
|
336 |
#define FUNC_LOG
|
|
337 |
|
|
338 |
#endif//FUNC_TRACE
|
|
339 |
|
|
340 |
//-----------------------------------------------------------------------------
|
|
341 |
// Timestamp trace macros
|
|
342 |
//-----------------------------------------------------------------------------
|
|
343 |
//
|
|
344 |
#ifdef TIMESTAMP_TRACE
|
|
345 |
|
|
346 |
#ifdef TRACE_INTO_FILE
|
|
347 |
|
|
348 |
#define TIMESTAMP( aCaption )\
|
|
349 |
{\
|
|
350 |
TTime t;\
|
|
351 |
t.HomeTime();\
|
|
352 |
TDateTime dt = t.DateTime();\
|
|
353 |
_LIT( KCaption, aCaption );\
|
|
354 |
RFileLogger::WriteFormat( KDir, KFile, EFileLoggingModeAppend,\
|
|
355 |
_PREFIX_TRACE("[TIMESTAMP] %S %d:%02d:%02d.%d us"),\
|
|
356 |
&KCaption, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond() );\
|
|
357 |
}
|
|
358 |
|
|
359 |
#else//TRACE_INTO_FILE not defined
|
|
360 |
|
|
361 |
#define TIMESTAMP( aCaption )\
|
|
362 |
{\
|
|
363 |
TTime t;\
|
|
364 |
t.HomeTime();\
|
|
365 |
TDateTime dt = t.DateTime();\
|
|
366 |
_LIT( KCaption, aCaption );\
|
|
367 |
RDebug::Print( _PREFIX_TRACE("[TIMESTAMP] %S %d:%02d:%02d.%d us"),\
|
|
368 |
&KCaption, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond() );\
|
|
369 |
}
|
|
370 |
|
|
371 |
#endif//TRACE_INTO_FILE
|
|
372 |
|
|
373 |
#else//TIMESTAMP_TRACE not defined
|
|
374 |
|
|
375 |
#define TIMESTAMP( aCaption )
|
|
376 |
|
|
377 |
#endif//TIMESTAMP_TRACE
|
|
378 |
|
|
379 |
#endif
|