|
1 /* |
|
2 * Copyright (c) 2007-2008 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 macro definitions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef MENUDEBUG_H |
|
20 #define MENUDEBUG_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32std.h> |
|
24 #include <flogger.h> |
|
25 |
|
26 // Maximum formatted size resulting from a single DEBUG* call |
|
27 #ifndef MAX_DEBUG_STRING_LENGTH |
|
28 #define MAX_DEBUG_STRING_LENGTH 4096 |
|
29 #endif |
|
30 |
|
31 #ifdef _MATRIX_MENU_TRACE_PERFORMANCE |
|
32 _LIT( KPerformanceLogDir, "menu" ); |
|
33 _LIT( KPerformanceLogFile, "performance.txt" ); |
|
34 #endif |
|
35 |
|
36 #ifdef _DEBUG |
|
37 #include "mymenudebug.h" |
|
38 |
|
39 // Load correct mymenudebug.h from module inc directory, |
|
40 // define your application-specific configuration like this: |
|
41 // ---------------------------------------------------------- |
|
42 // Debug file - debug output is disabled if the parent dir does not exist |
|
43 // _LIT(KDebugDirName, "menu"); |
|
44 // _LIT(KDebugFileName, "hnengine.txt"); |
|
45 |
|
46 // Replace the current debug file - if not defined appends to the file |
|
47 #ifndef APPEND_TO_DEBUG_FILE |
|
48 #define REPLACE_DEBUG_FILE |
|
49 #endif |
|
50 |
|
51 |
|
52 /** |
|
53 * @param aData |
|
54 */ |
|
55 static void DoOutput(TDesC8& aData); |
|
56 |
|
57 static void DebugStringNarrowL(const char* aFmt, ...) |
|
58 { |
|
59 VA_LIST args; |
|
60 VA_START(args, aFmt); |
|
61 |
|
62 TPtrC8 fmt(reinterpret_cast<const unsigned char *>(aFmt)); |
|
63 HBufC8* buf = HBufC8::NewLC(MAX_DEBUG_STRING_LENGTH); |
|
64 buf->Des().FormatList(fmt, args); |
|
65 buf->Des().Append('\n'); |
|
66 DoOutput(*buf); |
|
67 CleanupStack::PopAndDestroy(buf); |
|
68 |
|
69 VA_END(args); |
|
70 } |
|
71 |
|
72 static void DebugStringWideL(const char* aFmt, ...) |
|
73 { |
|
74 VA_LIST args; |
|
75 VA_START(args, aFmt); |
|
76 |
|
77 TPtrC8 fmt(reinterpret_cast<const unsigned char *>(aFmt)); |
|
78 HBufC* fmt16 = HBufC::NewLC(fmt.Length()); |
|
79 fmt16->Des().Copy(fmt); |
|
80 HBufC* buf = HBufC::NewLC(MAX_DEBUG_STRING_LENGTH); |
|
81 buf->Des().FormatList(*fmt16, args); |
|
82 buf->Des().Append('\n'); |
|
83 HBufC8* buf8 = HBufC8::NewLC(buf->Length()); |
|
84 buf8->Des().Copy(*buf); |
|
85 DoOutput(*buf8); |
|
86 CleanupStack::PopAndDestroy(3); // fmt16, buf, buf8 |
|
87 |
|
88 VA_END(args); |
|
89 } |
|
90 |
|
91 static void DebugBufferL(const TDesC8& aBuf) |
|
92 { |
|
93 DebugStringNarrowL("\"%S\"", &aBuf); |
|
94 } |
|
95 |
|
96 static void DebugBufferL(const TDesC& aBuf) |
|
97 { |
|
98 DebugStringWideL("\"%S\"", &aBuf); |
|
99 } |
|
100 |
|
101 static void DebugTimeL(const TTime& aTime) |
|
102 { |
|
103 TBuf<64> dateTimeString; |
|
104 _LIT(KDateString, "%E%D%X%N%Y %1 %2 %3"); |
|
105 aTime.FormatL(dateTimeString, KDateString); |
|
106 DebugBufferL(dateTimeString); |
|
107 _LIT(KTimeString, "%-B%:0%J%:1%T%:2%S%.%*C4%:3%+B"); |
|
108 aTime.FormatL(dateTimeString, KTimeString); |
|
109 DebugBufferL(dateTimeString); |
|
110 } |
|
111 |
|
112 |
|
113 static void DoOutput(TDesC8& aData) |
|
114 { |
|
115 RFileLogger::Write(KDebugDirName, |
|
116 KDebugFileName, |
|
117 EFileLoggingModeAppend, |
|
118 aData); |
|
119 } |
|
120 #endif |
|
121 |
|
122 #ifdef _MATRIX_MENU_TRACE_PERFORMANCE |
|
123 |
|
124 static void DoOutputPerf(TDesC8& aData) |
|
125 { |
|
126 RFileLogger::Write(KPerformanceLogDir, |
|
127 KPerformanceLogFile, |
|
128 EFileLoggingModeAppend, |
|
129 aData); |
|
130 } |
|
131 |
|
132 static void DebugStringNarrowPerfL(const char* aFmt, ...) |
|
133 { |
|
134 VA_LIST args; |
|
135 VA_START(args, aFmt); |
|
136 |
|
137 TPtrC8 fmt(reinterpret_cast<const unsigned char *>(aFmt)); |
|
138 HBufC8* buf = HBufC8::NewLC(MAX_DEBUG_STRING_LENGTH); |
|
139 buf->Des().FormatList(fmt, args); |
|
140 buf->Des().Append('\n'); |
|
141 |
|
142 TTime timestamp; |
|
143 timestamp.HomeTime(); |
|
144 |
|
145 TBuf<64> dateTimeString; |
|
146 TBuf8<64> dateTimeString8; |
|
147 |
|
148 _LIT(KTimeString, "%:0%J%:1%T%:2%S%.%*C4%:3"); |
|
149 timestamp.FormatL(dateTimeString, KTimeString); |
|
150 dateTimeString8.Copy( dateTimeString ); |
|
151 buf->Des().Insert( 0, _L8(" -> ") ); |
|
152 buf->Des().Insert( 0, dateTimeString8 ); |
|
153 |
|
154 DoOutputPerf(*buf); |
|
155 CleanupStack::PopAndDestroy(buf); |
|
156 |
|
157 VA_END(args); |
|
158 } |
|
159 #endif |
|
160 |
|
161 // MACROS |
|
162 // If you output one or more narrow descriptors by using '%S', |
|
163 // use DEBUGSTRING8 |
|
164 // else if you output one or more unicode descriptors by using '%S', |
|
165 // use DEBUGSTRING16 |
|
166 // else |
|
167 // use DEBUGSTRING |
|
168 // |
|
169 // Narrow and unicode cannot be mixed in a single DEBUGSTRINGx call. |
|
170 |
|
171 #ifdef _DEBUG |
|
172 #define DEBUGINIT() DebugInit() |
|
173 #define DEBUGINITSUSPENDED() DebugInit(ETrue) |
|
174 #define DEBUGENABLE() SetDebugEnabled(ETrue) |
|
175 #define DEBUGDISABLE() SetDebugEnabled(EFalse) |
|
176 #define DEBUGSUSPEND() SetDebugSuspended(ETrue) |
|
177 #define DEBUGCONTINUE() SetDebugSuspended(EFalse) |
|
178 #define DEBUG(x) TRAP_IGNORE( DebugStringNarrowL x ) |
|
179 #define DEBUG8(x) TRAP_IGNORE( DebugStringNarrowL x ) |
|
180 #define DEBUG16(x) TRAP_IGNORE( DebugStringWideL x ) |
|
181 #define DEBUGBUFFER(x) TRAP_IGNORE( DebugBufferL x ) |
|
182 #define DEBUGTIME(x) TRAP_IGNORE( DebugTimeL x ) |
|
183 #else |
|
184 #define DEBUGINIT() |
|
185 #define DEBUGINITSUSPENDED() |
|
186 #define DEBUGENABLE() |
|
187 #define DEBUGDISABLE() |
|
188 #define DEBUGSUSPEND() |
|
189 #define DEBUGCONTINUE() |
|
190 #define DEBUG(x) |
|
191 #define DEBUG8(x) |
|
192 #define DEBUG16(x) |
|
193 #define DEBUGBUFFER(x) |
|
194 #define DEBUGTIME(x) |
|
195 #endif |
|
196 |
|
197 #ifdef _MATRIX_MENU_TRACE_PERFORMANCE |
|
198 #define MMPERF(x) TRAP_IGNORE( DebugStringNarrowPerfL x ) |
|
199 #else |
|
200 #define MMPERF(x) |
|
201 #endif |
|
202 |
|
203 #endif // MENUDEBUG_H |
|
204 |