|
1 /* |
|
2 * Copyright (c) 2008 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 FMTXWATCHERDEBUG_H |
|
20 #define FMTXWATCHERDEBUG_H |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <e32debug.h> |
|
24 |
|
25 |
|
26 #ifdef _DEBUG |
|
27 #define FMTX_WATCHER_INFO_LOG_ENABLED |
|
28 #define FMTX_WATCHER_ERROR_LOG_ENABLED |
|
29 #endif // _DEBUG |
|
30 |
|
31 |
|
32 // Info logging |
|
33 #ifdef FMTX_WATCHER_INFO_LOG_ENABLED |
|
34 |
|
35 #define INFO_LOG( aMsg ) { _LIT( KMsg, aMsg ); RDebug::Print( KMsg ); } |
|
36 |
|
37 #define INFO_LOG1( aMsg, aArg1 )\ |
|
38 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1 ); } |
|
39 |
|
40 #define INFO_LOG2( aMsg, aArg1, aArg2 )\ |
|
41 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2 ); } |
|
42 |
|
43 #define INFO_LOG3( aMsg, aArg1, aArg2, aArg3 )\ |
|
44 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2, aArg3 ); } |
|
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 TFuncLog* self = static_cast< TFuncLog* >( aPtr ); |
|
56 self->iLeft = ETrue; |
|
57 RDebug::Printf( "%S-LEAVE", &self->iFunc ); // Leave detected |
|
58 } |
|
59 |
|
60 inline TFuncLog( const char* aFunc ) : |
|
61 iFunc( aFunc ? _S8( aFunc ) : _S8("") ), |
|
62 iLeft( EFalse ), |
|
63 iCanLeave( EFalse ) |
|
64 { |
|
65 TInt pos( iFunc.Find( KFuncNameTerminator ) ); |
|
66 if( pos != KErrNotFound ) |
|
67 { |
|
68 iFunc.Set( iFunc.Left( pos ) ); |
|
69 TInt patLen( KFuncLeavePattern().Length() ); |
|
70 iCanLeave = iFunc.Length() > patLen && |
|
71 !iFunc.Right( patLen ).Compare( KFuncLeavePattern ); |
|
72 } |
|
73 RDebug::Printf( "%S-START", &iFunc ); |
|
74 } |
|
75 |
|
76 inline ~TFuncLog() |
|
77 { |
|
78 if ( !iLeft ) |
|
79 { |
|
80 if ( iCanLeave ) |
|
81 { |
|
82 CleanupStack::Pop( this ); // Pop the cleanup item |
|
83 } |
|
84 RDebug::Printf( "%S-END", &iFunc ); // Normally finished |
|
85 } |
|
86 } |
|
87 |
|
88 TPtrC8 iFunc; |
|
89 TBool iLeft; |
|
90 TBool iCanLeave; |
|
91 }; |
|
92 |
|
93 #define FUNC_LOG\ |
|
94 TFuncLog _fl( __PRETTY_FUNCTION__ );\ |
|
95 TCleanupItem _flCi( TFuncLog::Cleanup, &_fl );\ |
|
96 if ( _fl.iCanLeave ) { CleanupStack::PushL( _flCi ); } |
|
97 |
|
98 #define TIMESTAMP( aCaption )\ |
|
99 {\ |
|
100 TTime t;\ |
|
101 t.HomeTime();\ |
|
102 RDebug::Printf( "%s %d us", aCaption, I64INT( t.Int64() ) );\ |
|
103 } |
|
104 |
|
105 #else // FMTX_WATCHER_INFO_LOG_ENABLED |
|
106 |
|
107 #define INFO_LOG( aMsg ) |
|
108 |
|
109 #define INFO_LOG1( aMsg, aArg1 ) |
|
110 |
|
111 #define INFO_LOG2( aMsg, aArg1, aArg2 ) |
|
112 |
|
113 #define INFO_LOG3( aMsg, aArg1, aArg2, aArg3 ) |
|
114 |
|
115 #define FUNC_LOG |
|
116 |
|
117 #define TIMESTAMP( aCaption ) |
|
118 |
|
119 #endif // FMTX_WATCHER_INFO_LOG_ENABLED |
|
120 |
|
121 |
|
122 // Error logging |
|
123 #ifdef FMTX_WATCHER_ERROR_LOG_ENABLED |
|
124 |
|
125 #define ERROR_LOG( aMsg ) { _LIT( KMsg, aMsg ); RDebug::Print( KMsg ); } |
|
126 |
|
127 #define ERROR_LOG1( aMsg, aArg1 )\ |
|
128 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1 ); } |
|
129 |
|
130 #define ERROR_LOG2( aMsg, aArg1, aArg2 )\ |
|
131 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2 ); } |
|
132 |
|
133 #define ERROR_LOG3( aMsg, aArg1, aArg2, aArg3 )\ |
|
134 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2, aArg3 ); } |
|
135 |
|
136 #define LOG_IF_ERROR( aErr, aMsg )\ |
|
137 if ( ( aErr ) != KErrNone )\ |
|
138 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg ); } |
|
139 |
|
140 #define LOG_IF_ERROR1( aErr, aMsg, aArg1 )\ |
|
141 if ( ( aErr ) != KErrNone )\ |
|
142 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1 ); } |
|
143 |
|
144 #define LOG_IF_ERROR2( aErr, aMsg, aArg1, aArg2 )\ |
|
145 if ( ( aErr ) != KErrNone )\ |
|
146 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2 ); } |
|
147 |
|
148 #define LOG_IF_ERROR3( aErr, aMsg, aArg1, aArg2, aArg3 )\ |
|
149 if ( ( aErr ) != KErrNone )\ |
|
150 { _LIT( KMsg, aMsg ); RDebug::Print( KMsg, aArg1, aArg2, aArg3 ); } |
|
151 |
|
152 #else // FMTX_WATCHER_ERROR_LOG_ENABLED |
|
153 |
|
154 #define ERROR_LOG( aMsg ) |
|
155 |
|
156 #define ERROR_LOG1( aMsg, aArg1 ) |
|
157 |
|
158 #define ERROR_LOG2( aMsg, aArg1, aArg2 ) |
|
159 |
|
160 #define ERROR_LOG3( aMsg, aArg1, aArg2, aArg3 ) |
|
161 |
|
162 // Remove compiler warning |
|
163 #define LOG_IF_ERROR( aErr, aMsg ) ( aErr ) = ( aErr ); |
|
164 |
|
165 #define LOG_IF_ERROR1( aErr, aMsg, aArg1 ) ( aErr ) = ( aErr ); |
|
166 |
|
167 #define LOG_IF_ERROR2( aErr, aMsg, aArg1, aArg2 ) ( aErr ) = ( aErr ); |
|
168 |
|
169 #define LOG_IF_ERROR3( aErr, aMsg, aArg1, aArg2, aArg3 ) ( aErr ) = ( aErr ); |
|
170 |
|
171 #endif // FMTX_WATCHER_ERROR_LOG_ENABLED |
|
172 |
|
173 |
|
174 #endif // FMTXWATCHERDEBUG_H |
|
175 |
|
176 // End of File |