|
1 /* |
|
2 * Copyright (c) 2007 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: Skin server's active data owner in backup/restore. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_AKNSSRVACTIVEBACKUPDATACLIENT_H |
|
20 #define C_AKNSSRVACTIVEBACKUPDATACLIENT_H |
|
21 |
|
22 #include <e32base.h> // CBase |
|
23 #include <connect/abclient.h> |
|
24 |
|
25 /** |
|
26 * Skin server's active data owner in backup/restore. |
|
27 * |
|
28 * Backed up files are not restored: |
|
29 * - if same file exists in system folder (cannot overwrite) |
|
30 * - if the same file exists in private directory |
|
31 * - if no matching .skn-file is found from private directory. |
|
32 * |
|
33 * If file is restored, it is re-created to the skin's private directory. |
|
34 * |
|
35 * @lib aknskinsrv.dll |
|
36 * @since S60 v3.1 |
|
37 */ |
|
38 NONSHARABLE_CLASS( CAknsSrvActiveBackupDataClient ) : public CBase, |
|
39 public conn::MActiveBackupDataClient |
|
40 { |
|
41 public: |
|
42 |
|
43 enum TAknsSrvBackupState |
|
44 { |
|
45 // initial state; open a file for processing |
|
46 EBackupNoFileOpen = 0, |
|
47 // nothing sent for current file - send the file header info |
|
48 EBackupOpenNothingSent, |
|
49 // part of the header info sent - need to send the rest of the header |
|
50 EBackupOpenPartHeaderSent, |
|
51 // need to send data from the current file |
|
52 EBackupOpenAllHeaderSent, |
|
53 // At the end of the current file. |
|
54 EBackupEndOfFile |
|
55 }; |
|
56 |
|
57 enum TAknsSrvRestoreState |
|
58 { |
|
59 // initial state; expecting number of files to restore. |
|
60 ERestoreNumberOfFiles = 0, |
|
61 // expecting checksum of 16 bytes |
|
62 ERestoreExpectChecksum, |
|
63 // continue reading checksum; it didn't fit completely in |
|
64 // one read |
|
65 ERestoreExpectMoreChecksum, |
|
66 // expecting to read file size of 16 bytes |
|
67 ERestoreExpectFileSize, |
|
68 // file size didn't fit into read buffer in one read. |
|
69 ERestoreExpectMoreFileSize, |
|
70 // the size of the filename to restore |
|
71 ERestoreExpectFileNameSize, |
|
72 // filename size didn't fit into read buffer in one read. |
|
73 ERestoreExpectMoreFileNameSize, |
|
74 // the filename to restore |
|
75 ERestoreExpectFileName, |
|
76 // filename didn't fit into read buffer in one read. |
|
77 ERestoreExpectMoreFileName, |
|
78 // the content of the file to restore |
|
79 ERestoreExpectData, |
|
80 // file content didn't fit into read buffer in one read. |
|
81 ERestoreExpectMoreData, |
|
82 // At the end of current file. Creates missing files to |
|
83 // restored directory. |
|
84 ERestoreComplete |
|
85 }; |
|
86 |
|
87 static CAknsSrvActiveBackupDataClient* NewL( RFs& aFsSession ); |
|
88 |
|
89 virtual ~CAknsSrvActiveBackupDataClient(); |
|
90 |
|
91 /** |
|
92 * This method is called when a backup or restore operation is |
|
93 * starting. Preparations can be done to prepare for BUR. |
|
94 * |
|
95 * @param aBackupStateValue the value of the current backup state |
|
96 */ |
|
97 void PrepareForBURL( TInt aBackupStateValue ); |
|
98 |
|
99 // from base class MActiveBackupDataClient |
|
100 |
|
101 /** |
|
102 * This method informs the active backup data client that all |
|
103 * snapshots have been supplied. If the client has not |
|
104 * received a snapshot then it should perform a base backup |
|
105 */ |
|
106 virtual void AllSnapshotsSuppliedL(); |
|
107 |
|
108 /** |
|
109 * This method receives all or part of a snapshot of data to allow |
|
110 * calculation of an incremental backup. The snapshot is one that |
|
111 * was previously supplied by the data owner. The snapshot data |
|
112 * should be read from the location supplied. The snapshot data may |
|
113 * be larger than the location supplied in which case the routine |
|
114 * will be called repeatedly until all data has been supplied. |
|
115 * |
|
116 * Snapshot data will also be supplied as part of a restore operation |
|
117 * |
|
118 * @param aDrive the drive being backed up |
|
119 * @param aBuffer a pointer to the base of the location from whence |
|
120 * data can be copied. |
|
121 * @param aLastSection ETrue if this is the last section of snapshot |
|
122 * data, else EFalse. |
|
123 */ |
|
124 virtual void ReceiveSnapshotDataL( |
|
125 TDriveNumber aDrive, TDesC8& aBuffer, TBool aLastSection); |
|
126 |
|
127 /** |
|
128 * This method returns the expected size of backup data that will be |
|
129 * supplied. If an incremental backup is underway then this method |
|
130 * then this method will not be called until after |
|
131 * ReceiveSnapshotDataL(). The size data will be used for the purpose |
|
132 * of tracking progess during a backup. If it is inaccurate then the |
|
133 * user may see irregular progress but the actual backup data will |
|
134 * not be affected so it is acceptable to return an estimated value. |
|
135 * |
|
136 * @param aDrive the drive being backed up. |
|
137 * @return the size of the data that will be returned |
|
138 */ |
|
139 virtual TUint GetExpectedDataSize(TDriveNumber aDrive); |
|
140 |
|
141 /** |
|
142 * This method returns a snapshot of data to accompany a backup. The |
|
143 * snapshot is expected to contain details on files / data being |
|
144 * backed up. The format of the snapshot is only meaningful to the |
|
145 * data owner. The snapshot will be supplied if the data owner is |
|
146 * asked for an incremental backup and for a restore operation. The |
|
147 * snapshot data should be copied to the location supplied. |
|
148 * |
|
149 * The snapshot data may be larger than the location supplied in |
|
150 * which case the routine will be called repeatedly until all data |
|
151 * has been retrieved. |
|
152 * |
|
153 * @param aDrive the drive being backed up |
|
154 * @param aBuffer a pointer to the base of the location where data |
|
155 * can be copied. |
|
156 * @param aFinished on return ETrue if all data has been returned |
|
157 * for this drive, else EFalse. |
|
158 */ |
|
159 virtual void GetSnapshotDataL( |
|
160 TDriveNumber aDrive, TPtr8& aBuffer, TBool& aFinished); |
|
161 |
|
162 /** |
|
163 * This method prepares the implementor to return backup data. It |
|
164 * will be followed by a sequence of calls to request the actual |
|
165 * data. |
|
166 * |
|
167 * @param aDrive the drive being backed up. |
|
168 */ |
|
169 virtual void InitialiseGetBackupDataL(TDriveNumber aDrive); |
|
170 |
|
171 /** |
|
172 * This method requests a section of backup data. |
|
173 * InitialiseGetBackupDataL() will have been called previously to |
|
174 * specify the drive concerned. The data returned may be base or |
|
175 * incremental depending on the type of backup and the capability of |
|
176 * the data owner. |
|
177 * |
|
178 * @param aBuffer a pointer to the base of the location where data |
|
179 * can be copied. |
|
180 * @param aFinished on return ETrue if all data has been returned |
|
181 * for this drive, else EFalse. |
|
182 */ |
|
183 virtual void GetBackupDataSectionL(TPtr8& aBuffer, TBool& aFinished); |
|
184 |
|
185 /** |
|
186 * This method prepares the implementor to receive base restore data |
|
187 * for a drive. It will be followed by a sequence of calls to supply |
|
188 * the actual data. |
|
189 * |
|
190 * @param aDrive the drive being restored. |
|
191 */ |
|
192 virtual void InitialiseRestoreBaseDataL(TDriveNumber aDrive); |
|
193 |
|
194 /** |
|
195 * This method receives a section of base restore data. |
|
196 * InitialiseRestoreBaseDataL() will have been called previously to |
|
197 * specify the drive concerned. |
|
198 * |
|
199 * @param aBuffer a pointer to the base of the location whence data |
|
200 * can be read. |
|
201 * @param aFinished ETrue if all data has been returned for this |
|
202 * drive, else EFalse. |
|
203 */ |
|
204 virtual void RestoreBaseDataSectionL(TDesC8& aBuffer, TBool aFinished); |
|
205 |
|
206 /** |
|
207 * This method prepares the implementor to receive incremental |
|
208 * restore data for a drive. It will be followed by a sequence |
|
209 * of calls to supply the actual data. If multiple increments |
|
210 * are supplied then this methid will be called before each increment |
|
211 * |
|
212 * @param aDrive the drive being restored. |
|
213 */ |
|
214 virtual void InitialiseRestoreIncrementDataL(TDriveNumber aDrive); |
|
215 |
|
216 /** |
|
217 * This method receives a section of increment restore data. |
|
218 * InitialiseRestoreIncrementDataL() will have been called |
|
219 * previously to specify the drive concerned. |
|
220 * |
|
221 * @param aBuffer a pointer to the base of the location whence data |
|
222 * can be read. |
|
223 * @param aFinished ETrue if all data has been returned for this |
|
224 * increment, else EFalse. |
|
225 */ |
|
226 virtual void RestoreIncrementDataSectionL(TDesC8& aBuffer, TBool aFinished); |
|
227 |
|
228 /** |
|
229 * This method is called when all data to be restored has been |
|
230 * supplied. |
|
231 * |
|
232 * @param aDrive the drive being restored. |
|
233 */ |
|
234 virtual void RestoreComplete(TDriveNumber aDrive); |
|
235 |
|
236 /** |
|
237 * This method is called if copying of data is terminated prematurely |
|
238 * to allow the implementor to tidy up. The same method applies to |
|
239 * all types of data and to backup and restore. |
|
240 */ |
|
241 virtual void TerminateMultiStageOperation(); |
|
242 |
|
243 /** |
|
244 * Gets a 32-bit checksum for its private data. |
|
245 * This routine is for test purposes. It must be implemented but an |
|
246 * invariant checksum value can be provided. Some tests may cause |
|
247 * checksum values to be compared. |
|
248 * |
|
249 * @param aDrive the drive containing data being checksummed |
|
250 * @return the 32-bit checksum |
|
251 */ |
|
252 virtual TUint GetDataChecksum(TDriveNumber aDrive); |
|
253 |
|
254 /** |
|
255 * This method prepares the implementor to return backup data on behalf of another data owner. |
|
256 * It will be followed by a sequence of calls to request the actual data. This method is only |
|
257 * for use by a proxy data manager that backs up data on behalf of other data owners. There |
|
258 * is no corresponding method for snapshots as it is assumed that a proxy data manager will |
|
259 * only handle base data. |
|
260 * |
|
261 * @param aSID the data owner whose data is to be backed up |
|
262 * @param aDrive the drive being backed up. |
|
263 */ |
|
264 virtual void InitialiseGetProxyBackupDataL(TSecureId aSID, TDriveNumber aDrive); |
|
265 |
|
266 /** |
|
267 This method prepares the implementor to receive base restore data for another data owner |
|
268 for a drive. It will be followed by a sequence of calls to supply the actual data. |
|
269 This method is only for use by a proxy data manager that restores up data on behalf of |
|
270 other data owners. There is no corresponding method for incremental data as it is assumed |
|
271 that a proxy data manager will only handle base data. |
|
272 |
|
273 @param aSID the data owner whose data is to be restored |
|
274 @param aDrive the drive being restored. |
|
275 */ |
|
276 virtual void InitialiseRestoreProxyBaseDataL(TSecureId aSID, TDriveNumber aDrive); |
|
277 |
|
278 private: |
|
279 |
|
280 /* Checks file integrity after restoration. */ |
|
281 TUint64 CheckSumL(const RFile& aOpenFile) const; |
|
282 |
|
283 /* Scans the .skn-files in the private directory. */ |
|
284 void ScanDirectoryForSkinFilesL( const TDesC& aRootDir ); |
|
285 |
|
286 /* Re-creates backed-up file to private directory. |
|
287 Also verifies that a matching .skn-file exists.*/ |
|
288 TInt RestoreFileInPrivateDirectoryL( const TDesC& aFileName ); |
|
289 |
|
290 CAknsSrvActiveBackupDataClient( RFs& aFsSession ); |
|
291 |
|
292 void ConstructL(); |
|
293 |
|
294 /* Initialise backup data. */ |
|
295 void DoInitialiseGetBackupDataL( TDriveNumber aDrive ); |
|
296 |
|
297 private: // data |
|
298 |
|
299 /** |
|
300 * Index of currently handled file in filename array. |
|
301 */ |
|
302 TInt iFileIndex; |
|
303 |
|
304 /** |
|
305 * Backup statemachine state. |
|
306 */ |
|
307 TAknsSrvBackupState iBackupState; |
|
308 |
|
309 /** |
|
310 * Restore statemachine state. |
|
311 */ |
|
312 TAknsSrvRestoreState iRestoreState; |
|
313 |
|
314 /** |
|
315 * Number of bytes sent from file header. |
|
316 */ |
|
317 TInt iHeaderSent; |
|
318 |
|
319 /** |
|
320 * Array of files to backup/restore. |
|
321 */ |
|
322 RArray<TParse> iFileArray; |
|
323 |
|
324 /** |
|
325 * "persistent" buffer. |
|
326 */ |
|
327 HBufC* iBuffer; |
|
328 |
|
329 /** |
|
330 * Currently handled file. |
|
331 */ |
|
332 RFile iFile; |
|
333 |
|
334 /** |
|
335 * Has any data been restored. |
|
336 */ |
|
337 TBool iDataRestored; |
|
338 |
|
339 /** |
|
340 * Checksum of backup file. Used by Restore. |
|
341 */ |
|
342 TUint32 iChecksum; |
|
343 |
|
344 /** |
|
345 * Size of file. Used by Restore. |
|
346 */ |
|
347 TUint32 iFileSize; |
|
348 |
|
349 /** |
|
350 * Lenght of filename. Used by Restore. |
|
351 */ |
|
352 TUint32 iFileNameSize; |
|
353 |
|
354 /* |
|
355 * File system session. |
|
356 */ |
|
357 RFs& iFsSession; |
|
358 |
|
359 /* |
|
360 * Number of files handled by Restore. |
|
361 * Note that actual number of restored files might be less than this, |
|
362 * since already existing files are not restored and orphaned files |
|
363 * (.skn-file missing) are not restored either. |
|
364 */ |
|
365 TInt iFilesRestored; |
|
366 |
|
367 /* |
|
368 * Number of files supposed to restore. |
|
369 */ |
|
370 TUint32 iNumberofFiles; |
|
371 |
|
372 /* |
|
373 * Indicates that there is an issue with current file. |
|
374 * All received Restore streams will be ignored, until a new file |
|
375 * is received. |
|
376 */ |
|
377 TBool iFileOpenError; |
|
378 }; |
|
379 |
|
380 #endif // C_AKNSSRVACTIVEBACKUPDATACLIENT_H |
|
381 |