applayerpluginsandutils/bookmarksupport/test/cenrepsrv/backup.h
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     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 /**
       
    17  @internalTechnology
       
    18 */
       
    19 
       
    20 #ifndef BACKUP_H
       
    21 #define BACKUP_H
       
    22 
       
    23 #include <e32base.h>
       
    24 #include <f32file.h>
       
    25 #include <e32property.h>
       
    26 #include <connect/abclient.h>
       
    27 #include "sessnotf.h"
       
    28 #include "srvrepos.h"
       
    29 		
       
    30 using namespace conn ;
       
    31 
       
    32 const TUint KArbitraryNumber = 1024 ;
       
    33 const TUint32 KBackupStreamVersion = 1 ;
       
    34 
       
    35 // Bitfield representing backup stream features present in the 
       
    36 // incoming backup stream.
       
    37 enum TBackupExtensions
       
    38 	{
       
    39 	ENoBackupExtensions = 0x00000000,
       
    40 	EDeletedKeysSupported = 0x00000001,
       
    41 	};
       
    42 
       
    43 // Backup stream extension features supported by this version of central 
       
    44 // repository backup/restore - OR together bitwise values defined in
       
    45 // TBackupExtensions to get correct value!
       
    46 const TUint32 KBackupExtensionsSupported = EDeletedKeysSupported ;
       
    47 
       
    48 class TRepositoryBackupStreamHeader
       
    49 	{
       
    50 public :
       
    51 	inline TRepositoryBackupStreamHeader(TStreamId aIndexStreamId) ;
       
    52 	inline TRepositoryBackupStreamHeader();
       
    53 	inline void ExternalizeL(RWriteStream& aStream) const;		
       
    54 	inline void InternalizeL(RReadStream& aStream);		
       
    55 	inline TUid getUid();
       
    56 	inline TStreamId getIndexStreamId() ;
       
    57 	inline TUint32 getVersion();
       
    58 	inline TUint32 getBackupExtensionsSupported();
       
    59 
       
    60 private :
       
    61 	TUid iBackupStreamUid ;
       
    62 	TUint32 iBackupStreamVersion ;
       
    63 	TStreamId iIndexStreamId ;
       
    64 	TUint32 iBackupExtensionsSupported ;
       
    65 	
       
    66 	// Reserved for future expansion
       
    67 	TUint32 iReserved1 ;
       
    68 	TUint32 iReserved2 ;	
       
    69 	TUint32 iReserved3 ;
       
    70 	TUint32 iReserved4 ;			
       
    71 	};
       
    72 	
       
    73 //
       
    74 // Backup stream index class - Used to hold association between a UID (in
       
    75 // our case the UID of a repository) and a stream ID - Can't use CStreamDictionary
       
    76 // because that only lets you retrieve stream IDs by a (previously known) UID rather
       
    77 // than iterate through its contents retrieving UID/StreamID pairs...
       
    78 // 
       
    79 
       
    80 class TRepositoryBackupStreamIndexElement
       
    81 	{
       
    82 
       
    83 public :
       
    84 	inline void Set (TUid aUid, TStreamId aSettingsStream, TStreamId aDeletedSettingsStream = KNullStreamIdValue) ;
       
    85 	inline void SetDeletedSettingsStream (TStreamId aDeletedSettingsStream) ;
       
    86 	inline void Get (TUid& aUid, TStreamId& aSettingsStreamId, TStreamId& aDeletedSettingsStreamId) ;
       
    87 	inline void GetDeletedSettingsStream (TStreamId& aDeletedSettingsStream) ;
       
    88 	inline void ExternalizeL(RWriteStream& aStream) const;		
       
    89 	inline void InternalizeL(RReadStream& aStream, TUint32 aBackupStreamExtensions = ENoBackupExtensions);		
       
    90 
       
    91 private:
       
    92 	TUid iUid ;
       
    93 	TStreamId iSettingsStream ;	
       
    94 	TStreamId iDeletedSettingsStream ;
       
    95 	};
       
    96 	
       
    97 class CRepositoryBackupStreamIndex : public CBase
       
    98 	{
       
    99 public:
       
   100 	inline static CRepositoryBackupStreamIndex* NewL() ;
       
   101 	inline static CRepositoryBackupStreamIndex* NewLC();
       
   102 	inline ~CRepositoryBackupStreamIndex();
       
   103 	inline void Close(void) ;
       
   104 
       
   105 	void AddL(TUid aUid, TStreamId aSettingStreamId, TStreamId aDeletedSettingsStreamId) ;
       
   106 	TInt GetNext(TUid& aUid, TStreamId& aSettingsStreamId, TStreamId& aDeletedSettingsStreamId) ;
       
   107 	inline void Reset();
       
   108 	inline void ExternalizeL(RWriteStream& aStream) const;
       
   109 	inline void InternalizeL(RReadStream& aStream, TUint32 aBackupStreamExtensions = ENoBackupExtensions);
       
   110 	
       
   111 private:
       
   112 	inline CRepositoryBackupStreamIndex(){} ;
       
   113 
       
   114 private:
       
   115 	TInt iIndex ;
       
   116 	RArray<TRepositoryBackupStreamIndexElement> iStreamIndex ;
       
   117 	};		
       
   118 	
       
   119 
       
   120 enum TRepositoryBackupState
       
   121 {
       
   122 	ENoBackupActivty,
       
   123 	EBackupInProgress,
       
   124 	ERestoreInProgress
       
   125 };
       
   126 
       
   127 //
       
   128 // Backup client class.
       
   129 //
       
   130 // Has Active object functionality to monitor the state of the publish and subscribe 
       
   131 // flags associated with backup and restore and also implements MActiveBackupDataClient
       
   132 // to perform active backup according to the "proxy data holder" model.
       
   133 // 
       
   134 class CRepositoryBackupClient : public CActive, public MActiveBackupDataClient 
       
   135 	{
       
   136 public:
       
   137 	static CRepositoryBackupClient* NewL(RFs& aFs);
       
   138 	static CRepositoryBackupClient* NewLC(RFs& aFs);
       
   139 	inline static TRepositoryBackupState GetBackupStatus(void) {return iBackupStatus;} ;
       
   140 	
       
   141 	CRepositoryBackupClient(RFs& aFs);
       
   142 	~CRepositoryBackupClient();
       
   143 	void ConstructL();
       
   144 	void StartL();
       
   145 	void NotifyChange();
       
   146 
       
   147 	// Implementations of virtual functions inherited from MActiveBackupDataClient
       
   148 	void AllSnapshotsSuppliedL();
       
   149 	void ReceiveSnapshotDataL(TDriveNumber aDrive, TDesC8& aBuffer, TBool aLastSection);
       
   150 	TUint GetExpectedDataSize(TDriveNumber aDrive);
       
   151 	void GetSnapshotDataL(TDriveNumber aDrive, TPtr8& aBuffer, TBool& aFinished);
       
   152 	void InitialiseGetBackupDataL(TDriveNumber aDrive);
       
   153 	void GetBackupDataSectionL(TPtr8& aBuffer, TBool& aFinished);
       
   154 
       
   155 	void InitialiseGetProxyBackupDataL(TSecureId aSID, TDriveNumber aDrive) ;
       
   156 	void InitialiseRestoreProxyBaseDataL(TSecureId aSID, TDriveNumber aDrive) ;
       
   157 
       
   158 	void InitialiseRestoreBaseDataL(TDriveNumber aDrive);
       
   159 	void RestoreBaseDataSectionL(TDesC8& aBuffer, TBool aFinished);
       
   160 	void InitialiseRestoreIncrementDataL(TDriveNumber aDrive);
       
   161 	void RestoreIncrementDataSectionL(TDesC8& aBuffer, TBool aFinished);
       
   162 	void RestoreComplete(TDriveNumber aDrive);
       
   163 		
       
   164 	void TerminateMultiStageOperation();
       
   165 	TUint GetDataChecksum(TDriveNumber aDrive);
       
   166 	void CompleteOwnerIdLookupTableL();
       
   167 	
       
   168 private:
       
   169 	// Usual active object stuff
       
   170 	void RunL() ;
       
   171 	void DoCancel() ;
       
   172 	TInt RunError(TInt aError) ;
       
   173 
       
   174 	void TestBURstatusL(void) ;	
       
   175 	
       
   176 	// Leaving version of RestoreComplete to make it a bit easier
       
   177 	// for us to handle cleanup...
       
   178 	void RestoreCompleteL();
       
   179 
       
   180 private:
       
   181 	enum TBackupDirectoryScan 
       
   182 		{
       
   183 		EScanRom,
       
   184 		EScanInstall,
       
   185 		EScanPersist
       
   186 		};
       
   187 		
       
   188 private:	
       
   189 	// Used to open a repository for backup and/or restore
       
   190 	CServerRepository* iRepository ;
       
   191 	
       
   192 	CSessionNotifier* iNotifier ;
       
   193 
       
   194 	// Used to subscribe to Backup/Restore flag
       
   195 	RProperty iBackupRestoreProperty ;
       
   196 	
       
   197 	// File server session used to get directory listings
       
   198 	RFs& iFs;
       
   199 	RFile iFile ;
       
   200 	
       
   201 	// Secure ID being restored
       
   202 	TSecureId iSid ;
       
   203 	
       
   204 	// Active backup client to register with BUR engine
       
   205 	CActiveBackupClient* iActiveBackupClient ;
       
   206 	
       
   207 	TBool iRomScanDone;
       
   208 	// Current state (backup in proress, restore in progress, etc, etc, etc)
       
   209 	static TRepositoryBackupState iBackupStatus ;
       
   210 
       
   211 	// Features supported by Backup Stream 
       
   212 	TUint32 iBackupExtensionsSupported ;	
       
   213 	};
       
   214 
       
   215 
       
   216 #include "backup.inl"
       
   217 
       
   218 #endif // BACKUP_H