|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 |
|
18 #ifndef __SWI_LOG_H__ |
|
19 #define __SWI_LOG_H__ |
|
20 |
|
21 #include <e32debug.h> |
|
22 |
|
23 namespace DSD |
|
24 { |
|
25 |
|
26 #ifdef _DEBUG |
|
27 |
|
28 #ifdef _OMXIL_MICSOURCE_DEBUG_TRACING_ON |
|
29 |
|
30 #define DEBUG_PRINTF(a) {DSD::DebugPrintf(__LINE__, __FILE__, a);} |
|
31 #define DEBUG_PRINTF2(a, b) {DSD::DebugPrintf(__LINE__, __FILE__, a, b);} |
|
32 #define DEBUG_PRINTF3(a, b, c) {DSD::DebugPrintf(__LINE__, __FILE__, a, b, c);} |
|
33 #define DEBUG_PRINTF4(a, b, c, d) {DSD::DebugPrintf(__LINE__, __FILE__, a, b, c, d);} |
|
34 #define DEBUG_PRINTF5(a, b, c, d, e) {DSD::DebugPrintf(__LINE__, __FILE__, a, b, c, d, e);} |
|
35 |
|
36 #define DEBUG_CODE_SECTION(a) TRAP_IGNORE({ a; }) |
|
37 |
|
38 class TTruncateOverflowHandler16 : public TDes16Overflow |
|
39 { |
|
40 public: |
|
41 virtual void Overflow( TDes16& aDes ); |
|
42 }; |
|
43 |
|
44 inline void TTruncateOverflowHandler16::Overflow( TDes16& aDes) |
|
45 { |
|
46 _LIT(KErrOverflowMsg,"Descriptor Overflow, hence value truncated"); |
|
47 if( aDes.MaxLength() >= KErrOverflowMsg().Length() + aDes.Length() ) |
|
48 aDes.Append(KErrOverflowMsg); |
|
49 } |
|
50 |
|
51 class TTruncateOverflowHandler8 : public TDes8Overflow |
|
52 { |
|
53 public: |
|
54 virtual void Overflow( TDes8& aDes ); |
|
55 }; |
|
56 |
|
57 inline void TTruncateOverflowHandler8::Overflow( TDes8& aDes) |
|
58 { |
|
59 _LIT(KErrOverflowMsg,"Descriptor Overflow, hence value truncated"); |
|
60 if( aDes.MaxLength() >= KErrOverflowMsg().Length() + aDes.Length() ) |
|
61 aDes.Append(KErrOverflowMsg); |
|
62 } |
|
63 |
|
64 // UTF-8 overload of the DebufPrintf method. Should be used by default, |
|
65 // since it's cheaper both in CPU cycles and stack space. |
|
66 |
|
67 inline void DebugPrintf(TInt aLine, char* aFile, TRefByValue<const TDesC8> aFormat, ...) |
|
68 { |
|
69 TTruncateOverflowHandler8 overflowHandler8; |
|
70 VA_LIST list; |
|
71 VA_START(list, aFormat); |
|
72 |
|
73 TTime now; |
|
74 now.HomeTime(); |
|
75 |
|
76 TBuf8<1024> buffer; |
|
77 _LIT8(KSwiLogPrefix, "[pcmcapturer] "); |
|
78 _LIT8(KSwiLineFileFormat, "TID[%d] : [%s:%d] -- "); |
|
79 buffer.Append(KSwiLogPrefix); |
|
80 RThread thread; |
|
81 TUint threadId = thread.Id(); |
|
82 thread.Close(); |
|
83 RProcess proc; |
|
84 TFileName fName = proc.FileName(); |
|
85 proc.Close(); |
|
86 buffer.AppendFormat(KSwiLineFileFormat, threadId, aFile, aLine); |
|
87 buffer.AppendFormatList(aFormat, list ,&overflowHandler8 ); |
|
88 buffer.Append(_L8("\r\n")); |
|
89 |
|
90 RDebug::RawPrint(buffer); |
|
91 |
|
92 VA_END(list); |
|
93 } |
|
94 |
|
95 // Unicode DebufPrintf overload |
|
96 |
|
97 inline void DebugPrintf(TInt aLine, char* aFile, TRefByValue<const TDesC16> aFormat, ...) |
|
98 { |
|
99 TTruncateOverflowHandler16 overflowHandler16; |
|
100 VA_LIST list; |
|
101 VA_START(list, aFormat); |
|
102 |
|
103 TTime now; |
|
104 now.HomeTime(); |
|
105 |
|
106 TBuf8<256> header; |
|
107 _LIT8(KSwiLogPrefix, "[pcmcapturer] "); |
|
108 _LIT8(KSwiLineFileFormat, "%Ld Line: % 5d, File: %s -- "); |
|
109 header.Append(KSwiLogPrefix); |
|
110 header.AppendFormat(KSwiLineFileFormat, now.Int64(), aLine, aFile); |
|
111 |
|
112 TBuf<1024> buffer; |
|
113 buffer.Copy(header); |
|
114 buffer.AppendFormatList(aFormat, list ,&overflowHandler16); |
|
115 buffer.Append(_L("\r\n")); |
|
116 |
|
117 RDebug::RawPrint(buffer); |
|
118 |
|
119 VA_END(list); |
|
120 } |
|
121 #else |
|
122 |
|
123 #define DEBUG_PRINTF(a) |
|
124 #define DEBUG_PRINTF2(a, b) |
|
125 #define DEBUG_PRINTF3(a, b, c) |
|
126 #define DEBUG_PRINTF4(a, b, c, d) |
|
127 #define DEBUG_PRINTF5(a, b, c, d, e) |
|
128 |
|
129 #define DEBUG_CODE_SECTION(a) |
|
130 |
|
131 #endif |
|
132 |
|
133 #else |
|
134 |
|
135 #define DEBUG_PRINTF(a) |
|
136 #define DEBUG_PRINTF2(a, b) |
|
137 #define DEBUG_PRINTF3(a, b, c) |
|
138 #define DEBUG_PRINTF4(a, b, c, d) |
|
139 #define DEBUG_PRINTF5(a, b, c, d, e) |
|
140 |
|
141 #define DEBUG_CODE_SECTION(a) |
|
142 |
|
143 #endif //_OMXIL_MICSOURCE_DEBUG_TRACING_ON |
|
144 |
|
145 |
|
146 } // namespace DSD |
|
147 |
|
148 #endif // __SWI_LOG_H__ |
|
149 |