backupandrestore/backupengine/src/sbheapwrapper.cpp
changeset 47 63cf70d3ecd8
parent 33 883e91c086aa
equal deleted inserted replaced
44:a5deb6b96675 47:63cf70d3ecd8
    20  @internalTechnology
    20  @internalTechnology
    21 */
    21 */
    22 
    22 
    23 #include "sbheapwrapper.h"
    23 #include "sbheapwrapper.h"
    24 #include "sbepanic.h"
    24 #include "sbepanic.h"
       
    25 #include "OstTraceDefinitions.h"
       
    26 #include "sbtrace.h"
       
    27 #ifdef OST_TRACE_COMPILER_IN_USE
       
    28 #include "sbheapwrapperTraces.h"
       
    29 #endif
    25 
    30 
    26 namespace conn
    31 namespace conn
    27 	{
    32 	{
    28 	CHeapWrapper* CHeapWrapper::NewL()
    33 	CHeapWrapper* CHeapWrapper::NewL()
    29 	/**
    34 	/**
    30 	Symbian 1st phase constructor
    35 	Symbian 1st phase constructor
    31 	
    36 	
    32 	@return pointer to a newly created CHeapWrapper object
    37 	@return pointer to a newly created CHeapWrapper object
    33 	*/
    38 	*/
    34 		{
    39 		{
       
    40 		OstTraceFunctionEntry0( CHEAPWRAPPER_NEWL_ENTRY );
    35 		CHeapWrapper* self = new (ELeave) CHeapWrapper();
    41 		CHeapWrapper* self = new (ELeave) CHeapWrapper();
    36 		
    42 		
       
    43 		OstTraceFunctionExit0( CHEAPWRAPPER_NEWL_EXIT );
    37 		return self;
    44 		return self;
    38 		}
    45 		}
    39 	
    46 	
    40 	TPtrC8& CHeapWrapper::ReadBufferL(const RChunk& aChunk)
    47 	TPtrC8& CHeapWrapper::ReadBufferL(const RChunk& aChunk)
    41 	/**
    48 	/**
    43 	
    50 	
    44 	@param aChunk The RChunk to interrogate for the heap information
    51 	@param aChunk The RChunk to interrogate for the heap information
    45 	@return reference to the descriptor stored on the global shared heap
    52 	@return reference to the descriptor stored on the global shared heap
    46 	*/
    53 	*/
    47 		{
    54 		{
       
    55 		OstTraceFunctionEntry0( CHEAPWRAPPER_READBUFFERL_ENTRY );
    48 		if (Header(aChunk).LockedFlag())
    56 		if (Header(aChunk).LockedFlag())
    49 			{
    57 			{
       
    58 		    OstTrace0(TRACE_ERROR, CHEAPWRAPPER_READBUFFERL, "Leave: KErrInUse");
    50 			User::Leave(KErrInUse);
    59 			User::Leave(KErrInUse);
    51 			}
    60 			}
    52 
    61 
    53 		CleanReadBuffer();
    62 		CleanReadBuffer();
    54 			
    63 			
    55 		iReadBuf = new (ELeave) TPtrC8(Buffer(aChunk));
    64 		iReadBuf = new (ELeave) TPtrC8(Buffer(aChunk));
    56 
    65 
       
    66 		OstTraceFunctionExit0( CHEAPWRAPPER_READBUFFERL_EXIT );
    57 		return *iReadBuf;
    67 		return *iReadBuf;
    58 		}
    68 		}
    59 		
    69 		
    60 	TPtr8& CHeapWrapper::WriteBufferL(const RChunk& aChunk)
    70 	TPtr8& CHeapWrapper::WriteBufferL(const RChunk& aChunk)
    61 	/**
    71 	/**
    63 	
    73 	
    64 	@param aChunk The RChunk to interrogate for the heap information
    74 	@param aChunk The RChunk to interrogate for the heap information
    65 	@return reference to the descriptor stored on the global shared heap
    75 	@return reference to the descriptor stored on the global shared heap
    66 	*/
    76 	*/
    67 		{
    77 		{
       
    78 		OstTraceFunctionEntry0( CHEAPWRAPPER_WRITEBUFFERL_ENTRY );
    68 		if (Header(aChunk).LockedFlag())
    79 		if (Header(aChunk).LockedFlag())
    69 			{
    80 			{
       
    81 		    OstTrace0(TRACE_ERROR, CHEAPWRAPPER_WRITEBUFFERL, "Leave: KErrInUse");
    70 			User::Leave(KErrInUse);
    82 			User::Leave(KErrInUse);
    71 			}
    83 			}
    72 
    84 
    73 		CleanReadBuffer();
    85 		CleanReadBuffer();
    74 
    86 
    75 		TPtr8& des = Buffer(aChunk);
    87 		TPtr8& des = Buffer(aChunk);
    76 		
    88 		
    77 		// Blank the descriptor as it's a write buffer
    89 		// Blank the descriptor as it's a write buffer
    78 		des.Zero();
    90 		des.Zero();
    79 		
    91 		
       
    92 		OstTraceFunctionExit0( CHEAPWRAPPER_WRITEBUFFERL_EXIT );
    80 		return des;
    93 		return des;
    81 		}
    94 		}
    82 		
    95 		
    83 	THeapWrapperHeader& CHeapWrapper::Header(const RChunk& aChunk) const
    96 	THeapWrapperHeader& CHeapWrapper::Header(const RChunk& aChunk) const
    84 	/**
    97 	/**
    97 	
   110 	
    98 	@param aChunk The RChunk to interrogate for the heap information
   111 	@param aChunk The RChunk to interrogate for the heap information
    99 	@return KErrNone always.
   112 	@return KErrNone always.
   100 	*/
   113 	*/
   101 		{
   114 		{
       
   115 		OstTraceFunctionEntry0( CHEAPWRAPPER_RESETHEAP_ENTRY );
   102 		TInt err = KErrNone;
   116 		TInt err = KErrNone;
   103 		TUint8* heapPtr = aChunk.Base();
   117 		TUint8* heapPtr = aChunk.Base();
   104 		
   118 		
   105 		new (&Header(aChunk)) THeapWrapperHeader;
   119 		new (&Header(aChunk)) THeapWrapperHeader;
   106 		
   120 		
   109 		header.SetLockedFlag(EFalse);
   123 		header.SetLockedFlag(EFalse);
   110 		
   124 		
   111 		// placement new a new descriptor on the heap to initialise it
   125 		// placement new a new descriptor on the heap to initialise it
   112 		new (heapPtr + KDescriptorOffset) TPtr8(heapPtr + KDataOffset, 0, aChunk.Size() - KDataOffset);
   126 		new (heapPtr + KDescriptorOffset) TPtr8(heapPtr + KDataOffset, 0, aChunk.Size() - KDataOffset);
   113 
   127 
       
   128 		OstTraceFunctionExit0( CHEAPWRAPPER_RESETHEAP_EXIT );
   114 		return err;
   129 		return err;
   115 		}
   130 		}
   116 
   131 
   117 	TPtr8& CHeapWrapper::Buffer(const RChunk& aChunk)
   132 	TPtr8& CHeapWrapper::Buffer(const RChunk& aChunk)
   118  	/**
   133  	/**
   119  	@param aChunk The RChunk to interrogate for the heap information
   134  	@param aChunk The RChunk to interrogate for the heap information
   120  	@return reference to the descriptor stored on the global shared heap
   135  	@return reference to the descriptor stored on the global shared heap
   121  	*/
   136  	*/
   122   		{
   137   		{
       
   138   		OstTraceFunctionEntry0( CHEAPWRAPPER_BUFFER_ENTRY );
   123   		TUint8* heapPtr = aChunk.Base();
   139   		TUint8* heapPtr = aChunk.Base();
   124 		
   140 		
   125 		// Set the descriptor
   141 		// Set the descriptor
   126 		TPtr8* descriptor = reinterpret_cast<TPtr8*>(heapPtr + KDescriptorOffset);
   142 		TPtr8* descriptor = reinterpret_cast<TPtr8*>(heapPtr + KDescriptorOffset);
   127 		const TInt length = descriptor->Length();
   143 		const TInt length = descriptor->Length();
   128 		const TInt maxLength = descriptor->MaxLength();
   144 		const TInt maxLength = descriptor->MaxLength();
   129 		descriptor->Set(heapPtr + KDataOffset, length, maxLength);
   145 		descriptor->Set(heapPtr + KDataOffset, length, maxLength);
   130 
   146 
       
   147 		OstTraceFunctionExit0( CHEAPWRAPPER_BUFFER_EXIT );
   131 		return *descriptor;
   148 		return *descriptor;
   132 		}
   149 		}
   133 		
   150 		
   134 	void CHeapWrapper::CleanReadBuffer()
   151 	void CHeapWrapper::CleanReadBuffer()
   135 	/**
   152 	/**
   136 	Delete and NULL the read buffer if necessary
   153 	Delete and NULL the read buffer if necessary
   137 	*/
   154 	*/
   138 		{
   155 		{
       
   156 		OstTraceFunctionEntry0( CHEAPWRAPPER_CLEANREADBUFFER_ENTRY );
   139 		delete iReadBuf;
   157 		delete iReadBuf;
   140 		iReadBuf = NULL;
   158 		iReadBuf = NULL;
       
   159 		OstTraceFunctionExit0( CHEAPWRAPPER_CLEANREADBUFFER_EXIT );
   141 		}
   160 		}
   142 		
   161 		
   143 	CHeapWrapper::~CHeapWrapper()
   162 	CHeapWrapper::~CHeapWrapper()
   144 		{
   163 		{
       
   164 		OstTraceFunctionEntry0( CHEAPWRAPPER_CHEAPWRAPPER_DES_ENTRY );
   145 		CleanReadBuffer();
   165 		CleanReadBuffer();
       
   166 		OstTraceFunctionExit0( CHEAPWRAPPER_CHEAPWRAPPER_DES_EXIT );
   146 		}
   167 		}
   147 	}
   168 	}