backupandrestore/backupengine/inc/sbheapwrapper.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 * Definition of CHeapWrapper and THeapWrapperHeader
       
    16 * 
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 /**
       
    23  @file
       
    24  @internalTechnology
       
    25 */
       
    26 
       
    27 #ifndef __HEAPWRAPPER_H__
       
    28 #define __HEAPWRAPPER_H__
       
    29 
       
    30 #include <e32std.h>
       
    31 #include <connect/sbtypes.h>
       
    32 
       
    33 namespace conn
       
    34 	{
       
    35 	/** KMaxGenericTypeSize must be a multiple of 4 to ensure that all structures are 4-byte aligned 
       
    36 	@internalTechnology */
       
    37 	const TInt KMaxGenericTypeSize = 1024;
       
    38 	
       
    39 	class THeapWrapperHeader
       
    40 	/**
       
    41 	This class is packed at the beginning of the heap and stores information about the data
       
    42 	contained in the descriptor.
       
    43 	
       
    44 	Note that all structures in here must be 4-byte aligned, using dummy padding if necessary.
       
    45 	
       
    46 	@internalTechnology
       
    47 	*/
       
    48 		{
       
    49 	public:
       
    50 		inline TBool LockedFlag();
       
    51 		inline void SetLockedFlag(TBool aLockedFlag);
       
    52 		inline TBuf8<KMaxGenericTypeSize>& GenericTransferTypeBuffer();
       
    53 
       
    54 	public:
       
    55 		/** Finished flag, set to ETrue when the data in the descriptor 
       
    56 		is the last in a multi-part transfer*/
       
    57 		TBool iFinished;
       
    58 
       
    59 	private:
       
    60 		/** Flag to indicate that the heap has been locked for writing 
       
    61 		by an instance of CHeapWrapper */
       
    62 		TBool iLockedFlag;
       
    63 
       
    64 		/** Generic transfer type */
       
    65 		TBuf8<KMaxGenericTypeSize> iGenericDataTransferInfo;
       
    66 		};
       
    67 		
       
    68 	inline TBool THeapWrapperHeader::LockedFlag()
       
    69 	/** Getter for the private locked flag 
       
    70 	@return The status of the locked flag */
       
    71 		{
       
    72 		return iLockedFlag;
       
    73 		}
       
    74 		
       
    75 	inline void THeapWrapperHeader::SetLockedFlag(TBool aLockedFlag)
       
    76 	/** Setter for the locked flag
       
    77 	@param aLockedFlag The new state of the heap locked flag */
       
    78 		{
       
    79 		iLockedFlag = aLockedFlag;
       
    80 		}
       
    81 
       
    82 	inline TBuf8<KMaxGenericTypeSize>& THeapWrapperHeader::GenericTransferTypeBuffer()
       
    83 	/** Getter for the generic type buffer
       
    84 	@return Reference to generic type buffer
       
    85 	*/
       
    86 		{
       
    87 		return iGenericDataTransferInfo;
       
    88 		}
       
    89 
       
    90 	
       
    91 	// Offsets for defining pointers relative the the RChunk::Base() pointer
       
    92 
       
    93 	/** Offset for the lock flag */
       
    94 	const TInt KHeaderOffset = 0;
       
    95 	
       
    96 	/** Offset to the beginning of the main descriptor */
       
    97 	const TInt KDescriptorOffset = KHeaderOffset + sizeof(THeapWrapperHeader); // lock flag is 1 byte
       
    98 	
       
    99 	/** Offset to the data that the TPtr8 will point to */
       
   100 	const TInt KDataOffset = KDescriptorOffset + sizeof(TPtr8);
       
   101 	
       
   102 	class CHeapWrapper : public CBase
       
   103 	/**
       
   104 	This class is instantiated to ensure that data is passed over the Global Shared Heap 
       
   105 	by a common interface
       
   106 	
       
   107 	@internalTechnology
       
   108 	*/
       
   109 		{
       
   110 	public:
       
   111 		static CHeapWrapper* NewL();
       
   112 		TPtrC8& ReadBufferL(const RChunk& aChunk);
       
   113 		TPtr8& WriteBufferL(const RChunk& aChunk);
       
   114 		TInt ResetHeap(const RChunk& aChunk);
       
   115 		THeapWrapperHeader& Header(const RChunk& aChunk) const;
       
   116 
       
   117 		/** virtual C++ destructor */
       
   118 		~CHeapWrapper();
       
   119 	private:
       
   120 		/** C++ constructor initialises read buffer pointer to NULL*/
       
   121 		CHeapWrapper() : iReadBuf(NULL) {};
       
   122 
       
   123 		TPtr8& Buffer(const RChunk& aChunk);
       
   124 		void CleanReadBuffer();
       
   125 	private:
       
   126 		/** Pointer to the global buffer */
       
   127 		TPtrC8* iReadBuf; 
       
   128 		};
       
   129 
       
   130 	} // namespace conn
       
   131 
       
   132 #endif //__HEAPWRAPPER_H__