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