|
1 /* |
|
2 * Copyright (c) 2006 - 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: Provides macros for logging and debugging. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef SVPLOGGER_H |
|
19 #define SVPLOGGER_H |
|
20 |
|
21 #ifdef _DEBUG // enable debug macros |
|
22 |
|
23 #ifndef COMPONENT |
|
24 #define COMPONENT |
|
25 _LIT( KComponent, "SVP" ); |
|
26 #endif // COMPONENT |
|
27 |
|
28 #include <e32svr.h> |
|
29 #include <e32cmn.h> |
|
30 #include "svpconsts.h" |
|
31 |
|
32 /***************************************************** |
|
33 * Format string for adding component to prints. |
|
34 * |
|
35 * Parameters passed within macros from code are |
|
36 * formatted with string that came as a parameter |
|
37 *****************************************************/ |
|
38 _LIT( KSVPPrintFormatString, "%S: %S" ); |
|
39 |
|
40 /* |
|
41 * Prints for text without params |
|
42 */ |
|
43 static inline void PrintL( const TDesC& aStr ) |
|
44 { |
|
45 HBufC* line = HBufC::NewLC( KSvpMaxDebugBufferSize ); |
|
46 TPtr ptr( line->Des() ); |
|
47 ptr.Format( KSVPPrintFormatString(), &KComponent(), &aStr ); |
|
48 RDebug::Print( line->Des() ); |
|
49 CleanupStack::PopAndDestroy( line ); |
|
50 } |
|
51 static inline void Print( const TDesC& aStr ) |
|
52 { |
|
53 TRAP_IGNORE( PrintL( aStr ) ) |
|
54 } |
|
55 |
|
56 /* |
|
57 * Prints for text with TInt as a param |
|
58 */ |
|
59 static inline void PrintL( const TDesC& aStr, const TInt& aTInt ) |
|
60 { |
|
61 HBufC* line1 = HBufC::NewLC( KSvpMaxDebugBufferSize ); |
|
62 TPtr ptr1( line1->Des() ); |
|
63 ptr1.Format( aStr, aTInt ); |
|
64 |
|
65 HBufC* line2 = HBufC::NewLC( KSvpMaxDebugBufferSize ); |
|
66 TPtr ptr2( line2->Des() ); |
|
67 ptr2.Format( KSVPPrintFormatString(), &KComponent(), line1 ); |
|
68 RDebug::Print( line2->Des() ); |
|
69 CleanupStack::PopAndDestroy( 2 ); |
|
70 } |
|
71 static inline void Print( const TDesC& aStr, const TInt& aTInt ) |
|
72 { |
|
73 TRAP_IGNORE( PrintL( aStr, aTInt ) ) |
|
74 } |
|
75 |
|
76 /* |
|
77 * Prints for text with any pointer as a param |
|
78 */ |
|
79 static inline void PrintL( const TDesC& aStr, const TAny* aPtr ) |
|
80 { |
|
81 HBufC* line1 = HBufC::NewLC( KSvpMaxDebugBufferSize ); |
|
82 TPtr ptr1( line1->Des() ); |
|
83 ptr1.Format( aStr, aPtr ); |
|
84 |
|
85 HBufC* line2 = HBufC::NewLC( KSvpMaxDebugBufferSize ); |
|
86 TPtr ptr2( line2->Des() ); |
|
87 ptr2.Format( KSVPPrintFormatString(), &KComponent(), line1 ); |
|
88 RDebug::Print( line2->Des() ); |
|
89 CleanupStack::PopAndDestroy( 2 ); |
|
90 } |
|
91 static inline void Print( const TDesC& aStr, const TAny* aPtr ) |
|
92 { |
|
93 TRAP_IGNORE( PrintL( aStr, aPtr ) ) |
|
94 } |
|
95 |
|
96 /* |
|
97 * Prints for text with two TInt as a param |
|
98 */ |
|
99 static inline void PrintL( const TDesC& aStr, |
|
100 const TInt& aTInt1, |
|
101 const TInt& aTInt2 ) |
|
102 { |
|
103 HBufC* line1 = HBufC::NewLC( KSvpMaxDebugBufferSize ); |
|
104 TPtr ptr1( line1->Des() ); |
|
105 ptr1.Format( aStr, aTInt1, aTInt2 ); |
|
106 |
|
107 HBufC* line2 = HBufC::NewLC( KSvpMaxDebugBufferSize ); |
|
108 TPtr ptr2( line2->Des() ); |
|
109 ptr2.Format( KSVPPrintFormatString(), &KComponent(), line1 ); |
|
110 RDebug::Print( line2->Des() ); |
|
111 CleanupStack::PopAndDestroy( 2 ); |
|
112 } |
|
113 static inline void Print( const TDesC& aStr, |
|
114 const TInt& aTInt1, |
|
115 const TInt& aTInt2 ) |
|
116 { |
|
117 TRAP_IGNORE( PrintL( aStr, aTInt1, aTInt2 ) ) |
|
118 } |
|
119 |
|
120 /* |
|
121 * Prints for text with TInt and a string as a parameter |
|
122 */ |
|
123 static inline void PrintL( const TDesC& aStr1, |
|
124 const TInt& aTInt, |
|
125 const TDesC* aStr2 ) |
|
126 { |
|
127 HBufC* line1 = HBufC::NewLC( KSvpMaxDebugBufferSize ); |
|
128 TPtr ptr1( line1->Des() ); |
|
129 ptr1.Format( aStr1, aTInt, aStr2 ); |
|
130 |
|
131 HBufC* line2 = HBufC::NewLC( KSvpMaxDebugBufferSize ); |
|
132 TPtr ptr2( line2->Des() ); |
|
133 ptr2.Format( KSVPPrintFormatString(), &KComponent(), line1 ); |
|
134 RDebug::Print( line2->Des() ); |
|
135 CleanupStack::PopAndDestroy( 2 ); |
|
136 } |
|
137 static inline void Print( const TDesC& aStr1, |
|
138 const TInt& aTInt, |
|
139 const TDesC* aStr2 ) |
|
140 { |
|
141 TRAP_IGNORE( PrintL( aStr1, aTInt, aStr2 ) ) |
|
142 } |
|
143 |
|
144 |
|
145 #define SVPDEBUG1( a ) { _LIT( KStr, a ); Print( KStr() ); } |
|
146 #define SVPDEBUG2( a, b ){ _LIT( KStr, a ); Print( KStr(), b ); } |
|
147 #define SVPDEBUG3( a, b, c ){ _LIT( KStr, a ); Print( KStr(), b, c ); } |
|
148 |
|
149 #else // _DEBUG |
|
150 |
|
151 #define SVPDEBUG1( a ) |
|
152 #define SVPDEBUG2( a, b ) |
|
153 #define SVPDEBUG3( a, b, c ) |
|
154 |
|
155 #endif // _DEBUG |
|
156 |
|
157 #endif // SVPLOGGER_H |