|
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: Debug macros and declarations. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef DEBUG_H |
|
20 #define DEBUG_H |
|
21 |
|
22 ////////////////////////////////////////////////////////////////////////////// |
|
23 // Here are parameters need to be modified. |
|
24 // Component name |
|
25 #define MODULE_NAME "USBLcdPlugin" |
|
26 ////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
28 |
|
29 // For handling unicode strings as L##MACRO is interpreted as LMACRO |
|
30 #define WIDEN2( x ) L##x |
|
31 #define WIDEN( x ) WIDEN2( x ) |
|
32 |
|
33 _LIT( KUsbPanicModule, ""WIDEN( MODULE_NAME ) ); |
|
34 |
|
35 #ifdef _DEBUG |
|
36 |
|
37 // Comment this line out if using real-time debugging |
|
38 //#define LOG_TO_FILE |
|
39 // =========================================================================== |
|
40 #if defined ( LOG_TO_FILE ) |
|
41 // =========================================================================== |
|
42 // Add corresponding libabry in mmp file |
|
43 // LIBRARY flogger.lib |
|
44 // The log file is located at |
|
45 // c:\logs\usb\MODULE_NAME.txt |
|
46 |
|
47 #include <flogger.h> |
|
48 |
|
49 #define DESC( x ) TPtrC( ( const TText* ) ( x ) ) |
|
50 #define DESC8( x ) TPtrC8( ( const TUint8* ) ( x ) ) |
|
51 _LIT( KUsbLogDir, "USB" ); |
|
52 _LIT( KUsbLogFile, ""WIDEN(MODULE_NAME)L".txt" ); |
|
53 |
|
54 // s: c string. |
|
55 #define LOG(s) RFileLogger::WriteFormat( KUsbLogDir, \ |
|
56 KUsbLogFile, EFileLoggingModeAppend, \ |
|
57 DESC8( "["MODULE_NAME"] "##s ) ) |
|
58 |
|
59 // s: c string contains "%x" |
|
60 // v: varaible corresponding to %x |
|
61 #define LOG1(s, v) RFileLogger::WriteFormat( KUsbLogDir, \ |
|
62 KUsbLogFile, EFileLoggingModeAppend, \ |
|
63 DESC8( "["MODULE_NAME"] "##s ), v) |
|
64 // s: c string contains "%x%y" |
|
65 // v1: varaible corresponding to %x |
|
66 // v2: varaible corresponding to %y |
|
67 #define LOG2(s, v1, v2) RFileLogger::WriteFormat( KUsbLogDir, \ |
|
68 KUsbLogFile, EFileLoggingModeAppend, \ |
|
69 DESC8( "["MODULE_NAME"] "##s ), v1, v2) |
|
70 |
|
71 // s: c string contains "%x%y%z" |
|
72 // v1: varaible corresponding to %x |
|
73 // v2: varaible corresponding to %y |
|
74 // v3: varaible corresponding to %z |
|
75 #define LOG3(s, v1, v2, v3) RFileLogger::WriteFormat( KUsbLogDir, \ |
|
76 KUsbLogFile, EFileLoggingModeAppend, \ |
|
77 DESC8( "["MODULE_NAME"] "##s ), v1, v2, v3 ) |
|
78 |
|
79 class TFuncLogger |
|
80 { |
|
81 public: |
|
82 TFuncLogger(const TDesC8& aFuncName) |
|
83 { |
|
84 iFuncName.Set( aFuncName ); |
|
85 RFileLogger::WriteFormat( KUsbLogDir, KUsbLogFile, EFileLoggingModeAppend, |
|
86 DESC8( "["MODULE_NAME"] >>%s" ), iFuncName.Ptr() ); |
|
87 } |
|
88 ~TFuncLogger() |
|
89 { |
|
90 RFileLogger::WriteFormat( KUsbLogDir, KUsbLogFile, |
|
91 EFileLoggingModeAppend, |
|
92 DESC8( "["MODULE_NAME"] <<%s" ), iFuncName.Ptr() ); |
|
93 } |
|
94 private: |
|
95 TPtrC8 iFuncName; |
|
96 }; |
|
97 // =========================================================================== |
|
98 #else //LOG_TO_FILE not defined |
|
99 // =========================================================================== |
|
100 #include <e32debug.h> |
|
101 |
|
102 // Paramters same as above. |
|
103 #define LOG( str ) { RDebug::Printf( "["MODULE_NAME"] %s", str ); } |
|
104 |
|
105 #define LOG1( s, v ) { RDebug::Printf( "["MODULE_NAME"] "##s , v ); } |
|
106 |
|
107 #define LOG2( s, v1,v2 ) { RDebug::Printf( "["MODULE_NAME"] "##s , v1, v2 ); } |
|
108 |
|
109 #define LOG3( s, v1, v2, v3 ) { RDebug::Printf( "["MODULE_NAME"] "##s , \ |
|
110 v1, v2, v3); } |
|
111 |
|
112 inline void LogBuf(const TDesC8& aBuf8) |
|
113 { |
|
114 LOG1("Buffer length = %d Buffer content:", aBuf8.Length()); |
|
115 |
|
116 TInt len(aBuf8.Length()); |
|
117 for (TInt i(0); i < len; ++i) |
|
118 RDebug::Print(_L("Buffer[%d] = 0x%x"), i, aBuf8[i]); |
|
119 } |
|
120 |
|
121 class TFuncLogger |
|
122 { |
|
123 public: |
|
124 TFuncLogger(const TPtrC8& aFuncName) : iFuncName( aFuncName ) |
|
125 { |
|
126 RDebug::Printf( "["MODULE_NAME"] >>%s", iFuncName.Ptr()); |
|
127 } |
|
128 ~TFuncLogger() |
|
129 { |
|
130 RDebug::Printf( "["MODULE_NAME"] <<%s", iFuncName.Ptr()); |
|
131 } |
|
132 private: |
|
133 TPtrC8 iFuncName; |
|
134 }; |
|
135 #endif // LOG_TO_FILE |
|
136 |
|
137 #define LEAVE( exp ) {volatile TInt err_ = exp; \ |
|
138 LOG3( "LEAVE(%d) @file: %s, line: %d", err_, __FILE__, __LINE__ );\ |
|
139 User::Leave( err_ );} |
|
140 |
|
141 #define LEAVEIFERROR( exp ) {volatile TInt err__ = exp; \ |
|
142 if(err__ < 0) LEAVE(err__);} |
|
143 |
|
144 #define PANIC( exp ) {volatile TInt err_ = exp; \ |
|
145 LOG3( "PANIC(%d) @file: %s, line: %d", err_, __FILE__, __LINE__ );\ |
|
146 User::Panic( KUsbPanicModule, err_ );} |
|
147 |
|
148 #define LOG_FUNC TFuncLogger __instrument(TPtrC8((TUint8*)__PRETTY_FUNCTION__)); |
|
149 |
|
150 #define ASSERT_DEBUG( exp, code ) {if(!(exp)) PANIC(code)} |
|
151 |
|
152 #else // _DEBUG not defined |
|
153 // =========================================================================== |
|
154 |
|
155 #define LOG( s ) |
|
156 #define LOG1( s, v ) |
|
157 #define LOG2( s, v1, v2 ) |
|
158 #define LOG3( s, v1, v2, v3 ) |
|
159 #define LOG_FUNC_ENTRY |
|
160 #define LOG_FUNC_EXIT |
|
161 #define LEAVE( exp ) User::Leave( exp ); |
|
162 #define LEAVEIFERROR( exp ) User::LeaveIfError( exp ); |
|
163 #define PANIC( err ) // in non-debug builds PANICs are silent |
|
164 #define LOG_FUNC |
|
165 #define ASSERT_DEBUG( exp, code ) |
|
166 inline void LogBuf(const TDesC8& /*aBuf8*/) |
|
167 {} |
|
168 // =========================================================================== |
|
169 #endif // _DEBUG |
|
170 // =========================================================================== |
|
171 #endif // DEBUG_H |
|
172 |
|
173 // End of File |