sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32\debug\crashMonitor\src\scmbytestreamutil.cpp sl@0: // some utility classes for writing data to flash buffer sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: sl@0: #include "scmbytestreamutil.h" sl@0: #include "scmtrace.h" sl@0: sl@0: sl@0: sl@0: namespace Debug sl@0: { sl@0: /** sl@0: * TByteStreamBase Constructor sl@0: * @param aBuffer - pointer to buffer that this utility will use sl@0: */ sl@0: TByteStreamBase::TByteStreamBase(TUint8* aBuffer) sl@0: : iBuffer(aBuffer) sl@0: , iPos(0) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * SetPosition sl@0: * @param aBuffer - Sets iPos sl@0: * @return void sl@0: */ sl@0: void TByteStreamBase::SetPosition(TInt aPos) sl@0: { sl@0: iPos = aPos; sl@0: } sl@0: sl@0: /** sl@0: * CurrentPosition sl@0: * @param aBuffer - Returns the current value of iPos sl@0: * @return Tint sl@0: */ sl@0: TInt TByteStreamBase::CurrentPosition() const sl@0: { sl@0: return iPos; sl@0: } sl@0: sl@0: /** sl@0: * TByteStreamReader Constructor sl@0: * @param aBuffer - pointer to buffer that this utility will use sl@0: */ sl@0: TByteStreamReader::TByteStreamReader(TUint8* aBuffer) sl@0: : TByteStreamBase(aBuffer) sl@0: { sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Constructor for TByteStreamWriter sl@0: * @param aBuffer buffer for writing sl@0: * @param aPhysEnabled whether or not physical writing to another media is enabled sl@0: */ sl@0: TByteStreamWriter::TByteStreamWriter(TUint8* aBuffer, TBool aPhysEnabled) sl@0: : TByteStreamBase(aBuffer) sl@0: , iPhysEnabled(aPhysEnabled) sl@0: , iBytesWritten(0) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * Writes a byte to the buffer sl@0: * @param aValue Byte to write sl@0: */ sl@0: void TByteStreamWriter::WriteByte(TUint8 aValue) sl@0: { sl@0: if(iBuffer) sl@0: { sl@0: iBuffer[iPos++] = aValue; sl@0: ++iBytesWritten; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Resets the byte counter back to zero sl@0: */ sl@0: void TByteStreamWriter::ResetBytesWritten() sl@0: { sl@0: iBytesWritten = 0; sl@0: } sl@0: sl@0: /** sl@0: * TCachedByteStreamWriter Constructor sl@0: * @param aBuffer - pointer to buffer that this utility will use sl@0: * @param aCacheSize - suggested length of cache to use if greater than EMaxCache sl@0: * cache length of EMaxCache will be used sl@0: */ sl@0: TCachedByteStreamWriter::TCachedByteStreamWriter(TUint8* aCacheBuffer, TInt aCacheSize, TBool aPhysEnabled) sl@0: : TByteStreamWriter(NULL, aPhysEnabled) sl@0: , iCacheSize(aCacheSize) sl@0: , iCacheBuffer(aCacheBuffer) sl@0: , iPhysicalWriter(NULL) sl@0: { sl@0: } sl@0: sl@0: sl@0: /** sl@0: * FlushCache sl@0: * Writes the contents of the cache to buffer amd/or to physical writer implementation sl@0: * if one is currently set sl@0: * @return void sl@0: */ sl@0: TInt TCachedByteStreamWriter::FlushCache() sl@0: { sl@0: TInt padCount = iCacheSize - iPos; sl@0: if(padCount > 0) sl@0: { sl@0: for(TInt i=0;iDoPhysicalWrite(iCacheBuffer, iBytesWritten, iPos); sl@0: } sl@0: } sl@0: sl@0: iPos = 0; sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: * Writes a byte to the cached buffer sl@0: * @param aValue Byte to write sl@0: */ sl@0: void TCachedByteStreamWriter::WriteByte(TUint8 aValue) sl@0: { sl@0: if(iPos == iCacheSize) sl@0: { sl@0: FlushCache(); sl@0: } sl@0: iCacheBuffer[iPos++] = aValue; sl@0: ++iBytesWritten; sl@0: } sl@0: sl@0: /** sl@0: * CurrentPosition sl@0: * @param aBuffer - need to return the position in buffer plus the write pos into cache sl@0: * @return Tint sl@0: */ sl@0: TInt TCachedByteStreamWriter::CurrentPosition() const sl@0: { sl@0: return iBytesWritten; sl@0: } sl@0: sl@0: /** sl@0: * SetWriterImpl sl@0: * @param aPhysicalWriter - sets the physical writer implementation to be used when the cache is flushed sl@0: * pass NULL to remove a previous writer implementation sl@0: * @return void sl@0: */ sl@0: void TCachedByteStreamWriter::SetWriterImpl(MPhysicalWriterImpl* aPhysicalWriter) sl@0: { sl@0: iPhysicalWriter = aPhysicalWriter; sl@0: } sl@0: } sl@0: sl@0: //eof sl@0: