|
1 /* |
|
2 * Copyright (c) 2004-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 the License "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 * Definition of CJournalFile |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @released |
|
23 @internalTechnology |
|
24 */ |
|
25 |
|
26 #ifndef __JOURNALFILE_H__ |
|
27 #define __JOURNALFILE_H__ |
|
28 |
|
29 #include <e32base.h> |
|
30 #include <s32file.h> |
|
31 |
|
32 #include "integrityservicesevent.h" |
|
33 #include "integritytree.h" |
|
34 |
|
35 namespace Swi |
|
36 { |
|
37 |
|
38 /** |
|
39 * The purpose of this class is to wrap a RFileWriteStream so that multiple |
|
40 * journal files can be held open by the client. This eliminates the need to |
|
41 * constantly open and close files. It also provides a locking mechanism to |
|
42 * prevent processes sharing the same TransactionID and Journal Path from |
|
43 * writing to the journal at the same time. |
|
44 * |
|
45 * @released |
|
46 * @internalTechnology |
|
47 */ |
|
48 class CJournalFile : public CBase |
|
49 { |
|
50 public: |
|
51 |
|
52 /** |
|
53 * Constructs a new CJournalFile |
|
54 * |
|
55 * @param aFs reference to the supplied file system session |
|
56 * @param aLoader reference to the RLoader session |
|
57 * @param aFileName the filename of the journal |
|
58 */ |
|
59 static CJournalFile* NewL(RFs& aFs, RLoader& aLoader, const TDesC& aFileName, TInt aDrive); |
|
60 |
|
61 /** |
|
62 * Constructs a new CJournalFile an places it on the cleanup stack |
|
63 * |
|
64 * @param aFs reference to the supplied file system session |
|
65 * @param aLoader reference to the RLoader session |
|
66 * @param aFileName the filename of the journal |
|
67 */ |
|
68 static CJournalFile* NewLC(RFs& aFs, RLoader& aLoader, const TDesC& aFileName, TInt aDrive); |
|
69 |
|
70 virtual ~CJournalFile(); |
|
71 |
|
72 /** |
|
73 * Records an event in this journal file. |
|
74 * |
|
75 * @param aEvent the event to record |
|
76 */ |
|
77 void EventL(TIntegrityServicesEvent aEvent); |
|
78 |
|
79 /** |
|
80 * Notifies Integrity Services that a file or directory is being added |
|
81 * so that it can be removed if a rollback occurs. A record is created |
|
82 * in the journal file on the appropriate drive. |
|
83 * |
|
84 * @param aFileName - Name of file or directory including path |
|
85 */ |
|
86 void AddL(const TDesC& aFileName); |
|
87 |
|
88 /** |
|
89 * Checks if the file being removed has already been journalled for |
|
90 * adding in the same journal file. If it has been, nothing is |
|
91 * journalled and the backup file name is set to zero length. Otherwise |
|
92 * a record is journalled for the removal and the backup filename is |
|
93 * set to the appropriate next name to use. |
|
94 * |
|
95 * @param aFileName - Name of file or directory including path |
|
96 * @param aBackupFileName - the generated backup filename to return or |
|
97 * zero-length if the file doesn't need to |
|
98 * be backed up. |
|
99 */ |
|
100 void RemoveL(const TDesC& aFileName, TDes& aBackupFileName); |
|
101 |
|
102 /** |
|
103 * Notifies Integrity Services that a file or directory is being added |
|
104 * that must later be removed. A record is created in the journal file |
|
105 * on the appropriate drive. |
|
106 * |
|
107 * @param aFileName - Name of file or directory including path |
|
108 */ |
|
109 void TemporaryL(const TDesC& aFileName); |
|
110 |
|
111 /** |
|
112 * Performs an operation on the file tree structure |
|
113 * |
|
114 * @param aFunc A function to apply to all nodes |
|
115 * @param aTypeFilter The type of node to apply the function to |
|
116 * @param aIntegrityServices The parent class for this journal, used exclusively in testing |
|
117 * @param aFailType The type of failure to induce, used exclusively in testing. |
|
118 * |
|
119 */ |
|
120 |
|
121 void JournalOperationL(TTreeWalkFunctionL aFunc, TIntegrityServicesEvent aTypeFilter, |
|
122 CIntegrityServices& aIntegrityServices, CIntegrityServices::TFailType aFailType); |
|
123 |
|
124 /** |
|
125 * Returns the last event found in the journal, used to determine how far the |
|
126 * installation progressed |
|
127 * |
|
128 * @return TIntegrityServicesEvent representing the last event in the file |
|
129 */ |
|
130 TIntegrityServicesEvent LastEvent() const; |
|
131 |
|
132 /** |
|
133 * Checks that the filename is valid and complete |
|
134 * |
|
135 * @param aFs a reference to an open file system session |
|
136 * @param aFileName the filename to check |
|
137 * @return TInt representing the drive specified in this filename |
|
138 */ |
|
139 static TInt CheckFileNameL(RFs& aFs, const TDesC& aFileName); |
|
140 |
|
141 /** |
|
142 * Accessor method that tells us which drive this journal file is on |
|
143 */ |
|
144 |
|
145 TInt Drive(); |
|
146 |
|
147 /** |
|
148 * Synchs the journal with the underlying media if appropriate |
|
149 */ |
|
150 |
|
151 void SynchL(); |
|
152 |
|
153 /** |
|
154 * Closes any file handle held open by this object. The journal file object |
|
155 * must not be used again after this call. |
|
156 */ |
|
157 |
|
158 void Close(); |
|
159 |
|
160 private: |
|
161 /** |
|
162 * Constructor for CJournalFile |
|
163 * |
|
164 * @param aFs a reference to the supplied file system session |
|
165 * @param aLoader reference to the RLoader session |
|
166 */ |
|
167 CJournalFile(RFs& aFs, RLoader& aLoader, TInt aDrive); |
|
168 |
|
169 /** |
|
170 * Second phase constructor for CJournalFile |
|
171 * |
|
172 * @param aFileName the filename of the journal |
|
173 */ |
|
174 void ConstructL(const TDesC& aFileName); |
|
175 |
|
176 /** |
|
177 * Reads and verifies the journal file |
|
178 */ |
|
179 void ReadL(); |
|
180 |
|
181 /** |
|
182 * Reads and verifies a journal entry from the supplied stream |
|
183 * |
|
184 * @param aJournalStream the stream to read |
|
185 * @param aDrive used to verify files referred to are only from that drive |
|
186 */ |
|
187 void ReadEntryL(RFileReadStream& aJournalStream, TInt aDrive); |
|
188 |
|
189 /** |
|
190 * Prepares to write to the journal file by opening an RFileWriteStream |
|
191 */ |
|
192 void PrepareToWriteL(); |
|
193 |
|
194 /** |
|
195 * Generates the next backup filename for this journal file. |
|
196 */ |
|
197 void NextBackupFileNameL(TDes& aBackupFileName); |
|
198 |
|
199 /** |
|
200 * Reference to the supplied file system session |
|
201 */ |
|
202 RFs& iFs; |
|
203 |
|
204 /** |
|
205 * Reference to RLoader server session |
|
206 */ |
|
207 RLoader& iLoader; |
|
208 |
|
209 /** |
|
210 * The write stream for this journal |
|
211 */ |
|
212 RFileWriteStream iWriteStream; |
|
213 |
|
214 /** |
|
215 * The last journal event recorded in the journal |
|
216 */ |
|
217 TIntegrityServicesEvent iLastEvent; |
|
218 |
|
219 CIntegrityTreeNode* iTreeRoot; |
|
220 |
|
221 /** |
|
222 * The count of backup files in this journal |
|
223 */ |
|
224 TInt iBackupFilesCount; |
|
225 |
|
226 /** |
|
227 * The filename of this journal |
|
228 */ |
|
229 TFileName iJournalFileName; |
|
230 |
|
231 /** |
|
232 * The drive number this journal file is on |
|
233 */ |
|
234 |
|
235 TInt iDrive; |
|
236 |
|
237 /** |
|
238 * The size this journal was last time we used it |
|
239 */ |
|
240 |
|
241 TInt iLastSize; |
|
242 }; |
|
243 |
|
244 } //namespace |
|
245 #endif |