|
1 // Copyright (c) 2004-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 @released |
|
19 */ |
|
20 |
|
21 |
|
22 #include "t_asyncbackuptransferhandler.h" |
|
23 |
|
24 using namespace conn; |
|
25 |
|
26 const TInt KZero = 0; |
|
27 |
|
28 namespace bur_ts |
|
29 { |
|
30 CAsyncBackupTransferHandler* CAsyncBackupTransferHandler::NewL(CBURTestStepBase* aTestStep) |
|
31 /** |
|
32 Symbian OS Constructor |
|
33 |
|
34 @internalComponent |
|
35 @released |
|
36 |
|
37 @param aTestStep - A pointer to a CBURTestStepBackup or CBURTestStepRestore that owns this object |
|
38 |
|
39 @return Pointer to a newly created CAsyncBackupTransferHandler object. |
|
40 */ |
|
41 { |
|
42 CAsyncBackupTransferHandler* self = new (ELeave) CAsyncBackupTransferHandler(aTestStep); |
|
43 CleanupStack::PushL(self); |
|
44 self->ConstructL(); |
|
45 CleanupStack::Pop(); |
|
46 return self; |
|
47 } |
|
48 |
|
49 CAsyncBackupTransferHandler::CAsyncBackupTransferHandler(CBURTestStepBase* aTestStep) |
|
50 /** |
|
51 C++ Constructor |
|
52 |
|
53 @internalComponent |
|
54 @released |
|
55 |
|
56 @param aTestStep - A pointer to a CBURTestStepBackup or CBURTestStepRestore that owns this object |
|
57 */ |
|
58 : CActive(EPriorityStandard), |
|
59 iActiveScheduler(NULL), |
|
60 iCurrentIndex(KZero), |
|
61 iSuccess(ETrue), |
|
62 iTestStep(aTestStep), |
|
63 iID(NULL) |
|
64 {} |
|
65 |
|
66 void CAsyncBackupTransferHandler::ConstructL() |
|
67 /** |
|
68 Symbian OS 2nd phase Constructor |
|
69 |
|
70 @internalComponent |
|
71 @released |
|
72 */ |
|
73 { |
|
74 iID = HBufC::NewL(KZero); |
|
75 iActiveScheduler = new (ELeave) CActiveSchedulerWait; |
|
76 CActiveScheduler::Add(this); |
|
77 } |
|
78 |
|
79 CAsyncBackupTransferHandler::~CAsyncBackupTransferHandler() |
|
80 /** |
|
81 C++ Destructor |
|
82 |
|
83 @internalComponent |
|
84 @released |
|
85 */ |
|
86 { |
|
87 // Cancel the active object |
|
88 if (IsActive()) |
|
89 { |
|
90 Cancel(); |
|
91 } |
|
92 delete iID; |
|
93 delete iActiveScheduler; |
|
94 } |
|
95 |
|
96 void CAsyncBackupTransferHandler::StartL() |
|
97 /** |
|
98 @internalComponent |
|
99 @released |
|
100 */ |
|
101 { |
|
102 iCurrentIndex = KZero; |
|
103 iSuccess = ETrue; |
|
104 ContinueL(); |
|
105 iActiveScheduler->Start(); |
|
106 } |
|
107 |
|
108 void CAsyncBackupTransferHandler::ContinueL() |
|
109 /** |
|
110 @internalComponent |
|
111 @released |
|
112 */ |
|
113 { |
|
114 // If all transfer types have been dealt with, there are no more requests |
|
115 // to be made and hence we can stop the active scheduler: |
|
116 if (iCurrentIndex == iTestStep->TransferTypes().Count()) |
|
117 { |
|
118 iActiveScheduler->AsyncStop(); |
|
119 } |
|
120 else if (!IsActive()) |
|
121 { |
|
122 CurrentIDL(); |
|
123 TUint expectedSize = 0; |
|
124 |
|
125 _LIT(KCurrentSid, "Current ID: "); |
|
126 iTestStep->LogWithText(LOG_LEVEL3, KCurrentSid, *iID); |
|
127 |
|
128 TRAPD(err, expectedSize = iTestStep->BackupClient()->ExpectedDataSizeL(*iTestStep->TransferTypes()[iCurrentIndex])); |
|
129 if(err != KErrNone) |
|
130 { |
|
131 _LIT(KLog1e, "Request expected data size error: "); |
|
132 iTestStep->LogWithNum(LOG_LEVEL5, KLog1e, err); |
|
133 } |
|
134 |
|
135 _LIT(KExpSize, "Expected Data Size: "); |
|
136 iTestStep->LogWithNum(LOG_LEVEL4, KExpSize, expectedSize); |
|
137 |
|
138 MakeRequestDataCallL(); |
|
139 } |
|
140 else |
|
141 { |
|
142 // Being called during an active state |
|
143 User::Leave(KErrInUse); |
|
144 } |
|
145 } |
|
146 |
|
147 void CAsyncBackupTransferHandler::MakeRequestDataCallL() |
|
148 { |
|
149 TRAPD(err1,iTestStep->BackupClient()->RequestDataL(*iTestStep->TransferTypes()[iCurrentIndex], iStatus)); |
|
150 if (err1 != KErrNone) |
|
151 { |
|
152 _LIT(KLog1, "Failed to request data for ID: "); |
|
153 iTestStep->LogWithText(LOG_LEVEL5, KLog1, *iID); |
|
154 _LIT(KLog2, "Error code: "); |
|
155 iTestStep->LogWithNum(LOG_LEVEL5, KLog2, err1); |
|
156 } |
|
157 iStatus = KRequestPending; |
|
158 SetActive(); |
|
159 } |
|
160 |
|
161 void CAsyncBackupTransferHandler::RunL() |
|
162 /** |
|
163 Upon completion of the request, gets backup data from the backup server, and |
|
164 saves it to the backup archive. |
|
165 |
|
166 @internalComponent |
|
167 @released |
|
168 */ |
|
169 { |
|
170 if (iStatus == KErrNone) |
|
171 { |
|
172 TBool isFinished; |
|
173 |
|
174 // Initialise following to NULL, or else SBEClient panics in debug builds: |
|
175 CSBGenericTransferType* receivedType = NULL; |
|
176 TPtrC8 pData = iTestStep->BackupClient()->TransferDataInfoL(receivedType, isFinished); |
|
177 CleanupStack::PushL(receivedType); |
|
178 |
|
179 // no need to push it onto CleanupStack as there is no ownership transfer |
|
180 CSBGenericTransferType* currentTransfer = iTestStep->TransferTypes()[iCurrentIndex]; |
|
181 |
|
182 if (KErrNone != (currentTransfer->Externalise()).CompareF(receivedType->Externalise())) |
|
183 { |
|
184 _LIT(KLogWrong, "The type of data requested doesn't much the received, please contact Connectivity team !"); |
|
185 iTestStep->LogWithText(LOG_LEVEL3, KLogWrong, *iID); |
|
186 } |
|
187 else if (pData.Size() > 0) |
|
188 { |
|
189 TRAPD(err, iTestStep->StorageManager()->ArchiveDataL(currentTransfer, pData, isFinished)); |
|
190 if (err != KErrNone) |
|
191 { |
|
192 iTestStep->StorageManager()->Reset(); |
|
193 _LIT(KLog1, "Error Saving data to archive for ID: "); |
|
194 iTestStep->LogWithText(LOG_LEVEL3, KLog1, *iID); |
|
195 _LIT(KLog2, "Error code: "); |
|
196 iTestStep->LogWithNum(LOG_LEVEL3, KLog2, err); |
|
197 } |
|
198 else |
|
199 { |
|
200 _LIT(KLog3, "Number of bytes saved: "); |
|
201 iTestStep->LogWithNum(LOG_LEVEL3, KLog3, pData.Size()); |
|
202 } |
|
203 } |
|
204 |
|
205 CleanupStack::PopAndDestroy(receivedType); |
|
206 if (isFinished) // if not then there are more data to come, so run again on the same type |
|
207 { |
|
208 ++iCurrentIndex; |
|
209 // Restart the active object to request more data: |
|
210 ContinueL(); |
|
211 } |
|
212 else // continue to request data |
|
213 { |
|
214 MakeRequestDataCallL(); |
|
215 } |
|
216 |
|
217 } |
|
218 else |
|
219 { |
|
220 User::Leave(iStatus.Int()); |
|
221 } |
|
222 } |
|
223 |
|
224 |
|
225 void CAsyncBackupTransferHandler::DoCancel() |
|
226 /** |
|
227 @internalComponent |
|
228 @released |
|
229 */ |
|
230 {} |
|
231 |
|
232 TInt CAsyncBackupTransferHandler::RunError(TInt aError) |
|
233 /** |
|
234 This overridden method prints an error message to the TestExecute log |
|
235 and then returns with the error passed to it by the Active Scheduler. |
|
236 |
|
237 @internalComponent |
|
238 @released |
|
239 |
|
240 @param aError - Error code passed down by the Active Scheduler. |
|
241 @return The error code returned by the Active Scheduler. |
|
242 */ |
|
243 { |
|
244 ++iCurrentIndex; |
|
245 _LIT(KErrorText, "Error while async call : "); |
|
246 iTestStep->LogWithNum(LOG_LEVEL4, KErrorText, aError); |
|
247 iSuccess = EFalse; |
|
248 if ((iTestStep->ExpectStatus() <= 0 && aError == iTestStep->ExpectStatus())|| |
|
249 (iTestStep->ExpectStatus2() <= 0 && aError == iTestStep->ExpectStatus2())) |
|
250 { |
|
251 _LIT(KSetSuccess, "Match expected,set result to success on error:"); |
|
252 iTestStep->LogWithNum(LOG_LEVEL4, KSetSuccess, aError); |
|
253 iSuccess = ETrue; |
|
254 } else { |
|
255 _LIT(KSetFail, "Unexpected error:"); |
|
256 iTestStep->LogWithNum(LOG_LEVEL4, KSetFail, aError); |
|
257 } |
|
258 TRAPD(err, ContinueL()); |
|
259 if (err != KErrNone) |
|
260 { |
|
261 _LIT(KErrorText1, "Error trying to issue another request : "); |
|
262 iTestStep->LogWithNum(LOG_LEVEL4, KErrorText1, err); |
|
263 } |
|
264 return KErrNone; |
|
265 } |
|
266 |
|
267 void CAsyncBackupTransferHandler::CurrentIDL() |
|
268 /** |
|
269 @internalComponent |
|
270 @released |
|
271 |
|
272 @return SecureId of the data owner currently being processed. |
|
273 */ |
|
274 { |
|
275 delete iID; |
|
276 iID = NULL; |
|
277 CSBGenericTransferType* transfer = iTestStep->TransferTypes()[iCurrentIndex]; |
|
278 TSBDerivedType type = transfer->DerivedTypeL(); |
|
279 TInt numberOfDigits = EHex; |
|
280 |
|
281 if (type == ESIDTransferDerivedType) |
|
282 { |
|
283 CSBSIDTransferType* sidType = CSBSIDTransferType::NewL(transfer); |
|
284 CleanupStack::PushL(sidType); |
|
285 iID = HBufC::NewL(numberOfDigits); |
|
286 TPtr pID = iID->Des(); |
|
287 |
|
288 pID.AppendNumUC(sidType->SecureIdL(), EHex); |
|
289 CleanupStack::PopAndDestroy(sidType); |
|
290 } |
|
291 else if (type == EPackageTransferDerivedType) |
|
292 { |
|
293 CSBPackageTransferType* pidType = CSBPackageTransferType::NewL(transfer); |
|
294 CleanupStack::PushL(pidType); |
|
295 iID = HBufC::NewL(numberOfDigits); |
|
296 TPtr pID = iID->Des(); |
|
297 pID.AppendNum(TSecureId(pidType->PackageIdL()), EHex); |
|
298 CleanupStack::PopAndDestroy(pidType); |
|
299 } |
|
300 else if (type == EJavaTransferDerivedType) |
|
301 { |
|
302 CSBJavaTransferType* javaType = CSBJavaTransferType::NewL(transfer); |
|
303 CleanupStack::PushL(javaType); |
|
304 iID = HBufC::NewL(javaType->SuiteHashL().Length()); |
|
305 TPtr pID = iID->Des(); |
|
306 pID.Append(javaType->SuiteHashL()); |
|
307 CleanupStack::PopAndDestroy(javaType); |
|
308 } |
|
309 } |
|
310 |
|
311 |
|
312 |
|
313 TBool CAsyncBackupTransferHandler::Success() |
|
314 /** |
|
315 @internalComponent |
|
316 @released |
|
317 |
|
318 @return Whether or not all data transfers completed successfully and resets the success. |
|
319 */ |
|
320 { |
|
321 TBool res = iSuccess; |
|
322 iSuccess = ETrue; |
|
323 return res; |
|
324 } |
|
325 } // end namespace |