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: // some utility classes for writing data to buffer sl@0: // sl@0: // WARNING: This file contains some APIs which are internal and are subject sl@0: // to change without notice. Such APIs should therefore not be used sl@0: // outside the Kernel and Hardware Services package. sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: #ifndef __SCMBYTESTREAMUTIL_H_ sl@0: #define __SCMBYTESTREAMUTIL_H_ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: sl@0: namespace Debug sl@0: { sl@0: /** sl@0: * Base class for byte stream write - simply deals with the supplied buffer & position sl@0: */ sl@0: class TByteStreamBase sl@0: { sl@0: public: sl@0: TByteStreamBase(TUint8* aBuffer); sl@0: virtual void SetPosition(TInt aPosition); sl@0: virtual TInt CurrentPosition() const; sl@0: sl@0: protected: sl@0: sl@0: /** sl@0: * Pointer to the buffer we will use to write/read to sl@0: */ sl@0: TUint8* iBuffer; sl@0: sl@0: /** sl@0: * Current position in buffer sl@0: */ sl@0: TInt iPos; sl@0: }; sl@0: sl@0: /** sl@0: * Class for reading byte stream sl@0: */ sl@0: class TByteStreamReader : public TByteStreamBase sl@0: { sl@0: public: sl@0: TByteStreamReader(TUint8* aBuffer); sl@0: inline virtual TUint8 ReadByte(); sl@0: inline TUint16 ReadShort(); sl@0: inline TUint32 ReadInt(); sl@0: inline TUint64 ReadInt64(); sl@0: }; sl@0: sl@0: /** sl@0: * Class for writing byte stream sl@0: */ sl@0: class TByteStreamWriter : public TByteStreamBase sl@0: { sl@0: public: sl@0: TByteStreamWriter(TUint8* aBuffer, TBool aPhsEnabled = ETrue); sl@0: virtual void WriteByte(TUint8 aValue); sl@0: inline void WriteShort(TUint16 aValue); sl@0: inline void WriteInt(TUint32 aValue); sl@0: inline void WriteInt64(TUint64 aValue); sl@0: inline virtual void EnablePhysicalWriting(); sl@0: inline virtual void DisablePhysicalWriting(); sl@0: inline virtual TBool PhysicalWritingEnabled() const {return iPhysEnabled;}; sl@0: inline TInt GetBytesWritten() const {return iBytesWritten;}; sl@0: void ResetBytesWritten(); sl@0: sl@0: protected: sl@0: sl@0: /** sl@0: * This records whether or not physical writing via DoPhysical write from set writer sl@0: */ sl@0: TBool iPhysEnabled; sl@0: sl@0: /** sl@0: * Records the number of bytes we have written to our buffer sl@0: */ sl@0: TInt iBytesWritten; sl@0: }; sl@0: sl@0: /** sl@0: * This is the interface to write to flash sl@0: */ sl@0: class MPhysicalWriterImpl sl@0: { sl@0: public: sl@0: virtual void DoPhysicalWrite(TAny* aData,TInt aPos, TInt aLen) = 0; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: *Class for writing byte stream via cache sl@0: */ sl@0: class TCachedByteStreamWriter : public TByteStreamWriter sl@0: { sl@0: public: sl@0: sl@0: TCachedByteStreamWriter(TUint8* aCacheBuffer, TInt aCacheSize, TBool aPhysEnabled = ETrue); sl@0: virtual TInt CurrentPosition() const; sl@0: virtual void WriteByte(TUint8 aValue); sl@0: virtual TInt FlushCache(); sl@0: void SetWriterImpl(MPhysicalWriterImpl* aPhysicalWriter); sl@0: TInt GetCacheSize() const {return iCacheSize; }; sl@0: sl@0: protected: sl@0: TInt iCacheSize; sl@0: TUint8* iCacheBuffer; sl@0: MPhysicalWriterImpl* iPhysicalWriter; sl@0: }; sl@0: sl@0: /** sl@0: * Serialization implementation interface sl@0: */ sl@0: class MByteStreamSerializable sl@0: { sl@0: public: sl@0: virtual TInt Serialize(TByteStreamWriter& aWriter) = 0; sl@0: virtual TInt Deserialize(TByteStreamReader& aReader) = 0; sl@0: virtual TInt GetSize() const = 0; sl@0: }; sl@0: } sl@0: sl@0: sl@0: #include sl@0: sl@0: sl@0: sl@0: #endif /*BYTESTREAMUTIL_H_*/