|
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 RABClientSession class. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 */ |
|
21 |
|
22 #include "abclientsession.h" |
|
23 #include "abclientserver.h" |
|
24 #include "panic.h" |
|
25 |
|
26 namespace conn |
|
27 { |
|
28 HBufC8* RABClientSession::GetDataFromServerLC(const TInt aDataLength, |
|
29 TABCallbackCommands aCallbackRequestingData) |
|
30 /** |
|
31 Following a callback call to the Active Backup Callback Handler, this method requests the data |
|
32 from the server. aDataLength will have been supplied by the original callback call from the server |
|
33 and all that remains is to make a synchronous call to get it copied over |
|
34 |
|
35 @param aDataLength The length of the data that will be received |
|
36 @param aCallbackRequestingData The callback enum identifying the callback requesting this data |
|
37 @return Pointer to a heap allocated descriptor containing data from the server |
|
38 */ |
|
39 { |
|
40 HBufC8* pReturnedData = HBufC8::NewLC(aDataLength); |
|
41 |
|
42 TPtr8 returnedData(pReturnedData->Des()); |
|
43 |
|
44 // Request that the server returns the promised data to the client for the specified callback |
|
45 User::LeaveIfError(SendReceive(EABMsgGetDataSync, |
|
46 TIpcArgs(static_cast<TInt>(aCallbackRequestingData), &returnedData))); |
|
47 |
|
48 return pReturnedData; |
|
49 } |
|
50 |
|
51 HBufC8* RABClientSession::GetDataFromServerLC(const TInt aDataLength, |
|
52 TABCallbackCommands aCallbackRequestingData, TDriveNumber& aDriveNum) |
|
53 /** |
|
54 Following a callback call to the Active Backup Callback Handler, this method requests the data |
|
55 from the server. aDataLength will have been supplied by the original callback call from the server |
|
56 and all that remains is to make a synchronous call to get it copied over. This should only be called |
|
57 from a ReceiveSnapshot callback |
|
58 |
|
59 @param aDataLength The length of the data that will be received |
|
60 @param aCallbackRequestingData The callback enum identifying the callback requesting this data |
|
61 @param aDriveNum The drive number |
|
62 |
|
63 @return Pointer to a heap allocated descriptor containing data from the server |
|
64 */ |
|
65 { |
|
66 TPckg<TDriveNumber> drvPkg(aDriveNum); |
|
67 HBufC8* pReturnedData = HBufC8::NewLC(aDataLength); |
|
68 |
|
69 TPtr8 returnedData(pReturnedData->Des()); |
|
70 |
|
71 // Request that the server returns the promised data to the client for the specified callback |
|
72 User::LeaveIfError(SendReceive(EABMsgGetDataSync, |
|
73 TIpcArgs(static_cast<TInt>(aCallbackRequestingData), &returnedData))); |
|
74 |
|
75 // Request that the server returns the drive number to the client for the specified callback |
|
76 TInt retVal = SendReceive(EABMsgGetDriveNumForSuppliedSnapshot); |
|
77 |
|
78 User::LeaveIfError(retVal); |
|
79 |
|
80 aDriveNum = static_cast<TDriveNumber>(retVal); |
|
81 |
|
82 return pReturnedData; |
|
83 } |
|
84 |
|
85 void RABClientSession::SendDataLengthToServerL(TDesC8& aData, TBool aFinished, |
|
86 TABCallbackCommands aCallbackSendingData) |
|
87 /** |
|
88 Send the length and finished flag back to the server. Limitations of IPC mean that we can only send |
|
89 fixed size data to the server, hence the length and finished flag are sent first so that the server |
|
90 may allocate the appropriate amount of space prior to the response containing the data |
|
91 |
|
92 @param aData Descriptor containing the data to send back to the server. Only the length of this |
|
93 is sent in this message |
|
94 @param aFinished Flag indicating that this is the last transfer from the client to server. If EFalse, |
|
95 the server must call the callback again |
|
96 @param aCallbackSendingData This |
|
97 */ |
|
98 { |
|
99 // Make the synchronous call back to the server telling it to allocate a big enough buffer |
|
100 // to handle the data transfer that will follow this |
|
101 User::LeaveIfError(SendReceive(EABMsgSendDataLength, TIpcArgs( |
|
102 static_cast<TInt>(aData.Size()), |
|
103 static_cast<TInt>(aFinished), |
|
104 static_cast<TInt>(aCallbackSendingData)))); |
|
105 } |
|
106 |
|
107 void RABClientSession::PrimeServerForCallbackL(TPckgBuf<TABCallbackCommands>& aCallback, |
|
108 TPckgBuf<TInt>& aArg1, TPckgBuf<TInt>& aArg2, TRequestStatus& aStatus) |
|
109 /** |
|
110 Send an async message to the server so that it can call us back when it's ready to make callback's |
|
111 |
|
112 @param aCallback This modifiable package buf is set by the server to indicate which callback to call |
|
113 @param aArg1 This is the first argument for the callback, set by the server |
|
114 @param aArg2 This is the second argument for the callback, set by the server |
|
115 @param aStatus The status |
|
116 */ |
|
117 { |
|
118 SendReceive(EABMsgPrimeForCallback, TIpcArgs(&aCallback, &aArg1, &aArg2), aStatus); |
|
119 } |
|
120 |
|
121 void RABClientSession::PrimeServerForCallbackWithResponseL(TPckgBuf<TABCallbackCommands>& aCallback, |
|
122 TPckgBuf<TInt>& aArg1, TPckgBuf<TInt>& aArg2, TInt aResult, TRequestStatus& aStatus) |
|
123 /** |
|
124 Send an async message to the server so that it can call us back when it's ready to make callback's. |
|
125 This call also returns a result from the previous callback for the server to respond to/return to the PC etc. |
|
126 |
|
127 @param aCallback This modifiable package buf is set by the server to indicate which callback to call |
|
128 @param aArg1 This is the first argument for the callback, set by the server |
|
129 @param aArg2 This is the second argument for the callback, set by the server |
|
130 @param aResult The return value of the previous callback to pass back to the server |
|
131 @param aStatus The status |
|
132 */ |
|
133 { |
|
134 SendReceive(EABMsgPrimeForCallbackAndResponse, TIpcArgs(&aCallback, &aArg1, &aArg2, aResult), aStatus); |
|
135 } |
|
136 |
|
137 void RABClientSession::PrimeServerForCallbackWithResponseL(TPckgBuf<TABCallbackCommands>& aCallback, |
|
138 TPckgBuf<TInt>& aArg1, TPckgBuf<TInt>& aArg2, TDesC8& aResult, TRequestStatus& aStatus) |
|
139 /** |
|
140 Send an async message to the server so that it can call us back when it's ready to make callback's. |
|
141 This call also returns a result from the previous callback for the server to respond to/return to the PC etc. |
|
142 |
|
143 @param aCallback This modifiable package buf is set by the server to indicate which callback to call |
|
144 @param aArg1 This is the first argument for the callback, set by the server |
|
145 @param aArg2 This is the second argument for the callback, set by the server |
|
146 @param aResult Data to send back to the server |
|
147 @param aStatus The status |
|
148 |
|
149 @pre A call to SendDataLengthToServerL must have preceeded this call so that the server may prepare to receive data |
|
150 */ |
|
151 { |
|
152 SendReceive(EABMsgPrimeForCallbackAndResponseDes, TIpcArgs(&aCallback, &aArg1, &aArg2, &aResult), aStatus); |
|
153 } |
|
154 |
|
155 void RABClientSession::PropagateLeave(TInt aLeaveCode) |
|
156 /** |
|
157 Send a synchronous IPC message to the server indicating that a leave has ocurred whilst executing a callback |
|
158 |
|
159 @param aLeaveCode The code to leave back to the server with |
|
160 @param aStatus The status |
|
161 */ |
|
162 { |
|
163 SendReceive(EABMsgPropagateLeave, TIpcArgs(aLeaveCode)); |
|
164 } |
|
165 |
|
166 void RABClientSession::BURModeInfoL(TDriveList& aDriveList, TBURPartType& aBackupType, TBackupIncType& aIncBackupType) |
|
167 /** |
|
168 This method returns the type(s) of backup / restore operation currently active |
|
169 |
|
170 @param aDriveList list of drives involved in backup and restore |
|
171 @param aBackupType enumerated type indicating whether a backup or restore |
|
172 is in progress and whether full or partial. |
|
173 @param aIncBackupType enumerated type indicating whetherr a backup is base |
|
174 or incremental. |
|
175 */ |
|
176 { |
|
177 TPckg<TBURPartType> partTypePkg(aBackupType); |
|
178 TPckg<TBackupIncType> incTypePkg(aIncBackupType); |
|
179 |
|
180 User::LeaveIfError(SendReceive(EABMsgBURModeInfo, TIpcArgs(&aDriveList, &partTypePkg, &incTypePkg))); |
|
181 } |
|
182 |
|
183 |
|
184 TBool RABClientSession::DoesPartialBURAffectMeL() |
|
185 /** |
|
186 This method can be called when a partial backup or restore is active and will indicate |
|
187 whether the calling process is expected to take part. If a full backup or restore is |
|
188 active then this method will return ETrue for all data owners. If no backup or restore |
|
189 is active then this method will return EFalse for all data owners. |
|
190 |
|
191 @return ETrue if the calling data owner is involved in the current backup or restore |
|
192 operation. |
|
193 */ |
|
194 { |
|
195 TPckgBuf<TBool> partialAffectsMe; |
|
196 |
|
197 User::LeaveIfError(SendReceive(EABMsgDoesPartialAffectMe, TIpcArgs(&partialAffectsMe))); |
|
198 |
|
199 return partialAffectsMe(); |
|
200 } |
|
201 |
|
202 |
|
203 void RABClientSession::ConfirmReadyForBURL(TInt aErrorCode) |
|
204 /** |
|
205 This method is called to indicate to the Secure Backup Server that the data owner is ready |
|
206 to participate in backup or restore. The data owner must call this method to indicate |
|
207 readiness or the Secure Backup Server will not request or supply backup data. |
|
208 |
|
209 N.B. The Secure Backup Server will supply snapshot data (if relevant) before a data |
|
210 owner indicates readiness as it assumes that the data owner requires snapshot data in |
|
211 order to prepare for a backp or restore. |
|
212 |
|
213 @param aErrorCode this should be set to KErrNone when the client is ready for |
|
214 backup or restore. If it is set to any other value then it indicates that the client |
|
215 cannot continue with the backup or restore and the error code will be supplied to |
|
216 the remote backup client. |
|
217 */ |
|
218 { |
|
219 User::LeaveIfError(SendReceive(EABMsgConfirmReadyForBUR, TIpcArgs(aErrorCode))); |
|
220 } |
|
221 |
|
222 void RABClientSession::CancelServerCallbackL() |
|
223 /** |
|
224 Inform the server that it can no longer call callbacks on the client |
|
225 */ |
|
226 { |
|
227 User::LeaveIfError(SendReceive(EABMsgClosingDownCallback)); |
|
228 } |
|
229 |
|
230 RABClientSession::RABClientSession() |
|
231 /** Class constructor. */ |
|
232 { |
|
233 } |
|
234 |
|
235 void RABClientSession::Close() |
|
236 /** Closes the Secure Backup Engine handle. */ |
|
237 { |
|
238 RSessionBase::Close(); |
|
239 } |
|
240 |
|
241 TInt RABClientSession::Connect() |
|
242 /** Connects the handle to the Secure Backup Engine. |
|
243 |
|
244 @return KErrNone if successful, KErrCouldNotConnect otherwise |
|
245 */ |
|
246 { |
|
247 TInt nRetry = KABRetryCount; |
|
248 TInt nRet = KErrNotFound; |
|
249 |
|
250 while(nRetry > 0 && nRet != KErrNone) |
|
251 { |
|
252 const TSecurityPolicy policy(static_cast<TSecureId>(KSBServerUID3)); |
|
253 nRet = CreateSession(KABServerName, Version(), KABASyncMessageSlots, EIpcSession_Unsharable,&policy); |
|
254 if(nRet == KErrNotFound || nRet == KErrServerTerminated) |
|
255 { |
|
256 StartServer(); |
|
257 } |
|
258 nRetry--; |
|
259 } |
|
260 |
|
261 return nRet; |
|
262 } |
|
263 |
|
264 TVersion RABClientSession::Version() const |
|
265 /** Returns the version of this API |
|
266 |
|
267 @return The version of this API |
|
268 */ |
|
269 { |
|
270 return TVersion (KABMajorVersionNumber, |
|
271 KABMinorVersionNumber, |
|
272 KABBuildVersionNumber); |
|
273 } |
|
274 |
|
275 // |
|
276 // Server startup code |
|
277 TInt RABClientSession::StartServer() |
|
278 /** Start the server as a thread on WINS or a process on ARM. |
|
279 |
|
280 Called by Connect when the kernel is unable to create a session |
|
281 with the AB server (if the process hosting it is not running). |
|
282 |
|
283 @return Standard Symbian OS code from RProcess/RThread create. |
|
284 */ |
|
285 { |
|
286 // |
|
287 // Servers UID |
|
288 const TUidType serverUid(KNullUid, KNullUid, KSBServerUID3); |
|
289 |
|
290 |
|
291 RProcess server; |
|
292 TInt nRet=server.Create(KSBImageName,KNullDesC,serverUid); |
|
293 if (nRet != KErrNone) |
|
294 { |
|
295 return nRet; |
|
296 } |
|
297 |
|
298 TRequestStatus stat; |
|
299 server.Rendezvous(stat); |
|
300 if (stat != KRequestPending) |
|
301 { |
|
302 server.Kill(0); |
|
303 } |
|
304 else |
|
305 { |
|
306 server.Resume(); |
|
307 } |
|
308 User::WaitForRequest(stat); |
|
309 return (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int(); |
|
310 |
|
311 } |
|
312 |
|
313 |
|
314 |
|
315 } // conn namespace |