sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
#ifndef FEATMGRDEBUG_H
|
sl@0
|
21 |
#define FEATMGRDEBUG_H
|
sl@0
|
22 |
|
sl@0
|
23 |
|
sl@0
|
24 |
// INCLUDES
|
sl@0
|
25 |
#include <e32debug.h>
|
sl@0
|
26 |
|
sl@0
|
27 |
// Enable macros to support error and/or info logging
|
sl@0
|
28 |
#ifdef _DEBUG
|
sl@0
|
29 |
//#define FEATMGR_INFO_LOG_ENABLED
|
sl@0
|
30 |
//#define FEATMGR_ERROR_LOG_ENABLED
|
sl@0
|
31 |
#define FEATMGR_TIMESTAMP_ENABLED
|
sl@0
|
32 |
#endif // _DEBUG
|
sl@0
|
33 |
|
sl@0
|
34 |
|
sl@0
|
35 |
/**
|
sl@0
|
36 |
* Prefix trace macro to complete tracing with component name.
|
sl@0
|
37 |
* Returns TDesC which can be used directly with RDebug or RFileLogger.
|
sl@0
|
38 |
*/
|
sl@0
|
39 |
#define PREFIX( aMsg ) TPtrC( (const TText*)L"[EFM]: " L##aMsg )
|
sl@0
|
40 |
|
sl@0
|
41 |
/**
|
sl@0
|
42 |
* Prefix error trace
|
sl@0
|
43 |
*/
|
sl@0
|
44 |
#define ERROR_PREFIX( aMsg ) PREFIX( "[ERROR]: " L##aMsg )
|
sl@0
|
45 |
|
sl@0
|
46 |
/**
|
sl@0
|
47 |
* Prefix macro for strings
|
sl@0
|
48 |
*/
|
sl@0
|
49 |
#define _PREFIX_CHAR( aMsg ) (const char*)"[EFM]: " ##aMsg
|
sl@0
|
50 |
|
sl@0
|
51 |
// Info logging
|
sl@0
|
52 |
#ifdef FEATMGR_INFO_LOG_ENABLED
|
sl@0
|
53 |
|
sl@0
|
54 |
#define INFO_LOG( aMsg ) { RDebug::Print( PREFIX( aMsg ) ); }
|
sl@0
|
55 |
|
sl@0
|
56 |
#define INFO_LOG1( aMsg, aArg1 )\
|
sl@0
|
57 |
{ RDebug::Print( PREFIX( aMsg ), aArg1 ); }
|
sl@0
|
58 |
|
sl@0
|
59 |
#define INFO_LOG2( aMsg, aArg1, aArg2 )\
|
sl@0
|
60 |
{ RDebug::Print( PREFIX( aMsg ), aArg1, aArg2 ); }
|
sl@0
|
61 |
|
sl@0
|
62 |
#define INFO_LOG3( aMsg, aArg1, aArg2, aArg3 )\
|
sl@0
|
63 |
{ RDebug::Print( PREFIX( aMsg ), aArg1, aArg2, aArg3 ); }
|
sl@0
|
64 |
|
sl@0
|
65 |
#define FUNC( aMsg, aP1 )\
|
sl@0
|
66 |
{\
|
sl@0
|
67 |
RDebug::Printf( aMsg, aP1 );\
|
sl@0
|
68 |
}\
|
sl@0
|
69 |
// Function log object
|
sl@0
|
70 |
_LIT8( KFuncNameTerminator, "(" );
|
sl@0
|
71 |
_LIT8( KFuncLeavePattern, "L" );
|
sl@0
|
72 |
|
sl@0
|
73 |
class TFuncLog
|
sl@0
|
74 |
{
|
sl@0
|
75 |
public:
|
sl@0
|
76 |
|
sl@0
|
77 |
static void Cleanup( TAny* aPtr )
|
sl@0
|
78 |
{
|
sl@0
|
79 |
TFuncLog* self = static_cast< TFuncLog* >( aPtr );
|
sl@0
|
80 |
self->iLeft = ETrue;
|
sl@0
|
81 |
FUNC( _PREFIX_CHAR("%S-LEAVE"), &self->iFunc ); // Leave detected
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
inline TFuncLog( const char* aFunc ) :
|
sl@0
|
85 |
iFunc( aFunc ? _S8( aFunc ) : _S8("") ),
|
sl@0
|
86 |
iLeft( EFalse ),
|
sl@0
|
87 |
iCleanupItem( Cleanup, this ),
|
sl@0
|
88 |
iCanLeave( EFalse )
|
sl@0
|
89 |
{
|
sl@0
|
90 |
TInt pos( iFunc.Find( KFuncNameTerminator ) );
|
sl@0
|
91 |
if( pos != KErrNotFound )
|
sl@0
|
92 |
{
|
sl@0
|
93 |
iFunc.Set( iFunc.Left( pos ) );
|
sl@0
|
94 |
iCanLeave = !iFunc.Right( KFuncLeavePattern().Length() ).Compare( KFuncLeavePattern );
|
sl@0
|
95 |
if ( iCanLeave )
|
sl@0
|
96 |
{
|
sl@0
|
97 |
CleanupStack::PushL( iCleanupItem ); // Ignore warnings
|
sl@0
|
98 |
}
|
sl@0
|
99 |
}
|
sl@0
|
100 |
FUNC( _PREFIX_CHAR("%S-START"), &iFunc );
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
inline ~TFuncLog()
|
sl@0
|
104 |
{
|
sl@0
|
105 |
if ( !iLeft )
|
sl@0
|
106 |
{
|
sl@0
|
107 |
if ( iCanLeave )
|
sl@0
|
108 |
{
|
sl@0
|
109 |
CleanupStack::Pop( this ); // Pop the cleanup item
|
sl@0
|
110 |
}
|
sl@0
|
111 |
FUNC( _PREFIX_CHAR("%S-END"), &iFunc ); // Normally finished
|
sl@0
|
112 |
}
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
private: // Data
|
sl@0
|
116 |
|
sl@0
|
117 |
TPtrC8 iFunc;
|
sl@0
|
118 |
TBool iLeft;
|
sl@0
|
119 |
TCleanupItem iCleanupItem;
|
sl@0
|
120 |
TBool iCanLeave;
|
sl@0
|
121 |
};
|
sl@0
|
122 |
|
sl@0
|
123 |
#define FUNC_LOG TFuncLog _fl( __PRETTY_FUNCTION__ );
|
sl@0
|
124 |
|
sl@0
|
125 |
#else // FEATMGR_INFO_LOG_ENABLED
|
sl@0
|
126 |
|
sl@0
|
127 |
#define INFO_LOG( aMsg )
|
sl@0
|
128 |
|
sl@0
|
129 |
#define INFO_LOG1( aMsg, aArg1 )
|
sl@0
|
130 |
|
sl@0
|
131 |
#define INFO_LOG2( aMsg, aArg1, aArg2 )
|
sl@0
|
132 |
|
sl@0
|
133 |
#define INFO_LOG3( aMsg, aArg1, aArg2, aArg3 )
|
sl@0
|
134 |
|
sl@0
|
135 |
#define FUNC_LOG
|
sl@0
|
136 |
|
sl@0
|
137 |
#endif // FEATMGR_INFO_LOG_ENABLED
|
sl@0
|
138 |
|
sl@0
|
139 |
// Timestamp logging
|
sl@0
|
140 |
#ifdef FEATMGR_TIMESTAMP_ENABLED
|
sl@0
|
141 |
|
sl@0
|
142 |
#define TIMESTAMP( aCaption )\
|
sl@0
|
143 |
{\
|
sl@0
|
144 |
TTime t;\
|
sl@0
|
145 |
t.HomeTime();\
|
sl@0
|
146 |
TDateTime dt = t.DateTime();\
|
sl@0
|
147 |
_LIT( KCaption, aCaption );\
|
sl@0
|
148 |
RDebug::Print( PREFIX("[TIMESTAMP] %S %d:%02d:%02d.%d us"),\
|
sl@0
|
149 |
&KCaption, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond() );\
|
sl@0
|
150 |
}
|
sl@0
|
151 |
|
sl@0
|
152 |
#else
|
sl@0
|
153 |
|
sl@0
|
154 |
#define TIMESTAMP( aCaption )
|
sl@0
|
155 |
|
sl@0
|
156 |
#endif // FEATMGR_TIMESTAMP_ENABLED
|
sl@0
|
157 |
|
sl@0
|
158 |
// Error logging
|
sl@0
|
159 |
#ifdef FEATMGR_ERROR_LOG_ENABLED
|
sl@0
|
160 |
|
sl@0
|
161 |
#define ERROR_LOG( aMsg )\
|
sl@0
|
162 |
{RDebug::Print( ERROR_PREFIX( aMsg ) ); }
|
sl@0
|
163 |
|
sl@0
|
164 |
#define ERROR_LOG1( aMsg, aArg1 )\
|
sl@0
|
165 |
{RDebug::Print( ERROR_PREFIX( aMsg ), aArg1 ); }
|
sl@0
|
166 |
|
sl@0
|
167 |
#define ERROR_LOG2( aMsg, aArg1, aArg2 )\
|
sl@0
|
168 |
{ RDebug::Print( ERROR_PREFIX( aMsg ), aArg1, aArg2 ); }
|
sl@0
|
169 |
|
sl@0
|
170 |
#define ERROR_LOG3( aMsg, aArg1, aArg2, aArg3 )\
|
sl@0
|
171 |
{ RDebug::Print( ERROR_PREFIX( aMsg ), aArg1, aArg2, aArg3 ); }
|
sl@0
|
172 |
|
sl@0
|
173 |
#define LOG_IF_ERROR( aErr, aMsg )\
|
sl@0
|
174 |
if ( ( aErr ) != KErrNone )\
|
sl@0
|
175 |
{ RDebug::Print( ERROR_PREFIX( aMsg )); }
|
sl@0
|
176 |
|
sl@0
|
177 |
#define LOG_IF_ERROR1( aErr, aMsg, aArg1 )\
|
sl@0
|
178 |
if ( ( aErr ) != KErrNone )\
|
sl@0
|
179 |
{ RDebug::Print( ERROR_PREFIX( aMsg ), aArg1 ); }
|
sl@0
|
180 |
|
sl@0
|
181 |
#define LOG_IF_ERROR2( aErr, aMsg, aArg1, aArg2 )\
|
sl@0
|
182 |
if ( ( aErr ) != KErrNone )\
|
sl@0
|
183 |
{ RDebug::Print( ERROR_PREFIX( aMsg ), aArg1, aArg2 ); }
|
sl@0
|
184 |
|
sl@0
|
185 |
#define LOG_IF_ERROR3( aErr, aMsg, aArg1, aArg2, aArg3 )\
|
sl@0
|
186 |
if ( ( aErr ) != KErrNone )\
|
sl@0
|
187 |
{ RDebug::Print( ERROR_PREFIX( aMsg ), aArg1, aArg2, aArg3 ); }
|
sl@0
|
188 |
|
sl@0
|
189 |
#else // FEATMGR_ERROR_LOG_ENABLED
|
sl@0
|
190 |
|
sl@0
|
191 |
#define ERROR_LOG( aMsg )
|
sl@0
|
192 |
|
sl@0
|
193 |
#define ERROR_LOG1( aMsg, aArg1 )
|
sl@0
|
194 |
|
sl@0
|
195 |
#define ERROR_LOG2( aMsg, aArg1, aArg2 )
|
sl@0
|
196 |
|
sl@0
|
197 |
#define ERROR_LOG3( aMsg, aArg1, aArg2, aArg3 )
|
sl@0
|
198 |
|
sl@0
|
199 |
// Remove compiler warning
|
sl@0
|
200 |
#define LOG_IF_ERROR( aErr, aMsg ) ( aErr ) = ( aErr );
|
sl@0
|
201 |
|
sl@0
|
202 |
#define LOG_IF_ERROR1( aErr, aMsg, aArg1 ) ( aErr ) = ( aErr );
|
sl@0
|
203 |
|
sl@0
|
204 |
#define LOG_IF_ERROR2( aErr, aMsg, aArg1, aArg2 ) ( aErr ) = ( aErr );
|
sl@0
|
205 |
|
sl@0
|
206 |
#define LOG_IF_ERROR3( aErr, aMsg, aArg1, aArg2, aArg3 ) ( aErr ) = ( aErr );
|
sl@0
|
207 |
|
sl@0
|
208 |
#endif // FEATMGR_ERROR_LOG_ENABLED
|
sl@0
|
209 |
|
sl@0
|
210 |
|
sl@0
|
211 |
#endif // FEATMGRDEBUG_H
|
sl@0
|
212 |
|
sl@0
|
213 |
// End of File
|