|
1 /* |
|
2 * Component Name: Headset Simulator |
|
3 * Author: Comarch S.A. |
|
4 * Version: 1.0 |
|
5 * Copyright (c) 2010 Comarch S.A. |
|
6 * |
|
7 * This Software is submitted by Comarch S.A. to Symbian Foundation Limited on |
|
8 * the basis of the Member Contribution Agreement entered between Comarch S.A. |
|
9 * and Symbian Foundation Limited on 5th June 2009 (“Agreement”) and may be |
|
10 * used only in accordance with the terms and conditions of the Agreement. |
|
11 * Any other usage, duplication or redistribution of this Software is not |
|
12 * allowed without written permission of Comarch S.A. |
|
13 * |
|
14 */ |
|
15 |
|
16 #ifndef PRJ_LOGGING_H |
|
17 #define PRJ_LOGGING_H |
|
18 |
|
19 #include <e32base.h> |
|
20 #include "debugconfig.h" |
|
21 |
|
22 enum TPanic |
|
23 { |
|
24 EInvalidNullState = 1, |
|
25 }; |
|
26 |
|
27 #ifdef PRJ_ENABLE_TRACE |
|
28 |
|
29 #ifdef PRJ_FILE_TRACE |
|
30 #include <flogger.h> |
|
31 #else |
|
32 #include <e32debug.h> |
|
33 #endif |
|
34 |
|
35 NONSHARABLE_CLASS(TOverflowTruncate16) : public TDes16Overflow |
|
36 { |
|
37 public: |
|
38 void Overflow( TDes16& /*aDes*/) |
|
39 { |
|
40 } |
|
41 }; |
|
42 |
|
43 NONSHARABLE_CLASS(TOverflowTruncate8) : public TDes8Overflow |
|
44 { |
|
45 public: |
|
46 void Overflow( TDes8& /*aDes*/) |
|
47 { |
|
48 } |
|
49 }; |
|
50 |
|
51 inline void Trace( TRefByValue <const TDesC16> aFmt, ... ) |
|
52 { |
|
53 VA_LIST list; |
|
54 VA_START(list,aFmt); |
|
55 #ifdef PRJ_FILE_TRACE |
|
56 RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list); |
|
57 #else |
|
58 RBuf16 theFinalString; |
|
59 theFinalString.Create( KMaxLogLineLength ); |
|
60 theFinalString.Append( KTracePrefix16 ); |
|
61 TOverflowTruncate16 overflow; |
|
62 theFinalString.AppendFormatList( aFmt, list, &overflow ); |
|
63 RDebug::Print( theFinalString ); |
|
64 theFinalString.Close(); |
|
65 #endif |
|
66 } |
|
67 |
|
68 inline void Trace( TRefByValue <const TDesC8> aFmt, ... ) |
|
69 { |
|
70 VA_LIST list; |
|
71 VA_START(list, aFmt); |
|
72 #ifdef PRJ_FILE_TRACE |
|
73 RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list); |
|
74 #else |
|
75 TOverflowTruncate8 overflow; |
|
76 RBuf8 buf8; |
|
77 buf8.Create( KMaxLogLineLength ); |
|
78 buf8.Append( KTracePrefix8 ); |
|
79 buf8.AppendFormatList( aFmt, list, &overflow ); |
|
80 |
|
81 RBuf16 buf16; |
|
82 buf16.Create( KMaxLogLineLength ); |
|
83 buf16.Copy( buf8 ); |
|
84 TRefByValue <const TDesC> tmpFmt( _L("%S") ); |
|
85 RDebug::Print( tmpFmt, &buf16 ); |
|
86 buf8.Close(); |
|
87 buf16.Close(); |
|
88 #endif |
|
89 } |
|
90 |
|
91 inline void TracePanic( char* aFile, TInt aLine, TInt aPanicCode, |
|
92 const TDesC& aPanicCategory ) |
|
93 { |
|
94 TPtrC8 fullFileName( (const TUint8*) aFile ); |
|
95 TPtrC8 fileName( fullFileName.Ptr() + fullFileName.LocateReverse( '\\' ) |
|
96 + 1 ); |
|
97 RBuf8 buf; |
|
98 buf.Create( KMaxLogLineLength ); |
|
99 buf.Append( KPanicPrefix8 ); |
|
100 buf.AppendFormat( _L8("%d at line %d in file %S"), aPanicCode, aLine, |
|
101 &fileName ); |
|
102 Trace( buf ); |
|
103 buf.Close(); |
|
104 User::Panic( aPanicCategory, aPanicCode ); |
|
105 } |
|
106 |
|
107 inline void TraceLeave( char* aFile, TInt aLine, TInt aReason ) |
|
108 { |
|
109 TPtrC8 fullFileName( (const TUint8*) aFile ); |
|
110 TPtrC8 fileName( fullFileName.Ptr() + fullFileName.LocateReverse( '\\' ) |
|
111 + 1 ); |
|
112 RBuf8 buf; |
|
113 buf.Create( KMaxLogLineLength ); |
|
114 buf.Append( KLeavePrefix8 ); |
|
115 buf.AppendFormat( _L8("%d at line %d in file %S"), aReason, aLine, |
|
116 &fileName ); |
|
117 Trace( buf ); |
|
118 buf.Close(); |
|
119 User::Leave( aReason ); |
|
120 } |
|
121 |
|
122 #define TRACE_INFO(p) {if(KTraceMask & KPRINTINFO) Trace p;} |
|
123 |
|
124 #define TRACE_ERROR(p) {if(KTraceMask & KPRINTERROR) Trace p;} |
|
125 |
|
126 #define TRACE_STATE(p) {if(KTraceMask & KPRINTSTATE) Trace p;} |
|
127 |
|
128 #define TRACE_WARNING(p) {if(KTraceMask & KPRINTWARNING) Trace p;} |
|
129 |
|
130 #define TRACE_INFO_SEG(p) {if(KTraceMask & KPRINTINFO) p;} |
|
131 |
|
132 #define TRACE_ASSERT(GUARD, CODE) {if (!(GUARD)) TracePanic(__FILE__, __LINE__, CODE, KPanicCategory);} |
|
133 |
|
134 #define PANIC(CODE) TracePanic(__FILE__, __LINE__, CODE, KPanicCategory) |
|
135 |
|
136 #define LEAVE_IF_ERROR(REASON) {if (REASON) TraceLeave(__FILE__, __LINE__, REASON);} |
|
137 |
|
138 #define LEAVE_IF_NULL(PTR) {if (!PTR) TraceLeave(__FILE__, __LINE__, KErrGeneral);} |
|
139 |
|
140 #define LEAVE(REASON) {TraceLeave(__FILE__, __LINE__, REASON);} |
|
141 |
|
142 #define TRACE_STATIC_FUNC_ENTRY {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncEntryFormat8, &ptr8);}} |
|
143 |
|
144 #define TRACE_FUNC_ENTRY {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncEntryThisFormat8, &ptr8, this);}} |
|
145 |
|
146 #define TRACE_FUNC_EXIT {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncExitFormat8, &ptr8);}} |
|
147 |
|
148 #define TRACE_STATIC_FUNC {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncFormat8, &ptr8);}} |
|
149 |
|
150 #define TRACE_FUNC {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncThisFormat8, &ptr8, this);}} |
|
151 |
|
152 #define RETURN_IF_ERR(ERR) {if(ERR) {TPtrC8 ptr8((TUint8*)__FILE__); Trace(_L8(" RETURN %d at file %S line %d"), ERR, &ptr8, __LINE__); return ERR;}} |
|
153 |
|
154 #else // PRJ_ENABLE_TRACE not defined |
|
155 #define TRACE_INFO(p) |
|
156 |
|
157 #define TRACE_ERROR(p) |
|
158 |
|
159 #define TRACE_STATE(p) |
|
160 |
|
161 #define TRACE_WARNING(p) |
|
162 |
|
163 #define TRACE_INFO_SEG(p) |
|
164 |
|
165 #define TRACE_ASSERT(GUARD, CODE) |
|
166 |
|
167 #define PANIC(CODE) {User::Panic(KPanicCategory, CODE);} |
|
168 |
|
169 #define LEAVE_IF_ERROR(REASON) {static_cast<void>(User::LeaveIfError(REASON));} |
|
170 |
|
171 #define LEAVE_IF_NULL(PTR) {static_cast<void>(User::LeaveIfNull(PTR));} |
|
172 |
|
173 #define LEAVE(REASON) {static_cast<void>(User::Leave(REASON));} |
|
174 |
|
175 #define TRACE_STATIC_FUNC_ENTRY |
|
176 |
|
177 #define TRACE_FUNC_ENTRY |
|
178 |
|
179 #define TRACE_FUNC_EXIT |
|
180 |
|
181 #define TRACE_STATIC_FUNC |
|
182 |
|
183 #define TRACE_FUNC |
|
184 |
|
185 #define RETURN_IF_ERR(ERR) {if(ERR) return ERR;} |
|
186 #endif // PRJ_ENABLE_TRACE |
|
187 #endif // PRJ_LOGGING_H |