os/kernelhwsrv/kernel/eka/debug/crashMonitor/inc/scmbytestreamutil.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // some utility classes for writing data to buffer
    15 // 
    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.
    19 //
    20 
    21 /**
    22  @file
    23  @internalTechnology
    24 */
    25 #ifndef __SCMBYTESTREAMUTIL_H_
    26 #define __SCMBYTESTREAMUTIL_H_
    27 
    28 #include <e32cmn.h> 
    29 #include <e32def.h>
    30 #include <e32const.h>
    31 
    32 
    33 namespace Debug 
    34 	{ 
    35 	/**
    36 	 * Base class for byte stream write - simply deals with the supplied buffer & position 
    37 	 */
    38 	class TByteStreamBase
    39 		{
    40 	public:
    41 		TByteStreamBase(TUint8* aBuffer);
    42 		virtual void SetPosition(TInt aPosition);
    43 		virtual TInt CurrentPosition() const;
    44 	
    45 	protected:	
    46 		
    47 		/**
    48 		 * Pointer to the buffer we will use to write/read to 
    49 		 */
    50 		TUint8* iBuffer;
    51 		
    52 		/**
    53 		 * Current position in buffer
    54 		 */
    55 		TInt iPos;	
    56 		};
    57 	
    58 	/**
    59 	 * Class for reading byte stream
    60 	 */
    61 	class TByteStreamReader : public TByteStreamBase		
    62 		{
    63 	public:
    64 		TByteStreamReader(TUint8* aBuffer);
    65 		inline virtual TUint8 ReadByte();
    66 		inline TUint16 ReadShort();
    67 		inline TUint32 ReadInt();
    68 		inline TUint64 ReadInt64();		
    69 		};	
    70 
    71 	/**
    72 	 * Class for writing byte stream
    73 	 */
    74 	class TByteStreamWriter : public TByteStreamBase		
    75 		{		
    76 	public:
    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();
    87 		
    88 	protected:
    89 		
    90 		/** 
    91 		 * This records whether or not physical writing via DoPhysical write from set writer
    92 		 */
    93 		TBool iPhysEnabled;
    94 		
    95 		/**
    96 		 * Records the number of bytes we have written to our buffer
    97 		 */
    98 		TInt iBytesWritten;
    99 		};	
   100 		
   101 	/**
   102 	 * This is the interface to write to flash
   103 	 */
   104 	class MPhysicalWriterImpl 
   105 		{
   106 		public:			
   107 			virtual void DoPhysicalWrite(TAny* aData,TInt aPos, TInt aLen) = 0;
   108 		};
   109 	
   110 	
   111 	/**
   112 	 *Class for writing byte stream via cache 
   113 	 */
   114 	class TCachedByteStreamWriter : public TByteStreamWriter		
   115 		{		
   116 	public:
   117 			
   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; };
   124 		
   125 	protected:		
   126 		TInt iCacheSize;
   127 		TUint8* iCacheBuffer;  			
   128 		MPhysicalWriterImpl* iPhysicalWriter;
   129 		};
   130 	
   131 	/**
   132 	 * Serialization implementation interface
   133 	 */
   134 	class MByteStreamSerializable
   135 		{
   136 	public:
   137 		virtual TInt Serialize(TByteStreamWriter& aWriter) = 0;
   138 		virtual TInt Deserialize(TByteStreamReader& aReader) = 0;
   139  		virtual TInt GetSize() const = 0;
   140 		};
   141 	}
   142 
   143 
   144 #include <scmbytestreamutil.inl>
   145 
   146 
   147 
   148 #endif /*BYTESTREAMUTIL_H_*/