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