|
1 /* |
|
2 * Copyright (c) 2003 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: This module defines event logger. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef _EVENTLOGGER_H_ |
|
21 #define _EVENTLOGGER_H_ |
|
22 |
|
23 // INCLUDES |
|
24 #include <eikenv.h> |
|
25 #include <coeutils.h> |
|
26 #include "eventmediatorapi.h" |
|
27 #include "eventmediator.h" |
|
28 |
|
29 _LIT(KEventLogFile, "eventlog.bin"); |
|
30 |
|
31 |
|
32 // CLASS DECLARATION |
|
33 |
|
34 /** |
|
35 * Contains general information about a log event. When reporting a log event an object of this class |
|
36 * Should be in the begining of the data descriptor. |
|
37 */ |
|
38 class TLogEvent |
|
39 { |
|
40 /* public: |
|
41 enum TLogCategory |
|
42 { EInfo, |
|
43 EWarning, |
|
44 EError, |
|
45 EDebug |
|
46 }; |
|
47 */ |
|
48 public: // Methods |
|
49 /** |
|
50 * Standard constructors |
|
51 */ |
|
52 TLogEvent(){}; |
|
53 TLogEvent(TUid aSource, TLogCategory aCategory, TUint aMsgId, TInt aDesCount):iSource(aSource), iCategory(aCategory),iMsgId(aMsgId),iDesCount(aDesCount){}; |
|
54 |
|
55 public: // Data |
|
56 // enumeration of log event categories |
|
57 |
|
58 // source of the log event |
|
59 TUid iSource; |
|
60 // category of the log event |
|
61 TLogCategory iCategory; |
|
62 // id of the log message |
|
63 TUint iMsgId; |
|
64 // number of data descriptors related to this iMsgId |
|
65 TInt iDesCount; |
|
66 }; |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 #define LOGFILE_MAX_LTH 20 // 20 kb |
|
74 #define KBYTES_TO_BYTES 1024 |
|
75 #define ELEM_HEADER_LTH 16 |
|
76 #define ELEM_TRAILER_LTH 12 |
|
77 //#define FILE_HEADER_LTH 16 NOTE! moved to eventmediatorapi.h |
|
78 #define FILE_BEGIN 0 |
|
79 #define END_MARK_1 0xefbeadde |
|
80 #define END_MARK_2 0xeeabedfe |
|
81 #define FILE_ID 0x474f4c45 // ELOG |
|
82 |
|
83 |
|
84 // CLASS DECLARATION |
|
85 |
|
86 /** |
|
87 * Class used to write the log file. |
|
88 */ |
|
89 class CEventLogger : public CBase |
|
90 { |
|
91 public: //Methods |
|
92 |
|
93 // Constructors and destructor |
|
94 |
|
95 /** |
|
96 * Default constructor, maximum length of log file set to LOGFILE_MAX_LTH |
|
97 */ |
|
98 static CEventLogger* NewL(CEventMediatorServer* aServer); |
|
99 |
|
100 /** |
|
101 * Constructor |
|
102 * @param aFileMaxLength: maximum length of log file in kbytes |
|
103 */ |
|
104 CEventLogger(TInt aFileMaxLength, CEventMediatorServer* aServer); |
|
105 |
|
106 /** |
|
107 * Destructor |
|
108 */ |
|
109 ~CEventLogger(); |
|
110 |
|
111 /** |
|
112 * Writes new event to the log file. |
|
113 * @param aEvent: descriptor containing instance of class TLogEvent |
|
114 * and data descriptor of the event appended to it |
|
115 */ |
|
116 void LogEvent(const TDesC8& aEvent); |
|
117 |
|
118 private: //Methods |
|
119 |
|
120 /** |
|
121 * Writes new event to the log file. |
|
122 * @param aInfo: general info on the event. |
|
123 * @param aData: event data. |
|
124 */ |
|
125 // void LogEvent(const TLogEvent& aInfo, const TDesC8& aData); |
|
126 |
|
127 /** |
|
128 * Opens the log file for reading and writing. |
|
129 * @return: Etrue if Successfull, EFalse if not |
|
130 */ |
|
131 TBool OpenLogFile(); |
|
132 |
|
133 /** |
|
134 * Closes the log file. |
|
135 */ |
|
136 void CloseLogFile(); |
|
137 |
|
138 /** |
|
139 * Reads the file header from the log file to a descriptor. |
|
140 * @param aFileHdr: descriptor to which the header is read. |
|
141 * @return: Etrue if Successfull, EFalse if not |
|
142 */ |
|
143 TBool GetFileHeader(TDes8 &aFileHdr); |
|
144 |
|
145 /** |
|
146 * Returns the position in the file to which a new element can be written. |
|
147 * @param aFileHdr: log file header. |
|
148 * @param aLength: length of the element about to be written. |
|
149 * @return: position to write the element to. |
|
150 */ |
|
151 TInt GetElemDataPosition(TDes8 &aFileHdr, TInt aLength); |
|
152 |
|
153 /** |
|
154 * Saves the log file header to the log file. |
|
155 * @param aPosition: the position to which new elements can be written. |
|
156 * @param aFileHdr: log file header. |
|
157 * @return: Etrue if Successfull, EFalse if not |
|
158 */ |
|
159 TBool SaveFileHeader(TInt aPosition, TDes8 &aFileHdr); |
|
160 |
|
161 /** |
|
162 * Stores the log file header to a descriptor. |
|
163 * @param aPosition: the position to which new elements can be written. |
|
164 * @param aFirstOffset: wrapping offset |
|
165 * @param aBuf: log file header. |
|
166 */ |
|
167 void StoreFileHeaderInfo(TInt aPosition, TInt aFirstOffset, TDes8 &aBuf); |
|
168 |
|
169 /** |
|
170 * Writes new event to the log file. |
|
171 * @param aPosition: the position to write the element to. |
|
172 * @param aEvent: descriptor containning the element |
|
173 * @return: the total length of the written element. |
|
174 */ |
|
175 TInt WriteLogElem(TInt aPosition, const TDesC8& aEvent); |
|
176 |
|
177 /** |
|
178 * Gets the time and formats it into a TUint32 object. |
|
179 * @return: the time stamp as an unsigned integer. |
|
180 */ |
|
181 // TUint32 GetTimeStamp(); |
|
182 |
|
183 private: |
|
184 /** |
|
185 * Default constructor. |
|
186 */ |
|
187 CEventLogger(CEventMediatorServer* aServer); |
|
188 private: //Data |
|
189 // file server |
|
190 RFs iFS; |
|
191 |
|
192 // log file |
|
193 RFile iLogFile; |
|
194 |
|
195 // log file max length |
|
196 TInt iFileMaxLength; |
|
197 |
|
198 // event number, starting from 1 |
|
199 TUint32 iEventNumber; |
|
200 |
|
201 CEventMediatorServer* iServer; |
|
202 }; |
|
203 |
|
204 |
|
205 // CLASS DECLARATION |
|
206 |
|
207 /** |
|
208 * Contains log file header, basically two integers position and wrapping offset. |
|
209 */ |
|
210 class TFileHeader |
|
211 { |
|
212 public: // Methods |
|
213 inline TInt32 GetPosition() const {return ((TInt32)(u.iData32[1]));}; |
|
214 inline TInt32 GetWrappingOffset() const {return ((TInt32)(u.iData32[2]));}; |
|
215 inline TInt32 GetEventNumber() const {return ((TInt32)(u.iData32[3]));}; |
|
216 inline void SetFileId() {u.iData32[0] = FILE_ID; }; |
|
217 inline void SetPosition(TInt32 aPosition) {u.iData32[1] = (TUint32)aPosition;}; |
|
218 inline void SetWrappingOffset(TInt32 aWO) {u.iData32[2] = (TUint32)aWO;}; |
|
219 inline void SetEventNumber(TInt32 aEventNumber) {u.iData32[3] = (TUint32)aEventNumber;}; |
|
220 |
|
221 private: // Data |
|
222 union // Currently union is not needed, only iData32 is used |
|
223 { |
|
224 TUint32 iData32[4]; |
|
225 TUint8 iData8[8]; |
|
226 } u; |
|
227 }; |
|
228 |
|
229 |
|
230 |
|
231 // CLASS DECLARATION |
|
232 |
|
233 /** |
|
234 * Contains log element header, consisting of four integer values: |
|
235 * length: length of the data beloging to the element |
|
236 * timestamp: the time the element was written. |
|
237 * source: Uid of the reporter of the element. |
|
238 * aCategory: the gategory of the log event. |
|
239 */ |
|
240 class TElemHeader |
|
241 { |
|
242 public: // Methods |
|
243 |
|
244 inline void SetEventLength(TUint32 aLength) {u.iData32[0] = (TUint32)aLength;}; |
|
245 inline void SetEventNumber(TUint32 aEventNumber) {u.iData32[1] = (TUint32)aEventNumber;}; |
|
246 // inline void SetTime(TUint32 aTimeStamp) {u.iData32[2] = (TUint32)aTimeStamp;}; |
|
247 inline void SetTime(const TInt64& aTimeStamp) {u.iData32[2] = I64LOW(aTimeStamp); u.iData32[3] = I64HIGH(aTimeStamp);}; |
|
248 |
|
249 private: // Data |
|
250 union |
|
251 { |
|
252 TUint32 iData32[4]; |
|
253 TUint8 iData8[8]; |
|
254 } u; |
|
255 }; |
|
256 |
|
257 |
|
258 // CLASS DECLARATION |
|
259 |
|
260 /** |
|
261 * Contains a constant log element trailer, consisting of two integer values. |
|
262 */ |
|
263 class TElemTrailer |
|
264 { |
|
265 public: // Methods |
|
266 inline void SetLogEndMark() {u.iData32[0] = END_MARK_1; |
|
267 u.iData32[1] = END_MARK_2;}; |
|
268 inline void SetEventLength(TUint32 aLength) {u.iData32[2] = (TUint32)aLength;}; |
|
269 private: // Data |
|
270 union |
|
271 { |
|
272 TUint32 iData32[3]; |
|
273 TUint8 iData8[8]; |
|
274 } u; |
|
275 }; |
|
276 |
|
277 |
|
278 #endif |