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 // some utility classes for writing data to buffer
16 // WARNING: This file contains some APIs which are internal and are subject
17 // to change without notice. Such APIs should therefore not be used
18 // outside the Kernel and Hardware Services package.
25 #ifndef __SCMBYTESTREAMUTIL_H_
26 #define __SCMBYTESTREAMUTIL_H_
36 * Base class for byte stream write - simply deals with the supplied buffer & position
41 TByteStreamBase(TUint8* aBuffer);
42 virtual void SetPosition(TInt aPosition);
43 virtual TInt CurrentPosition() const;
48 * Pointer to the buffer we will use to write/read to
53 * Current position in buffer
59 * Class for reading byte stream
61 class TByteStreamReader : public TByteStreamBase
64 TByteStreamReader(TUint8* aBuffer);
65 inline virtual TUint8 ReadByte();
66 inline TUint16 ReadShort();
67 inline TUint32 ReadInt();
68 inline TUint64 ReadInt64();
72 * Class for writing byte stream
74 class TByteStreamWriter : public TByteStreamBase
77 TByteStreamWriter(TUint8* aBuffer, TBool aPhsEnabled = ETrue);
78 virtual void WriteByte(TUint8 aValue);
79 inline void WriteShort(TUint16 aValue);
80 inline void WriteInt(TUint32 aValue);
81 inline void WriteInt64(TUint64 aValue);
82 inline virtual void EnablePhysicalWriting();
83 inline virtual void DisablePhysicalWriting();
84 inline virtual TBool PhysicalWritingEnabled() const {return iPhysEnabled;};
85 inline TInt GetBytesWritten() const {return iBytesWritten;};
86 void ResetBytesWritten();
91 * This records whether or not physical writing via DoPhysical write from set writer
96 * Records the number of bytes we have written to our buffer
102 * This is the interface to write to flash
104 class MPhysicalWriterImpl
107 virtual void DoPhysicalWrite(TAny* aData,TInt aPos, TInt aLen) = 0;
112 *Class for writing byte stream via cache
114 class TCachedByteStreamWriter : public TByteStreamWriter
118 TCachedByteStreamWriter(TUint8* aCacheBuffer, TInt aCacheSize, TBool aPhysEnabled = ETrue);
119 virtual TInt CurrentPosition() const;
120 virtual void WriteByte(TUint8 aValue);
121 virtual TInt FlushCache();
122 void SetWriterImpl(MPhysicalWriterImpl* aPhysicalWriter);
123 TInt GetCacheSize() const {return iCacheSize; };
127 TUint8* iCacheBuffer;
128 MPhysicalWriterImpl* iPhysicalWriter;
132 * Serialization implementation interface
134 class MByteStreamSerializable
137 virtual TInt Serialize(TByteStreamWriter& aWriter) = 0;
138 virtual TInt Deserialize(TByteStreamReader& aReader) = 0;
139 virtual TInt GetSize() const = 0;
144 #include <scmbytestreamutil.inl>
148 #endif /*BYTESTREAMUTIL_H_*/