os/kernelhwsrv/kernel/eka/debug/crashMonitor/inc/scmbytestreamutil.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/debug/crashMonitor/inc/scmbytestreamutil.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,148 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// some utility classes for writing data to buffer
    1.18 +// 
    1.19 +// WARNING: This file contains some APIs which are internal and are subject
    1.20 +//          to change without notice. Such APIs should therefore not be used
    1.21 +//          outside the Kernel and Hardware Services package.
    1.22 +//
    1.23 +
    1.24 +/**
    1.25 + @file
    1.26 + @internalTechnology
    1.27 +*/
    1.28 +#ifndef __SCMBYTESTREAMUTIL_H_
    1.29 +#define __SCMBYTESTREAMUTIL_H_
    1.30 +
    1.31 +#include <e32cmn.h> 
    1.32 +#include <e32def.h>
    1.33 +#include <e32const.h>
    1.34 +
    1.35 +
    1.36 +namespace Debug 
    1.37 +	{ 
    1.38 +	/**
    1.39 +	 * Base class for byte stream write - simply deals with the supplied buffer & position 
    1.40 +	 */
    1.41 +	class TByteStreamBase
    1.42 +		{
    1.43 +	public:
    1.44 +		TByteStreamBase(TUint8* aBuffer);
    1.45 +		virtual void SetPosition(TInt aPosition);
    1.46 +		virtual TInt CurrentPosition() const;
    1.47 +	
    1.48 +	protected:	
    1.49 +		
    1.50 +		/**
    1.51 +		 * Pointer to the buffer we will use to write/read to 
    1.52 +		 */
    1.53 +		TUint8* iBuffer;
    1.54 +		
    1.55 +		/**
    1.56 +		 * Current position in buffer
    1.57 +		 */
    1.58 +		TInt iPos;	
    1.59 +		};
    1.60 +	
    1.61 +	/**
    1.62 +	 * Class for reading byte stream
    1.63 +	 */
    1.64 +	class TByteStreamReader : public TByteStreamBase		
    1.65 +		{
    1.66 +	public:
    1.67 +		TByteStreamReader(TUint8* aBuffer);
    1.68 +		inline virtual TUint8 ReadByte();
    1.69 +		inline TUint16 ReadShort();
    1.70 +		inline TUint32 ReadInt();
    1.71 +		inline TUint64 ReadInt64();		
    1.72 +		};	
    1.73 +
    1.74 +	/**
    1.75 +	 * Class for writing byte stream
    1.76 +	 */
    1.77 +	class TByteStreamWriter : public TByteStreamBase		
    1.78 +		{		
    1.79 +	public:
    1.80 +		TByteStreamWriter(TUint8* aBuffer, TBool aPhsEnabled = ETrue);	
    1.81 +		virtual void WriteByte(TUint8 aValue);
    1.82 +		inline void WriteShort(TUint16 aValue);
    1.83 +		inline void WriteInt(TUint32 aValue);
    1.84 +		inline void WriteInt64(TUint64 aValue);
    1.85 +		inline virtual void EnablePhysicalWriting();
    1.86 +		inline virtual void DisablePhysicalWriting();
    1.87 +		inline virtual TBool PhysicalWritingEnabled() const {return iPhysEnabled;};
    1.88 +		inline TInt GetBytesWritten() const {return iBytesWritten;};	
    1.89 +		void ResetBytesWritten();
    1.90 +		
    1.91 +	protected:
    1.92 +		
    1.93 +		/** 
    1.94 +		 * This records whether or not physical writing via DoPhysical write from set writer
    1.95 +		 */
    1.96 +		TBool iPhysEnabled;
    1.97 +		
    1.98 +		/**
    1.99 +		 * Records the number of bytes we have written to our buffer
   1.100 +		 */
   1.101 +		TInt iBytesWritten;
   1.102 +		};	
   1.103 +		
   1.104 +	/**
   1.105 +	 * This is the interface to write to flash
   1.106 +	 */
   1.107 +	class MPhysicalWriterImpl 
   1.108 +		{
   1.109 +		public:			
   1.110 +			virtual void DoPhysicalWrite(TAny* aData,TInt aPos, TInt aLen) = 0;
   1.111 +		};
   1.112 +	
   1.113 +	
   1.114 +	/**
   1.115 +	 *Class for writing byte stream via cache 
   1.116 +	 */
   1.117 +	class TCachedByteStreamWriter : public TByteStreamWriter		
   1.118 +		{		
   1.119 +	public:
   1.120 +			
   1.121 +		TCachedByteStreamWriter(TUint8* aCacheBuffer, TInt aCacheSize,  TBool aPhysEnabled = ETrue);
   1.122 +		virtual TInt CurrentPosition() const;
   1.123 +		virtual void WriteByte(TUint8 aValue);
   1.124 +		virtual TInt FlushCache();
   1.125 +		void SetWriterImpl(MPhysicalWriterImpl* aPhysicalWriter);
   1.126 +		TInt GetCacheSize() const  {return iCacheSize; };
   1.127 +		
   1.128 +	protected:		
   1.129 +		TInt iCacheSize;
   1.130 +		TUint8* iCacheBuffer;  			
   1.131 +		MPhysicalWriterImpl* iPhysicalWriter;
   1.132 +		};
   1.133 +	
   1.134 +	/**
   1.135 +	 * Serialization implementation interface
   1.136 +	 */
   1.137 +	class MByteStreamSerializable
   1.138 +		{
   1.139 +	public:
   1.140 +		virtual TInt Serialize(TByteStreamWriter& aWriter) = 0;
   1.141 +		virtual TInt Deserialize(TByteStreamReader& aReader) = 0;
   1.142 + 		virtual TInt GetSize() const = 0;
   1.143 +		};
   1.144 +	}
   1.145 +
   1.146 +
   1.147 +#include <scmbytestreamutil.inl>
   1.148 +
   1.149 +
   1.150 +
   1.151 +#endif /*BYTESTREAMUTIL_H_*/