|
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 iID = 0; |
|
94 delete iActiveScheduler; |
|
95 iActiveScheduler = 0; |
|
96 } |
|
97 |
|
98 void CAsyncBackupTransferHandler::StartL() |
|
99 /** |
|
100 @internalComponent |
|
101 @released |
|
102 */ |
|
103 { |
|
104 iCurrentIndex = KZero; |
|
105 iSuccess = ETrue; |
|
106 ContinueL(); |
|
107 iActiveScheduler->Start(); |
|
108 } |
|
109 |
|
110 void CAsyncBackupTransferHandler::ContinueL() |
|
111 /** |
|
112 @internalComponent |
|
113 @released |
|
114 */ |
|
115 { |
|
116 // If all transfer types have been dealt with, there are no more requests |
|
117 // to be made and hence we can stop the active scheduler: |
|
118 if (iCurrentIndex == iTestStep->TransferTypes().Count()) |
|
119 { |
|
120 iActiveScheduler->AsyncStop(); |
|
121 } |
|
122 else if (!IsActive()) |
|
123 { |
|
124 CurrentIDL(); |
|
125 TUint expectedSize = 0; |
|
126 |
|
127 _LIT(KCurrentSid, "Current ID: "); |
|
128 iTestStep->LogWithText(LOG_LEVEL3, KCurrentSid, *iID); |
|
129 |
|
130 TRAPD(err, expectedSize = iTestStep->BackupClient()->ExpectedDataSizeL(*iTestStep->TransferTypes()[iCurrentIndex])); |
|
131 if(err != KErrNone) |
|
132 { |
|
133 _LIT(KLog1e, "Request expected data size error: "); |
|
134 iTestStep->LogWithNum(LOG_LEVEL5, KLog1e, err); |
|
135 } |
|
136 |
|
137 _LIT(KExpSize, "Expected Data Size: "); |
|
138 iTestStep->LogWithNum(LOG_LEVEL4, KExpSize, expectedSize); |
|
139 |
|
140 MakeRequestDataCallL(); |
|
141 } |
|
142 else |
|
143 { |
|
144 // Being called during an active state |
|
145 User::Leave(KErrInUse); |
|
146 } |
|
147 } |
|
148 |
|
149 void CAsyncBackupTransferHandler::MakeRequestDataCallL() |
|
150 { |
|
151 TRAPD(err1,iTestStep->BackupClient()->RequestDataL(*iTestStep->TransferTypes()[iCurrentIndex], iStatus)); |
|
152 if (err1 != KErrNone) |
|
153 { |
|
154 _LIT(KLog1, "Failed to request data for ID: "); |
|
155 iTestStep->LogWithText(LOG_LEVEL5, KLog1, *iID); |
|
156 _LIT(KLog2, "Error code: "); |
|
157 iTestStep->LogWithNum(LOG_LEVEL5, KLog2, err1); |
|
158 } |
|
159 iStatus = KRequestPending; |
|
160 SetActive(); |
|
161 } |
|
162 |
|
163 void CAsyncBackupTransferHandler::RunL() |
|
164 /** |
|
165 Upon completion of the request, gets backup data from the backup server, and |
|
166 saves it to the backup archive. |
|
167 |
|
168 @internalComponent |
|
169 @released |
|
170 */ |
|
171 { |
|
172 if (iStatus == KErrNone) |
|
173 { |
|
174 TBool isFinished; |
|
175 |
|
176 // Initialise following to NULL, or else SBEClient panics in debug builds: |
|
177 CSBGenericTransferType* receivedType = NULL; |
|
178 TPtrC8 pData = iTestStep->BackupClient()->TransferDataInfoL(receivedType, isFinished); |
|
179 CleanupStack::PushL(receivedType); |
|
180 |
|
181 // no need to push it onto CleanupStack as there is no ownership transfer |
|
182 CSBGenericTransferType* currentTransfer = iTestStep->TransferTypes()[iCurrentIndex]; |
|
183 |
|
184 if (KErrNone != (currentTransfer->Externalise()).CompareF(receivedType->Externalise())) |
|
185 { |
|
186 _LIT(KLogWrong, "The type of data requested doesn't much the received, please contact Connectivity team !"); |
|
187 iTestStep->LogWithText(LOG_LEVEL3, KLogWrong, *iID); |
|
188 } |
|
189 else if (pData.Size() > 0) |
|
190 { |
|
191 TRAPD(err, iTestStep->StorageManager()->ArchiveDataL(currentTransfer, pData, isFinished)); |
|
192 if (err != KErrNone) |
|
193 { |
|
194 iTestStep->StorageManager()->Reset(); |
|
195 _LIT(KLog1, "Error Saving data to archive for ID: "); |
|
196 iTestStep->LogWithText(LOG_LEVEL3, KLog1, *iID); |
|
197 _LIT(KLog2, "Error code: "); |
|
198 iTestStep->LogWithNum(LOG_LEVEL3, KLog2, err); |
|
199 } |
|
200 else |
|
201 { |
|
202 _LIT(KLog3, "Number of bytes saved: "); |
|
203 iTestStep->LogWithNum(LOG_LEVEL3, KLog3, pData.Size()); |
|
204 } |
|
205 } |
|
206 |
|
207 CleanupStack::PopAndDestroy(receivedType); |
|
208 if (isFinished) // if not then there are more data to come, so run again on the same type |
|
209 { |
|
210 ++iCurrentIndex; |
|
211 // Restart the active object to request more data: |
|
212 ContinueL(); |
|
213 } |
|
214 else // continue to request data |
|
215 { |
|
216 MakeRequestDataCallL(); |
|
217 } |
|
218 |
|
219 } |
|
220 else |
|
221 { |
|
222 User::Leave(iStatus.Int()); |
|
223 } |
|
224 } |
|
225 |
|
226 |
|
227 void CAsyncBackupTransferHandler::DoCancel() |
|
228 /** |
|
229 @internalComponent |
|
230 @released |
|
231 */ |
|
232 {} |
|
233 |
|
234 TInt CAsyncBackupTransferHandler::RunError(TInt aError) |
|
235 /** |
|
236 This overridden method prints an error message to the TestExecute log |
|
237 and then returns with the error passed to it by the Active Scheduler. |
|
238 |
|
239 @internalComponent |
|
240 @released |
|
241 |
|
242 @param aError - Error code passed down by the Active Scheduler. |
|
243 @return The error code returned by the Active Scheduler. |
|
244 */ |
|
245 { |
|
246 ++iCurrentIndex; |
|
247 _LIT(KErrorText, "Error while async call : "); |
|
248 iTestStep->LogWithNum(LOG_LEVEL4, KErrorText, aError); |
|
249 iSuccess = EFalse; |
|
250 TRAPD(err, ContinueL()); |
|
251 if (err != KErrNone) |
|
252 { |
|
253 _LIT(KErrorText1, "Error trying to issue another requst : "); |
|
254 iTestStep->LogWithNum(LOG_LEVEL4, KErrorText1, err); |
|
255 } |
|
256 return KErrNone; |
|
257 } |
|
258 |
|
259 void CAsyncBackupTransferHandler::CurrentIDL() |
|
260 /** |
|
261 @internalComponent |
|
262 @released |
|
263 |
|
264 @return SecureId of the data owner currently being processed. |
|
265 */ |
|
266 { |
|
267 delete iID; |
|
268 iID = NULL; |
|
269 CSBGenericTransferType* transfer = iTestStep->TransferTypes()[iCurrentIndex]; |
|
270 TSBDerivedType type = transfer->DerivedTypeL(); |
|
271 TInt numberOfDigits = EHex; |
|
272 |
|
273 if (type == ESIDTransferDerivedType) |
|
274 { |
|
275 CSBSIDTransferType* sidType = CSBSIDTransferType::NewL(transfer); |
|
276 CleanupStack::PushL(sidType); |
|
277 iID = HBufC::NewL(numberOfDigits); |
|
278 TPtr pID = iID->Des(); |
|
279 |
|
280 pID.AppendNumUC(sidType->SecureIdL(), EHex); |
|
281 CleanupStack::PopAndDestroy(sidType); |
|
282 } |
|
283 else if (type == EPackageTransferDerivedType) |
|
284 { |
|
285 CSBPackageTransferType* pidType = CSBPackageTransferType::NewL(transfer); |
|
286 CleanupStack::PushL(pidType); |
|
287 iID = HBufC::NewL(numberOfDigits); |
|
288 TPtr pID = iID->Des(); |
|
289 pID.AppendNum(TSecureId(pidType->PackageIdL()), EHex); |
|
290 CleanupStack::PopAndDestroy(pidType); |
|
291 } |
|
292 else if (type == EJavaTransferDerivedType) |
|
293 { |
|
294 CSBJavaTransferType* javaType = CSBJavaTransferType::NewL(transfer); |
|
295 CleanupStack::PushL(javaType); |
|
296 iID = HBufC::NewL(javaType->SuiteHashL().Length()); |
|
297 TPtr pID = iID->Des(); |
|
298 pID.Append(javaType->SuiteHashL()); |
|
299 CleanupStack::PopAndDestroy(javaType); |
|
300 } |
|
301 } |
|
302 |
|
303 |
|
304 |
|
305 TBool CAsyncBackupTransferHandler::Success() |
|
306 /** |
|
307 @internalComponent |
|
308 @released |
|
309 |
|
310 @return Whether or not all data transfers completed successfully and resets the success. |
|
311 */ |
|
312 { |
|
313 TBool res = iSuccess; |
|
314 iSuccess = ETrue; |
|
315 return res; |
|
316 } |
|
317 } // end namespace |