Design Pattern Examples
Overview of object-oriented design patterns
DataReaderWriter Class Reference

Represents a data reader/writer to a caller. More...

Inheritance diagram for DataReaderWriter:
Inheritance graph
Collaboration diagram for DataReaderWriter:
Collaboration graph

Public Types

enum  MemoryBlockNumber { Memory_Block_0 = 0 , Memory_Block_1 = 1 , Memory_Block_2 = 2 }
 Represents the memory blocks that can be accessed. Hides how memory blocks are actually identified. More...
 

Public Member Functions

 DataReaderWriter (MemoryBlockNumber blockNumber)
 Constructor for a data reader/writer.
 
byte[] Read (int byteOffset, uint maxBytes)
 Read a specified number of bytes.
 
void Write (int byteOffset, byte[] data, uint maxBytes)
 Write a specified number of bytes.
 
string BufferToString (byte[] data, uint maxBytes, int indent)
 Convert the specified data up to the specified number of bytes into a string by performing a "hex dump" on the data.
 
void Dispose ()
 Shut down the data reader/writer and dispose of resources.
 

Properties

uint MemoryBlockByteSize [get]
 Retrieve the size of the memory block in bytes.
 

Private Member Functions

string _GetBlockNameForBlockNumber (MemoryBlockNumber blockNumber)
 Helper function to convert a value from the MemoryBlockNumber enumeration, which specifies the number of a memory block, into the name of the block as required by the low-level Adapter_BackEnd DLL.
 
string _GetErrorMessage (DDR_ErrorCode errorCode)
 Convert the given error code to a string message.
 
string _ConstructErrorMessage (DDR_ErrorCode errorCode, string operation)
 Creates a formatted error message from the given operation, using the error code from the Adapter_BackEnd library.
 

Private Attributes

bool _disposed
 
bool _initialized
 
int _dataHandle
 
uint _memoryBlockByteSize
 

Detailed Description

Represents a data reader/writer to a caller.

Wraps the DataReaderWriterFunctions.

Definition at line 43 of file Adapter_FrontEndClass.cs.

Member Enumeration Documentation

◆ MemoryBlockNumber

Represents the memory blocks that can be accessed. Hides how memory blocks are actually identified.

Enumerator
Memory_Block_0 

First block.

Memory_Block_1 

Second block.

Memory_Block_2 

Third block.

Definition at line 49 of file Adapter_FrontEndClass.cs.

Constructor & Destructor Documentation

◆ DataReaderWriter()

DataReaderWriter ( MemoryBlockNumber  blockNumber)
inline

Constructor for a data reader/writer.

Parameters
blockNumberA value from the MemoryBlockNumber enumeration indicating the block of memory to open.
Exceptions
DataReaderWriterInitExceptionFailed to initialize the data reader/writer.

Definition at line 171 of file Adapter_FrontEndClass.cs.

References DataReaderWriter._ConstructErrorMessage(), DataReaderWriter._dataHandle, DataReaderWriter._GetBlockNameForBlockNumber(), DataReaderWriter._initialized, DataReaderWriter._memoryBlockByteSize, DataReadWriteFunctions.DDR_GetMemorySize(), and DataReadWriteFunctions.DDR_OpenMemoryBlock().

Member Function Documentation

◆ _ConstructErrorMessage()

string _ConstructErrorMessage ( DDR_ErrorCode  errorCode,
string  operation 
)
inlineprivate

Creates a formatted error message from the given operation, using the error code from the Adapter_BackEnd library.

Parameters
errorCodeThe error code from the underlying library to be converted to a string.
operationThe operation that was in process when the error occurred.
Returns
Returns an error message formatted as a string.

Definition at line 158 of file Adapter_FrontEndClass.cs.

References DataReaderWriter._GetErrorMessage().

Referenced by DataReaderWriter.__enter__(), DataReaderWriter.DataReaderWriter(), DataReaderWriter.Dispose(), DataReaderWriter.MemoryBlockByteSize(), DataReaderWriter.Read(), and DataReaderWriter.Write().

◆ _GetBlockNameForBlockNumber()

string _GetBlockNameForBlockNumber ( MemoryBlockNumber  blockNumber)
inlineprivate

Helper function to convert a value from the MemoryBlockNumber enumeration, which specifies the number of a memory block, into the name of the block as required by the low-level Adapter_BackEnd DLL.

Parameters
blockNumberValue from the MemoryBlockNumber enumeration for which to get the block name.
Returns
Returns a string containing the name of the block.

Definition at line 77 of file Adapter_FrontEndClass.cs.

References BLOCK_NAME_0, BLOCK_NAME_1, and BLOCK_NAME_2.

Referenced by DataReaderWriter.__enter__(), and DataReaderWriter.DataReaderWriter().

◆ _GetErrorMessage()

string _GetErrorMessage ( DDR_ErrorCode  errorCode)
inlineprivate

Convert the given error code to a string message.

Parameters
errorCodeA value from the DDR_ErrorCode enumeration.
Returns
A constant string describing the error.

Definition at line 107 of file Adapter_FrontEndClass.cs.

Referenced by DataReaderWriter._ConstructErrorMessage().

◆ BufferToString()

string BufferToString ( byte[]  data,
uint  maxBytes,
int  indent 
)
inline

Convert the specified data up to the specified number of bytes into a string by performing a "hex dump" on the data.

Parameters
dataThe data to process.
maxBytesThe number of bytes from the data to process.
indentNumber of spaces to indent each line.
Returns
A string containing the data in the form of a hex dump, possibly multiple lines.

Definition at line 352 of file Adapter_FrontEndClass.cs.

◆ Dispose()

void Dispose ( )
inline

Shut down the data reader/writer and dispose of resources.

Exceptions
DataReaderWriterInitExceptionData reader/writer not initialized.

Definition at line 389 of file Adapter_FrontEndClass.cs.

References DataReaderWriter._ConstructErrorMessage(), DataReaderWriter._dataHandle, DataReaderWriter._disposed, DataReaderWriter._initialized, and DataReadWriteFunctions.DDR_CloseMemoryBlock().

◆ Read()

byte[] Read ( int  byteOffset,
uint  maxBytes 
)
inline

Read a specified number of bytes.

Parameters
byteOffsetByte offset into the memory block from which to start reading.
maxBytesNumber of bytes to read
Returns
An array of bytes that were read.
Exceptions
DataReaderWriterInitExceptionData reader/writer not initialized.
DataReaderWriterExceptionFailed to read data.

Definition at line 211 of file Adapter_FrontEndClass.cs.

References DataReaderWriter._ConstructErrorMessage(), DataReaderWriter._dataHandle, DataReaderWriter._initialized, DDR_GetDataChunk(), and DataReadWriteFunctions.DDR_MAX_OFFSET.

◆ Write()

void Write ( int  byteOffset,
byte[]  data,
uint  maxBytes 
)
inline

Write a specified number of bytes.

Parameters
byteOffsetByte offset into the memory block to which to start writing.
dataArray of bytes to write. Must be at least 'maxBytes' in length.
maxBytesNumber of bytes to write
Exceptions
DataReaderWriterInitExceptionData reader/writer not initialized.
DataReaderWriterExceptionFailed to write data.

Definition at line 272 of file Adapter_FrontEndClass.cs.

References DataReaderWriter._ConstructErrorMessage(), DataReaderWriter._dataHandle, DataReaderWriter._initialized, DDR_GetDataChunk(), DDR_MAX_OFFSET, and DDR_SetDataChunk().

Member Data Documentation

◆ _dataHandle

◆ _disposed

bool _disposed
private

Definition at line 56 of file Adapter_FrontEndClass.cs.

Referenced by DataReaderWriter.Dispose().

◆ _initialized

◆ _memoryBlockByteSize

uint _memoryBlockByteSize
private

Property Documentation

◆ MemoryBlockByteSize

uint MemoryBlockByteSize
get

Retrieve the size of the memory block in bytes.

Definition at line 64 of file Adapter_FrontEndClass.cs.


The documentation for this class was generated from the following file: