|
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: Logger manager with read access to history files. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __CCALOGGERMANAGER_H__ |
|
20 #define __CCALOGGERMANAGER_H__ |
|
21 |
|
22 // INCLUDES |
|
23 |
|
24 #include <f32file.h> |
|
25 #include <s32file.h> |
|
26 |
|
27 #include "MCALoggerReadInterface.h" |
|
28 #include "MCALoggerWriteObserver.h" |
|
29 |
|
30 // FORWARD DECLARATIONS |
|
31 |
|
32 class MCALoggerMessageFactory; |
|
33 |
|
34 // CLASS DECLARATION |
|
35 |
|
36 /** |
|
37 * Logger manager with read access to history files. |
|
38 * |
|
39 * @lib CALogger.dll |
|
40 * @since 2.1 |
|
41 */ |
|
42 class CCALoggerManager : public CBase, |
|
43 public MCALoggerReadInterface, |
|
44 public MCALoggerWriteObserver |
|
45 { |
|
46 public: |
|
47 |
|
48 /** |
|
49 * Destructor. |
|
50 * Closes filesession. Resets toc and write arrays. |
|
51 */ |
|
52 virtual ~CCALoggerManager(); |
|
53 |
|
54 protected: |
|
55 |
|
56 /** |
|
57 * Two-phased constructor. Creates instance to CCALoggerManager |
|
58 * Can leave if there is no enough memory. |
|
59 * Can leave if Dll::SetTls call fails. |
|
60 * @return Instance to CCALoggerManager |
|
61 */ |
|
62 static CCALoggerManager* NewL(); |
|
63 |
|
64 /** |
|
65 * C++ default constructor. |
|
66 */ |
|
67 CCALoggerManager(); |
|
68 |
|
69 /** |
|
70 * By default Symbian 2nd phase constructor is private. |
|
71 */ |
|
72 void ConstructL(); |
|
73 |
|
74 private: //new methods |
|
75 |
|
76 /** |
|
77 * Get instance of CCALoggerManager |
|
78 * If instance is not yet created, creates instance. |
|
79 * Sets message factor if passed. |
|
80 * Reads toc file if not yet read and if messagefactory is set. |
|
81 * @since 2.1 |
|
82 * @param aMessageFactory Factory which is used for message and header |
|
83 * creation. |
|
84 * @param aCreate tells if instance should be created or not if not exists. |
|
85 * @return Singleton instance of CCALoggerManager |
|
86 */ |
|
87 static CCALoggerManager* InstanceL( |
|
88 MCALoggerMessageFactory* aMessageFactory, |
|
89 TBool aCreate = ETrue , TBool aNotFirstTime = ETrue ); |
|
90 |
|
91 /** |
|
92 * Get suitable filename. Check situation and updates suitable |
|
93 * filename. |
|
94 * If latest filename is checked before, just add one to current |
|
95 * number. Otherwise check out directory contents and see which |
|
96 * is last file number used. |
|
97 * @since 2.1 |
|
98 */ |
|
99 void SuitableLogFileNameL(); |
|
100 |
|
101 /** |
|
102 * Read header information from toc file and updates toc file |
|
103 * to contain only those headers that points to files that exists. |
|
104 * If message factory does not exists. This call does nothing. |
|
105 * Leaves if some other error than KErrNotFound in file open rutine. |
|
106 * Leaves if error happens when header is tried to append to array. |
|
107 * Leaves if toc filename rename fails |
|
108 * Leaves if leaves if new toc file creation fails. |
|
109 * Leaves if memory check fails with KErrDiskFull |
|
110 * @since 2.1 |
|
111 */ |
|
112 void ReadTocFileL( TBool aFirstTime ); |
|
113 |
|
114 /** |
|
115 * Append new header to toc file. Creates file if not exists. |
|
116 * Leaves if file open and creation fails. |
|
117 * Leaves if memory check fails with KErrDiskFull |
|
118 * @since 2.1 |
|
119 * @param aHeader New header information which will be written |
|
120 * @param aTemporary ETrue, and we are saving temporary toc file. |
|
121 * EFalse and we are saving real toc file. |
|
122 */ |
|
123 void WriteTocFileL( MCALoggerMessageHeader& aHeader, |
|
124 TBool aTemporary = EFalse ); |
|
125 |
|
126 /** |
|
127 * Read information from message file. |
|
128 * Leaves if message factory is not set with KErrNotReady |
|
129 * Leaves if history file cannot be opened. |
|
130 * Leaves if message append to array fails. |
|
131 * @since 2.1 |
|
132 * @param aMessageArray Client provides array for messages read from |
|
133 * file. Messages are appended to array. |
|
134 * @param aKey File to be read is recognized by header. Pointer to |
|
135 * aKey reference is used for task. |
|
136 */ |
|
137 void ReadMessageFileL( |
|
138 RPointerArray< MCALoggerMessage >& aMessageArray, |
|
139 MCALoggerMessageHeader& aKey ); |
|
140 |
|
141 /** |
|
142 * Checks if header already exists |
|
143 * Users aHeaders FilenameL method for key to check |
|
144 * @since 2.5 |
|
145 * @param aHeader Checked header |
|
146 * @return ETrue if exists, EFalse if not. |
|
147 */ |
|
148 TBool CheckIfHeaderExistsL( MCALoggerMessageHeader& aHeader ); |
|
149 |
|
150 /** |
|
151 * |
|
152 */ |
|
153 void PopulateTocArrayL( RPointerArray< MCALoggerMessageHeader >& aArray, |
|
154 const TDesC& aTocFilename |
|
155 |
|
156 #ifdef RD_MULTIPLE_DRIVE |
|
157 , TBool aFirstTime |
|
158 #endif |
|
159 ); |
|
160 /** |
|
161 * Leave if file operation return code is KErrDiskFull. |
|
162 * @param aErrorCode is file operation return code. |
|
163 */ |
|
164 void LeaveIfDiskFull( TInt aErrorCode ); |
|
165 |
|
166 |
|
167 |
|
168 public: //new methods |
|
169 |
|
170 /** |
|
171 * Get read interface to history data. Client cannot delete instance. |
|
172 * Leaves if instance call fails. |
|
173 * @since 2.1 |
|
174 * @param aMessageFactory Factory which is used for message and header |
|
175 * creation. |
|
176 * @return Pointer to instance of CCALoggerManager |
|
177 */ |
|
178 static MCALoggerReadInterface* ReadInstanceL( |
|
179 MCALoggerMessageFactory* aMessageFactory, TBool aFirstTime = EFalse ); |
|
180 |
|
181 /** |
|
182 * Creation of write instance to history data |
|
183 * Leaves if instance call fails. |
|
184 * Leaves if creation of CCALoggerWriter fails. |
|
185 * @since 2.1 |
|
186 * @param aMessageFactory Factory which is used for message and header |
|
187 * creation. |
|
188 * @return Pointer to new created CCALoggerWriter. Ownership is |
|
189 * transferred to the caller. |
|
190 */ |
|
191 static MCALoggerWriteInterface* WriteInstanceL( |
|
192 MCALoggerMessageFactory* aMessageFactory ); |
|
193 |
|
194 /** |
|
195 * Releases instance. This is only for testing purposes. |
|
196 * Sets Dll::Tls to NULL. |
|
197 * Leaves if instance call fails. |
|
198 */ |
|
199 static void ReleaseInstanceL(); |
|
200 |
|
201 public: // Inherited from MCALoggerWriteObserver |
|
202 |
|
203 /** |
|
204 * Add file to write buffer. TFileRelation contains two pointer. |
|
205 * MCALoggerMessageHeader and MCALoggerWriteInterface |
|
206 * Ownership of MCALoggerMessageHeader is transfered to this class |
|
207 * Ownership of MCALoggerWriteInterface will stay in caller. |
|
208 * Calls first RemoveFileL with MCALoggerWriteInterface parameter |
|
209 * to be sure that there is no other file in write array for |
|
210 * MCALoggerWriteInterface. Then appends TFileRelation parameter to |
|
211 * array. |
|
212 * Leaves if TPointerArray::Append fails. |
|
213 * @since 2.1 |
|
214 * @param iFile File information |
|
215 */ |
|
216 void AddFileL( TFileRelation aFile ); |
|
217 |
|
218 /** |
|
219 * Remove file from write array and append it to toc array. |
|
220 * After that header is written to toc file. |
|
221 * Leaves if TPointerArray::Append fails. |
|
222 * Leaves if header file write fails. |
|
223 * @since 2.1 |
|
224 * @param aWriter File to be removed |
|
225 * is recognized with file writer pointer. |
|
226 */ |
|
227 void RemoveFileL( MCALoggerWriteInterface& aWriter ); |
|
228 |
|
229 /** |
|
230 * Creates new filename for writer. Ownership is transfered to caller. |
|
231 * Leaves if HBufC::NewL fails. |
|
232 * Leaves if SuitableLogFileNameL fails. |
|
233 * @since 2.1 |
|
234 * @return Pointer to new filename. |
|
235 */ |
|
236 HBufC* CreateNewFilenameL(); |
|
237 |
|
238 #ifdef RD_MULTIPLE_DRIVE |
|
239 |
|
240 /** |
|
241 * Creates new filename for writer. Ownership is transfered to caller. |
|
242 * Leaves if HBufC::NewL fails. |
|
243 * Leaves if SuitableLogFileNameL fails. |
|
244 * @since 2.1 |
|
245 * @return Pointer to new filename. |
|
246 */ |
|
247 HBufC* CreateNewFilenameMDL(); |
|
248 |
|
249 /** |
|
250 * Creates new filename for writer. Ownership is transfered to caller. |
|
251 * Leaves if HBufC::NewL fails. |
|
252 * Leaves if SuitableLogFileNameL fails. |
|
253 * @since 2.1 |
|
254 * @return Pointer to new filename. |
|
255 */ |
|
256 TBool GetDriveStatusL( const TDriveNumber aDriveNumber ); |
|
257 |
|
258 #endif |
|
259 |
|
260 /** |
|
261 * Checks memory situation. Check if there is enough memory to write |
|
262 * file. |
|
263 * Leaves if SysUtil::FFSSPaceGBelowCriticalLevelL fails. |
|
264 * @since 2.1 |
|
265 * @param aMemoryRequired Memory required in bytes. |
|
266 * @return ETrue if there is enough memory and EFalse if not. |
|
267 */ |
|
268 TBool CheckMemoryL( TInt aMemoryRequired ); |
|
269 |
|
270 public: //Inherited from MCALoggerReadInterface |
|
271 |
|
272 /** |
|
273 * Client gets pointer to message header array trough parameter. |
|
274 * @since 2.1 |
|
275 * @param aHeaderArray Pointer to message header array is set to this |
|
276 * parameter. Ownership of array does not change. |
|
277 */ |
|
278 void GetLoggerMessageHeaderArray( |
|
279 RPointerArray< MCALoggerMessageHeader >*& aHeaderArray ); |
|
280 |
|
281 /** |
|
282 * Client asks logger to create messages to array concerning one header |
|
283 * Leaves with KErrNotFound if history file does not exists. |
|
284 * Leaves if history file read fails. |
|
285 * @since 2.1 |
|
286 * @param aMessageArray Client provides array for messages read from |
|
287 * file. Messages are appended to array. |
|
288 * @param aKey File to be read is recognized by header. Pointer to |
|
289 * aKey reference is used for task. |
|
290 */ |
|
291 void CreateLoggerMessagesL( |
|
292 RPointerArray< MCALoggerMessage >& aMessageArray, |
|
293 MCALoggerMessageHeader& aKey ); |
|
294 |
|
295 /** |
|
296 * Delete one history file recognized by header. |
|
297 * Leaves if MCALoggerMessageHeader::FileNameL fails. |
|
298 * WARNING: header passed will be deleted and removed from header |
|
299 * array. Array is same that client has been given to with |
|
300 * GetLoggerMessageHeaderArray so removal will be seen directly in |
|
301 * client side too. |
|
302 * @since 2.1 |
|
303 * @param aKey File to be read is recognized by header. Pointer to |
|
304 * aKey reference is used for task. |
|
305 */ |
|
306 void DeleteHistoryFileL( MCALoggerMessageHeader& aKey ); |
|
307 |
|
308 /** |
|
309 * Set message factory. Factory is used to create messages and message |
|
310 * headers for logger and client use. |
|
311 * @since 2.1 |
|
312 * @param aMessageFactory Pointer to message factory. |
|
313 */ |
|
314 void SetLoggerMessageFactory( |
|
315 MCALoggerMessageFactory* aMessageFactory ); |
|
316 |
|
317 private: |
|
318 |
|
319 /** |
|
320 * Reference to message factory for creation messages and files |
|
321 * when needed. Does not own. |
|
322 */ |
|
323 MCALoggerMessageFactory* iMessageFactory; |
|
324 |
|
325 /** |
|
326 * List of those files which have been created for writing, but not |
|
327 * yet ready ones. |
|
328 */ |
|
329 RArray< TFileRelation > iWriteFileArray; |
|
330 |
|
331 /** |
|
332 * List of those files which have been created for writing, but not |
|
333 * yet ready ones. |
|
334 */ |
|
335 RPointerArray< MCALoggerMessageHeader > iFileTocArray; |
|
336 |
|
337 /** |
|
338 * Temp list for toc file. Member variable for leave simpler error management. |
|
339 * eg. leaves. |
|
340 */ |
|
341 RPointerArray< MCALoggerMessageHeader > iFileTempTocArray; |
|
342 |
|
343 /** |
|
344 * We have checked latest possible file name number to give FileWriter. |
|
345 */ |
|
346 TBool iWeHaveLatestFileNameNumber; |
|
347 |
|
348 /** |
|
349 * Latest file name number to give FileWriter when asked. |
|
350 */ |
|
351 TInt iLatestFileNameNumber; |
|
352 |
|
353 /** |
|
354 * File Session for handling files. |
|
355 */ |
|
356 RFs iFileSession; |
|
357 |
|
358 |
|
359 |
|
360 /** |
|
361 * Table of contents. Header information of history files. |
|
362 */ |
|
363 TBool iTocFileRead; |
|
364 }; |
|
365 |
|
366 #endif // __CCALOGGERMANAGER_H__ |
|
367 |
|
368 // End of File |