backupandrestore/backupengine/inc/sbebufferhandler.h
changeset 0 d0791faffa3f
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 /**
       
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * Declaration of Classes used to handle buffers
       
    16 * 
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 /**
       
    23  @file
       
    24 */
       
    25 #ifndef __SBEBUFFERHANDLER_H__
       
    26 #define __SBEBUFFERHANDLER_H__
       
    27 
       
    28 #include <e32base.h>
       
    29 #include <f32file.h>
       
    30 #include <connect/sbtypes.h>
       
    31 #include <badesca.h>
       
    32 
       
    33 namespace conn
       
    34 	{
       
    35 	
       
    36 	const TInt KDesCArrayGranularity = 8;
       
    37 	
       
    38 	/**
       
    39 	This class defines the interface required to validate backup/restore data
       
    40 	
       
    41 	@internalTechnology
       
    42 	*/
       
    43 	class MValidationHandler
       
    44 		{
       
    45 	public:
       
    46 		/**
       
    47 		This method will check if the file name is in the 
       
    48 		list of the files to be restored/backuped up
       
    49 		
       
    50 		@param aFileName reference to the filename to check
       
    51 		@return ETrue if file to backup/restore is valid
       
    52 		*/
       
    53 		virtual TBool ValidFileL(const TDesC& aFileName) = 0;
       
    54 		};
       
    55 	
       
    56 	/** Temporary path used for restoring midlets
       
    57 	@internalTechnology
       
    58 	*/
       
    59 	_LIT(KMIDletTempRestorePath, "C:\\system\\temp\\MIDletRestore\\");
       
    60 
       
    61 
       
    62 	/* Reads a fixed size object from a buffer
       
    63 	@internalTechnology
       
    64 	*/
       
    65 	template<class T>
       
    66 	TBool ReadFromBufferF(T& aT, TUint8*& appCurrent, const TUint8* apEnd);
       
    67 	
       
    68 	/* Reads a vairable size object from a buffer
       
    69 	@internalTechnology
       
    70 	*/
       
    71 	TBool ReadFromBufferV(TPtr8& aT, TInt aSize, TUint8*& appCurrent,
       
    72 						  const TUint8* apEnd);
       
    73 						  
       
    74 	/** Simple class to wrap up the fixed elements for a snapshot.
       
    75 	@internalTechnology
       
    76 	*/
       
    77 	class TSnapshot
       
    78 		{
       
    79 	public:
       
    80 		TSnapshot()
       
    81 		/** Standard C++ Constructor.
       
    82 		*/
       
    83 			{
       
    84 			}
       
    85 		TSnapshot(const TDesC& aFileName, TInt64 aModified) :
       
    86 			iFileName(aFileName), iModified(aModified)
       
    87 		/** Standard C++ Constructor.
       
    88 		@param aFileName name of file
       
    89 		@param aModified modification attribute of file
       
    90 		*/
       
    91 			{
       
    92 			}
       
    93 	public:
       
    94 		TFileName	iFileName; /*<! Filename */
       
    95 		TInt64		iModified; /*<! The modified time of the file */
       
    96 		};
       
    97 		
       
    98 	/** Simple class to store snapshot file
       
    99         @internalComponent
       
   100 	*/
       
   101 	class CSnapshot : public CBase
       
   102 		{
       
   103 	public:
       
   104 		static CSnapshot* NewLC(const TInt64& aModified, const TDesC& aFileName);
       
   105 		static CSnapshot* NewLC(const TSnapshot& aSnapshot);
       
   106 		
       
   107 		static TInt Compare(const CSnapshot& aFirst, const CSnapshot& aSecond);
       
   108 		static TBool Match(const CSnapshot& aFirst, const CSnapshot& aSecond);
       
   109 
       
   110 		
       
   111 		~CSnapshot();
       
   112 		const TInt64& Modified() const;
       
   113 		const TDesC& FileName() const;
       
   114 		void Snapshot(TSnapshot& aSnapshot);
       
   115 		
       
   116 	private:
       
   117 		CSnapshot(const TInt64& aModified);
       
   118 		void ConstructL(const TDesC& aFileName);
       
   119 		
       
   120 	private:
       
   121     	TInt64				iModified; /*<! The type of the selection */
       
   122     	HBufC*		       	iFileName; /*<! The actual selection */
       
   123 		};
       
   124 	
       
   125 	/** Simple array of TSnapshot
       
   126 	@internalTechnology
       
   127 	*/
       
   128 	typedef RPointerArray<CSnapshot> RSnapshots;
       
   129 
       
   130 	/** Simple class to wrap up the fixed elements for a file.
       
   131 
       
   132 	@internalComponent
       
   133 	*/
       
   134 	class TFileFixedHeader
       
   135 		{
       
   136 	public:
       
   137 		TFileFixedHeader()
       
   138 		/** Standard C++ constructor
       
   139 		*/
       
   140 			{
       
   141 			}
       
   142 		
       
   143 		
       
   144 		TFileFixedHeader(const TUint aFileNameLength, TUint aFileSize, 
       
   145 						 TUint aAttributes, TInt64 aModified) :
       
   146 			iFileNameLength(aFileNameLength), iFileSize(aFileSize), iAttributes(aAttributes), iModified(aModified)
       
   147 		/** Standard C++ constructor
       
   148 		*/
       
   149 			{
       
   150 			}
       
   151 	public:
       
   152 		TUint	iFileNameLength; /*<! The length of the name of the current file */
       
   153 		TUint	iFileSize; /*<! The length of the current file */
       
   154 		TUint	iAttributes; /*<! The attributes for the file */
       
   155 		TInt64	iModified; /*<! The modifed time for the file */
       
   156 		}; 
       
   157 
       
   158 	/** Class to write one or more files to a memory buffer
       
   159 	@internalTechnology
       
   160 	*/
       
   161 	class CBufferFileWriter : public CBase
       
   162 		{
       
   163 	public:
       
   164 		// Constructors
       
   165 		static CBufferFileWriter* NewL(RFs& aFs, CDesCArray* aFileNames);
       
   166 		~CBufferFileWriter();
       
   167 		
       
   168 		// Methods
       
   169 		void StartL(TPtr8& aBuffer, TBool& aCompleted);
       
   170 		void ContinueL(TPtr8& aBuffer, TBool& aCompleted);
       
   171 		void WriteToBufferL(TPtr8& aBuffer, TBool& aCompleted);
       
   172 	private:
       
   173 		// Constructors
       
   174 		CBufferFileWriter(RFs& aFs, CDesCArray* aFileNames);
       
   175 		void ConstructL();
       
   176 		
       
   177 	private:
       
   178 		RFs&				iFs; /*<! File server to use */
       
   179 		CDesCArray*			iFileNames; /*<! Array of files to write to the buffer */
       
   180 		
       
   181 		// State
       
   182 		RFile				iFileHandle; /*<! File handle of current file writing to buffer */
       
   183 		TBool				iFileOpen; /*<! Is the file open */
       
   184 		TInt				iCurrentFile; /*<! Current file we are writing -> offset into array */
       
   185 		TInt				iOffset; /*<! Offset into file to start writing from */
       
   186 		TBool				iHeaderWritten; /*<! Has the header been written */
       
   187 		TBool				iFileNameWritten; /*<! Have we written the filename? */
       
   188 		}; // CBufferFileWriter
       
   189 		
       
   190 	/** Class to read one or more files from a memory buffer to disk
       
   191 	@internalTechnology
       
   192 	*/
       
   193 	class CBufferFileReader : public CBase
       
   194 		{
       
   195 	public:
       
   196 		// Constructors
       
   197 		static CBufferFileReader* NewL(RFs& aFs, RSnapshots* aSnapshots = NULL, MValidationHandler* aValidationHandler = NULL);
       
   198 		~CBufferFileReader();
       
   199 		
       
   200 		// Methods
       
   201 		void StartL(const TDesC8& aBuffer, TBool aLastSection);
       
   202 		void ContinueL(const TDesC8& aBuffer, TBool aLastSection);
       
   203 		void ReadFromBufferL(const TDesC8& aBuffer, TBool aLastSection);
       
   204 		void ReadMIDletsFromBufferL(const TDesC8& aBuffer, TBool aLastSection, 
       
   205 			CDesCArray& aUnpackedFileNames);
       
   206 		void Reset();
       
   207 	private:
       
   208 		// Constructors
       
   209 		CBufferFileReader(RFs& aFs, RSnapshots* aSnapshots, MValidationHandler* aValidationHandler);
       
   210 		void CheckFileInSnapshotL();
       
   211 		void RecreateDirL();
       
   212 		void RecreateFileL();
       
   213 		TBool WriteToFileL(TUint8*& aCurrent, const TUint8* aEnd);
       
   214 		void RedirectMIDletRestorePathL(const TDesC& aOriginal, CDesCArray& aRedirected);
       
   215 	private:
       
   216 		TFileFixedHeader iFixedHeader; 
       
   217 	
       
   218 		RFs&				iFs; /*<! File server to use */
       
   219 		RSnapshots*			iSnapshots; /*<! Snapshot used to detect deleted files */
       
   220 		
       
   221 		// State
       
   222 		TBool				iFixedHeaderRead; /*<! Have we read the fixed header? */
       
   223 		TBool				iFileNameRead; /*<! Have we read the filename? */
       
   224 		TBool				iSnapshotChecked; /*! Have we checked the snapshot */
       
   225 		TBool				iRestore; /*<! Are we skipping the bytes are restoring them? */
       
   226 		TInt				iLeftToSkip; /*<! If we are skipping data, how much is left? */
       
   227 		TFileName			iFileName; /*<! The file name */
       
   228 		RFile				iFileHandle; /*<! The file handle */
       
   229 		TBool				iFileOpen; /*<! Is the file open? */
       
   230 		MValidationHandler* iValidationHandler; /*<! Handler to Validation Implementation */
       
   231 		TUint				iBytesRead; /*<! Number of bytes Read */
       
   232 		}; // CBufferFileReader
       
   233 		
       
   234 		
       
   235 	/** Class to write snapshot data to a memory buffer
       
   236 	@internalTechnology
       
   237 	*/
       
   238 	class CBufferSnapshotWriter : public CBase
       
   239 		{
       
   240 	public:
       
   241 		// Constructors
       
   242 		static CBufferSnapshotWriter* NewL(RSnapshots* aSnapshot);
       
   243 		~CBufferSnapshotWriter();
       
   244 		
       
   245 		// Methods
       
   246 		void StartL(TPtr8& aBuffer, TBool& aCompleted);
       
   247 		void ContinueL(TPtr8& aBuffer, TBool& aCompleted);
       
   248 	private:
       
   249 		// Constructors
       
   250 		CBufferSnapshotWriter(RSnapshots* aSnapshot);
       
   251 		void ConstructL();
       
   252 		
       
   253 		void WriteToBufferL(TPtr8& aBuffer, TBool& aCompleted);
       
   254 	private:
       
   255 		// Files
       
   256 		RSnapshots*			iSnapshots; /*<! List of files */
       
   257 	
       
   258 		// State
       
   259 		TInt				iCurrentSnapshot; /*<! Current file writing */
       
   260 		}; // CBufferSnapshotWriter
       
   261 		
       
   262 	/** Class to read snapshot data from a memory buffer
       
   263 	@internalTechnology
       
   264 	*/
       
   265 	class CBufferSnapshotReader : public CBase
       
   266 		{
       
   267 	public:
       
   268 		// Constructors
       
   269 		static CBufferSnapshotReader* NewL(RSnapshots& aSnapshots);
       
   270 		~CBufferSnapshotReader();
       
   271 		
       
   272 		// Methods
       
   273 		void StartL(const TDesC8& aBuffer, TBool aLastSection);
       
   274 		void ContinueL(const TDesC8& aBuffer, TBool aLastSection);
       
   275 	private:
       
   276 		// Constructor
       
   277 		CBufferSnapshotReader(RSnapshots& aSnapshots);
       
   278 		
       
   279 		void ReadFromBufferL(const TDesC8& aBuffer, TBool aLastSection);
       
   280 	private:
       
   281 		// Files
       
   282 		RSnapshots&			iSnapshots; /*<! Build up list of files here */
       
   283 		
       
   284 		// State
       
   285 		TSnapshot				iSnapshot; /*<! The fixed header */
       
   286 		}; // CBufferSnapshotReader
       
   287 	
       
   288 	} // namespace
       
   289 
       
   290 
       
   291 #endif // __SBEBUFFERHANDLER_H__