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