1 /* |
|
2 * Copyright (c) 2005 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: CMMCScBkupStateRequestListOfPublicFiles implementation |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "CMMCScBkupStateRequestListOfPublicFiles.h" |
|
20 |
|
21 // System includes |
|
22 #include <e32std.h> |
|
23 |
|
24 // User includes |
|
25 #include "MMCScBkupLogger.h" |
|
26 #include "MMCScBkupSBEUtils.h" |
|
27 #include "CMMCScBkupDataOwnerInfo.h" |
|
28 #include "RMMCScBkupProgressSizer.h" |
|
29 #include "CMMCScBkupDataOwnerInfo.h" |
|
30 #include "MMMCScBkupProgressObserver.h" |
|
31 #include "CMMCScBkupFileListCollection.h" |
|
32 #include "CMMCScBkupDataOwnerCollection.h" |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 // ========================= MEMBER FUNCTIONS ================================ |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // CMMCScBkupStateRequestListOfPublicFiles::CMMCScBkupStateRequestListOfPublicFiles() |
|
41 // |
|
42 // C++ constructor. |
|
43 // --------------------------------------------------------------------------- |
|
44 CMMCScBkupStateRequestListOfPublicFiles::CMMCScBkupStateRequestListOfPublicFiles( MMMCScBkupDriver& aDriver ) |
|
45 : CMMCScBkupState( aDriver ) |
|
46 { |
|
47 __LOG1("CMMCScBkupStateRequestListOfPublicFiles::CMMCScBkupStateRequestListOfPublicFiles() - 0x%08x", StateId().iUid ); |
|
48 } |
|
49 |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CMMCScBkupStateRequestListOfPublicFiles::~CMMCScBkupStateRequestListOfPublicFiles() |
|
53 // |
|
54 // Destructor. |
|
55 // --------------------------------------------------------------------------- |
|
56 CMMCScBkupStateRequestListOfPublicFiles::~CMMCScBkupStateRequestListOfPublicFiles() |
|
57 { |
|
58 Cancel(); |
|
59 // |
|
60 delete iRequestObject; |
|
61 } |
|
62 |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // CMMCScBkupStateRequestListOfPublicFiles::ConstructL() |
|
66 // |
|
67 // |
|
68 // --------------------------------------------------------------------------- |
|
69 void CMMCScBkupStateRequestListOfPublicFiles::ConstructL() |
|
70 { |
|
71 iRequestObject = CMMCScBkupStateRequestSpecificPublicFileInfo::NewL(Driver()); |
|
72 } |
|
73 |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // CMMCScBkupStateRequestListOfPublicFiles::NewL() |
|
77 // |
|
78 // |
|
79 // --------------------------------------------------------------------------- |
|
80 CMMCScBkupStateRequestListOfPublicFiles* CMMCScBkupStateRequestListOfPublicFiles::NewL( MMMCScBkupDriver& aDriver ) |
|
81 { |
|
82 CMMCScBkupStateRequestListOfPublicFiles* self = new(ELeave) CMMCScBkupStateRequestListOfPublicFiles( aDriver ); |
|
83 CleanupStack::PushL(self); |
|
84 self->ConstructL(); |
|
85 CleanupStack::Pop(self); |
|
86 return self; |
|
87 } |
|
88 |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // CMMCScBkupStateRequestListOfPublicFiles::StateId() |
|
92 // |
|
93 // |
|
94 // --------------------------------------------------------------------------- |
|
95 TMMCScBkupStateId CMMCScBkupStateRequestListOfPublicFiles::StateId() const |
|
96 { |
|
97 return KMMCScBkupStateIdRequestListOfPublicFiles; |
|
98 } |
|
99 |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // CMMCScBkupStateRequestListOfPublicFiles::NextStateId() |
|
103 // |
|
104 // |
|
105 // --------------------------------------------------------------------------- |
|
106 TMMCScBkupStateId CMMCScBkupStateRequestListOfPublicFiles::NextStateId() const |
|
107 { |
|
108 return KMMCScBkupStateIdValidateDiskSpace; |
|
109 } |
|
110 |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // CMMCScBkupStateRequestListOfPublicFiles::PerformStateInitL() |
|
114 // |
|
115 // |
|
116 // --------------------------------------------------------------------------- |
|
117 void CMMCScBkupStateRequestListOfPublicFiles::PerformStateInitL() |
|
118 { |
|
119 // Set to -1 so that the first time RunL is called, we start with |
|
120 // the data owner at index 0. |
|
121 iCurrentDataOwnerIndex = -1; |
|
122 CompleteSelf(KErrNone); |
|
123 } |
|
124 |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // CMMCScBkupStateRequestListOfPublicFiles::PerformAsynchronousStateStepL() |
|
128 // |
|
129 // |
|
130 // --------------------------------------------------------------------------- |
|
131 void CMMCScBkupStateRequestListOfPublicFiles::PerformAsynchronousStateStepL() |
|
132 { |
|
133 CMMCScBkupDataOwnerCollection& dataOwners = Driver().DrvDataOwners(); |
|
134 if (++iCurrentDataOwnerIndex < dataOwners.Count()) |
|
135 { |
|
136 CMMCScBkupDataOwnerInfo& owner = dataOwners.Owner(iCurrentDataOwnerIndex); |
|
137 |
|
138 const TBool hasPublicFiles = (owner.Owner().PassiveSettings() & EHasPublicFiles); |
|
139 if (hasPublicFiles) |
|
140 { |
|
141 // Request all the public files (on all supported drives) for this |
|
142 // particular data owner |
|
143 __ASSERT_ALWAYS(iRequestObject->IsActive() == EFalse, User::Invariant()); |
|
144 // |
|
145 iRequestObject->RequestL(owner, iStatus); |
|
146 SetActive(); |
|
147 } |
|
148 else |
|
149 { |
|
150 // Try next data owner |
|
151 CompleteSelf(); |
|
152 } |
|
153 } |
|
154 } |
|
155 |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // CMMCScBkupStateRequestListOfPublicFiles::PerformAsynchronousErrorCleanup() |
|
159 // |
|
160 // |
|
161 // --------------------------------------------------------------------------- |
|
162 TBool CMMCScBkupStateRequestListOfPublicFiles::PerformAsynchronousErrorCleanup(TInt aError) |
|
163 { |
|
164 (void) aError; |
|
165 __LOG1("CMMCScBkupStateRequestListOfPublicFiles::PerformAsynchronousErrorCleanup() - **** - error: %d", aError ); |
|
166 |
|
167 // Cancel requester. Its probably already inactive, but just in case... |
|
168 PerformAsynchronousCancellation(); |
|
169 |
|
170 // Reset state and move to next item. Treat the current (badly behaving) item |
|
171 // as completed/processed. |
|
172 CMMCScBkupDataOwnerCollection& dataOwners = Driver().DrvDataOwners(); |
|
173 if ( iCurrentDataOwnerIndex < dataOwners.Count() ) |
|
174 { |
|
175 CMMCScBkupDataOwnerInfo& owner = dataOwners.Owner( iCurrentDataOwnerIndex ); |
|
176 (void) owner; |
|
177 __LOGFILE2("CMMCScBkupStateRequestListOfPublicFiles::PerformAsynchronousErrorCleanup() - **** - error: %d, SID: 0x%08x - PUBLIC data skipped for DO", aError, owner.SecureId().iId ); |
|
178 |
|
179 // Ensures that asynchronous state step is called again.. |
|
180 CompleteSelf(); |
|
181 } |
|
182 |
|
183 return ETrue; |
|
184 } |
|
185 |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // CMMCScBkupStateRequestListOfPublicFiles::PerformAsynchronousCancellation() |
|
189 // |
|
190 // |
|
191 // --------------------------------------------------------------------------- |
|
192 void CMMCScBkupStateRequestListOfPublicFiles::PerformAsynchronousCancellation() |
|
193 { |
|
194 if ( iRequestObject ) |
|
195 { |
|
196 iRequestObject->Cancel(); |
|
197 } |
|
198 } |
|
199 |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // CMMCScBkupStateRequestListOfPublicFiles::PerformLastRightsL() |
|
203 // |
|
204 // |
|
205 // --------------------------------------------------------------------------- |
|
206 void CMMCScBkupStateRequestListOfPublicFiles::PerformLastRightsL() |
|
207 { |
|
208 // Now we can calculate the progress |
|
209 TInt64 totalProgressAmount = 0; |
|
210 |
|
211 // Calculate the total progress required for the entire backup operation |
|
212 CMMCScBkupDataOwnerCollection& dataOwners = Driver().DrvDataOwners(); |
|
213 const TInt count = dataOwners.Count(); |
|
214 // |
|
215 RMMCScBkupProgressSizer sizer( Driver().DrvParamsBase().DriveAndOperations() ); |
|
216 for(TInt i=0; i<count; i++) |
|
217 { |
|
218 CMMCScBkupDataOwnerInfo& owner = dataOwners.Owner( i ); |
|
219 // |
|
220 totalProgressAmount += sizer.BackupTotalProgressValueL( owner ); |
|
221 } |
|
222 |
|
223 // Check whether all categories have been processed and either store current |
|
224 // progress information in driver or inform progress handler about cumulative progress. |
|
225 // If size is getting beyond file system limitation (2GB), leave with KErrxxx. |
|
226 if(Driver().DrvLastCategory()) |
|
227 { |
|
228 __LOG2("CMMCScBkupStateRequestListOfPublicFiles::PerformLastRightsL() - report progress understood (%Ld + %Ld)", |
|
229 totalProgressAmount, Driver().DrvTotalProgress()); |
|
230 |
|
231 Driver().DrvStoreTotalProgress( totalProgressAmount ); |
|
232 |
|
233 if( Driver().DrvTotalProgress() > KMaxTInt ) |
|
234 { |
|
235 __LOG1("CMMCScBkupStateRequestListOfPublicFiles::PerformLastRightsL() - leaving with KErrNotSupported due amount of data (%Ld)", |
|
236 Driver().DrvTotalProgress()); |
|
237 Driver().DrvProgressHandler().MMCScBkupStartBackuping( EFalse ); |
|
238 User::Leave( KErrNotSupported ); |
|
239 } |
|
240 else |
|
241 { |
|
242 Driver().DrvProgressHandler().MMCScBkupHandleProgressDomainUnderstood( Driver().DrvTotalProgress() ); |
|
243 } |
|
244 } |
|
245 else |
|
246 { |
|
247 __LOG2("CMMCScBkupStateRequestListOfPublicFiles::PerformLastRightsL() - adding progress amount %Ld to existing %Ld)", |
|
248 totalProgressAmount, Driver().DrvTotalProgress()); |
|
249 |
|
250 if( (totalProgressAmount + Driver().DrvTotalProgress()) > KMaxTInt ) |
|
251 { |
|
252 __LOG1("CMMCScBkupStateRequestListOfPublicFiles::PerformLastRightsL() - leaving due amount of data (%Ld)", |
|
253 totalProgressAmount + Driver().DrvTotalProgress()); |
|
254 User::Leave(KErrNotSupported); |
|
255 } |
|
256 else |
|
257 { |
|
258 Driver().DrvStoreTotalProgress( totalProgressAmount ); |
|
259 } |
|
260 } |
|
261 } |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 // --------------------------------------------------------------------------- |
|
303 // CMMCScBkupStateRequestSpecificPublicFileInfo::CMMCScBkupStateRequestSpecificPublicFileInfo() |
|
304 // |
|
305 // |
|
306 // --------------------------------------------------------------------------- |
|
307 CMMCScBkupStateRequestSpecificPublicFileInfo::CMMCScBkupStateRequestSpecificPublicFileInfo( MMMCScBkupDriver& aDriver ) |
|
308 : CMMCScBkupDriveSpecificRequest( aDriver.DrvParamsBase().DriveAndOperations(), EMMCScBkupOwnerDataTypePublicData ), iDriver(aDriver) |
|
309 { |
|
310 } |
|
311 |
|
312 |
|
313 // --------------------------------------------------------------------------- |
|
314 // CMMCScBkupStateRequestSpecificPublicFileInfo::NewL() |
|
315 // |
|
316 // |
|
317 // --------------------------------------------------------------------------- |
|
318 CMMCScBkupStateRequestSpecificPublicFileInfo* CMMCScBkupStateRequestSpecificPublicFileInfo::NewL( MMMCScBkupDriver& aDriver ) |
|
319 { |
|
320 CMMCScBkupStateRequestSpecificPublicFileInfo* self = new (ELeave) CMMCScBkupStateRequestSpecificPublicFileInfo(aDriver); |
|
321 CleanupStack::PushL(self); |
|
322 self->ConstructL(); |
|
323 CleanupStack::Pop(self); |
|
324 return self; |
|
325 } |
|
326 |
|
327 |
|
328 // --------------------------------------------------------------------------- |
|
329 // CMMCScBkupStateRequestSpecificPublicFileInfo::RequestL() |
|
330 // |
|
331 // |
|
332 // --------------------------------------------------------------------------- |
|
333 void CMMCScBkupStateRequestSpecificPublicFileInfo::RequestL( CMMCScBkupDataOwnerInfo& aOwner, TRequestStatus& aObserver ) |
|
334 { |
|
335 iOwner = &aOwner; |
|
336 CMMCScBkupDriveSpecificRequest::RequestL( aObserver ); |
|
337 |
|
338 // Start the asynchronous request. |
|
339 CompleteSelf(KErrNone); |
|
340 } |
|
341 |
|
342 |
|
343 // --------------------------------------------------------------------------- |
|
344 // CMMCScBkupStateRequestSpecificPublicFileInfo::RunL() |
|
345 // |
|
346 // |
|
347 // --------------------------------------------------------------------------- |
|
348 void CMMCScBkupStateRequestSpecificPublicFileInfo::RunL() |
|
349 { |
|
350 __LOG1("CMMCScBkupStateRequestSpecificPublicFileInfo::RunL() - START - iStatus: %d", iStatus.Int()); |
|
351 User::LeaveIfError(iStatus.Int()); |
|
352 // |
|
353 CDataOwnerInfo& owner = iOwner->Owner(); |
|
354 const TDriveList& ownerDrives = owner.DriveList(); |
|
355 TDriveNumber drive = EDriveA; |
|
356 const TBool driveAvailable = NextValidDrive(drive, ownerDrives); |
|
357 const TSecureId secureId = iOwner->SecureId(); |
|
358 |
|
359 __LOG3("CMMCScBkupStateRequestSpecificPublicFileInfo::RunL() - secureId: 0x%08x, driveAvailable: %d, drive: %c", secureId.iId, driveAvailable, drive + 'A'); |
|
360 |
|
361 if (driveAvailable) |
|
362 { |
|
363 // This drive needs to be scanned... |
|
364 TInt err( KErrNone ); |
|
365 RFileArray files; |
|
366 CleanupClosePushL(files); |
|
367 |
|
368 // Get a copy of the generic data type for which we are |
|
369 // requesting file listings... |
|
370 CSBGenericDataType* genericDataType = CSBSecureId::NewL( secureId ); |
|
371 CleanupStack::PushL( genericDataType ); |
|
372 TRAP( err, Driver().DrvSecureBackupClient().PublicFileListL( drive, *genericDataType, files ) ); |
|
373 if( err != KErrNone && err != KErrNotFound ) |
|
374 { |
|
375 User::Leave( err ); |
|
376 } |
|
377 CleanupStack::PopAndDestroy( genericDataType ); |
|
378 // Additionally we need to request list of public files registered for packages. |
|
379 if( MMCScBkupSBEUtils::HasSystemDataL( owner ) ) |
|
380 { |
|
381 RFileArray pkgFiles; |
|
382 CleanupClosePushL( pkgFiles ); |
|
383 __LOG2("CMMCScBkupStateRequestSpecificPublicFileInfo::RunL() - have %d files before package listing for DO, err %d", files.Count(), err); |
|
384 TRAP( err, Driver().DrvSecureBackupClient().PublicFileListL( drive, owner.Identifier(), pkgFiles ) ); |
|
385 __LOG2("CMMCScBkupStateRequestSpecificPublicFileInfo::RunL() - have %d package files for DO, err %d", files.Count(), err); |
|
386 const TInt pkgCount = pkgFiles.Count(); |
|
387 for(TInt i = 0; i < pkgCount; i++) |
|
388 { |
|
389 files.AppendL( pkgFiles[i] ); |
|
390 } |
|
391 CleanupStack::PopAndDestroy( &pkgFiles ); |
|
392 } |
|
393 |
|
394 // Add to the file list |
|
395 __LOG1("CMMCScBkupStateRequestSpecificPublicFileInfo::RunL() - have %d files for DO", files.Count()); |
|
396 if (files.Count()) |
|
397 { |
|
398 |
|
399 // We want to be told by the public file collection exactly which files |
|
400 // it added... We need to do this in order to report progress as accurately |
|
401 // as possible during the backup operation. |
|
402 RArray< const CMMCScBkupFileInfo* > addedItems; |
|
403 CleanupClosePushL(addedItems); |
|
404 |
|
405 // Add them to the public data file collection |
|
406 Driver().DrvFileList().AppendL( files, addedItems, secureId ); |
|
407 |
|
408 // For each identified file, update the data owner with the size of public data |
|
409 const TInt count = addedItems.Count(); |
|
410 for(TInt i=0; i<count; i++) |
|
411 { |
|
412 const CMMCScBkupFileInfo& file = *addedItems[i]; |
|
413 const TInt size = file.Size(); |
|
414 // |
|
415 __LOG3("CMMCScBkupStateRequestSpecificPublicFileInfo::RunL() - file[%04d] = %S, size: %d", i, &file.FileName(), size); |
|
416 iOwner->AddToOperationalSizeL( EMMCScBkupOwnerDataTypePublicData, drive, size ); |
|
417 } |
|
418 // |
|
419 CleanupStack::PopAndDestroy( &addedItems ); |
|
420 } |
|
421 // |
|
422 CleanupStack::PopAndDestroy( &files ); |
|
423 |
|
424 // Complete ourself to try the next drive |
|
425 CompleteSelf( KErrNone ); |
|
426 } |
|
427 else |
|
428 { |
|
429 CompleteObserverRequest( KErrNone ); |
|
430 } |
|
431 |
|
432 __LOG("CMMCScBkupStateRequestSpecificPublicFileInfo::RunL() - END"); |
|
433 } |
|
434 |
|
435 |
|
436 // --------------------------------------------------------------------------- |
|
437 // CMMCScBkupStateRequestSpecificPublicFileInfo::DoCancel() |
|
438 // |
|
439 // |
|
440 // --------------------------------------------------------------------------- |
|
441 void CMMCScBkupStateRequestSpecificPublicFileInfo::DoCancel() |
|
442 { |
|
443 } |
|
444 |
|
445 |
|
446 |
|
447 |
|