sl@0
|
1 |
// Copyright (c) 1997-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 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <babackup.h>
|
sl@0
|
17 |
#include <bafl/backup_std.h>
|
sl@0
|
18 |
#include <e32std.h>
|
sl@0
|
19 |
#include <e32base.h>
|
sl@0
|
20 |
#include <baksrv.h>
|
sl@0
|
21 |
#include "Baksrvs.h"
|
sl@0
|
22 |
#include <e32math.h>
|
sl@0
|
23 |
#include <e32svr.h>
|
sl@0
|
24 |
#include <baflpan.h>
|
sl@0
|
25 |
|
sl@0
|
26 |
#define UNUSED_VAR(a) a = a
|
sl@0
|
27 |
|
sl@0
|
28 |
const TUid KServerUid3={0x10004900};
|
sl@0
|
29 |
const TInt KBADefaultPriority = CActive::EPriorityUserInput;
|
sl@0
|
30 |
_LIT(KBackupSrvName,"baksrvs");
|
sl@0
|
31 |
|
sl@0
|
32 |
//
|
sl@0
|
33 |
// class RBaBackupSession
|
sl@0
|
34 |
//
|
sl@0
|
35 |
|
sl@0
|
36 |
const TInt KNumConnectRetries =10;
|
sl@0
|
37 |
|
sl@0
|
38 |
|
sl@0
|
39 |
class RBaBackupSession : public RSessionBase
|
sl@0
|
40 |
{
|
sl@0
|
41 |
public:
|
sl@0
|
42 |
TInt Connect();
|
sl@0
|
43 |
void RegisterForNotifications(TRequestStatus& aStatus) const;
|
sl@0
|
44 |
void DeregisterForNotifications() const;
|
sl@0
|
45 |
void GetEvent(TDes& aFileName,MBackupObserver::TFileLockFlags& aFileFlag) const;
|
sl@0
|
46 |
void CloseAllFiles(MBackupObserver::TFileLockFlags aFlags,TRequestStatus& aStatus) const;
|
sl@0
|
47 |
void RestartApps() const;
|
sl@0
|
48 |
TInt CloseFile(const TDesC& aFileName,MBackupObserver::TFileLockFlags aFlags) const;
|
sl@0
|
49 |
void RestartFile(const TDesC& aFileName) const;
|
sl@0
|
50 |
TInt NotifyChangeFileLock(const TDesC& aFileName) const;
|
sl@0
|
51 |
void NotifyChangeFileLockCancel(const TDesC& aFileName) const;
|
sl@0
|
52 |
void CloseServer() const;
|
sl@0
|
53 |
void NotifyBackupOperation(const TBackupOperationAttributes& aBackupOperationAttributes);
|
sl@0
|
54 |
TBool IsBackupOperationRunning() const;
|
sl@0
|
55 |
void BackupOperationEventReady(TRequestStatus& aStatus, TPckgBuf<TBackupOperationAttributes>& aBackupOperationAttributes) const;
|
sl@0
|
56 |
void CancelOutstandingEventForBackupOperation() const;
|
sl@0
|
57 |
void GetBackupOperationEvent(TBackupOperationAttributes& aBackupOperationAttributes) const;
|
sl@0
|
58 |
void SetBackupOperationObserverIsPresent(TBool aObserverIsPresent) const;
|
sl@0
|
59 |
private:
|
sl@0
|
60 |
TInt StartServer();
|
sl@0
|
61 |
};
|
sl@0
|
62 |
|
sl@0
|
63 |
TInt RBaBackupSession::Connect()
|
sl@0
|
64 |
{
|
sl@0
|
65 |
TInt err=KErrNone;
|
sl@0
|
66 |
TInt retry=KNumConnectRetries;
|
sl@0
|
67 |
FOREVER
|
sl@0
|
68 |
{
|
sl@0
|
69 |
err=CreateSession(__BACKUP_SERVER_NAME_V2,TVersion(KBakServMajorVN,KBakServMinorVN,KBakServBuildVN),KBakServMessageSlots);
|
sl@0
|
70 |
if ((--retry>0) && ((err==KErrNotFound) || (err==KErrServerTerminated)))
|
sl@0
|
71 |
{
|
sl@0
|
72 |
err = StartServer();
|
sl@0
|
73 |
if ((err!=KErrNone) && (err!=KErrAlreadyExists))
|
sl@0
|
74 |
{
|
sl@0
|
75 |
break;
|
sl@0
|
76 |
}
|
sl@0
|
77 |
}
|
sl@0
|
78 |
else
|
sl@0
|
79 |
{
|
sl@0
|
80 |
break;
|
sl@0
|
81 |
}
|
sl@0
|
82 |
}
|
sl@0
|
83 |
return err;
|
sl@0
|
84 |
}
|
sl@0
|
85 |
|
sl@0
|
86 |
TInt RBaBackupSession::StartServer()
|
sl@0
|
87 |
{
|
sl@0
|
88 |
const TUidType serverUid(KNullUid,KNullUid,KServerUid3);
|
sl@0
|
89 |
TInt error=KErrNone;
|
sl@0
|
90 |
RProcess server;
|
sl@0
|
91 |
error = server.Create(KBackupSrvName,KNullDesC,serverUid);
|
sl@0
|
92 |
if(error!=KErrNone)
|
sl@0
|
93 |
return error;
|
sl@0
|
94 |
TRequestStatus stat;
|
sl@0
|
95 |
server.Rendezvous(stat);
|
sl@0
|
96 |
if (stat!=KRequestPending)
|
sl@0
|
97 |
server.Kill(0); // abort startup
|
sl@0
|
98 |
else
|
sl@0
|
99 |
server.Resume(); // logon OK - start the server
|
sl@0
|
100 |
User::WaitForRequest(stat); // wait for start or death
|
sl@0
|
101 |
// we can't use the 'exit reason' if the server panicked as this
|
sl@0
|
102 |
// is the panic 'reason' and may be '0' which cannot be distinguished
|
sl@0
|
103 |
// from KErrNone
|
sl@0
|
104 |
error=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
|
sl@0
|
105 |
server.Close();
|
sl@0
|
106 |
return error;
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
|
sl@0
|
110 |
void RBaBackupSession::RegisterForNotifications(TRequestStatus& aStatus) const
|
sl@0
|
111 |
{
|
sl@0
|
112 |
SendReceive(EBakOpCodeEventReady,aStatus);
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
void RBaBackupSession::DeregisterForNotifications() const
|
sl@0
|
116 |
{
|
sl@0
|
117 |
SendReceive(EBakOpCodeStopNotifications);
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
void RBaBackupSession::GetEvent(TDes& aFileName,MBackupObserver::TFileLockFlags& aFileFlag) const
|
sl@0
|
121 |
{
|
sl@0
|
122 |
TBuf<KMaxFileName+1> buf;
|
sl@0
|
123 |
if (SendReceive(EBakOpCodeGetEvent,TIpcArgs(&buf))!=KErrServerTerminated)
|
sl@0
|
124 |
{
|
sl@0
|
125 |
TBuf<1> num=buf.Left(1);
|
sl@0
|
126 |
buf.Delete(0,1);
|
sl@0
|
127 |
aFileName=buf;
|
sl@0
|
128 |
aFileFlag=(MBackupObserver::TFileLockFlags)(num[0]-'0');
|
sl@0
|
129 |
}
|
sl@0
|
130 |
}
|
sl@0
|
131 |
|
sl@0
|
132 |
void RBaBackupSession::CloseAllFiles(MBackupObserver::TFileLockFlags aFlags,TRequestStatus& aStatus) const
|
sl@0
|
133 |
{
|
sl@0
|
134 |
SendReceive(EBakOpCodeCloseAllFiles,TIpcArgs(aFlags),aStatus);
|
sl@0
|
135 |
}
|
sl@0
|
136 |
|
sl@0
|
137 |
void RBaBackupSession::RestartApps() const
|
sl@0
|
138 |
{
|
sl@0
|
139 |
SendReceive(EBakOpCodeRestartAll);
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
TInt RBaBackupSession::CloseFile(const TDesC& aFileName,MBackupObserver::TFileLockFlags aFlags) const
|
sl@0
|
143 |
{
|
sl@0
|
144 |
const TInt err=SendReceive(EBakOpCodeCloseFile,TIpcArgs(aFileName.Length(),&aFileName,aFlags));
|
sl@0
|
145 |
return err;
|
sl@0
|
146 |
}
|
sl@0
|
147 |
|
sl@0
|
148 |
void RBaBackupSession::RestartFile(const TDesC& aFileName) const
|
sl@0
|
149 |
{
|
sl@0
|
150 |
SendReceive(EBakOpCodeRestartFile,TIpcArgs(aFileName.Length(),&aFileName));
|
sl@0
|
151 |
}
|
sl@0
|
152 |
|
sl@0
|
153 |
TInt RBaBackupSession::NotifyChangeFileLock(const TDesC& aFileName) const
|
sl@0
|
154 |
{
|
sl@0
|
155 |
return SendReceive(EBakOpCodeNotifyLockChange,TIpcArgs(aFileName.Length(),&aFileName));
|
sl@0
|
156 |
}
|
sl@0
|
157 |
|
sl@0
|
158 |
void RBaBackupSession::NotifyChangeFileLockCancel(const TDesC& aFileName) const
|
sl@0
|
159 |
{
|
sl@0
|
160 |
SendReceive(EBakOpCodeNotifyLockChangeCancel,TIpcArgs(aFileName.Length(),&aFileName));
|
sl@0
|
161 |
}
|
sl@0
|
162 |
|
sl@0
|
163 |
void RBaBackupSession::CloseServer() const
|
sl@0
|
164 |
{
|
sl@0
|
165 |
Send(EBakOpCodeCloseServer);
|
sl@0
|
166 |
}
|
sl@0
|
167 |
|
sl@0
|
168 |
void RBaBackupSession::NotifyBackupOperation(const TBackupOperationAttributes& aBackupOperationAttributes)
|
sl@0
|
169 |
{
|
sl@0
|
170 |
TPckgC<TBackupOperationAttributes> backupOpAttPkg(aBackupOperationAttributes);
|
sl@0
|
171 |
SendReceive(EBakOpCodeNotifyBackupOperation, TIpcArgs(&backupOpAttPkg));
|
sl@0
|
172 |
}
|
sl@0
|
173 |
|
sl@0
|
174 |
void RBaBackupSession::CancelOutstandingEventForBackupOperation() const
|
sl@0
|
175 |
{
|
sl@0
|
176 |
SendReceive(EBakOpCodeCancelOutstandingBackupOperationEvent);
|
sl@0
|
177 |
}
|
sl@0
|
178 |
|
sl@0
|
179 |
TBool RBaBackupSession::IsBackupOperationRunning() const
|
sl@0
|
180 |
{
|
sl@0
|
181 |
TBool isRunning=EFalse;
|
sl@0
|
182 |
TPckg<TBool> pkg(isRunning);
|
sl@0
|
183 |
SendReceive(EBakOpCodeGetBackupOperationState, TIpcArgs(&pkg));
|
sl@0
|
184 |
return pkg();
|
sl@0
|
185 |
}
|
sl@0
|
186 |
|
sl@0
|
187 |
void RBaBackupSession::BackupOperationEventReady(TRequestStatus& aStatus, TPckgBuf<TBackupOperationAttributes>& aBackupOperationAttributes) const
|
sl@0
|
188 |
{
|
sl@0
|
189 |
SendReceive(EBakOpCodeBackupOperationEventReady,TIpcArgs(&aBackupOperationAttributes),aStatus);
|
sl@0
|
190 |
}
|
sl@0
|
191 |
|
sl@0
|
192 |
void RBaBackupSession::GetBackupOperationEvent(TBackupOperationAttributes& aBackupOperationAttributes) const
|
sl@0
|
193 |
{
|
sl@0
|
194 |
TPckg<TBackupOperationAttributes> backupOpAttPkg(aBackupOperationAttributes);
|
sl@0
|
195 |
SendReceive(EBakOpCodeGetBackupOperationEvent, TIpcArgs(&backupOpAttPkg));
|
sl@0
|
196 |
}
|
sl@0
|
197 |
|
sl@0
|
198 |
void RBaBackupSession::SetBackupOperationObserverIsPresent(TBool aObserverIsPresent) const
|
sl@0
|
199 |
{
|
sl@0
|
200 |
Send(EBakOpCodeSetBackupOperationObserverIsPresent, TIpcArgs(aObserverIsPresent));
|
sl@0
|
201 |
}
|
sl@0
|
202 |
|
sl@0
|
203 |
//
|
sl@0
|
204 |
// class CBaLockChangeNotifier
|
sl@0
|
205 |
//
|
sl@0
|
206 |
|
sl@0
|
207 |
NONSHARABLE_CLASS(CBaLockChangeNotifier) : public CActive
|
sl@0
|
208 |
{
|
sl@0
|
209 |
public:
|
sl@0
|
210 |
static CBaLockChangeNotifier* NewL(RBaBackupSession& aBackupSession);
|
sl@0
|
211 |
~CBaLockChangeNotifier();
|
sl@0
|
212 |
void AddL(const TDesC& aFileName, MBackupObserver& aObserver);
|
sl@0
|
213 |
void Remove(const TDesC& aFileName);
|
sl@0
|
214 |
protected:
|
sl@0
|
215 |
void StartNotifications();
|
sl@0
|
216 |
void StopNotifications();
|
sl@0
|
217 |
private: // from CActive
|
sl@0
|
218 |
void DoCancel();
|
sl@0
|
219 |
void RunL();
|
sl@0
|
220 |
private:
|
sl@0
|
221 |
CBaLockChangeNotifier(RBaBackupSession& aBackupSession);
|
sl@0
|
222 |
void DoRunL();
|
sl@0
|
223 |
TInt Find(const TDesC& aFileName) const;
|
sl@0
|
224 |
private:
|
sl@0
|
225 |
class TFileItem
|
sl@0
|
226 |
{
|
sl@0
|
227 |
public:
|
sl@0
|
228 |
TFileItem(HBufC* aFile,MBackupObserver& aObserver);
|
sl@0
|
229 |
public:
|
sl@0
|
230 |
HBufC* iFile;
|
sl@0
|
231 |
MBackupObserver& iObserver;
|
sl@0
|
232 |
};
|
sl@0
|
233 |
private:
|
sl@0
|
234 |
RBaBackupSession& iBackupSession;
|
sl@0
|
235 |
RArray<TFileItem> iFileItems;
|
sl@0
|
236 |
};
|
sl@0
|
237 |
|
sl@0
|
238 |
CBaLockChangeNotifier::TFileItem::TFileItem(HBufC* aFile,MBackupObserver& aObserver)
|
sl@0
|
239 |
: iFile(aFile),
|
sl@0
|
240 |
iObserver(aObserver)
|
sl@0
|
241 |
{}
|
sl@0
|
242 |
|
sl@0
|
243 |
CBaLockChangeNotifier* CBaLockChangeNotifier::NewL(RBaBackupSession& aBackupSession)
|
sl@0
|
244 |
{ // static
|
sl@0
|
245 |
CBaLockChangeNotifier* self=new(ELeave) CBaLockChangeNotifier(aBackupSession);
|
sl@0
|
246 |
CActiveScheduler::Add(self);
|
sl@0
|
247 |
return self;
|
sl@0
|
248 |
}
|
sl@0
|
249 |
|
sl@0
|
250 |
CBaLockChangeNotifier::~CBaLockChangeNotifier()
|
sl@0
|
251 |
{
|
sl@0
|
252 |
Cancel();
|
sl@0
|
253 |
|
sl@0
|
254 |
const TInt count=iFileItems.Count();
|
sl@0
|
255 |
for (TInt ii=0;ii<count;ii++)
|
sl@0
|
256 |
{
|
sl@0
|
257 |
delete iFileItems[ii].iFile;
|
sl@0
|
258 |
}
|
sl@0
|
259 |
iFileItems.Close();
|
sl@0
|
260 |
}
|
sl@0
|
261 |
|
sl@0
|
262 |
void CBaLockChangeNotifier::StartNotifications()
|
sl@0
|
263 |
{
|
sl@0
|
264 |
if(!IsActive())
|
sl@0
|
265 |
{
|
sl@0
|
266 |
iBackupSession.RegisterForNotifications(iStatus);
|
sl@0
|
267 |
SetActive();
|
sl@0
|
268 |
}
|
sl@0
|
269 |
}
|
sl@0
|
270 |
|
sl@0
|
271 |
void CBaLockChangeNotifier:: StopNotifications()
|
sl@0
|
272 |
{
|
sl@0
|
273 |
const TInt count=iFileItems.Count();
|
sl@0
|
274 |
|
sl@0
|
275 |
if(count==0)
|
sl@0
|
276 |
{
|
sl@0
|
277 |
Cancel();
|
sl@0
|
278 |
}
|
sl@0
|
279 |
}
|
sl@0
|
280 |
|
sl@0
|
281 |
void CBaLockChangeNotifier::AddL(const TDesC& aFileName, MBackupObserver& aObserver)
|
sl@0
|
282 |
{
|
sl@0
|
283 |
StartNotifications();
|
sl@0
|
284 |
|
sl@0
|
285 |
HBufC* file=aFileName.AllocLC();
|
sl@0
|
286 |
TFileItem fileItem(file,aObserver);
|
sl@0
|
287 |
User::LeaveIfError(iFileItems.Append(fileItem));
|
sl@0
|
288 |
CleanupStack::Pop(); // file
|
sl@0
|
289 |
const TInt err=iBackupSession.NotifyChangeFileLock(aFileName);
|
sl@0
|
290 |
if (err!=KErrNone)
|
sl@0
|
291 |
{
|
sl@0
|
292 |
delete file;
|
sl@0
|
293 |
iFileItems.Remove(iFileItems.Count()-1);
|
sl@0
|
294 |
iFileItems.Compress();
|
sl@0
|
295 |
User::Leave(err);
|
sl@0
|
296 |
}
|
sl@0
|
297 |
}
|
sl@0
|
298 |
|
sl@0
|
299 |
void CBaLockChangeNotifier::Remove(const TDesC& aFileName)
|
sl@0
|
300 |
{
|
sl@0
|
301 |
const TInt index=Find(aFileName);
|
sl@0
|
302 |
if (index!=KErrNotFound)
|
sl@0
|
303 |
{
|
sl@0
|
304 |
const TFileItem& fileItem=iFileItems[index];
|
sl@0
|
305 |
iBackupSession.NotifyChangeFileLockCancel(*fileItem.iFile);
|
sl@0
|
306 |
delete fileItem.iFile;
|
sl@0
|
307 |
iFileItems.Remove(index);
|
sl@0
|
308 |
iFileItems.Compress();
|
sl@0
|
309 |
}
|
sl@0
|
310 |
|
sl@0
|
311 |
StopNotifications();
|
sl@0
|
312 |
}
|
sl@0
|
313 |
|
sl@0
|
314 |
|
sl@0
|
315 |
void CBaLockChangeNotifier::DoCancel()
|
sl@0
|
316 |
{
|
sl@0
|
317 |
const TInt count=iFileItems.Count();
|
sl@0
|
318 |
|
sl@0
|
319 |
// release the locks on all outstandng files in this session
|
sl@0
|
320 |
for (TInt ii=0;ii<count;ii++)
|
sl@0
|
321 |
{
|
sl@0
|
322 |
const TFileItem& fileItem=iFileItems[ii];
|
sl@0
|
323 |
iBackupSession.NotifyChangeFileLockCancel(*fileItem.iFile);
|
sl@0
|
324 |
}
|
sl@0
|
325 |
iBackupSession.DeregisterForNotifications();
|
sl@0
|
326 |
}
|
sl@0
|
327 |
|
sl@0
|
328 |
void CBaLockChangeNotifier::RunL()
|
sl@0
|
329 |
{
|
sl@0
|
330 |
TRAPD(err,DoRunL());
|
sl@0
|
331 |
if (err!=KErrServerTerminated)
|
sl@0
|
332 |
{
|
sl@0
|
333 |
StartNotifications();
|
sl@0
|
334 |
}
|
sl@0
|
335 |
User::LeaveIfError(err);
|
sl@0
|
336 |
}
|
sl@0
|
337 |
|
sl@0
|
338 |
CBaLockChangeNotifier::CBaLockChangeNotifier(RBaBackupSession& aBackupSession)
|
sl@0
|
339 |
: CActive(KBADefaultPriority), iBackupSession(aBackupSession)
|
sl@0
|
340 |
{}
|
sl@0
|
341 |
|
sl@0
|
342 |
|
sl@0
|
343 |
void CBaLockChangeNotifier::DoRunL()
|
sl@0
|
344 |
{
|
sl@0
|
345 |
const TInt status=iStatus.Int();
|
sl@0
|
346 |
|
sl@0
|
347 |
if (status<0)
|
sl@0
|
348 |
{
|
sl@0
|
349 |
User::Leave(status);
|
sl@0
|
350 |
}
|
sl@0
|
351 |
TFileName fileName;
|
sl@0
|
352 |
MBackupObserver::TFileLockFlags fileFlag;
|
sl@0
|
353 |
iBackupSession.GetEvent(fileName,fileFlag);
|
sl@0
|
354 |
TInt err=KErrNone;
|
sl@0
|
355 |
const TInt count=iFileItems.Count();
|
sl@0
|
356 |
for (TInt ii=0;ii<count;ii++)
|
sl@0
|
357 |
{
|
sl@0
|
358 |
const TFileItem& fileItem=iFileItems[ii];
|
sl@0
|
359 |
if (fileItem.iFile->MatchF(fileName)==0)
|
sl@0
|
360 |
{
|
sl@0
|
361 |
TRAPD(r,fileItem.iObserver.ChangeFileLockL(*fileItem.iFile,fileFlag));
|
sl@0
|
362 |
if (r!=KErrNone && err==KErrNone)
|
sl@0
|
363 |
{
|
sl@0
|
364 |
err=r;
|
sl@0
|
365 |
}
|
sl@0
|
366 |
}
|
sl@0
|
367 |
}
|
sl@0
|
368 |
User::LeaveIfError(err);
|
sl@0
|
369 |
}
|
sl@0
|
370 |
|
sl@0
|
371 |
TInt CBaLockChangeNotifier::Find(const TDesC& aFileName) const
|
sl@0
|
372 |
{
|
sl@0
|
373 |
TInt index=KErrNotFound;
|
sl@0
|
374 |
const TInt count=iFileItems.Count();
|
sl@0
|
375 |
for (TInt ii=0;ii<count;ii++)
|
sl@0
|
376 |
{
|
sl@0
|
377 |
const TFileItem& fileItem=iFileItems[ii];
|
sl@0
|
378 |
if (*fileItem.iFile==aFileName)
|
sl@0
|
379 |
{
|
sl@0
|
380 |
index=ii;
|
sl@0
|
381 |
break;
|
sl@0
|
382 |
}
|
sl@0
|
383 |
}
|
sl@0
|
384 |
return index;
|
sl@0
|
385 |
}
|
sl@0
|
386 |
|
sl@0
|
387 |
//
|
sl@0
|
388 |
// class CBaBackupOperationNotifier
|
sl@0
|
389 |
//
|
sl@0
|
390 |
|
sl@0
|
391 |
NONSHARABLE_CLASS(CBaBackupOperationNotifier) : public CActive
|
sl@0
|
392 |
{
|
sl@0
|
393 |
public:
|
sl@0
|
394 |
static CBaBackupOperationNotifier* NewL(RBaBackupSession& aBackupSession);
|
sl@0
|
395 |
~CBaBackupOperationNotifier();
|
sl@0
|
396 |
void AddBackupOperationObserverL(MBackupOperationObserver& aBackupSession);
|
sl@0
|
397 |
void RemoveBackupOperationObserver(MBackupOperationObserver& aBackupSession);
|
sl@0
|
398 |
private: // from CActive
|
sl@0
|
399 |
void DoCancel();
|
sl@0
|
400 |
void RunL();
|
sl@0
|
401 |
private:
|
sl@0
|
402 |
CBaBackupOperationNotifier(RBaBackupSession& aBackupSession);
|
sl@0
|
403 |
void Queue();
|
sl@0
|
404 |
void DoRunL();
|
sl@0
|
405 |
private:
|
sl@0
|
406 |
RPointerArray<MBackupOperationObserver> iObservers;
|
sl@0
|
407 |
RBaBackupSession& iBackupSession;
|
sl@0
|
408 |
TPckgBuf<TBackupOperationAttributes> iBackupOperationAttributes;
|
sl@0
|
409 |
};
|
sl@0
|
410 |
|
sl@0
|
411 |
|
sl@0
|
412 |
CBaBackupOperationNotifier* CBaBackupOperationNotifier::NewL(RBaBackupSession& aBackupSession)
|
sl@0
|
413 |
{ // static
|
sl@0
|
414 |
CBaBackupOperationNotifier* self=new(ELeave) CBaBackupOperationNotifier(aBackupSession);
|
sl@0
|
415 |
CActiveScheduler::Add(self);
|
sl@0
|
416 |
return self;
|
sl@0
|
417 |
}
|
sl@0
|
418 |
|
sl@0
|
419 |
CBaBackupOperationNotifier::~CBaBackupOperationNotifier()
|
sl@0
|
420 |
{
|
sl@0
|
421 |
Cancel();
|
sl@0
|
422 |
iObservers.Reset();
|
sl@0
|
423 |
iObservers.Close();
|
sl@0
|
424 |
}
|
sl@0
|
425 |
|
sl@0
|
426 |
void CBaBackupOperationNotifier::AddBackupOperationObserverL(MBackupOperationObserver& aBackupOperationObserver)
|
sl@0
|
427 |
{
|
sl@0
|
428 |
const TInt index = iObservers.Find(&aBackupOperationObserver);
|
sl@0
|
429 |
if (index == KErrNotFound)
|
sl@0
|
430 |
{
|
sl@0
|
431 |
User::LeaveIfError(iObservers.Append(&aBackupOperationObserver));
|
sl@0
|
432 |
if (iBackupSession.IsBackupOperationRunning())
|
sl@0
|
433 |
{
|
sl@0
|
434 |
TBackupOperationAttributes backupOperationAttributes;
|
sl@0
|
435 |
iBackupSession.GetBackupOperationEvent(backupOperationAttributes);
|
sl@0
|
436 |
aBackupOperationObserver.HandleBackupOperationEventL(backupOperationAttributes);
|
sl@0
|
437 |
}
|
sl@0
|
438 |
}
|
sl@0
|
439 |
Queue();
|
sl@0
|
440 |
}
|
sl@0
|
441 |
|
sl@0
|
442 |
void CBaBackupOperationNotifier::RemoveBackupOperationObserver(MBackupOperationObserver& aBackupOperationObserver)
|
sl@0
|
443 |
{
|
sl@0
|
444 |
const TInt index = iObservers.Find(&aBackupOperationObserver);
|
sl@0
|
445 |
if (index != KErrNotFound)
|
sl@0
|
446 |
{
|
sl@0
|
447 |
iObservers.Remove(index);
|
sl@0
|
448 |
if (iObservers.Count() == 0)
|
sl@0
|
449 |
{
|
sl@0
|
450 |
iBackupSession.CancelOutstandingEventForBackupOperation();
|
sl@0
|
451 |
iBackupSession.SetBackupOperationObserverIsPresent(EFalse);
|
sl@0
|
452 |
}
|
sl@0
|
453 |
}
|
sl@0
|
454 |
}
|
sl@0
|
455 |
|
sl@0
|
456 |
void CBaBackupOperationNotifier::DoCancel()
|
sl@0
|
457 |
{
|
sl@0
|
458 |
TBackupOperationAttributes backupOperationAttributes;
|
sl@0
|
459 |
iBackupSession.GetBackupOperationEvent(backupOperationAttributes);
|
sl@0
|
460 |
const TInt count = iObservers.Count();
|
sl@0
|
461 |
for (TInt index=0; index<count; ++index)
|
sl@0
|
462 |
{
|
sl@0
|
463 |
// TRAP and ignore the errCode
|
sl@0
|
464 |
TRAPD(errCode, iObservers[index]->HandleBackupOperationEventL(backupOperationAttributes));
|
sl@0
|
465 |
UNUSED_VAR(errCode);
|
sl@0
|
466 |
}
|
sl@0
|
467 |
iBackupSession.CancelOutstandingEventForBackupOperation();
|
sl@0
|
468 |
}
|
sl@0
|
469 |
|
sl@0
|
470 |
void CBaBackupOperationNotifier::RunL()
|
sl@0
|
471 |
{
|
sl@0
|
472 |
const TInt status=iStatus.Int();
|
sl@0
|
473 |
if (status!=KErrCancel && iObservers.Count()>0)
|
sl@0
|
474 |
{
|
sl@0
|
475 |
TRAPD(err,DoRunL());
|
sl@0
|
476 |
if (err!=KErrServerTerminated)
|
sl@0
|
477 |
{
|
sl@0
|
478 |
Queue();
|
sl@0
|
479 |
}
|
sl@0
|
480 |
User::LeaveIfError(err);
|
sl@0
|
481 |
}
|
sl@0
|
482 |
}
|
sl@0
|
483 |
|
sl@0
|
484 |
CBaBackupOperationNotifier::CBaBackupOperationNotifier(RBaBackupSession& aBackupSession)
|
sl@0
|
485 |
: CActive(EPriorityStandard), iBackupSession(aBackupSession)
|
sl@0
|
486 |
{}
|
sl@0
|
487 |
|
sl@0
|
488 |
void CBaBackupOperationNotifier::Queue()
|
sl@0
|
489 |
{
|
sl@0
|
490 |
if (!IsActive())
|
sl@0
|
491 |
{
|
sl@0
|
492 |
iStatus=KRequestPending;
|
sl@0
|
493 |
SetActive();
|
sl@0
|
494 |
iBackupSession.SetBackupOperationObserverIsPresent(ETrue);
|
sl@0
|
495 |
iBackupSession.BackupOperationEventReady(iStatus, iBackupOperationAttributes);
|
sl@0
|
496 |
}
|
sl@0
|
497 |
}
|
sl@0
|
498 |
|
sl@0
|
499 |
void CBaBackupOperationNotifier::DoRunL()
|
sl@0
|
500 |
{
|
sl@0
|
501 |
const TInt status=iStatus.Int();
|
sl@0
|
502 |
if (status<0)
|
sl@0
|
503 |
{
|
sl@0
|
504 |
User::Leave(status);
|
sl@0
|
505 |
}
|
sl@0
|
506 |
const TInt count = iObservers.Count();
|
sl@0
|
507 |
for (TInt index=0; index<count; ++index)
|
sl@0
|
508 |
{
|
sl@0
|
509 |
iObservers[index]->HandleBackupOperationEventL(iBackupOperationAttributes());
|
sl@0
|
510 |
}
|
sl@0
|
511 |
}
|
sl@0
|
512 |
|
sl@0
|
513 |
//
|
sl@0
|
514 |
// class CBaBackupSessionWrapper
|
sl@0
|
515 |
//
|
sl@0
|
516 |
|
sl@0
|
517 |
/**
|
sl@0
|
518 |
* Returns a newly created CBaBackupSessionWrapper, passing ownership immediately
|
sl@0
|
519 |
*/
|
sl@0
|
520 |
EXPORT_C CBaBackupSessionWrapper* CBaBackupSessionWrapper::NewL()
|
sl@0
|
521 |
{ // static
|
sl@0
|
522 |
CBaBackupSessionWrapper* self=new(ELeave) CBaBackupSessionWrapper();
|
sl@0
|
523 |
CleanupStack::PushL(self);
|
sl@0
|
524 |
self->ConstructL();
|
sl@0
|
525 |
CleanupStack::Pop(); // self
|
sl@0
|
526 |
return self;
|
sl@0
|
527 |
}
|
sl@0
|
528 |
|
sl@0
|
529 |
/**
|
sl@0
|
530 |
* D'tor. Any files or apps that have been closed will be restarted
|
sl@0
|
531 |
*/
|
sl@0
|
532 |
EXPORT_C CBaBackupSessionWrapper::~CBaBackupSessionWrapper()
|
sl@0
|
533 |
{
|
sl@0
|
534 |
delete iLockChangeNotifier;
|
sl@0
|
535 |
delete iBackupOperationNotifier;
|
sl@0
|
536 |
if (iBackupSession)
|
sl@0
|
537 |
{
|
sl@0
|
538 |
iBackupSession->Close();
|
sl@0
|
539 |
delete iBackupSession;
|
sl@0
|
540 |
}
|
sl@0
|
541 |
}
|
sl@0
|
542 |
|
sl@0
|
543 |
/**
|
sl@0
|
544 |
Register the specified file to the server. The given observer will be called back when
|
sl@0
|
545 |
the lock state of the file should be modified
|
sl@0
|
546 |
|
sl@0
|
547 |
@param aFileName the name of the file to be observed.
|
sl@0
|
548 |
@param aObserver the observer which will be called back when the lock state of the file should be modified.
|
sl@0
|
549 |
|
sl@0
|
550 |
@leave KErrServerBusy if the server is busy with the other client or under CloseAll operation. KErrNoMemory
|
sl@0
|
551 |
if not enough memory to register this file.
|
sl@0
|
552 |
*/
|
sl@0
|
553 |
EXPORT_C void CBaBackupSessionWrapper::RegisterFileL(const TDesC& aFileName,MBackupObserver& aObserver)
|
sl@0
|
554 |
{
|
sl@0
|
555 |
if (!iLockChangeNotifier)
|
sl@0
|
556 |
{
|
sl@0
|
557 |
iLockChangeNotifier=CBaLockChangeNotifier::NewL(*iBackupSession);
|
sl@0
|
558 |
}
|
sl@0
|
559 |
|
sl@0
|
560 |
__ASSERT_ALWAYS(iLockChangeNotifier, Panic(EBafPanicNullPointer));
|
sl@0
|
561 |
iLockChangeNotifier->AddL(aFileName,aObserver);
|
sl@0
|
562 |
}
|
sl@0
|
563 |
|
sl@0
|
564 |
/**
|
sl@0
|
565 |
* Stop sending this client requests to alter the lock state of aFileName
|
sl@0
|
566 |
*/
|
sl@0
|
567 |
EXPORT_C void CBaBackupSessionWrapper::DeregisterFile(const TDesC& aFileName)
|
sl@0
|
568 |
{
|
sl@0
|
569 |
if(iLockChangeNotifier)
|
sl@0
|
570 |
iLockChangeNotifier->Remove(aFileName);
|
sl@0
|
571 |
}
|
sl@0
|
572 |
|
sl@0
|
573 |
/**
|
sl@0
|
574 |
Closes all non-system apps and signal all registered files to have their locks altered according to aFlags.
|
sl@0
|
575 |
Returns immediately before having finished all processing. aStatus will be completed when everything is
|
sl@0
|
576 |
closed or closing has completed. Possible error codes are
|
sl@0
|
577 |
KErrNoMemory - Not enough memory to signal all apps/files to close
|
sl@0
|
578 |
KErrServerBusy - Another client has some files closed - No-one else should attempt any backup operation
|
sl@0
|
579 |
KErrLocked - Not all apps were successfully closed
|
sl@0
|
580 |
In all cases, an undefined number of apps/files may have been closed and backup may still be possible although
|
sl@0
|
581 |
install/restore operations should not be attempted.
|
sl@0
|
582 |
|
sl@0
|
583 |
@param aFlags the file lock state to request the other clients with.
|
sl@0
|
584 |
@param aStatus the request status to be completed when all files have been closed.
|
sl@0
|
585 |
@publishedPartner
|
sl@0
|
586 |
@released
|
sl@0
|
587 |
@capability WriteDeviceData
|
sl@0
|
588 |
*/
|
sl@0
|
589 |
EXPORT_C void CBaBackupSessionWrapper::CloseAll(MBackupObserver::TFileLockFlags aFlags,TRequestStatus& aStatus)
|
sl@0
|
590 |
{
|
sl@0
|
591 |
iBackupSession->CloseAllFiles(aFlags,aStatus);
|
sl@0
|
592 |
}
|
sl@0
|
593 |
|
sl@0
|
594 |
/**
|
sl@0
|
595 |
* Opposite of CloseAll. Can safely be called nothing has been closed by this client
|
sl@0
|
596 |
*
|
sl@0
|
597 |
* @publishedPartner
|
sl@0
|
598 |
* @released
|
sl@0
|
599 |
* @capability WriteDeviceData
|
sl@0
|
600 |
*/
|
sl@0
|
601 |
EXPORT_C void CBaBackupSessionWrapper::RestartAll()
|
sl@0
|
602 |
{
|
sl@0
|
603 |
iBackupSession->RestartApps();
|
sl@0
|
604 |
}
|
sl@0
|
605 |
|
sl@0
|
606 |
/**
|
sl@0
|
607 |
Close or reduce use of aFileName depending on the state of aFlags.
|
sl@0
|
608 |
|
sl@0
|
609 |
@param aFileName the name of the file to be closed / changed the file lock state.
|
sl@0
|
610 |
@param aFlag the file lock state to change to.
|
sl@0
|
611 |
@leave KErrNoMemory if not enough memory to signal the files to close. KErrServerIsBusy if another client
|
sl@0
|
612 |
has some files being closed.
|
sl@0
|
613 |
@publishedPartner
|
sl@0
|
614 |
@released
|
sl@0
|
615 |
@capability WriteDeviceData
|
sl@0
|
616 |
*/
|
sl@0
|
617 |
EXPORT_C void CBaBackupSessionWrapper::CloseFileL(const TDesC& aFileName,MBackupObserver::TFileLockFlags aFlags)
|
sl@0
|
618 |
{
|
sl@0
|
619 |
User::LeaveIfError(iBackupSession->CloseFile(aFileName,aFlags));
|
sl@0
|
620 |
}
|
sl@0
|
621 |
|
sl@0
|
622 |
/**
|
sl@0
|
623 |
* Opposite of CloseFileL. Can be safely called if CloseFileL hasn't been called before
|
sl@0
|
624 |
*
|
sl@0
|
625 |
* @publishedPartner
|
sl@0
|
626 |
* @released
|
sl@0
|
627 |
* @capability WriteDeviceData
|
sl@0
|
628 |
*/
|
sl@0
|
629 |
EXPORT_C void CBaBackupSessionWrapper::RestartFile(const TDesC& aFileName)
|
sl@0
|
630 |
{
|
sl@0
|
631 |
iBackupSession->RestartFile(aFileName);
|
sl@0
|
632 |
}
|
sl@0
|
633 |
|
sl@0
|
634 |
CBaBackupSessionWrapper::CBaBackupSessionWrapper()
|
sl@0
|
635 |
{}
|
sl@0
|
636 |
|
sl@0
|
637 |
void CBaBackupSessionWrapper::ConstructL()
|
sl@0
|
638 |
{
|
sl@0
|
639 |
iBackupSession=new(ELeave) RBaBackupSession();
|
sl@0
|
640 |
User::LeaveIfError(iBackupSession->Connect());
|
sl@0
|
641 |
}
|
sl@0
|
642 |
|
sl@0
|
643 |
|
sl@0
|
644 |
/**
|
sl@0
|
645 |
* Registers the observer aBackupOperationObserver for getting notifications whether a backup or
|
sl@0
|
646 |
* restore operation starts or ends.
|
sl@0
|
647 |
*
|
sl@0
|
648 |
* @since App-Framework_6.2
|
sl@0
|
649 |
*/
|
sl@0
|
650 |
EXPORT_C void CBaBackupSessionWrapper::RegisterBackupOperationObserverL(MBackupOperationObserver& aBackupOperationObserver)
|
sl@0
|
651 |
{
|
sl@0
|
652 |
if (!iBackupOperationNotifier)
|
sl@0
|
653 |
{
|
sl@0
|
654 |
iBackupOperationNotifier=CBaBackupOperationNotifier::NewL(*iBackupSession);
|
sl@0
|
655 |
}
|
sl@0
|
656 |
iBackupOperationNotifier->AddBackupOperationObserverL(aBackupOperationObserver);
|
sl@0
|
657 |
}
|
sl@0
|
658 |
|
sl@0
|
659 |
/**
|
sl@0
|
660 |
* De-registers the observer aBackupOperationObserver for getting notifications whether a backup or
|
sl@0
|
661 |
* restore operation starts or ends.
|
sl@0
|
662 |
*
|
sl@0
|
663 |
* @since App-Framework_6.2
|
sl@0
|
664 |
*/
|
sl@0
|
665 |
EXPORT_C void CBaBackupSessionWrapper::DeRegisterBackupOperationObserver(MBackupOperationObserver& aBackupOperationObserver)
|
sl@0
|
666 |
{
|
sl@0
|
667 |
if (iBackupOperationNotifier)
|
sl@0
|
668 |
{
|
sl@0
|
669 |
iBackupOperationNotifier->RemoveBackupOperationObserver(aBackupOperationObserver);
|
sl@0
|
670 |
}
|
sl@0
|
671 |
}
|
sl@0
|
672 |
|
sl@0
|
673 |
/**
|
sl@0
|
674 |
* Returns ETrue when either a backup or restore operation is running, otherwise it retunrs EFalse.
|
sl@0
|
675 |
*
|
sl@0
|
676 |
* @since App-Framework_6.2
|
sl@0
|
677 |
*/
|
sl@0
|
678 |
EXPORT_C TBool CBaBackupSessionWrapper::IsBackupOperationRunning() const
|
sl@0
|
679 |
{
|
sl@0
|
680 |
return iBackupSession->IsBackupOperationRunning();
|
sl@0
|
681 |
}
|
sl@0
|
682 |
|
sl@0
|
683 |
/**
|
sl@0
|
684 |
* Notifies the server that a backup operation is going to happen.
|
sl@0
|
685 |
*
|
sl@0
|
686 |
* @since App-Framework_6.2
|
sl@0
|
687 |
* @publishedPartner
|
sl@0
|
688 |
* @released
|
sl@0
|
689 |
* @capability WriteDeviceData
|
sl@0
|
690 |
*/
|
sl@0
|
691 |
EXPORT_C void CBaBackupSessionWrapper::NotifyBackupOperationL(const TBackupOperationAttributes& aBackupOperationAttributes)
|
sl@0
|
692 |
{
|
sl@0
|
693 |
iBackupSession->NotifyBackupOperation(aBackupOperationAttributes);
|
sl@0
|
694 |
}
|
sl@0
|
695 |
|
sl@0
|
696 |
|
sl@0
|
697 |
EXPORT_C void MBackupOperationObserver::Reserved1()
|
sl@0
|
698 |
{
|
sl@0
|
699 |
}
|