19 @file |
19 @file |
20 @internalTechnology |
20 @internalTechnology |
21 */ |
21 */ |
22 |
22 |
23 |
23 |
24 #ifndef USBLOGGER_H |
24 #ifndef LOGGER_H |
25 #define USBLOGGER_H |
25 #define LOGGER_H |
26 |
26 |
27 #include <e32base.h> |
27 #include <e32base.h> |
28 |
28 |
29 #define LEAVEIFERRORL(err, trace) \ |
29 // Control function entry and exit logging using a compile-time switch. |
30 { \ |
30 #define __LOG_FUNCTIONS__ |
31 TInt munged_err=(err); \ |
|
32 if (munged_err < 0) \ |
|
33 { \ |
|
34 trace; \ |
|
35 User::Leave(munged_err);\ |
|
36 }\ |
|
37 } |
|
38 |
31 |
39 #endif // USBLOGGER_H |
32 class TFunctionLogger; |
40 |
33 |
|
34 #ifndef __COMMSDEBUGUTILITY_H__ // comms-infras/commsdebugutility.h not included |
|
35 #ifdef _DEBUG // If this is a debug build... |
|
36 // Set flogging active. |
|
37 #define __FLOG_ACTIVE |
|
38 #endif |
|
39 #endif |
|
40 |
|
41 #ifdef __FLOG_ACTIVE |
|
42 #define IF_FLOGGING(a) a |
|
43 #else |
|
44 #define IF_FLOGGING(a) |
|
45 #endif |
|
46 |
|
47 _LIT8(KDefaultLogFile, "USB"); |
|
48 |
|
49 #ifdef __FLOG_ACTIVE |
|
50 #define LEAVEIFERRORL(a) VerboseLeaveIfErrorL(KLogComponent, __FILE__, __LINE__, a) |
|
51 #define LEAVEL(a) VerboseLeaveL(KLogComponent, __FILE__, __LINE__, a) |
|
52 #define _USB_PANIC(CAT, CODE) VerbosePanic(KLogComponent, __FILE__, __LINE__, CODE, (TText8*)#CODE, CAT) |
|
53 #define PANIC_MSG(msg, cat, code) VerboseMsgPanic(KLogComponent, __FILE__, __LINE__, msg, cat, code); |
|
54 #define FLOG(a) CUsbLog::Write(KDefaultLogFile, a); |
|
55 #define FTRACE(a) {a;} |
|
56 #define LOGTEXT(text) CUsbLog::Write(KLogComponent, text); |
|
57 #define LOGTEXT2(text, a) CUsbLog::WriteFormat(KLogComponent, text, a); |
|
58 #define LOGTEXT3(text, a, b) CUsbLog::WriteFormat(KLogComponent, text, a, b); |
|
59 #define LOGTEXT4(text, a, b, c) CUsbLog::WriteFormat(KLogComponent, text, a, b, c); |
|
60 #define LOGTEXT5(text, a, b, c, d) CUsbLog::WriteFormat(KLogComponent, text, a, b, c, d); |
|
61 #define LOGTEXT6(text, a, b, c, d, e) CUsbLog::WriteFormat(KLogComponent, text, a, b, c, d, e); |
|
62 #define LOGTEXT7(text, a, b, c, d, e, f) CUsbLog::WriteFormat(KLogComponent, text, a, b, c, d, e, f); |
|
63 #define LOGHEXDESC(desc) CUsbLog::HexDump(KLogComponent, 0, 0, desc.Ptr() , desc.Length()); |
|
64 #define LOGHEXRAW(data, len) CUsbLog::HexDump(KLogComponent, 0, 0, data, len); |
|
65 #else |
|
66 #define LEAVEIFERRORL(a) static_cast<void>(User::LeaveIfError(a)) |
|
67 #define LEAVEL(a) User::Leave(a) |
|
68 #define _USB_PANIC(CAT, CODE) User::Panic(CAT, CODE) |
|
69 #define PANIC_MSG(msg, cat, code) msg.Panic(cat, code); |
|
70 #define FLOG(a) |
|
71 #define FTRACE(a) |
|
72 #define LOGTEXT(text) |
|
73 #define LOGTEXT2(text, a) |
|
74 #define LOGTEXT3(text, a, b) |
|
75 #define LOGTEXT4(text, a, b, c) |
|
76 #define LOGTEXT5(text, a, b, c, d) |
|
77 #define LOGTEXT6(text, a, b, c, d, e) |
|
78 #define LOGTEXT7(text, a, b, c, d, e, f) |
|
79 #define LOGHEXDESC(desc) |
|
80 #define LOGHEXRAW(data, len) |
|
81 #endif // __FLOG_ACTIVE |
|
82 |
|
83 #define FORCED_LOG_FUNC TFunctionLogger __instrument(KLogComponent, TPtrC8((TUint8*)__PRETTY_FUNCTION__), (TAny*)this); |
|
84 #define FORCED_LOG_STATIC_FUNC_ENTRY TFunctionLogger __instrument(KLogComponent, TPtrC8((TUint8*)__PRETTY_FUNCTION__), (TAny*)NULL); |
|
85 |
|
86 #if ( defined __FLOG_ACTIVE && defined __LOG_FUNCTIONS__ ) |
|
87 #define LOG_LINE CUsbLog::Write(KLogComponent, KNullDesC8()); |
|
88 #define LOG_FUNC FORCED_LOG_FUNC |
|
89 #define LOG_STATIC_FUNC_ENTRY FORCED_LOG_STATIC_FUNC_ENTRY |
|
90 #else |
|
91 #define LOG_LINE |
|
92 #define LOG_FUNC |
|
93 #define LOG_STATIC_FUNC_ENTRY |
|
94 #endif |
|
95 |
|
96 |
|
97 |
|
98 NONSHARABLE_CLASS(CUsbLog) : public CBase |
|
99 { |
|
100 public: |
|
101 IMPORT_C static TInt Connect(); |
|
102 IMPORT_C static void Close(); |
|
103 |
|
104 IMPORT_C static void Write(const TDesC8& aCmpt, const TDesC8& aText); |
|
105 IMPORT_C static void WriteFormat(const TDesC8& aCmpt, TRefByValue<const TDesC8> aFmt, ...); |
|
106 IMPORT_C static void WriteFormat(const TDesC8& aCmpt, TRefByValue<const TDesC8> aFmt, VA_LIST& aList); |
|
107 IMPORT_C static void Write(const TDesC8& aCmpt, const TDesC16& aText); |
|
108 IMPORT_C static void WriteFormat(const TDesC8& aCmpt, TRefByValue<const TDesC16> aFmt, ...); |
|
109 IMPORT_C static void WriteFormat(const TDesC8& aCmpt, TRefByValue<const TDesC16> aFmt, VA_LIST& aList); |
|
110 IMPORT_C static void HexDump(const TDesC8& aCmpt, const TText* aHeader, const TText* aMargin, const TUint8* aPtr, TInt aLen); |
|
111 }; |
|
112 |
|
113 |
|
114 #ifndef NO_FPRINT |
|
115 inline void FPrint(const TRefByValue<const TDesC> IF_FLOGGING(aFmt), ...) |
|
116 { |
|
117 #ifdef __FLOG_ACTIVE |
|
118 VA_LIST list; |
|
119 VA_START(list,aFmt); |
|
120 CUsbLog::WriteFormat(KDefaultLogFile, aFmt, list); |
|
121 #endif |
|
122 } |
|
123 #endif |
|
124 |
|
125 |
|
126 #ifndef NO_FHEX_PTR |
|
127 inline void FHex(const TUint8* IF_FLOGGING(aPtr), TInt IF_FLOGGING(aLen)) |
|
128 { |
|
129 #ifdef __FLOG_ACTIVE |
|
130 CUsbLog::HexDump(KDefaultLogFile, 0, 0, aPtr, aLen); |
|
131 #endif |
|
132 } |
|
133 #endif |
|
134 |
|
135 |
|
136 #ifndef NO_FHEX_DESC |
|
137 inline void FHex(const TDesC8& IF_FLOGGING(aDes)) |
|
138 { |
|
139 #ifdef __FLOG_ACTIVE |
|
140 FHex(aDes.Ptr(), aDes.Length()); |
|
141 #endif |
|
142 } |
|
143 #endif |
|
144 |
|
145 |
|
146 IMPORT_C void VerboseLeaveIfErrorL(const TDesC8& aCpt, |
|
147 char* aFile, |
|
148 TInt aLine, |
|
149 TInt aReason); |
|
150 |
|
151 IMPORT_C void VerboseLeaveL(const TDesC8& aCpt, |
|
152 char* aFile, |
|
153 TInt aLine, |
|
154 TInt aReason); |
|
155 |
|
156 IMPORT_C void VerbosePanic(const TDesC8& aCpt, |
|
157 char* aFile, |
|
158 TInt aLine, |
|
159 TInt aPanicCode, |
|
160 TText8* aPanicName, |
|
161 const TDesC& aPanicCategory); |
|
162 |
|
163 IMPORT_C void VerboseMsgPanic(const TDesC8& aCpt, |
|
164 char* aFile, |
|
165 TInt aLine, |
|
166 const RMessage2& aMsg, |
|
167 const TDesC& aCat, |
|
168 TInt aPanicCode); |
|
169 |
|
170 |
|
171 NONSHARABLE_CLASS(TFunctionLogger) |
|
172 { |
|
173 public: |
|
174 IMPORT_C TFunctionLogger(const TDesC8& aCpt, const TDesC8& aString, TAny* aThis); |
|
175 IMPORT_C ~TFunctionLogger(); |
|
176 |
|
177 private: |
|
178 TPtrC8 iCpt; |
|
179 TPtrC8 iString; |
|
180 }; |
|
181 |
|
182 #endif // LOGGER_H |
|
183 |