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