1 /* |
|
2 * Copyright (c) 2002 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 * Phone logger |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef __CPHONELOGGER_H |
|
21 #define __CPHONELOGGER_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32std.h> |
|
25 #include <coemain.h> |
|
26 #include "phoneconstants.h" |
|
27 #include "stringpool.h" |
|
28 |
|
29 // FORWARD DECLARATIONS |
|
30 class RFileLogger; |
|
31 class MPEEngineInfo; |
|
32 class MPEPhoneModel; |
|
33 |
|
34 enum TPhoneUILoggingLevel |
|
35 { |
|
36 ENo, // No logging at all. |
|
37 EOnlyFatal, // Only fatal errors etc. are logged |
|
38 EBasic, // Normal logging (fatals + PE mesages etc), |
|
39 EMethodStartEnd, // All above & function starts and ends are logged |
|
40 // (where added) |
|
41 EAll // All above & extra logging |
|
42 }; |
|
43 |
|
44 enum TPhoneUILoggingComponent |
|
45 { |
|
46 EPhoneAbstractFactoryClient, |
|
47 EPhoneControl, |
|
48 EPhonePhoneapp, |
|
49 EPhoneUIView, |
|
50 EPhoneUIStates, |
|
51 EPhoneUIUtils, |
|
52 PhoneUIVoIPExtension, |
|
53 EPhoneMediatorCenter, |
|
54 EPhoneAmountOfLoggingComponents |
|
55 }; |
|
56 |
|
57 // CLASS DECLARATION |
|
58 |
|
59 /** |
|
60 @private |
|
61 @class CPhone |
|
62 @since 7.0 |
|
63 A utility used in phone application for logging in debug builds. Log |
|
64 files are placed in the directory %EPOCROOT%/epoc32/wins/c/logs/phoneapp |
|
65 */ |
|
66 class CPhoneLogger : public TDesOverflow , public CCoeStatic |
|
67 { |
|
68 public: // New methods |
|
69 |
|
70 /** |
|
71 * C++ constructor |
|
72 * @param aUid Uid for CCoeStatic uid. |
|
73 */ |
|
74 IMPORT_C CPhoneLogger(TUid aUid); |
|
75 |
|
76 /** |
|
77 * C++ destructor. Closes the log file. |
|
78 */ |
|
79 IMPORT_C virtual ~CPhoneLogger(); |
|
80 |
|
81 /** |
|
82 * Formats a log message by given numerous parameters and writes it in |
|
83 * the log file. |
|
84 * @param aLevel is the logging level. log messages below chosen |
|
85 * level are not printed out. |
|
86 * @param aLoggingComponent identifies the component where the log |
|
87 * message originates from. |
|
88 * @param aFmt is the log message, it may include formatting |
|
89 * @return None. |
|
90 */ |
|
91 IMPORT_C void LogIt( |
|
92 TPhoneUILoggingLevel aLevel, |
|
93 TPhoneUILoggingComponent aLoggingComponent, |
|
94 TRefByValue<const TDesC> aFmt, ...); |
|
95 |
|
96 /** |
|
97 * Checks if logging components level is enough to log. |
|
98 * @aLevel is level of the log message whose printage needs to be judged |
|
99 * @aLoggingComponent is the component where the log message |
|
100 * originates from |
|
101 * @return ETrue if logging is needed, based on aLevel, |
|
102 * aLoggingComponent and current log level. |
|
103 */ |
|
104 TBool CheckLogLevel( |
|
105 TPhoneUILoggingLevel aLevel, |
|
106 TPhoneUILoggingComponent aLoggingComponent ); |
|
107 |
|
108 /** |
|
109 * Writes comment to log file. |
|
110 * |
|
111 * @param aComment - A comment descriptor to be logged. |
|
112 * @return None. |
|
113 */ |
|
114 void WriteComment( const TDesC& aComment ); |
|
115 |
|
116 /** |
|
117 * Creates a specified log message by given parameters and writes it |
|
118 * in the log file. |
|
119 * |
|
120 * @param aMessage - Ordinal of enumerated phone engine command. |
|
121 * Converts it in to descriptor. |
|
122 * @param aCallId - ID of current call. |
|
123 * @return None. |
|
124 */ |
|
125 IMPORT_C void LogMsgFromControlToView ( |
|
126 const TInt aMessage, |
|
127 const TInt aCallId ); |
|
128 |
|
129 /** |
|
130 * Creates a PE specified log message by given parameters and writes |
|
131 * it in the log file. |
|
132 * |
|
133 * @param aMessage - Ordinal of enumerated phone engine command. |
|
134 * Converts it in to descriptor. |
|
135 * @param aCallId - ID of current call. |
|
136 * @return None. |
|
137 */ |
|
138 IMPORT_C void LogMsgFromPEToPhoneUI ( |
|
139 const TInt aMessage, |
|
140 const TInt aCallId ); |
|
141 |
|
142 /** |
|
143 * Creates a PE specified log message by given TPEMessage id and call |
|
144 * id and writes it in the log file. |
|
145 * |
|
146 * @param aMessage - Ordinal of enumerated phone engine command. |
|
147 * Converts it in to descriptor. |
|
148 * @param aCallId - ID of current call. |
|
149 * @return None. |
|
150 */ |
|
151 IMPORT_C void LogMsgFromPhoneUIToPE( |
|
152 const TInt aMessage, |
|
153 const TInt aCallId ); |
|
154 |
|
155 /** |
|
156 * Logs message from Phone Engine to Phoneapp execution ending. |
|
157 * (When message is executed succesfully, this function is called). |
|
158 * |
|
159 * @param aMessage - Ordinal of enumerated phone engine command. |
|
160 * Converts it in to descriptor. |
|
161 * @return None. |
|
162 */ |
|
163 IMPORT_C void LogMsgFromPEToPhoneUIEnd( const TInt aMessage ); |
|
164 |
|
165 /** |
|
166 * Logs state change. |
|
167 * |
|
168 * @param aCurrentState Current state of phoneapp. |
|
169 * @param aNewState Next state of phoneapp. |
|
170 * @return None. |
|
171 */ |
|
172 IMPORT_C void LogStateChange( |
|
173 const TInt aCurrentState, |
|
174 const TInt aNewState ); |
|
175 |
|
176 /** |
|
177 * Sets pointer to Phone Engine |
|
178 * @param aPhoneEngine pointer to Phone Engine instance |
|
179 */ |
|
180 IMPORT_C void SetPhoneEngine( MPEPhoneModel* aPhoneEngine ); |
|
181 |
|
182 private: // Methods from TDesOverflow |
|
183 |
|
184 /** |
|
185 * Formats a log message by given numerous parameters and writes |
|
186 * it in the log file. |
|
187 * |
|
188 * @param aFmt - |
|
189 * @return None. |
|
190 */ |
|
191 void LogIt( TRefByValue<const TDesC> aFmt, ...); |
|
192 |
|
193 /** |
|
194 * Handles the overflow. This function is called when the |
|
195 * TDes16::AppendFormat() variant, which takes an overflow handler |
|
196 * argument, fails. TDes16::AppendFormat() variant called by LogIt(). |
|
197 * |
|
198 * @param aDes - The 16 bit modifiable descriptor whose overflow |
|
199 * results in the call to this overflow handler. |
|
200 * @return None. |
|
201 */ |
|
202 IMPORT_C virtual void Overflow(TDes16& aDes); |
|
203 |
|
204 private: // New methods |
|
205 |
|
206 /** |
|
207 * Provides string representation for TPEMessagesFromPhoneEngine. |
|
208 * |
|
209 * @param aDes - Descriptor for copying string representation. |
|
210 * @return None. |
|
211 */ |
|
212 void GetPEToPhoneUIStringById( TDes16& aDes, const TInt aID ); |
|
213 |
|
214 /** |
|
215 * Provides string representation for TPACommandId. |
|
216 * |
|
217 * @param aDes - Descriptor for copying string representation. |
|
218 * @param aID - Descriptor for copying string representation. |
|
219 * @return None. |
|
220 */ |
|
221 void GetPhoneUIToPEStringById( TDes16& aDes, const TInt aID ); |
|
222 |
|
223 /** |
|
224 * Provides string representation for MPhoneViewCommandId. |
|
225 * |
|
226 * @param aDes - Descriptor for copying string representation. |
|
227 * @param aID - Descriptor for copying string representation. |
|
228 * @return None. |
|
229 */ |
|
230 void GetPhoneUIToViewStringById( TDes16& aDes, const TInt aID ); |
|
231 |
|
232 /** |
|
233 * Recounts TPhoneStateId enumeration values for logger. |
|
234 * |
|
235 * @param aID - TPhoneStateId enumeration value |
|
236 * @return - Value of recounted enumeration id |
|
237 */ |
|
238 TInt RecountStateId( TInt aId ); |
|
239 |
|
240 /** |
|
241 * Recounts TPhoneStateId GSM-variant enumeration values for logger. |
|
242 * |
|
243 * @param aID - TPhoneStateId enumeration value |
|
244 * @return - Value of recounted enumeration id |
|
245 */ |
|
246 TInt RecountStateIdGSM( TInt aId ); |
|
247 |
|
248 /** |
|
249 * Provides string representation for state |
|
250 * |
|
251 * @param aDes - Descriptor for copying string representation. |
|
252 * @param aID - Id of the state. |
|
253 * @return - None. |
|
254 */ |
|
255 void GetStateName( TDes16& aDes, const TInt aID ); |
|
256 |
|
257 /** Array of logging levels for each component */ |
|
258 TFixedArray<TPhoneUILoggingLevel, EPhoneAmountOfLoggingComponents> |
|
259 iLogLevelArray; |
|
260 |
|
261 private: // attributes |
|
262 |
|
263 // String pool handle |
|
264 RStringPool iPool; |
|
265 |
|
266 /** |
|
267 * Pointer to Phone Engine - uses relation |
|
268 */ |
|
269 MPEPhoneModel* iPhoneEngine; |
|
270 }; |
|
271 |
|
272 class CPhoneMethodLogger: public CBase |
|
273 { |
|
274 public: |
|
275 |
|
276 /** Method logger constructor. constructor. |
|
277 * Writes time lable and "Enter: " + the given string. |
|
278 */ |
|
279 IMPORT_C CPhoneMethodLogger( |
|
280 TPhoneUILoggingComponent aLoggingComponent, |
|
281 TPtrC aString); |
|
282 |
|
283 /** Destructor. |
|
284 * Writes time lable and "Leave: " + the given string. |
|
285 */ |
|
286 IMPORT_C ~CPhoneMethodLogger(); |
|
287 |
|
288 private: |
|
289 |
|
290 TBuf<128> iString; |
|
291 TPhoneUILoggingComponent iLoggingComponent; |
|
292 }; |
|
293 |
|
294 // These are empty logging macros when PHONEUI_LOGGING_OUTPUT==0 |
|
295 |
|
296 #if (PHONEUI_LOGGING_OUTPUT==0) |
|
297 #define __PHONELOG(A, B, C) |
|
298 #define __PHONELOG1(A,B, C, X) |
|
299 #define __PHONELOG2(A,B, C, X, Y) |
|
300 #define __PHONELOG3(A,B, C, X, Y, Z) |
|
301 #define __PHONELOGENGINEMSG( C, X ) |
|
302 #define __PHONELOGENGINEMSGEND( C) |
|
303 #define __PHONELOGENGINECMD( C) |
|
304 #define __PHONELOGSTATECHANGE( C, X) |
|
305 #define __LOGMETHODSTARTEND(A,C) |
|
306 #define __PHONELOGVIEWMSG( C, X ) |
|
307 |
|
308 // These are the real logging macros that uses CPhoneLogger class. |
|
309 #else |
|
310 |
|
311 //If logging method == 2 define log file name. |
|
312 |
|
313 #define __PHONELOG(A, B, C) (static_cast<CPhoneLogger*> \ |
|
314 (CCoeEnv::Static(KUidPhoneUILoggerSingleton)))-> \ |
|
315 LogIt(A, B, _L(C) ); |
|
316 |
|
317 #define __PHONELOG1(A, B, C, X) (static_cast<CPhoneLogger*> \ |
|
318 (CCoeEnv::Static(KUidPhoneUILoggerSingleton)))-> \ |
|
319 LogIt(A, B, _L(C), X); |
|
320 |
|
321 #define __PHONELOG2(A, B, C, X, Y) (static_cast<CPhoneLogger*> \ |
|
322 (CCoeEnv::Static(KUidPhoneUILoggerSingleton)))-> \ |
|
323 LogIt(A, B, _L(C), X, Y); |
|
324 |
|
325 #define __PHONELOG3(A, B, C, X, Y, Z) (static_cast<CPhoneLogger*> \ |
|
326 (CCoeEnv::Static(KUidPhoneUILoggerSingleton)))-> \ |
|
327 LogIt(A, B, _L(C), X, Y, Z); |
|
328 |
|
329 #define __PHONELOGENGINEMSG( C, X ) (static_cast<CPhoneLogger*> \ |
|
330 (CCoeEnv::Static(KUidPhoneUILoggerSingleton)))-> \ |
|
331 LogMsgFromPEToPhoneUI( (TInt)C, X); |
|
332 |
|
333 #define __PHONELOGENGINEMSGEND( C ) (static_cast<CPhoneLogger*> \ |
|
334 (CCoeEnv::Static(KUidPhoneUILoggerSingleton)))-> \ |
|
335 LogMsgFromPEToPhoneUIEnd( (TInt)C ); |
|
336 |
|
337 #define __PHONELOGENGINECMD( C ) (static_cast<CPhoneLogger*> \ |
|
338 (CCoeEnv::Static(KUidPhoneUILoggerSingleton)))-> \ |
|
339 LogMsgFromPhoneUIToPE( (TInt)C, 0 ); |
|
340 |
|
341 #define __PHONELOGVIEWMSG( C, X ) (static_cast<CPhoneLogger*> \ |
|
342 (CCoeEnv::Static(KUidPhoneUILoggerSingleton)))-> \ |
|
343 LogMsgFromControlToView( (TInt)C, X); |
|
344 |
|
345 #define __PHONELOGSTATECHANGE( C, X ) (static_cast<CPhoneLogger*> \ |
|
346 (CCoeEnv::Static(KUidPhoneUILoggerSingleton)))-> \ |
|
347 LogStateChange( (TInt)C, TInt(X) ); |
|
348 |
|
349 #define __LOGMETHODSTARTEND( A, C ) CPhoneMethodLogger __log( A, ( _L(C) ) ); |
|
350 |
|
351 |
|
352 #endif // else --> #if (PHONE_LOGGING_METHOD==0 ) |
|
353 |
|
354 #endif // #ifndef __CPhoneLogger_H__ |
|
355 |
|