|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 |
|
19 CABDataOwnerCallbackImplementation implementation |
|
20 */ |
|
21 |
|
22 #include "abdataowner.h" |
|
23 #include "abtesterlog.h" |
|
24 #include <connect/sbdefs.h> |
|
25 |
|
26 namespace conn |
|
27 { |
|
28 const TInt KSourceSize = 8000; |
|
29 |
|
30 CABDataOwnerCallbackImplementation* CABDataOwnerCallbackImplementation::NewL(TSecureId aID) |
|
31 { |
|
32 CABDataOwnerCallbackImplementation* self = new (ELeave) CABDataOwnerCallbackImplementation(aID); |
|
33 //CleanupStack::PushL(self); |
|
34 //self->ConstructL(); |
|
35 //CleanupStack::Pop(self); |
|
36 return self; |
|
37 } |
|
38 |
|
39 |
|
40 |
|
41 CABDataOwnerCallbackImplementation::CABDataOwnerCallbackImplementation(TSecureId aID) : iABClient(NULL), iVersion(1,0,0), iProxy(EFalse), iSourceSize(KSourceSize), iID(aID) |
|
42 { |
|
43 } |
|
44 |
|
45 void CABDataOwnerCallbackImplementation::SetABClient(CActiveBackupClient* aABClient) |
|
46 { |
|
47 iABClient = aABClient; |
|
48 } |
|
49 |
|
50 CABDataOwnerCallbackImplementation::~CABDataOwnerCallbackImplementation() |
|
51 { |
|
52 delete iABClient; |
|
53 delete iSnapshot; |
|
54 delete iData; |
|
55 } |
|
56 |
|
57 // from MActiveBackupDataClient - callbacks |
|
58 void CABDataOwnerCallbackImplementation::AllSnapshotsSuppliedL() |
|
59 { |
|
60 __LOG1("[0x%08x]: CABDataOwnerCallbackImplementation::AllSnapshotsSuppliedL()", iID.iId); |
|
61 } |
|
62 |
|
63 void CABDataOwnerCallbackImplementation::ReceiveSnapshotDataL(TDriveNumber aDrive, TDesC8& aBuffer, TBool /*aLastSection*/) |
|
64 { |
|
65 __LOG1("[0x%08x]: CABDataOwnerCallbackImplementation::ReceiveSnapshotDataL()", iID.iId); |
|
66 // Create or append a buffer containing the snapshot |
|
67 if (!iSnapshot) |
|
68 { |
|
69 iSnapshot = CABData::NewL(aDrive); |
|
70 } |
|
71 |
|
72 iSnapshot->AddDataL(aBuffer); |
|
73 } |
|
74 |
|
75 TUint CABDataOwnerCallbackImplementation::GetExpectedDataSize(TDriveNumber /*aDrive*/) |
|
76 { |
|
77 __LOG1("[0x%08x]: CABDataOwnerCallbackImplementation::GetExpectedDataSize()", iID.iId); |
|
78 |
|
79 return iSourceSize; |
|
80 } |
|
81 |
|
82 void CABDataOwnerCallbackImplementation::GetSnapshotDataL(TDriveNumber /*aDrive*/, TPtr8& aBuffer, TBool& aFinished) |
|
83 { |
|
84 __LOG1("[0x%08x]: CABDataOwnerCallbackImplementation::GetSnapshotDataL()", iID.iId); |
|
85 aBuffer.Append(KABTestSnapshot()); |
|
86 |
|
87 aFinished = ETrue; |
|
88 } |
|
89 |
|
90 void CABDataOwnerCallbackImplementation::InitialiseGetBackupDataL(TDriveNumber /*aDrive*/) |
|
91 { |
|
92 __LOG1("[0x%08x]: CABDataOwnerCallbackImplementation::InitialiseGetBackupData()", iID.iId); |
|
93 iOffset = 0; |
|
94 |
|
95 if (!iSnapshot) |
|
96 { |
|
97 iFillChar = 66; |
|
98 } |
|
99 else |
|
100 { |
|
101 iFillChar = 73; |
|
102 } |
|
103 } |
|
104 |
|
105 void CABDataOwnerCallbackImplementation::GetBackupDataSectionL(TPtr8& aBuffer, TBool& aFinished) |
|
106 { |
|
107 __LOG1("[0x%08x]: CABDataOwnerCallbackImplementation::GetBackupDataSectionL()", iID.iId); |
|
108 |
|
109 FillBuffer(aBuffer, aFinished); |
|
110 } |
|
111 |
|
112 void CABDataOwnerCallbackImplementation::InitialiseRestoreBaseDataL(TDriveNumber aDrive) |
|
113 { |
|
114 __LOG("CABDataOwnerCallbackImplementation::InitialiseRestoreBaseDataL()"); |
|
115 // WaitForMillisecondsL(KABInitTime); |
|
116 |
|
117 iData = CABData::NewL(aDrive); |
|
118 } |
|
119 |
|
120 void CABDataOwnerCallbackImplementation::RestoreBaseDataSectionL(TDesC8& aBuffer, TBool aFinished) |
|
121 { |
|
122 __LOG1("[0x%08x]: CABDataOwnerCallbackImplementation::RestoreBaseDataSectionL()", iID.iId); |
|
123 |
|
124 // append a buffer containing the base data |
|
125 iData->AddDataL(aBuffer); |
|
126 |
|
127 if (aFinished) |
|
128 { |
|
129 ValidateRestoredData(); |
|
130 |
|
131 delete iData; |
|
132 iData = NULL; |
|
133 } |
|
134 } |
|
135 |
|
136 void CABDataOwnerCallbackImplementation::InitialiseRestoreIncrementDataL(TDriveNumber aDrive) |
|
137 { |
|
138 __LOG1("[0x%08x]: CABDataOwnerCallbackImplementation::InitialiseRestoreIncrementDataL()", iID.iId); |
|
139 if (!iSnapshot) |
|
140 { |
|
141 User::Leave(KErrCorrupt); |
|
142 } |
|
143 |
|
144 if (!iData) |
|
145 { |
|
146 iData = CABData::NewL(aDrive); |
|
147 } |
|
148 } |
|
149 |
|
150 void CABDataOwnerCallbackImplementation::RestoreIncrementDataSectionL(TDesC8& aBuffer, TBool aFinished) |
|
151 { |
|
152 __LOG1("[0x%08x]: CABDataOwnerCallbackImplementation::RestoreIncrementDataSectionL()", iID.iId); |
|
153 |
|
154 iData->AddDataL(aBuffer); |
|
155 |
|
156 if (aFinished) |
|
157 { |
|
158 ValidateRestoredData(); |
|
159 |
|
160 delete iData; |
|
161 iData = NULL; |
|
162 } |
|
163 } |
|
164 |
|
165 void CABDataOwnerCallbackImplementation::RestoreComplete(TDriveNumber /*aDrive*/) |
|
166 { |
|
167 __LOG1("[0x%08x]: CABDataOwnerCallbackImplementation::RestoreComplete()", iID.iId); |
|
168 } |
|
169 |
|
170 void CABDataOwnerCallbackImplementation::TerminateMultiStageOperation() |
|
171 { |
|
172 __LOG1("[0x%08x]: CABDataOwnerCallbackImplementation::TerminateMultiStageOperation()", iID.iId); |
|
173 // We also don't do anything here until we start testing multipart? |
|
174 } |
|
175 |
|
176 TUint CABDataOwnerCallbackImplementation::GetDataChecksum(TDriveNumber /*aDrive*/) |
|
177 { |
|
178 __LOG1("[0x%08x]: CABDataOwnerCallbackImplementation::GetDataChecksum()", iID.iId); |
|
179 return 0; |
|
180 } |
|
181 |
|
182 void CABDataOwnerCallbackImplementation::WaitForMillisecondsL(TInt aMilliseconds) |
|
183 { |
|
184 RTimer timer; |
|
185 TRequestStatus status; |
|
186 |
|
187 User::LeaveIfError(timer.CreateLocal()); |
|
188 |
|
189 timer.After(status, aMilliseconds); |
|
190 User::WaitForRequest(status); |
|
191 } |
|
192 |
|
193 TBool CABDataOwnerCallbackImplementation::ValidateRestoredData() |
|
194 { |
|
195 TBool result = ETrue; |
|
196 |
|
197 __LOG3("[0x%08x]: Received data : %d %c's", iID.iId, (*iData)().Size(), (*iData)()[0]); |
|
198 |
|
199 return result; |
|
200 } |
|
201 |
|
202 TBool CABDataOwnerCallbackImplementation::ValidateRestoredSnapshot() |
|
203 { |
|
204 TBool result = ETrue; |
|
205 |
|
206 if ((*iSnapshot)() != KABTestSnapshot()) |
|
207 { |
|
208 __LOG1("[0x%08x]: Snapshot was NOT received correctly", iID.iId); |
|
209 result = EFalse; |
|
210 } |
|
211 else |
|
212 { |
|
213 __LOG1("[0x%08x]: Snapshot was received correctly", iID.iId); |
|
214 } |
|
215 |
|
216 return result; |
|
217 } |
|
218 |
|
219 void CABDataOwnerCallbackImplementation::InitialiseGetProxyBackupDataL(TSecureId aSID, TDriveNumber /*aDrive*/) |
|
220 { |
|
221 __LOG1("[0x%08x]: CABDataOwnerCallbackImplementation::InitialiseGetProxyBackupDataL()", iID.iId); |
|
222 __LOG2("[0x%08x]: Proxy data about to be requested for SID 0x%08x", iID.iId, aSID.iId); |
|
223 iProxy = ETrue; |
|
224 iOffset = 0; |
|
225 |
|
226 iFillChar = 80; // 'P' |
|
227 } |
|
228 |
|
229 void CABDataOwnerCallbackImplementation::InitialiseRestoreProxyBaseDataL(TSecureId aSID, TDriveNumber aDrive) |
|
230 { |
|
231 __LOG1("[0x%08x]: CABDataOwnerCallbackImplementation::InitialiseRestoreProxyBaseDataL()", iID.iId); |
|
232 __LOG2("[0x%08x]: Proxy data about to be restored for SID 0x%08x", iID.iId, aSID.iId); |
|
233 iProxy = ETrue; |
|
234 iData = CABData::NewL(aDrive); |
|
235 } |
|
236 |
|
237 void CABDataOwnerCallbackImplementation::FillBuffer(TDes8& aDes, TBool& aFinished) |
|
238 { |
|
239 TInt bytesToAdd; |
|
240 TChar fillChar(iFillChar); |
|
241 |
|
242 if ((iOffset + aDes.MaxSize()) < iSourceSize) |
|
243 { |
|
244 aFinished = EFalse; |
|
245 bytesToAdd = aDes.MaxSize(); |
|
246 } |
|
247 else |
|
248 { |
|
249 aFinished = ETrue; |
|
250 bytesToAdd = iSourceSize - iOffset; |
|
251 } |
|
252 |
|
253 aDes.Fill(fillChar, bytesToAdd); |
|
254 |
|
255 iOffset += bytesToAdd; |
|
256 } |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 CABDataOwner* CABDataOwner::NewL() |
|
264 { |
|
265 CABDataOwner* self = new (ELeave) CABDataOwner; |
|
266 CleanupStack::PushL(self); |
|
267 self->ConstructL(); |
|
268 CleanupStack::Pop(self); |
|
269 return self; |
|
270 } |
|
271 |
|
272 void CABDataOwner::StartL() |
|
273 { |
|
274 CActiveScheduler::Add(this); |
|
275 Subscribe(); |
|
276 CActiveScheduler::Start(); |
|
277 } |
|
278 |
|
279 void CABDataOwner::RunL() |
|
280 { |
|
281 if (iStatus == KErrNone) |
|
282 { |
|
283 __LOG1("[0x%08x]: ABTester RunL", iID.iId); |
|
284 Subscribe(); |
|
285 CheckStatusL(); |
|
286 } |
|
287 else |
|
288 { |
|
289 __LOG2("[0x%08x]: RunL leaves with code %d", iID.iId, iStatus.Int()); |
|
290 User::Leave(iStatus.Int()); |
|
291 } |
|
292 } |
|
293 |
|
294 void CABDataOwner::Subscribe() |
|
295 { |
|
296 __LOG1("[0x%08x]: Subscibe", iID.iId); |
|
297 iProperty.Subscribe(iStatus); // Wait until SBE tells us that we're in normal mode again |
|
298 SetActive(); |
|
299 } |
|
300 |
|
301 TInt CABDataOwner::RunError(TInt aError) |
|
302 { |
|
303 __LOG2("ABDataOwner [0x%08x] Panic'd with error code %d", iID.iId, aError); |
|
304 |
|
305 Subscribe(); |
|
306 |
|
307 return KErrNone; |
|
308 } |
|
309 |
|
310 void CABDataOwner::CheckStatusL() |
|
311 { |
|
312 TInt backupInfo =0; |
|
313 iProperty.Get(backupInfo); |
|
314 __LOG1("[0x%08x]: CABDataOwner::CheckStatus", iID.iId); |
|
315 if ((backupInfo & KBURPartTypeMask) == EBURNormal || (backupInfo & KBURPartTypeMask) == EBURUnset) |
|
316 { |
|
317 delete iABClient; |
|
318 iABClient = NULL; |
|
319 __LOG2("[0x%08x]: Backup Mode Normal or Unset, deleting client", iID.iId, backupInfo); |
|
320 } |
|
321 else |
|
322 { |
|
323 if (iABClient == NULL) |
|
324 { |
|
325 iABClient = CActiveBackupClient::NewL(iCallback); |
|
326 iCallback->SetABClient(iABClient); |
|
327 // do nothing |
|
328 __LOG1("[0x%08x]: In Backup/Restore: ConfirmReadyForBUR", iID.iId); |
|
329 } |
|
330 |
|
331 TDriveList driveList; |
|
332 TBURPartType partType; |
|
333 TBackupIncType incType; |
|
334 TInt err; |
|
335 TRAP(err, iABClient->BURModeInfoL(driveList, partType, incType)); |
|
336 if (err != KErrNone) |
|
337 { |
|
338 __LOG2("[0x%08x]: BURModeInfoL error %d", iID.iId, err); |
|
339 } |
|
340 |
|
341 TBool amIaffected = ETrue; |
|
342 |
|
343 if (partType == EBURRestorePartial || partType == EBURBackupPartial) |
|
344 { |
|
345 TRAP(err, amIaffected = iABClient->DoesPartialBURAffectMeL()); |
|
346 if (err == KErrNone) |
|
347 { |
|
348 if (amIaffected) |
|
349 { |
|
350 __LOG1("[0x%08x]: RunL: Partial Affects me!", iID.iId); |
|
351 } |
|
352 else |
|
353 { |
|
354 __LOG1("[0x%08x]: RunL: Partial Does NOT Affect me!", iID.iId); |
|
355 } |
|
356 } |
|
357 else |
|
358 { |
|
359 __LOG2("[0x%08x]: Error calling DoesPartialBURAffectMeL()", iID.iId, err); |
|
360 |
|
361 User::After(5000000); |
|
362 TRAP(err, amIaffected = iABClient->DoesPartialBURAffectMeL()); |
|
363 __LOG2("[0x%08x]: Called DoesPartialBURAffectMeL() again after 5sec: ", iID.iId, err); |
|
364 } |
|
365 } |
|
366 |
|
367 if (amIaffected) |
|
368 { |
|
369 // Confirm that this data owner is ready for backup/restore operations |
|
370 iABClient->ConfirmReadyForBURL(KErrNone); |
|
371 } |
|
372 } |
|
373 } |
|
374 |
|
375 void CABDataOwner::DoCancel() |
|
376 { |
|
377 } |
|
378 |
|
379 CABDataOwner::~CABDataOwner() |
|
380 { |
|
381 if (IsActive()) |
|
382 { |
|
383 Cancel(); |
|
384 } |
|
385 delete iCallback; |
|
386 delete iABClient; |
|
387 } |
|
388 |
|
389 void CABDataOwner::ConstructL() |
|
390 { |
|
391 RProcess process; |
|
392 iID = process.SecureId(); |
|
393 process.Close(); |
|
394 iABClient = NULL; |
|
395 |
|
396 iCallback = CABDataOwnerCallbackImplementation::NewL(iID); |
|
397 |
|
398 iProperty.Attach(TUid::Uid(KUidSystemCategoryValue), KUidBackupRestoreKey); |
|
399 TInt backupInfo = 0; |
|
400 iProperty.Get(backupInfo); |
|
401 if ((backupInfo & KBURPartTypeMask) != EBURNormal || (backupInfo & KBURPartTypeMask) != EBURUnset) |
|
402 { |
|
403 iABClient = CActiveBackupClient::NewL(iCallback); |
|
404 iCallback->SetABClient(iABClient); |
|
405 |
|
406 // Confirm that this data owner is ready for backup/restore operations |
|
407 iABClient->ConfirmReadyForBURL(KErrNone); |
|
408 // do nothing |
|
409 __LOG1("[0x%08x]: In Backup/Restore: ConfirmReadyForBUR", iID.iId); |
|
410 } |
|
411 __LOG1("[0x%08x]: ABTester ConstructL", iID.iId); |
|
412 } |
|
413 } |
|
414 |
|
415 void RunActiveBackupClientL() |
|
416 { |
|
417 CActiveScheduler* pScheduler = new (ELeave) CActiveScheduler(); |
|
418 CleanupStack::PushL(pScheduler); |
|
419 CActiveScheduler::Install(pScheduler); |
|
420 conn::CABDataOwner* pDO = conn::CABDataOwner::NewL(); |
|
421 CleanupStack::PushL(pDO); |
|
422 |
|
423 pDO->StartL(); |
|
424 |
|
425 CleanupStack::PopAndDestroy(pDO); |
|
426 CleanupStack::PopAndDestroy(pScheduler); |
|
427 } |
|
428 |
|
429 TInt E32Main() |
|
430 { |
|
431 __UHEAP_MARK; |
|
432 CTrapCleanup* pCleanup = CTrapCleanup::New(); |
|
433 TInt nRet = KErrNone; |
|
434 |
|
435 if(pCleanup != NULL) |
|
436 { |
|
437 TRAP(nRet, RunActiveBackupClientL()); |
|
438 delete pCleanup; |
|
439 } |
|
440 |
|
441 __UHEAP_MARKEND; |
|
442 return nRet; |
|
443 } |