|
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: Debug definitions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef SYSVERSIONINFODEBUG_H |
|
20 #define SYSVERSIONINFODEBUG_H |
|
21 |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <e32debug.h> |
|
26 |
|
27 // Function trace |
|
28 //#define SYSVERSIONINFO_FUNC_LOG |
|
29 |
|
30 // Informative trace |
|
31 //#define SYSVERSIONINFO_INFO_LOG |
|
32 |
|
33 // Error trace |
|
34 //#define SYSVERSIONINFO_ERROR_LOG |
|
35 |
|
36 #ifdef _DEBUG |
|
37 #ifndef SYSVERSIONINFO_ERROR_LOG |
|
38 #define SYSVERSIONINFO_ERROR_LOG |
|
39 #endif // SYSVERSIONINFO_ERROR_LOG |
|
40 #endif // _DEBUG |
|
41 |
|
42 |
|
43 // Function logging |
|
44 #ifdef SYSVERSIONINFO_FUNC_LOG |
|
45 |
|
46 // Function log object |
|
47 _LIT8( KFuncNameTerminator, "(" ); |
|
48 _LIT8( KFuncLeavePattern, "L" ); |
|
49 |
|
50 class TFuncLog |
|
51 { |
|
52 public: |
|
53 static void Cleanup( TAny* aPtr ) |
|
54 { |
|
55 // Leave detected |
|
56 TFuncLog* self = static_cast< TFuncLog* >( aPtr ); |
|
57 self->iLeft = ETrue; |
|
58 if ( self->iLogClient ) |
|
59 { |
|
60 TName name( RThread().Name() ); |
|
61 _LIT( KMsg, "Client=%S-LEAVE" ); |
|
62 RDebug::Print( KMsg, &name ); |
|
63 } |
|
64 RDebug::Printf( "%S-LEAVE", &self->iFunc ); |
|
65 } |
|
66 |
|
67 inline TFuncLog( const char* aFunc, TBool aLogClient ) : |
|
68 iFunc( aFunc ? _S8( aFunc ) : _S8("") ), |
|
69 iLogClient( aLogClient ), |
|
70 iLeft( EFalse ), |
|
71 iCanLeave( EFalse ) |
|
72 { |
|
73 TInt pos( iFunc.Find( KFuncNameTerminator ) ); |
|
74 if( pos != KErrNotFound ) |
|
75 { |
|
76 iFunc.Set( iFunc.Left( pos ) ); |
|
77 TInt patLen( KFuncLeavePattern().Length() ); |
|
78 iCanLeave = iFunc.Length() > patLen && |
|
79 !iFunc.Right( patLen ).Compare( KFuncLeavePattern ); |
|
80 } |
|
81 RDebug::Printf( "%S-START", &iFunc ); |
|
82 if ( iLogClient ) |
|
83 { |
|
84 TName name( RThread().Name() ); |
|
85 _LIT( KMsg, "Client=%S-START" ); |
|
86 RDebug::Print( KMsg, &name ); |
|
87 } |
|
88 } |
|
89 |
|
90 inline ~TFuncLog() |
|
91 { |
|
92 if ( !iLeft ) |
|
93 { |
|
94 if ( iCanLeave ) |
|
95 { |
|
96 CleanupStack::Pop( this ); // Pop the cleanup item |
|
97 } |
|
98 // Normally finished |
|
99 if ( iLogClient ) |
|
100 { |
|
101 TName name( RThread().Name() ); |
|
102 _LIT( KMsg, "Client=%S-END" ); |
|
103 RDebug::Print( KMsg, &name ); |
|
104 } |
|
105 RDebug::Printf( "%S-END", &iFunc ); |
|
106 } |
|
107 } |
|
108 |
|
109 TPtrC8 iFunc; |
|
110 TBool iLogClient; |
|
111 TBool iLeft; |
|
112 TBool iCanLeave; |
|
113 }; |
|
114 |
|
115 #define FUNC_LOG\ |
|
116 TFuncLog _fl( __PRETTY_FUNCTION__, EFalse );\ |
|
117 TCleanupItem _flCi( TFuncLog::Cleanup, &_fl );\ |
|
118 if ( _fl.iCanLeave ) { CleanupStack::PushL( _flCi ); } |
|
119 |
|
120 #define FUNC_LOG_WITH_CLIENT_NAME\ |
|
121 TFuncLog _fl( __PRETTY_FUNCTION__, ETrue );\ |
|
122 TCleanupItem _flCi( TFuncLog::Cleanup, &_fl );\ |
|
123 if ( _fl.iCanLeave ) { CleanupStack::PushL( _flCi ); } |
|
124 |
|
125 #else // SYSVERSIONINFO_FUNC_LOG |
|
126 |
|
127 #define FUNC_LOG |
|
128 |
|
129 #define FUNC_LOG_WITH_CLIENT_NAME |
|
130 |
|
131 #endif // SYSVERSIONINFO_FUNC_LOG |
|
132 |
|
133 // Informative logging |
|
134 #ifdef SYSVERSIONINFO_INFO_LOG |
|
135 |
|
136 #define INFO_LOG( aMsg ) { _LIT( KMsg, aMsg ); RDebug::Print( KMsg ); } |
|
137 |
|
138 #define INFO_LOG1( aMsg, aArg1 )\ |
|
139 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1 ); } |
|
140 |
|
141 #define INFO_LOG2( aMsg, aArg1, aArg2 )\ |
|
142 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2 ); } |
|
143 |
|
144 #define INFO_LOG3( aMsg, aArg1, aArg2, aArg3 )\ |
|
145 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2, aArg3 ); } |
|
146 |
|
147 #else // SYSVERSIONINFO_INFO_LOG |
|
148 |
|
149 #define INFO_LOG( aMsg ) |
|
150 |
|
151 #define INFO_LOG1( aMsg, aArg1 ) |
|
152 |
|
153 #define INFO_LOG2( aMsg, aArg1, aArg2 ) |
|
154 |
|
155 #define INFO_LOG3( aMsg, aArg1, aArg2, aArg3 ) |
|
156 |
|
157 #endif // SYSVERSIONINFO_INFO_LOG |
|
158 |
|
159 |
|
160 // Error logging |
|
161 #ifdef SYSVERSIONINFO_ERROR_LOG |
|
162 |
|
163 #define ERROR_LOG( aMsg ) { _LIT( KMsg, aMsg ); RDebug::Print( KMsg ); } |
|
164 |
|
165 #define ERROR_LOG1( aMsg, aArg1 )\ |
|
166 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1 ); } |
|
167 |
|
168 #define ERROR_LOG2( aMsg, aArg1, aArg2 )\ |
|
169 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2 ); } |
|
170 |
|
171 #define ERROR_LOG3( aMsg, aArg1, aArg2, aArg3 )\ |
|
172 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2, aArg3 ); } |
|
173 |
|
174 #define LOG_IF_ERROR( aErr, aMsg )\ |
|
175 if ( ( aErr ) != KErrNone )\ |
|
176 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg ); } |
|
177 |
|
178 #define LOG_IF_ERROR1( aErr, aMsg, aArg1 )\ |
|
179 if ( ( aErr ) != KErrNone )\ |
|
180 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1 ); } |
|
181 |
|
182 #define LOG_IF_ERROR2( aErr, aMsg, aArg1, aArg2 )\ |
|
183 if ( ( aErr ) != KErrNone )\ |
|
184 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2 ); } |
|
185 |
|
186 #define LOG_IF_ERROR3( aErr, aMsg, aArg1, aArg2, aArg3 )\ |
|
187 if ( ( aErr ) != KErrNone )\ |
|
188 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2, aArg3 ); } |
|
189 |
|
190 #else // SYSVERSIONINFO_ERROR_LOG |
|
191 |
|
192 #define ERROR_LOG( aMsg ) |
|
193 |
|
194 #define ERROR_LOG1( aMsg, aArg1 ) |
|
195 |
|
196 #define ERROR_LOG2( aMsg, aArg1, aArg2 ) |
|
197 |
|
198 #define ERROR_LOG3( aMsg, aArg1, aArg2, aArg3 ) |
|
199 |
|
200 #define LOG_IF_ERROR( aErr, aMsg ) |
|
201 |
|
202 #define LOG_IF_ERROR1( aErr, aMsg, aArg1 ) |
|
203 |
|
204 #define LOG_IF_ERROR2( aErr, aMsg, aArg1, aArg2 ) |
|
205 |
|
206 #define LOG_IF_ERROR3( aErr, aMsg, aArg1, aArg2, aArg3 ) |
|
207 |
|
208 #endif // SYSVERSIONINFO_ERROR_LOG |
|
209 |
|
210 |
|
211 #endif // SYSVERSIONINFODEBUG_H |
|
212 |
|
213 // End of File |