|
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 // Implementation of RSBEClientSession class. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 */ |
|
21 |
|
22 #include "sbeclientsession.h" |
|
23 #include "sbeclientserver.h" |
|
24 #include <connect/sbtypes.h> |
|
25 #include <connect/panic.h> |
|
26 |
|
27 namespace conn |
|
28 { |
|
29 |
|
30 RSBEClientSession* RSBEClientSession::NewL() |
|
31 /** Symbian OS constructor |
|
32 @return pointer to an instantiated RSBEClientSession object */ |
|
33 { |
|
34 RSBEClientSession* self = new (ELeave) RSBEClientSession(); |
|
35 CleanupStack::PushL(self); |
|
36 self->ConstructL(); |
|
37 CleanupStack::Pop(self); |
|
38 return self; |
|
39 } |
|
40 |
|
41 void RSBEClientSession::ConstructL() |
|
42 /** Symbian second phase constructor */ |
|
43 { |
|
44 iGSHInterface = CHeapWrapper::NewL(); |
|
45 } |
|
46 |
|
47 RSBEClientSession::RSBEClientSession() : iCallbackHandler(NULL) |
|
48 /** Class constructor. */ |
|
49 { |
|
50 } |
|
51 |
|
52 RSBEClientSession::~RSBEClientSession() |
|
53 /** Class destructor. */ |
|
54 { |
|
55 delete iGSHInterface; |
|
56 delete iCallbackHandler; |
|
57 } |
|
58 |
|
59 void RSBEClientSession::Close() |
|
60 /** Closes the Secure Backup Engine handle. */ |
|
61 { |
|
62 iGlobalSharedHeap.Close(); |
|
63 RSessionBase::Close(); |
|
64 } |
|
65 |
|
66 TInt RSBEClientSession::Connect() |
|
67 /** Connects the handle to the Secure Backup Engine. |
|
68 |
|
69 @return KErrNone if successful, KErrCouldNotConnect otherwise |
|
70 */ |
|
71 { |
|
72 TInt nRetry = KSBERetryCount; |
|
73 TInt nRet = KErrNotFound; |
|
74 |
|
75 while(nRetry > 0 && nRet != KErrNone) |
|
76 { |
|
77 const TSecurityPolicy policy(static_cast<TSecureId>(KSBServerUID3)); |
|
78 nRet = CreateSession(KSBEServerName, Version(), KSBEASyncMessageSlots, EIpcSession_Unsharable,&policy); |
|
79 if(nRet == KErrNotFound || nRet == KErrServerTerminated) |
|
80 { |
|
81 StartServer(); |
|
82 } |
|
83 nRetry--; |
|
84 } |
|
85 |
|
86 // If we were succesful, then get a handle to the server created and owned GSH |
|
87 if (nRet == KErrNone) |
|
88 { |
|
89 nRet = GetGlobalSharedHeapHandle(); |
|
90 } |
|
91 |
|
92 return nRet; |
|
93 } |
|
94 |
|
95 TVersion RSBEClientSession::Version() const |
|
96 /** Returns the version of this API |
|
97 |
|
98 @return The version of this API |
|
99 */ |
|
100 { |
|
101 return TVersion (KSBEMajorVersionNumber, |
|
102 KSBEMinorVersionNumber, |
|
103 KSBEBuildVersionNumber); |
|
104 } |
|
105 |
|
106 // |
|
107 // Server startup code |
|
108 TInt RSBEClientSession::StartServer() |
|
109 /** Start the server as a thread on WINS or a process on ARM. |
|
110 |
|
111 Called by Connect when the kernel is unable to create a session |
|
112 with the SBE server (as its not running). |
|
113 |
|
114 @return Standard Symbian OS code from RProcess/RThread create. |
|
115 */ |
|
116 { |
|
117 // |
|
118 // Servers UID |
|
119 const TUidType serverUid(KNullUid, KNullUid, KSBServerUID3); |
|
120 |
|
121 |
|
122 RProcess server; |
|
123 TInt nRet=server.Create(KSBImageName,KNullDesC,serverUid); |
|
124 if (nRet != KErrNone) |
|
125 { |
|
126 return nRet; |
|
127 } |
|
128 |
|
129 TRequestStatus stat; |
|
130 server.Rendezvous(stat); |
|
131 if (stat != KRequestPending) |
|
132 { |
|
133 server.Kill(0); |
|
134 } |
|
135 else |
|
136 { |
|
137 server.Resume(); |
|
138 } |
|
139 User::WaitForRequest(stat); |
|
140 return (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int(); |
|
141 |
|
142 } |
|
143 |
|
144 |
|
145 void RSBEClientSession::ListOfDataOwnersL(RPointerArray<CDataOwnerInfo>& aDataOwners) |
|
146 /** |
|
147 Return the list of private data owners on the device that have backup registration files. |
|
148 If a leave does occur, then aDataOwners |
|
149 |
|
150 @param aDataOwners Pointer array holding the list of Data owners requiring backup functionality. |
|
151 Any items present in this array will be lost |
|
152 */ |
|
153 { |
|
154 // Get the server to construct the flattened array and return the size of it |
|
155 TInt result = SendReceive(ESBEMsgPrepDataOwnerInfo); |
|
156 |
|
157 User::LeaveIfError(result); |
|
158 |
|
159 iDataOwnersArray = &aDataOwners; |
|
160 |
|
161 PopulateListOfDataOwnersL(result); |
|
162 } |
|
163 |
|
164 void RSBEClientSession::PublicFileListL(TDriveNumber aDrive, CSBGenericDataType& aGenericDataType, |
|
165 RFileArray& aFiles) |
|
166 /** |
|
167 Get the list of public files to backup for a particular Data Owner on a particular drive |
|
168 |
|
169 @param aDrive The drive that the public files exist on |
|
170 @param aGenericDataType Reference to the generic data type that is being passed to the SBEngine. |
|
171 @param aFiles An empty array of file information that will be filled with details of the public files |
|
172 @leave If a synchronous IPC call to the SBEngine returns an error code (i.e. if SBEngine leaves) |
|
173 */ |
|
174 { |
|
175 // request the public file list |
|
176 TInt result = SendReceive(ESBEMsgPrepPublicFiles, TIpcArgs(aDrive, |
|
177 &(aGenericDataType.Externalise()))); |
|
178 |
|
179 User::LeaveIfError(result); |
|
180 |
|
181 iFileArray = &aFiles; |
|
182 |
|
183 PopulatePublicFileListL(result); |
|
184 } |
|
185 |
|
186 void RSBEClientSession::RawPublicFileListL( TDriveNumber aDrive, |
|
187 CSBGenericDataType& aGenericDataType, |
|
188 RRestoreFileFilterArray& aFileFilter) |
|
189 /** |
|
190 Get the list of public files to backup for a particular Data Owner on a particular drive for |
|
191 a partial restore |
|
192 |
|
193 @param aDrive The drive that the public files exist on |
|
194 @param aGenericDataType Reference to the generic data type that is passed to the SBEngine. |
|
195 @param aFileFilter Empty array that will be filled with the files/directories to be backed up |
|
196 on return |
|
197 @leave If a synchronous IPC call to the SBEngine returns an error code (i.e. if SBEngine leaves) |
|
198 */ |
|
199 { |
|
200 // ensure that the array is cleared out before populating with externalised data |
|
201 aFileFilter.Reset(); |
|
202 |
|
203 TPckgC<TDriveNumber> drive(aDrive); |
|
204 |
|
205 // request the public file list |
|
206 TInt result = SendReceive(ESBEMsgPrepPublicFilesRaw, TIpcArgs(&drive, |
|
207 &(aGenericDataType.Externalise()))); |
|
208 |
|
209 User::LeaveIfError(result); |
|
210 |
|
211 // Create a descriptor big enough for the array to be externalised into |
|
212 HBufC8* pFileArray = HBufC8::NewL(result); |
|
213 CleanupStack::PushL(pFileArray); |
|
214 |
|
215 TPtr8 fileArray(pFileArray->Des()); |
|
216 User::LeaveIfError(SendReceive(ESBEMsgGetPublicFilesRaw, TIpcArgs(&fileArray))); |
|
217 |
|
218 RRestoreFileFilterArray* pFileFilter = RRestoreFileFilterArray::InternaliseL(fileArray); |
|
219 CleanupStack::PushL(pFileFilter); |
|
220 CleanupClosePushL(*pFileFilter); |
|
221 |
|
222 TInt count = pFileFilter->Count(); |
|
223 for (TInt x = 0; x < count; x++) |
|
224 { |
|
225 aFileFilter.AppendL((*pFileFilter)[x]); |
|
226 } // for x |
|
227 |
|
228 CleanupStack::PopAndDestroy(pFileFilter); // CleanupClosePushL(*pFileFilter) |
|
229 CleanupStack::PopAndDestroy(pFileFilter); // CleanupStack::PushL(pFileFilter) |
|
230 CleanupStack::PopAndDestroy(pFileArray); |
|
231 } |
|
232 |
|
233 void RSBEClientSession::PublicFileListXMLL(TDriveNumber aDrive, TSecureId aSID, HBufC*& aFileList) |
|
234 /** |
|
235 Get the list of public files in XML format |
|
236 |
|
237 @param aDrive The drive to get the list for |
|
238 @param aSID The SID of the data owner to get the public files for |
|
239 @param aFileList The descriptor to populate on return should be NULL |
|
240 @leave If a synchronous IPC call to the SBEngine returns an error code (i.e. if SBEngine leaves) |
|
241 */ |
|
242 { |
|
243 TPckgC<TDriveNumber> drive(aDrive); |
|
244 TPckgC<TSecureId> sid(aSID); |
|
245 |
|
246 // request the public file list |
|
247 TInt result = SendReceive(ESBEMsgPrepPublicFilesXML, TIpcArgs(&drive, &sid)); |
|
248 |
|
249 User::LeaveIfError(result); |
|
250 |
|
251 // Create a descriptor big enough for the array to be externalised into |
|
252 aFileList = HBufC::NewL(result); |
|
253 |
|
254 TPtr fileList(aFileList->Des()); |
|
255 User::LeaveIfError(SendReceive(ESBEMsgPrepPublicFilesXML, TIpcArgs(&fileList))); |
|
256 } |
|
257 |
|
258 void RSBEClientSession::SetBURModeL(const TDriveList& aDriveList, TBURPartType aBURType, |
|
259 TBackupIncType aBackupIncType) |
|
260 /** |
|
261 Set the Backup and Restore mode on/off and configure the BUR options |
|
262 |
|
263 @param aDriveList Array of drives that are to be backed up during the operations |
|
264 @param aBURType Set the device into Full/Partial BUR or normal operation |
|
265 @param aBackupIncType Base/Incremental backup |
|
266 @leave If a synchronous IPC call to the SBEngine returns an error code (i.e. if SBEngine leaves) |
|
267 */ |
|
268 { |
|
269 User::LeaveIfError(SendReceive(ESBEMsgSetBURMode, TIpcArgs(&aDriveList, aBURType, aBackupIncType))); |
|
270 } |
|
271 |
|
272 void RSBEClientSession::SetSIDListForPartialBURL(RSIDArray& aSIDs) |
|
273 /** |
|
274 If a partial backup is required then this sets the list of data owners. |
|
275 This method must only be called when the device has just been put into backup or restore mode. |
|
276 It must only be called once for a backup or restore operation. |
|
277 |
|
278 @param aSIDs array of affected data owners. |
|
279 @leave If a synchronous IPC call to the SBEngine returns an error code (i.e. if SBEngine leaves) |
|
280 */ |
|
281 { |
|
282 HBufC8* pFlattenedArray = aSIDs.ExternaliseL(); |
|
283 CleanupStack::PushL(pFlattenedArray); |
|
284 |
|
285 TPtrC8 flatArray(pFlattenedArray->Des()); |
|
286 |
|
287 User::LeaveIfError(SendReceive(ESBEMsgSetSIDListPartial, TIpcArgs(&flatArray))); |
|
288 |
|
289 CleanupStack::PopAndDestroy(pFlattenedArray); |
|
290 } |
|
291 |
|
292 void RSBEClientSession::SIDStatusL(RSIDStatusArray& aSIDStatus) |
|
293 /** |
|
294 Gets the status of a set of data owners. |
|
295 This method must only be called in backup or restore mode. |
|
296 |
|
297 @param aSIDStatus an array of structures for information about data owners. On return |
|
298 the status information is filled in. |
|
299 @leave If a synchronous IPC call to the SBEngine returns an error code (i.e. if SBEngine leaves) |
|
300 */ |
|
301 { |
|
302 HBufC8* pExternalisedArray = aSIDStatus.ExternaliseL(); |
|
303 CleanupStack::PushL(pExternalisedArray); |
|
304 |
|
305 TPtr8 externArray(pExternalisedArray->Des()); |
|
306 User::LeaveIfError(SendReceive(ESBEMsgPrepSIDStatus, TIpcArgs(&externArray))); |
|
307 |
|
308 // Reset the descriptor, ready for getting the returned externalised array |
|
309 externArray.Zero(); |
|
310 |
|
311 User::LeaveIfError(SendReceive(ESBEMsgGetSIDStatus, TIpcArgs(&externArray))); |
|
312 RSIDStatusArray* pInternalisedArray = RSIDStatusArray::InternaliseL(externArray); |
|
313 |
|
314 CleanupStack::PopAndDestroy(pExternalisedArray); // pExternalisedArray |
|
315 |
|
316 CleanupStack::PushL(pInternalisedArray); |
|
317 CleanupClosePushL(*pInternalisedArray); |
|
318 |
|
319 aSIDStatus.Reset(); |
|
320 |
|
321 // Copy the returned array into the passed array |
|
322 TInt count = pInternalisedArray->Count(); |
|
323 for (TInt index = 0; index < count; index++) |
|
324 { |
|
325 aSIDStatus.AppendL((*pInternalisedArray)[index]); |
|
326 } |
|
327 CleanupStack::PopAndDestroy(pInternalisedArray); // pInternalisedArray->Close() |
|
328 CleanupStack::PopAndDestroy(pInternalisedArray); // pInternalisedArray |
|
329 } |
|
330 |
|
331 TPtr8& RSBEClientSession::TransferDataAddressL() |
|
332 /** |
|
333 Provides access to the base of the global chunk used to transfer data between |
|
334 the Secure Backup Engine and a Secure Backup Server. This method should be used |
|
335 when the Secure Backup Server is providing data to the Secure Backup Engine (either as part |
|
336 of a restore operation or when supplying snapshots during a backup operation. |
|
337 |
|
338 The Secure Backup Engine only uses one global chunk at a time. It is not permissible to |
|
339 try to carry out multiple backup or restore operations in parallel. Normally a chunk |
|
340 of global heap would be protected by a mutex. In this case, all the methods of the |
|
341 CSecureBackupEngine must be regarded as synchronous and mutually exclusive - it is not |
|
342 permissible to make parallel calls. |
|
343 |
|
344 The global chunk used during a backup or restore operation may change and so the address must |
|
345 be requested whenever required rather than being cached. |
|
346 |
|
347 @return Pointer to the start of the buffer for writing |
|
348 */ |
|
349 { |
|
350 return iGSHInterface->WriteBufferL(iGlobalSharedHeap); |
|
351 } |
|
352 |
|
353 TPtrC8& RSBEClientSession::TransferDataInfoL(CSBGenericTransferType*& aGenericTransferType, |
|
354 TBool& aFinished) |
|
355 /** |
|
356 Provides access to the data received from the Secure Backup Engine during a backup operation. |
|
357 |
|
358 This method should be called after a synchronous or asynchronous request for data has |
|
359 completed. |
|
360 |
|
361 @param aGenericTransferType Pointer reference that a Generic Transfer Type is allocated to |
|
362 @param aFinished Flag that will be set to ETrue if the data on the GSH is the last in the series |
|
363 @return Pointer to the start of the buffer for reading |
|
364 */ |
|
365 { |
|
366 TPtrC8& returnedBuf = iGSHInterface->ReadBufferL(iGlobalSharedHeap); |
|
367 |
|
368 TDesC8& genTypeBuffer = iGSHInterface->Header(iGlobalSharedHeap).GenericTransferTypeBuffer(); |
|
369 if (genTypeBuffer.Size() == 0) |
|
370 { |
|
371 User::Leave(KErrNotReady); |
|
372 } |
|
373 |
|
374 // Create a new client-side transfer type and pass ownership |
|
375 aGenericTransferType = CSBGenericTransferType::NewL(genTypeBuffer); |
|
376 CleanupStack::PushL(aGenericTransferType); |
|
377 |
|
378 aFinished = iGSHInterface->Header(iGlobalSharedHeap).iFinished; |
|
379 |
|
380 CleanupStack::Pop(aGenericTransferType); |
|
381 |
|
382 return returnedBuf; |
|
383 } |
|
384 |
|
385 TInt RSBEClientSession::GetGlobalSharedHeapHandle() |
|
386 /** |
|
387 Requests the handle for the Global Anonymous Shared Heap from the server that owns it and |
|
388 sets the member RChunk with it. |
|
389 |
|
390 @return An error code resulting from the server request for the handle, KErrNone if ok |
|
391 */ |
|
392 { |
|
393 TInt ret = SendReceive(ESBEMsgGetGSHHandle); |
|
394 |
|
395 // ret is negative if an error has ocurred |
|
396 if (ret > KErrNone) |
|
397 { |
|
398 ret = iGlobalSharedHeap.SetReturnedHandle(ret); |
|
399 |
|
400 // Since a handle was returned, there were no errors |
|
401 ret = KErrNone; |
|
402 } |
|
403 |
|
404 return ret; |
|
405 } |
|
406 |
|
407 void RSBEClientSession::RequestDataL(CSBGenericTransferType& aGenericTransferType, |
|
408 TRequestStatus& aStatus) |
|
409 /** |
|
410 Asynchronous request of the Secure Backup Engine to supply data for a particular data owner. |
|
411 When the supplied TRequestStatus has been completed by the server, TransferDataInfoL should |
|
412 be called to retrieve the requested data. |
|
413 |
|
414 @param aGenericTransferType Reference to the identifier of the data requested |
|
415 @param aStatus TRequestStatus object used by the server to signal the client that a response |
|
416 is ready |
|
417 */ |
|
418 { |
|
419 const TDesC8& transBuf = aGenericTransferType.Externalise(); |
|
420 SendReceive(ESBEMsgRequestDataAsync, TIpcArgs(&transBuf), aStatus); |
|
421 } |
|
422 |
|
423 void RSBEClientSession::RequestDataL(CSBGenericTransferType& aGenericTransferType) |
|
424 /** |
|
425 Synchronous request of the Secure Backup Engine to supply data for a particular data owner. |
|
426 When the supplied TRequestStatus has been completed by the server, TransferDataInfoL should |
|
427 be called to retrieve the requested data. |
|
428 |
|
429 @param aGenericTransferType Reference to the identifier of the data requested |
|
430 @leave If a synchronous IPC call to the SBEngine returns an error code (i.e. if SBEngine leaves) |
|
431 */ |
|
432 { |
|
433 User::LeaveIfError(SendReceive(ESBEMsgRequestDataSync, |
|
434 TIpcArgs(&(aGenericTransferType.Externalise())))); |
|
435 } |
|
436 |
|
437 void RSBEClientSession::SupplyDataL(CSBGenericTransferType& aGenericTransferType, |
|
438 TBool aFinished, TRequestStatus& aStatus) |
|
439 /** |
|
440 Synchronous method for signalling to the server that the client has placed an amount |
|
441 of data in the Global Shared Heap and |
|
442 |
|
443 @param aGenericTransferType Information about the data that has been transferred |
|
444 @param aFinished ETrue indicates that additional SupplyDataL calls will be made as |
|
445 part of this transfer operation |
|
446 @leave If a synchronous IPC call to the SBEngine returns an error code (i.e. if SBEngine leaves) |
|
447 */ |
|
448 { |
|
449 iGSHInterface->Header(iGlobalSharedHeap).GenericTransferTypeBuffer() |
|
450 = aGenericTransferType.Externalise(); |
|
451 |
|
452 SendReceive(ESBEMsgSupplyDataSync, TIpcArgs(aFinished), aStatus); |
|
453 } |
|
454 |
|
455 void RSBEClientSession::SupplyDataL(CSBGenericTransferType& aGenericTransferType, |
|
456 TBool aFinished) |
|
457 /** |
|
458 Synchronous method for signalling to the server that the client has placed an amount |
|
459 of data in the Global Shared Heap and |
|
460 |
|
461 @param aGenericTransferType Information about the data that has been transferred |
|
462 @param aFinished ETrue indicates that additional SupplyDataL calls will be made as |
|
463 part of this transfer operation |
|
464 @leave If a synchronous IPC call to the SBEngine returns an error code (i.e. if SBEngine leaves) |
|
465 */ |
|
466 { |
|
467 iGSHInterface->Header(iGlobalSharedHeap).GenericTransferTypeBuffer() |
|
468 = aGenericTransferType.Externalise(); |
|
469 |
|
470 User::LeaveIfError(SendReceive(ESBEMsgSupplyDataSync, TIpcArgs(aFinished))); |
|
471 } |
|
472 |
|
473 void RSBEClientSession::AllSnapshotsSuppliedL() |
|
474 /** |
|
475 This methods informs the data owner that all snapshots have been supplied. |
|
476 |
|
477 @leave If a synchronous IPC call to the SBEngine returns an error code (i.e. if SBEngine leaves) |
|
478 */ |
|
479 { |
|
480 User::LeaveIfError(SendReceive(ESBEMsgAllSnapshotsSupplied)); |
|
481 |
|
482 } |
|
483 |
|
484 TUint RSBEClientSession::ExpectedDataSizeL(CSBGenericTransferType& aGenericTransferType) |
|
485 /** |
|
486 Get the expected total size of the data to be returned by the SBE for the purposes |
|
487 of calculating progress information |
|
488 |
|
489 @param aGenericTransferType Reference to the identifier of the data to be retrieved |
|
490 @leave If a synchronous IPC call to the SBEngine returns an error code (i.e. if SBEngine leaves) |
|
491 */ |
|
492 { |
|
493 TPckgBuf<TUint> sizePkg; |
|
494 |
|
495 TPtrC8 genType(aGenericTransferType.Externalise()); |
|
496 |
|
497 User::LeaveIfError(SendReceive(ESBEMsgGetExpectedDataSize, TIpcArgs(&genType, &sizePkg))); |
|
498 |
|
499 return sizePkg(); |
|
500 } |
|
501 |
|
502 void RSBEClientSession::AllSystemFilesRestored() |
|
503 /** |
|
504 Signal the Secure Backup Engine that registration files are to be parsed and Active data owners |
|
505 are to be started |
|
506 */ |
|
507 { |
|
508 SendReceive(ESBEMsgAllSystemFilesRestored); |
|
509 } |
|
510 |
|
511 /** |
|
512 Return the list of private data owners on the device that have backup registration files. |
|
513 If a leave does occur, then aDataOwners |
|
514 |
|
515 @param aDataOwners Pointer array holding the list of Data owners requiring backup functionality. |
|
516 Any items present in this array will be lost |
|
517 @param aStatus is TRequestStatus& |
|
518 */ |
|
519 void RSBEClientSession::ListOfDataOwnersL(RPointerArray<CDataOwnerInfo>& aDataOwners, TRequestStatus& aStatus) |
|
520 { |
|
521 if (iCallbackHandler == NULL) |
|
522 { |
|
523 iCallbackHandler = CSBECallbackHandler::NewL(*this); |
|
524 } |
|
525 |
|
526 if (iCallbackHandler->IsActive()) |
|
527 { |
|
528 User::Leave(KErrInUse); |
|
529 } |
|
530 else |
|
531 { |
|
532 iDataOwnersArray = &aDataOwners; |
|
533 SendReceive(ESBEMsgPrepDataOwnerInfo, iCallbackHandler->iStatus); |
|
534 iCallbackHandler->StartL(aStatus, EListOfDataOwners); |
|
535 } |
|
536 } |
|
537 |
|
538 /** |
|
539 Get the list of public files to backup for a particular Data Owner on a particular drive |
|
540 |
|
541 @param aDrive The drive that the public files exist on |
|
542 @param aGenericDataType Reference to the generic data type that is being passed to the SBEngine. |
|
543 @param aFiles An empty array of file information that will be filled with details of the public files |
|
544 @param aStatus A reference to TRequestStatus |
|
545 |
|
546 */ |
|
547 void RSBEClientSession::PublicFileListL(TDriveNumber aDrive, CSBGenericDataType& aGenericDataType, RFileArray& aFiles, TRequestStatus& aStatus) |
|
548 { |
|
549 if (iCallbackHandler == NULL) |
|
550 { |
|
551 iCallbackHandler = CSBECallbackHandler::NewL(*this); |
|
552 } |
|
553 |
|
554 if (iCallbackHandler->IsActive()) |
|
555 { |
|
556 User::Leave(KErrInUse); |
|
557 } |
|
558 else |
|
559 { |
|
560 iFileArray = &aFiles; |
|
561 // request the public file list |
|
562 SendReceive(ESBEMsgPrepPublicFiles, TIpcArgs(aDrive, &(aGenericDataType.Externalise())), iCallbackHandler->iStatus); |
|
563 iCallbackHandler->StartL(aStatus,EPublicFileList); |
|
564 } |
|
565 } |
|
566 |
|
567 void RSBEClientSession::SetBURModeL(const TDriveList& aDriveList, TBURPartType aBURType, |
|
568 TBackupIncType aBackupIncType, TRequestStatus& aStatus) |
|
569 /** |
|
570 Set the Backup and Restore mode on/off and configure the BUR options asynchronously. |
|
571 |
|
572 @param aDriveList Array of drives that are to be backed up during the operations |
|
573 @param aBURType Set the device into Full/Partial BUR or normal operation |
|
574 @param aBackupIncType Base/Incremental backup |
|
575 @param aStatus A reference to TRequestStatus |
|
576 */ |
|
577 |
|
578 { |
|
579 SendReceive(ESBEMsgSetBURMode, TIpcArgs(&aDriveList, aBURType, aBackupIncType), aStatus); |
|
580 } |
|
581 |
|
582 /** |
|
583 This methods informs the data owner that all snapshots have been supplied. |
|
584 |
|
585 @param aStatus A reference to TRequestStatus |
|
586 */ |
|
587 void RSBEClientSession::AllSnapshotsSuppliedL(TRequestStatus& aStatus) |
|
588 { |
|
589 SendReceive(ESBEMsgAllSnapshotsSupplied, aStatus); |
|
590 } |
|
591 |
|
592 /** |
|
593 Signal the Secure Backup Engine that registration files are to be parsed and Active data owners |
|
594 are to be started |
|
595 |
|
596 @param aStatus A reference to TRequestStatus |
|
597 */ |
|
598 void RSBEClientSession::AllSystemFilesRestoredL(TRequestStatus& aStatus) |
|
599 { |
|
600 SendReceive(ESBEMsgAllSystemFilesRestored, aStatus); |
|
601 } |
|
602 |
|
603 |
|
604 /** |
|
605 Method to perform and IPC call to populate list of data owners. |
|
606 @param aBufferSize Size of the buffer needed to be allocated for the IPC call |
|
607 |
|
608 @InternalTechnology |
|
609 */ |
|
610 void RSBEClientSession::PopulateListOfDataOwnersL(TUint aBufferSize) |
|
611 { |
|
612 __ASSERT_DEBUG(iDataOwnersArray, Panic(KErrBadHandle)); |
|
613 iDataOwnersArray->ResetAndDestroy(); |
|
614 |
|
615 // Create a descriptor that's appropriate to hold the buffer to be returned |
|
616 HBufC8* pReturnedBuf = HBufC8::NewL(aBufferSize); |
|
617 |
|
618 CleanupStack::PushL(pReturnedBuf); |
|
619 |
|
620 TPtr8 returnedBuf(pReturnedBuf->Des()); |
|
621 // Request that the server returns the previously packed array |
|
622 TInt result = SendReceive(ESBEMsgGetDataOwnerInfo, TIpcArgs(&returnedBuf)); |
|
623 User::LeaveIfError(result); |
|
624 |
|
625 TInt offset = 0; |
|
626 |
|
627 for (TInt index = 0; index < result; index++) |
|
628 { |
|
629 CDataOwnerInfo* pDOI = CDataOwnerInfo::NewL(returnedBuf.Mid(offset)); |
|
630 CleanupStack::PushL(pDOI); |
|
631 |
|
632 iDataOwnersArray->AppendL(pDOI); |
|
633 |
|
634 CleanupStack::Pop(pDOI); |
|
635 |
|
636 offset += (*iDataOwnersArray)[index]->Size(); |
|
637 } |
|
638 |
|
639 CleanupStack::PopAndDestroy(pReturnedBuf); |
|
640 } |
|
641 |
|
642 /** |
|
643 Method to perform and IPC call to populate list of public files. |
|
644 @param aBufferSize Size of the buffer needed to be allocated for the IPC call |
|
645 |
|
646 @InternalTechnology |
|
647 */ |
|
648 void RSBEClientSession::PopulatePublicFileListL(TUint aBufferSize) |
|
649 { |
|
650 __ASSERT_DEBUG(iFileArray, Panic(KErrBadHandle)); |
|
651 iFileArray->Reset(); |
|
652 |
|
653 // Create a descriptor big enough for the array to be externalised into |
|
654 HBufC8* pFileArray = HBufC8::NewL(aBufferSize); |
|
655 CleanupStack::PushL(pFileArray); |
|
656 |
|
657 TPtr8 fileArray(pFileArray->Des()); |
|
658 User::LeaveIfError(SendReceive(ESBEMsgGetPublicFiles, TIpcArgs(&fileArray))); |
|
659 |
|
660 RFileArray* pFiles = RFileArray::InternaliseL(fileArray); |
|
661 CleanupStack::PopAndDestroy(pFileArray); |
|
662 CleanupStack::PushL(pFiles); |
|
663 CleanupClosePushL(*pFiles); |
|
664 |
|
665 TInt count = pFiles->Count(); |
|
666 for (TInt x = 0; x < count; x++) |
|
667 { |
|
668 iFileArray->AppendL((*pFiles)[0]); |
|
669 pFiles->Remove(0); // We're running out of memory, hence be frugal |
|
670 } // for x |
|
671 |
|
672 CleanupStack::PopAndDestroy(pFiles); // CleanupClosePushL(*pFiles) |
|
673 CleanupStack::PopAndDestroy(pFiles); // CleanupStack::PushL(pFiles) |
|
674 } |
|
675 |
|
676 void RSBEClientSession::PublicFileListL(TDriveNumber aDrive, CSBGenericDataType& aGenericDataType, |
|
677 RPointerArray<CSBEFileEntry>& aFileList, TBool& aFinished, |
|
678 TInt aTotalListCursor, TInt aMaxResponseSize, TRequestStatus& aStatus) |
|
679 /** |
|
680 This asynchronous method is used to retrieve the list of public files for the specified data owner |
|
681 on the specified drive. Upon completion of aStatus, the caller should check aFileList |
|
682 @param aDrive The drive that contains the public files being retrieved |
|
683 @param aGenericDataType The identifier for the data owner that owns the public files |
|
684 @param aFileList Upon completion of aStatus, this array will contain the list of public files returned |
|
685 @param aFinished Upon completion of aStatus, this flag will be set to indicate that there are more |
|
686 file entries available for this data owner and another call to this method should be made |
|
687 @param aTotalListCursor Specifies the index into the complete list of public files for this data owner to start |
|
688 the next chunk of file entries from. The number of entries returned by a call to this |
|
689 method can be determined by querying the count of aFileList |
|
690 @param aMaxResponseSize The maximum total size in bytes of externalised CSBEFileEntry objects that will be returned |
|
691 @param aStatus The TRequestStatus that will be completed once the engine has fully processed this request |
|
692 */ |
|
693 { |
|
694 if (iCallbackHandler == NULL) |
|
695 { |
|
696 iCallbackHandler = CSBECallbackHandler::NewL(*this); |
|
697 } |
|
698 |
|
699 if (iCallbackHandler->IsActive()) |
|
700 { |
|
701 User::Leave(KErrInUse); |
|
702 } |
|
703 else |
|
704 { |
|
705 iFileList = &aFileList; |
|
706 iFinished = &aFinished; |
|
707 iTotalListCursor = &aTotalListCursor; |
|
708 /* TPckgC<TDriveNumber> drivePkg(aDrive); |
|
709 TPckgC<TInt> cursorPkg(aTotalListCursor); |
|
710 TPckgC<TInt> maxResp(aMaxResponseSize);*/ |
|
711 SendReceive(ESBEMsgPrepLargePublicFiles, TIpcArgs(static_cast<TInt>(aDrive), |
|
712 &(aGenericDataType.Externalise()), aTotalListCursor, aMaxResponseSize), |
|
713 iCallbackHandler->iStatus); |
|
714 iCallbackHandler->StartL(aStatus,ELargePublicFileList); |
|
715 } |
|
716 } |
|
717 |
|
718 void RSBEClientSession::PopulateLargePublicFileListL(TInt aResult) |
|
719 /** |
|
720 Callback following the asynchronous completion of the request for the public file list |
|
721 @param aResult The error code returned by the engine as a result of the initial request |
|
722 */ |
|
723 { |
|
724 // Retrieve the return parameters (finished flag and entry count) from SBE |
|
725 if (KErrNone == aResult) |
|
726 { |
|
727 TBool finishedFlag; |
|
728 TInt numEntries; |
|
729 TPckg<TBool> finishPkg(finishedFlag); |
|
730 TPckg<TInt> numEntriesPkg(numEntries); |
|
731 User::LeaveIfError(SendReceive(ESBEMsgGetLargePublicFiles, TIpcArgs(&finishPkg, &numEntriesPkg))); |
|
732 |
|
733 *iFinished = finishPkg(); |
|
734 TInt numberOfReturnedEntries = numEntriesPkg(); |
|
735 |
|
736 iFileList->ResetAndDestroy(); |
|
737 TInt cursor = 0; |
|
738 TPtrC8 returnedBuf(iGSHInterface->ReadBufferL(iGlobalSharedHeap)); |
|
739 |
|
740 // Retrieve the file list from GSH |
|
741 // Pack into the previously supplied array |
|
742 for (TInt entryIndex = 0; entryIndex < numberOfReturnedEntries; ++entryIndex) |
|
743 { |
|
744 TInt bytesRead = 0; |
|
745 CSBEFileEntry* nextEntry = CSBEFileEntry::NewLC(returnedBuf.Mid(cursor), bytesRead); |
|
746 cursor += bytesRead; |
|
747 iFileList->AppendL(nextEntry); |
|
748 CleanupStack::Pop(nextEntry); |
|
749 } |
|
750 } |
|
751 else |
|
752 { |
|
753 *iFinished = EFalse; |
|
754 } |
|
755 } |
|
756 |
|
757 |
|
758 // |
|
759 // CSBECallbackHandler // |
|
760 // |
|
761 |
|
762 /** Symbian OS constructor |
|
763 @param aClientSession reference to a ClientSession to call callbacks on |
|
764 @return pointer to an instantiated RSBEClientSession object |
|
765 */ |
|
766 CSBECallbackHandler* CSBECallbackHandler::NewL(RSBEClientSession& aClientSession) |
|
767 { |
|
768 CSBECallbackHandler* self = new (ELeave) CSBECallbackHandler(aClientSession); |
|
769 CleanupStack::PushL(self); |
|
770 self->ConstructL(); |
|
771 CleanupStack::Pop(self); |
|
772 return self; |
|
773 } |
|
774 |
|
775 /** Symbian second phase constructor */ |
|
776 void CSBECallbackHandler::ConstructL() |
|
777 { |
|
778 } |
|
779 |
|
780 /** Class constructor. */ |
|
781 CSBECallbackHandler::CSBECallbackHandler(RSBEClientSession& aClientSession) |
|
782 : CActive(EPriorityNormal), iClientSession(aClientSession) |
|
783 { |
|
784 CActiveScheduler::Add(this); |
|
785 } |
|
786 /** Class destructor. */ |
|
787 CSBECallbackHandler::~CSBECallbackHandler() |
|
788 { |
|
789 Cancel(); |
|
790 } |
|
791 |
|
792 /** Starts Callback Handler |
|
793 |
|
794 @param aStatus Reference to the Client's request Status |
|
795 @param aState State in order to make a relevant callback |
|
796 |
|
797 */ |
|
798 void CSBECallbackHandler::StartL(TRequestStatus& aStatus, TState aState) |
|
799 { |
|
800 aStatus = KRequestPending; |
|
801 iObserver = &aStatus; |
|
802 iState = aState; |
|
803 SetActive(); |
|
804 } |
|
805 |
|
806 /** |
|
807 Cancels outsanding request |
|
808 */ |
|
809 void CSBECallbackHandler::CancelRequest() |
|
810 { |
|
811 Cancel(); |
|
812 } |
|
813 /** |
|
814 CActive::RunL() implementation |
|
815 */ |
|
816 void CSBECallbackHandler::RunL() |
|
817 { |
|
818 TInt result = iStatus.Int(); |
|
819 if (result >= KErrNone) |
|
820 { |
|
821 switch (iState) |
|
822 { |
|
823 case EListOfDataOwners: |
|
824 iClientSession.PopulateListOfDataOwnersL(result); |
|
825 break; |
|
826 case EPublicFileList: |
|
827 iClientSession.PopulatePublicFileListL(result); |
|
828 break; |
|
829 case ELargePublicFileList: |
|
830 iClientSession.PopulateLargePublicFileListL(result); |
|
831 break; |
|
832 default: |
|
833 result = KErrNotSupported; |
|
834 break; |
|
835 } //switch |
|
836 } // if |
|
837 |
|
838 User::LeaveIfError(result); |
|
839 |
|
840 CompleteObserver(KErrNone); |
|
841 } |
|
842 |
|
843 /** |
|
844 CActive::DoCancel() implmenation |
|
845 Completes observer's status with KErrCancel and sets the state to None |
|
846 */ |
|
847 void CSBECallbackHandler::DoCancel() |
|
848 { |
|
849 iState = ENone; |
|
850 // just to avoid repeating the code |
|
851 CompleteObserver(KErrCancel); |
|
852 } |
|
853 |
|
854 /** |
|
855 Method for completing Client's request status |
|
856 @param aError Completion Error |
|
857 */ |
|
858 void CSBECallbackHandler::CompleteObserver(TInt aError) |
|
859 { |
|
860 if(iObserver) |
|
861 { |
|
862 User::RequestComplete(iObserver, aError); |
|
863 iObserver = NULL; |
|
864 } |
|
865 } |
|
866 |
|
867 /** |
|
868 If RunL() leaves a CompleteObserver() method called |
|
869 |
|
870 @aError Error code |
|
871 */ |
|
872 TInt CSBECallbackHandler::RunError(TInt aError) |
|
873 { |
|
874 CompleteObserver(aError); |
|
875 return KErrNone; |
|
876 } |
|
877 |
|
878 |
|
879 } // conn namespace |