persistentstorage/sql/SRC/Server/SqlBur.h
changeset 0 08ec8eefde2f
child 8 fa9941cf3867
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2006-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 #ifndef __SQLBUR_H__
       
    17 #define __SQLBUR_H__
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <f32file.h>
       
    21 #include <f32file64.h>
       
    22 #include <e32property.h>
       
    23 #include <connect/abclient.h> // MactiveBackupDataClient
       
    24 #include "SqlSrvBurInterface.h"
       
    25 
       
    26 using namespace conn;
       
    27 
       
    28 //-----------------------------------------
       
    29 // CSqlBackupClient
       
    30 //-----------------------------------------
       
    31 
       
    32 /**
       
    33 	This class is called by the Backup and Restore Framework
       
    34 	when a backup or restore is requested by the user
       
    35 	It implements the active proxy backup and restore as
       
    36 	defined in the MActiveBackupDataClient interface.
       
    37 	
       
    38 	@internalComponent
       
    39 */
       
    40 
       
    41 // derives from the framework mixin MActiveBackupClient
       
    42 class CSqlBackupClient : public CActive, public MActiveBackupDataClient
       
    43 	{
       
    44 	public:
       
    45 		static CSqlBackupClient *NewLC(MSqlSrvBurInterface *aBurInterface);
       
    46 		static CSqlBackupClient *NewL(MSqlSrvBurInterface *aBufInterface);
       
    47 		
       
    48 		~CSqlBackupClient();
       
    49 		
       
    50 		// AO implementations
       
    51 		void StartL();
       
    52 		void NotifyChange();
       
    53 		
       
    54 		// impl of virtuals from MActiveBackupDataClient	
       
    55 		void AllSnapshotsSuppliedL();
       
    56 		void ReceiveSnapshotDataL(TDriveNumber aDrive, TDesC8& aBuffer, TBool aLastSection);
       
    57 		TUint GetExpectedDataSize(TDriveNumber aDrive);
       
    58 		void GetSnapshotDataL(TDriveNumber aDrive, TPtr8& aBuffer, TBool& aFinished);
       
    59 		void InitialiseGetBackupDataL(TDriveNumber aDrive);
       
    60 		void GetBackupDataSectionL(TPtr8& aBuffer, TBool& aFinished);
       
    61 		void InitialiseRestoreBaseDataL(TDriveNumber aDrive);
       
    62 		void RestoreBaseDataSectionL(TDesC8& aBuffer, TBool aFinished);
       
    63 		void InitialiseRestoreIncrementDataL(TDriveNumber aDrive);
       
    64 		void RestoreIncrementDataSectionL(TDesC8& aBuffer, TBool aFinished);
       
    65 		void RestoreComplete(TDriveNumber aDrive);
       
    66 		void InitialiseGetProxyBackupDataL(TSecureId aSid, TDriveNumber aDrive);
       
    67 		void InitialiseRestoreProxyBaseDataL(TSecureId aSid, TDriveNumber aDrive);
       
    68 		void TerminateMultiStageOperation();
       
    69 		TUint GetDataChecksum(TDriveNumber aDrive);	
       
    70 		
       
    71 		// to validate successful BUR
       
    72 		TUint64 CheckSumL(const RFile64 &aOpenFile) const;
       
    73 		
       
    74 		// for debug
       
    75 		//void SetConsole(CConsoleBase *aConsole);
       
    76 	private:
       
    77 		CSqlBackupClient(MSqlSrvBurInterface *aInterface);
       
    78 		void ConstructL();
       
    79 		
       
    80 		// active object methods
       
    81 		void RunL();
       
    82 		void DoCancel();
       
    83 		TInt RunError(TInt aError);
       
    84 		
       
    85 		// used to determine what the BUR status is and to respond as required
       
    86 		void TestBurStatusL();
       
    87 	
       
    88 		// this is used to ask the SQL server for a list of databases to backup
       
    89 		// we ask the database server because the decision to backup is not
       
    90 		// only based on the UID but also the database backup flag stored in
       
    91 		// the database metadata - and we don't want to have to know how that
       
    92 		// is implemented
       
    93 		void GetBackupListL(TSecureId aSid);
       
    94 		void CopyBufData(const TDesC8& aInBuf, TInt& aInBufReadPos, TDes& aOutBuf, TInt aDataLen);
       
    95 		
       
    96 	private:
       
    97 	
       
    98 		// state machine for backup
       
    99 		enum
       
   100 			{
       
   101 			EBackupNoFileOpen=0, // not currently processing a file
       
   102 			EBackupOpenNothingSent, // file open and ready, but nothing sent yet
       
   103 			EBackupOpenPartHeaderSent, // part of the header is sent, but more remains
       
   104 			EBackupOpenAllHeaderSent, // all of the header is sent, ready to send the data
       
   105 			EBackupEndOfFile // all done, tidy up after backup
       
   106 			};
       
   107 
       
   108 		// state machine for restore
       
   109 		// this is more complicated because we are driven by the backup engine
       
   110 		// and have incomplete information most of the time
       
   111 		enum
       
   112 			{
       
   113 			ERestoreExpectChecksum=0, 		// checksum marks the start of the next file
       
   114 			ERestoreExpectOldFileSize, 		// the size of the file - backup file header version 0
       
   115 			ERestoreExpectVersion, 			// backup header version
       
   116 			ERestoreExpectFileSize, 		// the size of the file, backup file header version 2+
       
   117 			ERestoreExpectFileNameSize, 	// the size of the file name
       
   118 			ERestoreExpectFileName, 		// the name of the file to restore
       
   119 			ERestoreExpectData, 			// now for the data
       
   120 			ERestoreComplete 				// tidy up after restore
       
   121 			};
       
   122 			
       
   123 		CActiveBackupClient *iActiveBackupClient;
       
   124 		RProperty iProperty;
       
   125 		MSqlSrvBurInterface *iInterface; // the SQL server
       
   126 		RArray<TParse> iFileList; // which is populated by the SQL server
       
   127 		RFile64 iFile;
       
   128 		TInt iFileIndex;
       
   129 		TUint iState;
       
   130 		HBufC* iBuffer; // used for the header data
       
   131 		TInt iHeaderSent; // how many header bytes sent so far
       
   132 		TUint32 iChecksum; // used by restore
       
   133 		TInt64 iFileSize; // used by restore
       
   134 		TUint32 iFileNameSize; // used by restore
       
   135 		TBool iAnyData; // set to true if the restore actually sends any data to us
       
   136 		TSecureId iSid; // the sid being backed up/restored
       
   137 
       
   138 	};
       
   139 
       
   140 #endif // __SQLBUR_H__