|
1 /* |
|
2 * Copyright (c) 2009 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 * |
|
16 */ |
|
17 /** |
|
18 * |
|
19 **/ |
|
20 |
|
21 #include "debug.h" |
|
22 |
|
23 #define RD_CALENDAR_PREVIEW |
|
24 |
|
25 #ifndef PIM_TRACE_H |
|
26 #define PIM_TRACE_H |
|
27 |
|
28 #if defined (_DEBUG) || defined (_PIM_FILE_LOG) || defined (_DISPLAY_WARNINGS) |
|
29 //Includes |
|
30 #include <e32base.h> |
|
31 #include <e32std.h> |
|
32 #include <flogger.h> |
|
33 #include <e32svr.h> |
|
34 #include <f32file.h> |
|
35 #include <AknGlobalConfirmationQuery.h> |
|
36 const TInt KMaxLogLineLength = 512; |
|
37 #endif |
|
38 |
|
39 /** |
|
40 * Define our own trap and assert macros to prevent compiler warnings. |
|
41 */ |
|
42 #if defined (_DISPLAY_WARNINGS) |
|
43 _LIT( KWarningFormat, " error %d trapped %S line %d"); |
|
44 inline void DisplayWarningNote( TInt aError, const TDesC8& aFile, TInt aWarningNote ) |
|
45 { |
|
46 if ( aError ) |
|
47 { |
|
48 TRAP_IGNORE( |
|
49 CAknGlobalConfirmationQuery* cq = CAknGlobalConfirmationQuery::NewL(); |
|
50 CleanupStack::PushL( cq ); |
|
51 |
|
52 TBuf<KMaxLogLineLength> text; |
|
53 TBuf<128> fileName; |
|
54 fileName.Copy( aFile ); |
|
55 text.Format( KWarningFormat, aError, &fileName, aWarningNote ); |
|
56 |
|
57 TRequestStatus stat = KRequestPending; |
|
58 cq->ShowConfirmationQueryL( stat, text, R_AVKON_SOFTKEYS_YES_NO ); |
|
59 User::WaitForRequest( stat ); |
|
60 |
|
61 CleanupStack::PopAndDestroy( cq ); |
|
62 ); |
|
63 } |
|
64 } |
|
65 |
|
66 inline void DisplayWarningNote( const TDesC& aNote ) |
|
67 { |
|
68 TRAP_IGNORE( |
|
69 CAknGlobalConfirmationQuery* cq = CAknGlobalConfirmationQuery::NewL(); |
|
70 CleanupStack::PushL( cq ); |
|
71 |
|
72 |
|
73 TRequestStatus stat = KRequestPending; |
|
74 cq->ShowConfirmationQueryL( stat, aNote, R_AVKON_SOFTKEYS_YES_NO ); |
|
75 User::WaitForRequest( stat ); |
|
76 |
|
77 CleanupStack::PopAndDestroy( cq ); |
|
78 ); |
|
79 } |
|
80 |
|
81 #undef TRAP_INSTRUMENTATION_LEAVE |
|
82 #define TRAP_INSTRUMENTATION_LEAVE(aResult) DisplayWarningNote( aResult,TPtrC8( ( TText8* )__FILE__), __LINE__); |
|
83 |
|
84 #define PIM_TRAP_HANDLE( _err, _s ) \ |
|
85 { \ |
|
86 TRAP( _err, _s; ); \ |
|
87 DisplayWarningNote( _err,TPtrC8( ( TText8* )__FILE__),__LINE__ ); \ |
|
88 } |
|
89 #define PIM_TRAPD_HANDLE( _s ) \ |
|
90 { \ |
|
91 TRAPD( _err, _s; ); \ |
|
92 DisplayWarningNote( _err, TPtrC8( ( TText8* )__FILE__), __LINE__ ); \ |
|
93 } |
|
94 #define WARNING_NOTE( _s ) DisplayWarningNote( _s ); |
|
95 |
|
96 #elif defined( _DEBUG ) |
|
97 #define PIM_TRAP_HANDLE( _err, _s ) \ |
|
98 { \ |
|
99 TRAP( _err, _s; ); \ |
|
100 ASSERT( !_err ); \ |
|
101 } |
|
102 #define PIM_TRAPD_HANDLE( _s ) \ |
|
103 { \ |
|
104 TRAPD( _err, _s; ); \ |
|
105 ASSERT( !_err ); \ |
|
106 } |
|
107 #define WARNING_NOTE( _s ) |
|
108 #else |
|
109 // urel |
|
110 #define PIM_TRAP_HANDLE( _err, _s ) TRAP_IGNORE( _s; ); |
|
111 #define PIM_TRAPD_HANDLE( _s ) TRAP_IGNORE( _s; ); |
|
112 #define WARNING_NOTE( _s ) |
|
113 #endif // _DEBUG |
|
114 |
|
115 #if defined (_DEBUG) || defined (_PIM_FILE_LOG) |
|
116 |
|
117 |
|
118 /********************************************************************************************************************/ |
|
119 |
|
120 // MMP MACROS |
|
121 #if defined( TRACE_MODULE_AIAGENDAPLUGINENGINE ) |
|
122 _LIT8( KModuleName8, "AIAgendaPluginEngine" ); |
|
123 #elif defined( TRACE_MODULE_CALENDAR ) |
|
124 _LIT8( KModuleName8, "calendar" ); |
|
125 #elif defined( TRACE_MODULE_CALENGLOBALDATA ) |
|
126 _LIT8( KModuleName8, "CalenGlobalData" ); |
|
127 #elif defined( TRACE_MODULE_CALENCOMMONUI ) |
|
128 _LIT8( KModuleName8, "CalenCommonUi" ); |
|
129 #elif defined( TRACE_MODULE_CALENDEFAULTEDITORS ) |
|
130 _LIT8( KModuleName8, "CalenDefaultEditors" ); |
|
131 #elif defined( TRACE_MODULE_CALENLUNAR ) |
|
132 _LIT8( KModuleName8, "CalenLunar" ); |
|
133 #elif defined( TRACE_MODULE_CALENLUNARPLUGIN ) |
|
134 _LIT8( KModuleName8, "CalenLunarPlugin" ); |
|
135 #elif defined( TRACE_MODULE_CALENTHAIPLUGIN ) |
|
136 _LIT8( KModuleName8, "CalenThaiPlugin" ); |
|
137 #elif defined( TRACE_MODULE_CALENSVR ) |
|
138 _LIT8( KModuleName8, "CalenSvr" ); |
|
139 #elif defined( TRACE_MODULE_CALENSVRCLIENT ) |
|
140 _LIT8( KModuleName8, "CalenSvrClient" ); |
|
141 #else // default |
|
142 _LIT8( KModuleName8, "CalendarUI" ); |
|
143 #endif |
|
144 |
|
145 // traces |
|
146 // [module_name]_ENTRY_POINT;[thread_id];[function_name];[filename]:[line_number]; |
|
147 _LIT8( KFuncEntryFormat8, ";%S_ENTRY_POINT;%d;%S;%S:%d;"); |
|
148 // [module_name]_EXIT_POINT;[thread_id];[function_name];[filename]:[line_number]; |
|
149 _LIT8( KFuncExitFormat8, ";%S_EXIT_POINT;%d;%S;%S:%d;"); |
|
150 |
|
151 /********************************************************************************************************************/ |
|
152 NONSHARABLE_CLASS(TOverflowTruncate8) : public TDes8Overflow |
|
153 { |
|
154 public: |
|
155 void Overflow(TDes8& /*aDes*/) {} |
|
156 }; |
|
157 |
|
158 //Trace macro 8bit |
|
159 // Disable lint warning of function having a variable number of |
|
160 // arguments |
|
161 //lint -esym( 960, 69 ) |
|
162 inline void TraceDebugPrint( TRefByValue<const TDesC8> aFmt, ...) |
|
163 { |
|
164 VA_LIST list; |
|
165 |
|
166 // Disabled lint warning of comma operator |
|
167 //lint -esym( 960, 42 ) |
|
168 VA_START( list, aFmt ); |
|
169 |
|
170 TOverflowTruncate8 overflow; |
|
171 TBuf8<KMaxLogLineLength> buf8; |
|
172 buf8.AppendFormatList( aFmt, list, &overflow ); |
|
173 TBuf16<KMaxLogLineLength> buf16( buf8.Length() ); |
|
174 buf16.Copy( buf8 ); |
|
175 TRefByValue<const TDesC> tmpFmt( _L("%S") ); |
|
176 #if defined (_PIM_FILE_LOG) |
|
177 _LIT( KLogDir, "CalenUi"); |
|
178 _LIT( KLogDir2, "c://CalenUi"); |
|
179 _LIT( KLogFile, "log.txt"); |
|
180 _LIT( KDir, "c://logs//CalenUi" ); |
|
181 _LIT( KDir2, "c://logs//CalenUi" ); |
|
182 |
|
183 RFs fs; |
|
184 fs.Connect(); |
|
185 fs.MkDirAll( KDir ); |
|
186 |
|
187 RFileLogger fileLogger; |
|
188 fileLogger.Connect(); |
|
189 fileLogger.CreateLog( KLogDir, KLogFile, EFileLoggingModeAppend ); |
|
190 fileLogger.SetDateAndTime( EFalse, ETrue ); |
|
191 fileLogger.WriteFormat( tmpFmt, &buf16 ); |
|
192 fileLogger.CloseLog(); |
|
193 fileLogger.Close(); |
|
194 |
|
195 fs.MkDirAll( KDir2 ); |
|
196 |
|
197 RFileLogger fileLogger2; |
|
198 fileLogger2.Connect(); |
|
199 fileLogger2.CreateLog( KLogDir2, KLogFile, EFileLoggingModeAppend ); |
|
200 fileLogger2.SetDateAndTime( EFalse, ETrue ); |
|
201 fileLogger2.WriteFormat( tmpFmt, &buf16 ); |
|
202 fileLogger2.CloseLog(); |
|
203 fileLogger2.Close(); |
|
204 fs.Close(); |
|
205 |
|
206 #else |
|
207 RDebug::Print( tmpFmt, &buf16 ); |
|
208 #endif |
|
209 } |
|
210 |
|
211 _LIT8( KWarningFormat2, " error %d trapped line %d"); |
|
212 inline void WriteTrapInfo( TInt aError, TInt aWarningNote ) |
|
213 { |
|
214 if ( aError ) |
|
215 { |
|
216 TBuf8<128> text; |
|
217 text.Format( KWarningFormat2, aError, aWarningNote ); |
|
218 |
|
219 TraceDebugPrint(text); |
|
220 } |
|
221 } |
|
222 |
|
223 |
|
224 #undef TRAP_INSTRUMENTATION_LEAVE |
|
225 #define TRAP_INSTRUMENTATION_LEAVE(aResult) WriteTrapInfo( aResult, __LINE__); |
|
226 |
|
227 /********************************************************************************************************************/ |
|
228 //Debug print |
|
229 #ifdef TRACE_ENTRY_EXIT_POINT // MACRO IN MMP FILE |
|
230 #ifdef __ARMCC__ |
|
231 #define TRACE_FUNC_ENTRY_DEBUG_PRINT \ |
|
232 { \ |
|
233 const TUint threadId( RThread().Id() ); \ |
|
234 TPtrC8 ptr8File( (TUint8*)__MODULE__ ); \ |
|
235 TPtrC8 ptr8PF( (TUint8*)__PRETTY_FUNCTION__ ); \ |
|
236 TraceDebugPrint( KFuncEntryFormat8, &KModuleName8, threadId, &ptr8PF, &ptr8File, __LINE__ ); \ |
|
237 } |
|
238 #define TRACE_FUNC_EXIT_DEBUG_PRINT \ |
|
239 { \ |
|
240 const TUint threadId( RThread().Id() ); \ |
|
241 TPtrC8 ptr8File( (TUint8*)__MODULE__ ); \ |
|
242 TPtrC8 ptr8PF( (TUint8*)__PRETTY_FUNCTION__ ); \ |
|
243 TraceDebugPrint( KFuncExitFormat8, &KModuleName8, threadId, &ptr8PF, &ptr8File, __LINE__ ); \ |
|
244 } |
|
245 #else // __WINS__ |
|
246 #define TRACE_FUNC_ENTRY_DEBUG_PRINT \ |
|
247 { \ |
|
248 const TUint threadId( RThread().Id() ); \ |
|
249 TPtrC8 ptr8File( (TUint8*)__FILE__ ); \ |
|
250 TPtrC8 ptr8PF( (TUint8*)__PRETTY_FUNCTION__ ); \ |
|
251 TraceDebugPrint( KFuncEntryFormat8, &KModuleName8, threadId, &ptr8PF, &ptr8File, __LINE__ ); \ |
|
252 } |
|
253 #define TRACE_FUNC_EXIT_DEBUG_PRINT \ |
|
254 { \ |
|
255 const TUint threadId( RThread().Id() ); \ |
|
256 TPtrC8 ptr8File( (TUint8*)__FILE__ ); \ |
|
257 TPtrC8 ptr8PF( (TUint8*)__PRETTY_FUNCTION__ ); \ |
|
258 TraceDebugPrint( KFuncExitFormat8, &KModuleName8, threadId, &ptr8PF, &ptr8File, __LINE__ ); \ |
|
259 } |
|
260 #endif |
|
261 #endif |
|
262 |
|
263 /********************************************************************************************************************/ |
|
264 //Check if trace should be activated |
|
265 #ifdef TRACE_ENTRY_EXIT_POINT // MACRO IN MMP FILE |
|
266 #define TRACE_ENTRY_POINT TRACE_FUNC_ENTRY_DEBUG_PRINT |
|
267 #define TRACE_EXIT_POINT TRACE_FUNC_EXIT_DEBUG_PRINT |
|
268 #else |
|
269 #define TRACE_ENTRY_POINT |
|
270 #define TRACE_EXIT_POINT |
|
271 #endif |
|
272 |
|
273 #else |
|
274 #define TRACE_ENTRY_POINT |
|
275 #define TRACE_EXIT_POINT |
|
276 |
|
277 #endif // defined (_DEBUG) || defined (_PIM_FILE_LOG) |
|
278 |
|
279 #endif // PIM_TRACE_H |