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