os/kernelhwsrv/kernel/eka/debug/crashMonitor/inc/scmbytestreamutil.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// some utility classes for writing data to buffer
sl@0
    15
// 
sl@0
    16
// WARNING: This file contains some APIs which are internal and are subject
sl@0
    17
//          to change without notice. Such APIs should therefore not be used
sl@0
    18
//          outside the Kernel and Hardware Services package.
sl@0
    19
//
sl@0
    20
sl@0
    21
/**
sl@0
    22
 @file
sl@0
    23
 @internalTechnology
sl@0
    24
*/
sl@0
    25
#ifndef __SCMBYTESTREAMUTIL_H_
sl@0
    26
#define __SCMBYTESTREAMUTIL_H_
sl@0
    27
sl@0
    28
#include <e32cmn.h> 
sl@0
    29
#include <e32def.h>
sl@0
    30
#include <e32const.h>
sl@0
    31
sl@0
    32
sl@0
    33
namespace Debug 
sl@0
    34
	{ 
sl@0
    35
	/**
sl@0
    36
	 * Base class for byte stream write - simply deals with the supplied buffer & position 
sl@0
    37
	 */
sl@0
    38
	class TByteStreamBase
sl@0
    39
		{
sl@0
    40
	public:
sl@0
    41
		TByteStreamBase(TUint8* aBuffer);
sl@0
    42
		virtual void SetPosition(TInt aPosition);
sl@0
    43
		virtual TInt CurrentPosition() const;
sl@0
    44
	
sl@0
    45
	protected:	
sl@0
    46
		
sl@0
    47
		/**
sl@0
    48
		 * Pointer to the buffer we will use to write/read to 
sl@0
    49
		 */
sl@0
    50
		TUint8* iBuffer;
sl@0
    51
		
sl@0
    52
		/**
sl@0
    53
		 * Current position in buffer
sl@0
    54
		 */
sl@0
    55
		TInt iPos;	
sl@0
    56
		};
sl@0
    57
	
sl@0
    58
	/**
sl@0
    59
	 * Class for reading byte stream
sl@0
    60
	 */
sl@0
    61
	class TByteStreamReader : public TByteStreamBase		
sl@0
    62
		{
sl@0
    63
	public:
sl@0
    64
		TByteStreamReader(TUint8* aBuffer);
sl@0
    65
		inline virtual TUint8 ReadByte();
sl@0
    66
		inline TUint16 ReadShort();
sl@0
    67
		inline TUint32 ReadInt();
sl@0
    68
		inline TUint64 ReadInt64();		
sl@0
    69
		};	
sl@0
    70
sl@0
    71
	/**
sl@0
    72
	 * Class for writing byte stream
sl@0
    73
	 */
sl@0
    74
	class TByteStreamWriter : public TByteStreamBase		
sl@0
    75
		{		
sl@0
    76
	public:
sl@0
    77
		TByteStreamWriter(TUint8* aBuffer, TBool aPhsEnabled = ETrue);	
sl@0
    78
		virtual void WriteByte(TUint8 aValue);
sl@0
    79
		inline void WriteShort(TUint16 aValue);
sl@0
    80
		inline void WriteInt(TUint32 aValue);
sl@0
    81
		inline void WriteInt64(TUint64 aValue);
sl@0
    82
		inline virtual void EnablePhysicalWriting();
sl@0
    83
		inline virtual void DisablePhysicalWriting();
sl@0
    84
		inline virtual TBool PhysicalWritingEnabled() const {return iPhysEnabled;};
sl@0
    85
		inline TInt GetBytesWritten() const {return iBytesWritten;};	
sl@0
    86
		void ResetBytesWritten();
sl@0
    87
		
sl@0
    88
	protected:
sl@0
    89
		
sl@0
    90
		/** 
sl@0
    91
		 * This records whether or not physical writing via DoPhysical write from set writer
sl@0
    92
		 */
sl@0
    93
		TBool iPhysEnabled;
sl@0
    94
		
sl@0
    95
		/**
sl@0
    96
		 * Records the number of bytes we have written to our buffer
sl@0
    97
		 */
sl@0
    98
		TInt iBytesWritten;
sl@0
    99
		};	
sl@0
   100
		
sl@0
   101
	/**
sl@0
   102
	 * This is the interface to write to flash
sl@0
   103
	 */
sl@0
   104
	class MPhysicalWriterImpl 
sl@0
   105
		{
sl@0
   106
		public:			
sl@0
   107
			virtual void DoPhysicalWrite(TAny* aData,TInt aPos, TInt aLen) = 0;
sl@0
   108
		};
sl@0
   109
	
sl@0
   110
	
sl@0
   111
	/**
sl@0
   112
	 *Class for writing byte stream via cache 
sl@0
   113
	 */
sl@0
   114
	class TCachedByteStreamWriter : public TByteStreamWriter		
sl@0
   115
		{		
sl@0
   116
	public:
sl@0
   117
			
sl@0
   118
		TCachedByteStreamWriter(TUint8* aCacheBuffer, TInt aCacheSize,  TBool aPhysEnabled = ETrue);
sl@0
   119
		virtual TInt CurrentPosition() const;
sl@0
   120
		virtual void WriteByte(TUint8 aValue);
sl@0
   121
		virtual TInt FlushCache();
sl@0
   122
		void SetWriterImpl(MPhysicalWriterImpl* aPhysicalWriter);
sl@0
   123
		TInt GetCacheSize() const  {return iCacheSize; };
sl@0
   124
		
sl@0
   125
	protected:		
sl@0
   126
		TInt iCacheSize;
sl@0
   127
		TUint8* iCacheBuffer;  			
sl@0
   128
		MPhysicalWriterImpl* iPhysicalWriter;
sl@0
   129
		};
sl@0
   130
	
sl@0
   131
	/**
sl@0
   132
	 * Serialization implementation interface
sl@0
   133
	 */
sl@0
   134
	class MByteStreamSerializable
sl@0
   135
		{
sl@0
   136
	public:
sl@0
   137
		virtual TInt Serialize(TByteStreamWriter& aWriter) = 0;
sl@0
   138
		virtual TInt Deserialize(TByteStreamReader& aReader) = 0;
sl@0
   139
 		virtual TInt GetSize() const = 0;
sl@0
   140
		};
sl@0
   141
	}
sl@0
   142
sl@0
   143
sl@0
   144
#include <scmbytestreamutil.inl>
sl@0
   145
sl@0
   146
sl@0
   147
sl@0
   148
#endif /*BYTESTREAMUTIL_H_*/