|
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 CActiveBackupClient class. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 */ |
|
21 |
|
22 #include "abachandler.h" |
|
23 #include "abclientsession.h" |
|
24 #include "panic.h" |
|
25 |
|
26 namespace conn |
|
27 { |
|
28 CActiveBackupCallbackHandler* CActiveBackupCallbackHandler::NewL(MActiveBackupDataClient* aABDC, |
|
29 RABClientSession& aClientSession) |
|
30 /** |
|
31 Symbian first phase constructor |
|
32 @param aABDC pointer to the client's callback implementation |
|
33 @param aClientSession reference to the client's session |
|
34 @return Pointer to a created CActiveBackupCallbackHandler object |
|
35 */ |
|
36 { |
|
37 CActiveBackupCallbackHandler* self = new (ELeave) CActiveBackupCallbackHandler(aABDC, aClientSession); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 CActiveBackupCallbackHandler::CActiveBackupCallbackHandler(MActiveBackupDataClient* aABDC, |
|
45 RABClientSession& aClientSession) : CActive(EPriorityNormal), iActiveBackupDataClient(aABDC), |
|
46 iClientSession(aClientSession), iTransferBuffer(NULL) |
|
47 /** |
|
48 C++ Constructor |
|
49 @param aABDC pointer to the client's callback implementation |
|
50 @param aClientSession reference to the client's session |
|
51 @panic KErrArgument if the pointer aABDC is NULL |
|
52 */ |
|
53 { |
|
54 __ASSERT_DEBUG(aABDC, Panic(KErrArgument)); |
|
55 } |
|
56 |
|
57 CActiveBackupCallbackHandler::~CActiveBackupCallbackHandler() |
|
58 /** |
|
59 C++ Destructor |
|
60 */ |
|
61 { |
|
62 // Cancel any outstanding Async requests (i.e. close down the callback interface) |
|
63 Cancel(); |
|
64 delete iTransferBuffer; |
|
65 } |
|
66 |
|
67 void CActiveBackupCallbackHandler::RunL() |
|
68 /** |
|
69 Handle messages "initiated" by the server. Because of IPC limitations, the client primes the |
|
70 server with a message containing modifiable package buffers that are filled with identifiers |
|
71 and arguments for the callback interface |
|
72 */ |
|
73 { |
|
74 if (iStatus == KErrNone) |
|
75 { |
|
76 switch(iCallbackCommand()) |
|
77 { |
|
78 case EABCallbackAllSnapshotsSupplied: |
|
79 { |
|
80 iActiveBackupDataClient->AllSnapshotsSuppliedL(); |
|
81 |
|
82 PrimeServerForCallbackL(); |
|
83 } break; |
|
84 case EABCallbackReceiveSnapshotData: |
|
85 { |
|
86 TDriveNumber driveNum = EDriveC; // Initialise to keep the compiler happy |
|
87 |
|
88 HBufC8* pReceivedData = iClientSession.GetDataFromServerLC(iCallbackArg1(), |
|
89 EABCallbackReceiveSnapshotData, driveNum); |
|
90 |
|
91 // Call the client method for handling receipt of the snapshot |
|
92 iActiveBackupDataClient->ReceiveSnapshotDataL(driveNum, |
|
93 *pReceivedData, static_cast<TBool>(iCallbackArg2())); |
|
94 |
|
95 // Reprime the server |
|
96 PrimeServerForCallbackL(); |
|
97 |
|
98 CleanupStack::PopAndDestroy(pReceivedData); |
|
99 } break; |
|
100 case EABCallbackGetExpectedDataSize: |
|
101 { |
|
102 TUint dataSize = iActiveBackupDataClient->GetExpectedDataSize(static_cast<TDriveNumber>(iCallbackArg1())); |
|
103 |
|
104 // Reprime the server |
|
105 PrimeServerForCallbackWithResponseL(dataSize); |
|
106 } break; |
|
107 case EABCallbackGetSnapshotData: |
|
108 { |
|
109 // Create an empty TPtr8 to point at the buffer to fill |
|
110 TPtr8 bufferToSend(CreateFixedBufferL()); |
|
111 |
|
112 TBool finished = ETrue; |
|
113 |
|
114 // Zero our descriptor so that it can be refilled |
|
115 bufferToSend.Zero(); |
|
116 |
|
117 // Callback the AB client to populate our descriptor |
|
118 iActiveBackupDataClient->GetSnapshotDataL(static_cast<TDriveNumber>(iCallbackArg1()), |
|
119 bufferToSend, finished); |
|
120 |
|
121 // Send the length and some other info to the server to allow it to prepare for the actual transfer |
|
122 iClientSession.SendDataLengthToServerL(bufferToSend, finished, EABCallbackGetSnapshotData); |
|
123 |
|
124 iTransferBuffer->Des().SetLength(bufferToSend.Length()); |
|
125 |
|
126 // Send the actual data back to the server and prime for the next callback |
|
127 PrimeServerForCallbackWithResponseL(*iTransferBuffer); |
|
128 } break; |
|
129 case EABCallbackInitialiseGetBackupData: |
|
130 { |
|
131 iActiveBackupDataClient->InitialiseGetBackupDataL(static_cast<TDriveNumber>(iCallbackArg1())); |
|
132 |
|
133 // Reprime the server |
|
134 PrimeServerForCallbackL(); |
|
135 } break; |
|
136 case EABCallbackGetBackupDataSection: |
|
137 { |
|
138 // Create an empty TPtr8 to point at the buffer to fill |
|
139 TPtr8 bufferToSend(CreateFixedBufferL()); |
|
140 |
|
141 TBool finished = ETrue; |
|
142 |
|
143 // Zero our descriptor so that it can be refilled |
|
144 bufferToSend.Zero(); |
|
145 |
|
146 // Callback the AB client to populate our descriptor |
|
147 iActiveBackupDataClient->GetBackupDataSectionL(bufferToSend, finished); |
|
148 |
|
149 // Send the length and some other info to the server to allow it to prepare for the actual transfer |
|
150 iClientSession.SendDataLengthToServerL(bufferToSend, finished, EABCallbackGetBackupDataSection); |
|
151 |
|
152 iTransferBuffer->Des().SetLength(bufferToSend.Length()); |
|
153 |
|
154 // Send the actual data back to the server and prime for the next callback |
|
155 PrimeServerForCallbackWithResponseL(*iTransferBuffer); |
|
156 } break; |
|
157 case EABCallbackInitialiseRestoreBaseDataSection: |
|
158 { |
|
159 iActiveBackupDataClient->InitialiseRestoreBaseDataL(static_cast<TDriveNumber>(iCallbackArg1())); |
|
160 |
|
161 // Reprime the server |
|
162 PrimeServerForCallbackL(); |
|
163 } break; |
|
164 case EABCallbackRestoreBaseDataSection: |
|
165 { |
|
166 HBufC8* pReceivedData = iClientSession.GetDataFromServerLC(iCallbackArg1(), |
|
167 EABCallbackRestoreBaseDataSection); |
|
168 |
|
169 // Call the client method for handling receipt of the snapshot |
|
170 iActiveBackupDataClient->RestoreBaseDataSectionL(*pReceivedData, |
|
171 static_cast<TBool>(iCallbackArg2())); |
|
172 |
|
173 // Reprime the server |
|
174 PrimeServerForCallbackL(); |
|
175 |
|
176 CleanupStack::PopAndDestroy(pReceivedData); |
|
177 } break; |
|
178 case EABCallbackInitialiseRestoreIncrementData: |
|
179 { |
|
180 iActiveBackupDataClient->InitialiseRestoreIncrementDataL(static_cast<TDriveNumber>(iCallbackArg1())); |
|
181 |
|
182 // Reprime the server |
|
183 PrimeServerForCallbackL(); |
|
184 } break; |
|
185 case EABCallbackRestoreIncrementDataSection: |
|
186 { |
|
187 HBufC8* pReceivedData = iClientSession.GetDataFromServerLC(iCallbackArg1(), |
|
188 EABCallbackRestoreIncrementDataSection); |
|
189 |
|
190 // Call the client method for handling receipt of the snapshot |
|
191 iActiveBackupDataClient->RestoreIncrementDataSectionL(*pReceivedData, |
|
192 static_cast<TBool>(iCallbackArg2())); |
|
193 |
|
194 // Reprime the server |
|
195 PrimeServerForCallbackL(); |
|
196 |
|
197 CleanupStack::PopAndDestroy(pReceivedData); |
|
198 } break; |
|
199 case EABCallbackRestoreComplete: |
|
200 { |
|
201 iActiveBackupDataClient->RestoreComplete(static_cast<TDriveNumber>(iCallbackArg1())); |
|
202 |
|
203 // Reprime the server |
|
204 PrimeServerForCallbackL(); |
|
205 } break; |
|
206 case EABCallbackTerminateMultiStageOperation: |
|
207 { |
|
208 iActiveBackupDataClient->TerminateMultiStageOperation(); |
|
209 |
|
210 // Reprime the server |
|
211 PrimeServerForCallbackL(); |
|
212 } break; |
|
213 case EABCallbackGetDataChecksum: |
|
214 { |
|
215 iActiveBackupDataClient->GetDataChecksum(static_cast<TDriveNumber>(iCallbackArg1())); |
|
216 |
|
217 // Reprime the server |
|
218 PrimeServerForCallbackL(); |
|
219 } break; |
|
220 case EABCallbackInitialiseGetProxyBackupData: |
|
221 { |
|
222 iActiveBackupDataClient->InitialiseGetProxyBackupDataL(static_cast<TSecureId>(iCallbackArg1()), |
|
223 static_cast<TDriveNumber>(iCallbackArg2())); |
|
224 |
|
225 // Reprime the server |
|
226 PrimeServerForCallbackL(); |
|
227 } break; |
|
228 case EABCallbackInitialiseRestoreProxyBaseData: |
|
229 { |
|
230 iActiveBackupDataClient->InitialiseRestoreProxyBaseDataL(static_cast<TSecureId>( |
|
231 iCallbackArg1()), static_cast<TDriveNumber>(iCallbackArg2())); |
|
232 |
|
233 // Reprime the server |
|
234 PrimeServerForCallbackL(); |
|
235 } break; |
|
236 default: |
|
237 { |
|
238 // Call the server to leave with KErrNotSupported |
|
239 User::Leave(KErrNotSupported); |
|
240 } |
|
241 } |
|
242 |
|
243 // Set us up for another call |
|
244 SetActive(); |
|
245 |
|
246 } |
|
247 } |
|
248 |
|
249 void CActiveBackupCallbackHandler::PrimeServerForCallbackL() |
|
250 /** |
|
251 Reprime the server with a new IPC message to respond to |
|
252 */ |
|
253 { |
|
254 iClientSession.PrimeServerForCallbackL(iCallbackCommand, iCallbackArg1, iCallbackArg2, iStatus); |
|
255 } |
|
256 |
|
257 void CActiveBackupCallbackHandler::PrimeServerForCallbackWithResponseL(TInt aResponse) |
|
258 /** |
|
259 Reprime the server with a new IPC message to respond to, sending the result of the previous callback |
|
260 |
|
261 @param aResponse The response to send back to the server i.e. the result of the last callback made |
|
262 */ |
|
263 { |
|
264 iClientSession.PrimeServerForCallbackWithResponseL(iCallbackCommand, iCallbackArg1, iCallbackArg2, aResponse, iStatus); |
|
265 } |
|
266 |
|
267 void CActiveBackupCallbackHandler::PrimeServerForCallbackWithResponseL(TDesC8& aResponse) |
|
268 /** |
|
269 Reprime the server with a new IPC message to respond to, sending the result of the previous callback |
|
270 |
|
271 @param aResponse The response to send back to the server i.e. the result of the last callback made |
|
272 */ |
|
273 { |
|
274 iClientSession.PrimeServerForCallbackWithResponseL(iCallbackCommand, iCallbackArg1, iCallbackArg2, aResponse, iStatus); |
|
275 } |
|
276 |
|
277 TInt CActiveBackupCallbackHandler::RunError(TInt aError) |
|
278 /** |
|
279 Handle any leaves that occur from within the RunL and hence from the callback methods. In order |
|
280 to propagate leaves over to the PC client, they must be sent to the backup engine to leave to the |
|
281 client |
|
282 |
|
283 @param aError The leave code that has been trapped from within the RunL. Propagate this code to the engine |
|
284 @return Any unhandled leave code |
|
285 */ |
|
286 { |
|
287 iClientSession.PropagateLeave(aError); |
|
288 |
|
289 PrimeServerForCallbackL(); |
|
290 SetActive(); |
|
291 |
|
292 return KErrNone; // Is this correct or do we return the error code even though it's been handled? |
|
293 } |
|
294 |
|
295 void CActiveBackupCallbackHandler::DoCancel() |
|
296 /** |
|
297 Immediately cancel any outstanding calls to the backup engine |
|
298 */ |
|
299 { |
|
300 // we can't do anything with the error code here |
|
301 TRAP_IGNORE(iClientSession.CancelServerCallbackL()); |
|
302 } |
|
303 |
|
304 void CActiveBackupCallbackHandler::ConstructL() |
|
305 /** |
|
306 Add this object to the scheduler |
|
307 |
|
308 @panic KErrNotFound Debug only - If an ActiveScheduler is not installed |
|
309 @leave Release only - If an ActiveScheduler is not installed |
|
310 */ |
|
311 { |
|
312 if (!CActiveScheduler::Current()) |
|
313 { |
|
314 __ASSERT_DEBUG(0, Panic(KErrNotFound)); |
|
315 } |
|
316 |
|
317 // Add this AO to the scheduler |
|
318 CActiveScheduler::Add(this); |
|
319 SetActive(); |
|
320 } |
|
321 |
|
322 void CActiveBackupCallbackHandler::StartListeningForServerMessagesL() |
|
323 /** |
|
324 Send an asynchronous IPC message to the server in order that it has a vehicle for "initiating" |
|
325 a callback on iActiveBackupDataClient. This should only be called once as it will start the |
|
326 active scheduler |
|
327 */ |
|
328 { |
|
329 // Prime the server with the first prime for callback IPC message |
|
330 PrimeServerForCallbackL(); |
|
331 } |
|
332 |
|
333 TPtr8 CActiveBackupCallbackHandler::CreateFixedBufferL() |
|
334 /** |
|
335 Creates a buffer of the exact size. |
|
336 */ |
|
337 { |
|
338 delete iTransferBuffer; |
|
339 iTransferBuffer = NULL; |
|
340 |
|
341 iTransferBuffer = HBufC8::NewL(iCallbackArg1()); |
|
342 |
|
343 return TPtr8(const_cast<TUint8*>(iTransferBuffer->Ptr()), iCallbackArg1()); |
|
344 } |
|
345 } |
|
346 |