|
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 HSPPLUGIN_LOGGING_H |
|
20 #define HSPPLUGIN_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 fileName( fullFileName.Ptr() + fullFileName.LocateReverse( '\\' ) |
|
99 + 1 ); |
|
100 RBuf8 buf; |
|
101 buf.Create( KMaxLogLineLength ); |
|
102 buf.Append( KPanicPrefix8 ); |
|
103 buf.AppendFormat( _L8("%d at line %d in file %S"), aPanicCode, aLine, |
|
104 &fileName ); |
|
105 Trace( buf ); |
|
106 buf.Close(); |
|
107 User::Panic( aPanicCategory, aPanicCode ); |
|
108 } |
|
109 |
|
110 inline void TraceLeave( char* aFile, TInt aLine, TInt aReason ) |
|
111 { |
|
112 TPtrC8 fullFileName( (const TUint8*) aFile ); |
|
113 TPtrC8 fileName( fullFileName.Ptr() + fullFileName.LocateReverse( '\\' ) |
|
114 + 1 ); |
|
115 RBuf8 buf; |
|
116 buf.Create( KMaxLogLineLength ); |
|
117 buf.Append( KLeavePrefix8 ); |
|
118 buf.AppendFormat( _L8("%d at line %d in file %S"), aReason, aLine, |
|
119 &fileName ); |
|
120 Trace( buf ); |
|
121 buf.Close(); |
|
122 User::Leave( aReason ); |
|
123 } |
|
124 |
|
125 #define TRACE_INFO(p) {if(KTraceMask & KPRINTINFO) Trace p;} |
|
126 |
|
127 #define TRACE_ERROR(p) {if(KTraceMask & KPRINTERROR) Trace p;} |
|
128 |
|
129 #define TRACE_STATE(p) {if(KTraceMask & KPRINTSTATE) Trace p;} |
|
130 |
|
131 #define TRACE_WARNING(p) {if(KTraceMask & KPRINTWARNING) Trace p;} |
|
132 |
|
133 #define TRACE_INFO_SEG(p) {if(KTraceMask & KPRINTINFO) p;} |
|
134 |
|
135 #define TRACE_ASSERT(GUARD, CODE) {if (!(GUARD)) TracePanic(__FILE__, __LINE__, CODE, KPanicCategory);} |
|
136 |
|
137 #define PANIC(CODE) TracePanic(__FILE__, __LINE__, CODE, KPanicCategory) |
|
138 |
|
139 #define LEAVE_IF_ERROR(REASON) {if (REASON) TraceLeave(__FILE__, __LINE__, REASON);} |
|
140 |
|
141 #define LEAVE_IF_NULL(PTR) {if (!PTR) TraceLeave(__FILE__, __LINE__, KErrGeneral);} |
|
142 |
|
143 #define LEAVE(REASON) {TraceLeave(__FILE__, __LINE__, REASON);} |
|
144 |
|
145 #define TRACE_STATIC_FUNC_ENTRY {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncEntryFormat8, &ptr8);}} |
|
146 |
|
147 #define TRACE_FUNC_ENTRY {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncEntryThisFormat8, &ptr8, this);}} |
|
148 |
|
149 #define TRACE_FUNC_EXIT {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncExitFormat8, &ptr8);}} |
|
150 |
|
151 #define TRACE_STATIC_FUNC {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncFormat8, &ptr8);}} |
|
152 |
|
153 #define TRACE_FUNC {if(KTraceMask & KPRINTINFO) { TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); Trace(KFuncThisFormat8, &ptr8, this);}} |
|
154 |
|
155 #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;}} |
|
156 |
|
157 #else // PRJ_ENABLE_TRACE not defined |
|
158 #define TRACE_INFO(p) |
|
159 |
|
160 #define TRACE_ERROR(p) |
|
161 |
|
162 #define TRACE_STATE(p) |
|
163 |
|
164 #define TRACE_WARNING(p) |
|
165 |
|
166 #define TRACE_INFO_SEG(p) |
|
167 |
|
168 #define TRACE_ASSERT(GUARD, CODE) |
|
169 |
|
170 #define PANIC(CODE) {User::Panic(KPanicCategory, CODE);} |
|
171 |
|
172 #define LEAVE_IF_ERROR(REASON) {static_cast<void>(User::LeaveIfError(REASON));} |
|
173 |
|
174 #define LEAVE_IF_NULL(PTR) {static_cast<void>(User::LeaveIfNull(PTR));} |
|
175 |
|
176 #define LEAVE(REASON) {static_cast<void>(User::Leave(REASON));} |
|
177 |
|
178 #define TRACE_STATIC_FUNC_ENTRY |
|
179 |
|
180 #define TRACE_FUNC_ENTRY |
|
181 |
|
182 #define TRACE_FUNC_EXIT |
|
183 |
|
184 #define TRACE_STATIC_FUNC |
|
185 |
|
186 #define TRACE_FUNC |
|
187 |
|
188 #define RETURN_IF_ERR(ERR) {if(ERR) return ERR;} |
|
189 #endif // PRJ_ENABLE_TRACE |
|
190 #endif // HSPPLUGIN_LOGGING_H |