|
1 /* |
|
2 * Copyright (c) 2004-2009 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 the License "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: |
|
15 * Print functions used in debug mode |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalComponent |
|
23 */ |
|
24 |
|
25 #ifndef __SWI_LOG_H__ |
|
26 #define __SWI_LOG_H__ |
|
27 |
|
28 #include <e32debug.h> |
|
29 |
|
30 class TTruncateOverflowHandler16 : public TDes16Overflow |
|
31 { |
|
32 public: |
|
33 virtual void Overflow(TDes16& aDes); |
|
34 }; |
|
35 |
|
36 inline void TTruncateOverflowHandler16::Overflow(TDes16&) |
|
37 { |
|
38 |
|
39 } |
|
40 |
|
41 class TTruncateOverflowHandler8 : public TDes8Overflow |
|
42 { |
|
43 public: |
|
44 virtual void Overflow(TDes8& aDes); |
|
45 }; |
|
46 |
|
47 inline void TTruncateOverflowHandler8::Overflow(TDes8&) |
|
48 { |
|
49 |
|
50 } |
|
51 |
|
52 namespace Swi |
|
53 { |
|
54 |
|
55 #ifdef _DEBUG |
|
56 |
|
57 #define DEBUG_PRINTF(a) {Swi::DebugPrintf(__LINE__, __FILE__, a);} |
|
58 #define DEBUG_PRINTF2(a, b) {Swi::DebugPrintf(__LINE__, __FILE__, a, b);} |
|
59 #define DEBUG_PRINTF3(a, b, c) {Swi::DebugPrintf(__LINE__, __FILE__, a, b, c);} |
|
60 #define DEBUG_PRINTF4(a, b, c, d) {Swi::DebugPrintf(__LINE__, __FILE__, a, b, c, d);} |
|
61 #define DEBUG_PRINTF5(a, b, c, d, e) {Swi::DebugPrintf(__LINE__, __FILE__, a, b, c, d, e);} |
|
62 |
|
63 #define DEBUG_CODE_SECTION(a) TRAP_IGNORE({ a; }) |
|
64 |
|
65 // UTF-8 overload of the DebufPrintf method. Should be used by default, |
|
66 // since it's cheaper both in CPU cycles and stack space. |
|
67 |
|
68 inline void DebugPrintf(TInt aLine, char* aFile, TRefByValue<const TDesC8> aFormat, ...) |
|
69 { |
|
70 TTruncateOverflowHandler8 overflowHandler8; |
|
71 VA_LIST list; |
|
72 VA_START(list, aFormat); |
|
73 |
|
74 TTime now; |
|
75 now.HomeTime(); |
|
76 |
|
77 TBuf8<512> buffer; |
|
78 _LIT8(KSwiLogPrefix, "[SWI] "); |
|
79 _LIT8(KSwiLineFileFormat, "%Ld Line: % 5d, File: %s -- "); |
|
80 buffer.Append(KSwiLogPrefix); |
|
81 buffer.AppendFormat(KSwiLineFileFormat, now.Int64(), aLine, aFile); |
|
82 buffer.AppendFormatList(aFormat, list, &overflowHandler8); |
|
83 _LIT8(KSwiMsgEnd, "\r\n"); |
|
84 if(buffer.MaxLength() >= (buffer.Length() + KSwiMsgEnd().Length())) |
|
85 { |
|
86 buffer.Append(KSwiMsgEnd); |
|
87 } |
|
88 |
|
89 RDebug::RawPrint(buffer); |
|
90 |
|
91 VA_END(list); |
|
92 } |
|
93 |
|
94 // Unicode DebufPrintf overload |
|
95 |
|
96 inline void DebugPrintf(TInt aLine, char* aFile, TRefByValue<const TDesC16> aFormat, ...) |
|
97 { |
|
98 TTruncateOverflowHandler16 overflowHandler16; |
|
99 VA_LIST list; |
|
100 VA_START(list, aFormat); |
|
101 |
|
102 TTime now; |
|
103 now.HomeTime(); |
|
104 |
|
105 TBuf8<256> header; |
|
106 _LIT8(KSwiLogPrefix, "[SWI] "); |
|
107 _LIT8(KSwiLineFileFormat, "%Ld Line: % 5d, File: %s -- "); |
|
108 header.Append(KSwiLogPrefix); |
|
109 header.AppendFormat(KSwiLineFileFormat, now.Int64(), aLine, aFile); |
|
110 |
|
111 TBuf<256> buffer; |
|
112 buffer.Copy(header); |
|
113 buffer.AppendFormatList(aFormat, list , &overflowHandler16); |
|
114 _LIT(KSwiMsgEnd, "\r\n"); |
|
115 if(buffer.MaxLength() >= (buffer.Length() + KSwiMsgEnd().Length())) |
|
116 { |
|
117 buffer.Append(KSwiMsgEnd); |
|
118 } |
|
119 |
|
120 RDebug::RawPrint(buffer); |
|
121 |
|
122 VA_END(list); |
|
123 } |
|
124 |
|
125 #else |
|
126 |
|
127 #define DEBUG_PRINTF(a) |
|
128 #define DEBUG_PRINTF2(a, b) |
|
129 #define DEBUG_PRINTF3(a, b, c) |
|
130 #define DEBUG_PRINTF4(a, b, c, d) |
|
131 #define DEBUG_PRINTF5(a, b, c, d, e) |
|
132 |
|
133 #define DEBUG_CODE_SECTION(a) |
|
134 |
|
135 #endif |
|
136 |
|
137 |
|
138 } // namespace Swi |
|
139 |
|
140 #endif // __SWI_LOG_H__ |