Update contrib.
1 // Copyright (c) 2008-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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\debug\crashMonitor\src\scmbytestreamutil.cpp
15 // some utility classes for writing data to flash buffer
25 #include "scmbytestreamutil.h"
33 * TByteStreamBase Constructor
34 * @param aBuffer - pointer to buffer that this utility will use
36 TByteStreamBase::TByteStreamBase(TUint8* aBuffer)
44 * @param aBuffer - Sets iPos
47 void TByteStreamBase::SetPosition(TInt aPos)
54 * @param aBuffer - Returns the current value of iPos
57 TInt TByteStreamBase::CurrentPosition() const
63 * TByteStreamReader Constructor
64 * @param aBuffer - pointer to buffer that this utility will use
66 TByteStreamReader::TByteStreamReader(TUint8* aBuffer)
67 : TByteStreamBase(aBuffer)
73 * Constructor for TByteStreamWriter
74 * @param aBuffer buffer for writing
75 * @param aPhysEnabled whether or not physical writing to another media is enabled
77 TByteStreamWriter::TByteStreamWriter(TUint8* aBuffer, TBool aPhysEnabled)
78 : TByteStreamBase(aBuffer)
79 , iPhysEnabled(aPhysEnabled)
85 * Writes a byte to the buffer
86 * @param aValue Byte to write
88 void TByteStreamWriter::WriteByte(TUint8 aValue)
92 iBuffer[iPos++] = aValue;
98 * Resets the byte counter back to zero
100 void TByteStreamWriter::ResetBytesWritten()
106 * TCachedByteStreamWriter Constructor
107 * @param aBuffer - pointer to buffer that this utility will use
108 * @param aCacheSize - suggested length of cache to use if greater than EMaxCache
109 * cache length of EMaxCache will be used
111 TCachedByteStreamWriter::TCachedByteStreamWriter(TUint8* aCacheBuffer, TInt aCacheSize, TBool aPhysEnabled)
112 : TByteStreamWriter(NULL, aPhysEnabled)
113 , iCacheSize(aCacheSize)
114 , iCacheBuffer(aCacheBuffer)
115 , iPhysicalWriter(NULL)
122 * Writes the contents of the cache to buffer amd/or to physical writer implementation
123 * if one is currently set
126 TInt TCachedByteStreamWriter::FlushCache()
128 TInt padCount = iCacheSize - iPos;
131 for(TInt i=0;i<padCount;i++)
133 iCacheBuffer[iPos++] = 0;
139 if(iPhysicalWriter) // do we have a writer to send the cache data to
141 iPhysicalWriter->DoPhysicalWrite(iCacheBuffer, iBytesWritten, iPos);
150 * Writes a byte to the cached buffer
151 * @param aValue Byte to write
153 void TCachedByteStreamWriter::WriteByte(TUint8 aValue)
155 if(iPos == iCacheSize)
159 iCacheBuffer[iPos++] = aValue;
165 * @param aBuffer - need to return the position in buffer plus the write pos into cache
168 TInt TCachedByteStreamWriter::CurrentPosition() const
170 return iBytesWritten;
175 * @param aPhysicalWriter - sets the physical writer implementation to be used when the cache is flushed
176 * pass NULL to remove a previous writer implementation
179 void TCachedByteStreamWriter::SetWriterImpl(MPhysicalWriterImpl* aPhysicalWriter)
181 iPhysicalWriter = aPhysicalWriter;