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