Design Pattern Examples
Overview of object-oriented design patterns
Adapter_BackEnd.h File Reference

Declaration of the "low-level" memory block read/write functions that are provided in a separate DLL called Adapter_BackEnd.dll, which is wrapped or adapted to by the various programming languages as part of the Adapter Pattern examples. More...

#include <stdint.h>
Include dependency graph for Adapter_BackEnd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define __ADAPTER_BACKENDFUNCTIONS_H__
 
#define DllExport
 

Enumerations

enum  { DDR_MAX_OFFSET = 32 , DDR_INVALID_HANDLE = -1 }
 
enum  DDR_ErrorCode {
  DDR_ErrorCode_Success = 0 , DDR_ErrorCode_Block_Already_Opened = 1 , DDR_ErrorCode_Block_Not_Opened = 2 , DDR_ErrorCode_Invalid_Block_Name = 3 ,
  DDR_ErrorCode_Invalid_Handle = 4 , DDR_ErrorCode_Invalid_Offset = 5 , DDR_ErrorCode_Null_Argument = 6
}
 Represents the possible errors that can be returned from the memory block access functions. More...
 

Functions

DllExport DDR_ErrorCode DDR_OpenMemoryBlock (const char *blockName, int *dataHandle)
 Open access to a memory block for exclusive use, given the name of the memory block.
 
DllExport DDR_ErrorCode DDR_CloseMemoryBlock (int dataHandle)
 Close access to a previously opened memory block, thus releasing it for others to open.
 
DllExport DDR_ErrorCode DDR_GetMemorySize (int dataHandle, int *memorySizeInChunks)
 Retrieve the number of chunks in the memory block indicated by the handle to the successfully opened memory block.
 
DllExport DDR_ErrorCode DDR_GetDataChunk (int dataHandle, int chunkOffset, uint32_t *value)
 Read a single 32-bit value at the given offset in the memory block indicated by the specified handle.
 
DllExport DDR_ErrorCode DDR_SetDataChunk (int dataHandle, int chunkOffset, uint32_t value)
 Writes a single 32-bit value to the given offset in the memory block indicated by the specified handle.
 

Variables

DllExport const char * BLOCK_NAME_0
 Name of the first block.
 
DllExport const char * BLOCK_NAME_1
 Name of the second block.
 
DllExport const char * BLOCK_NAME_2
 Name of the third block.
 

Detailed Description

Declaration of the "low-level" memory block read/write functions that are provided in a separate DLL called Adapter_BackEnd.dll, which is wrapped or adapted to by the various programming languages as part of the Adapter Pattern examples.

Definition in file Adapter_BackEnd.h.

Macro Definition Documentation

◆ __ADAPTER_BACKENDFUNCTIONS_H__

#define __ADAPTER_BACKENDFUNCTIONS_H__

Definition at line 10 of file Adapter_BackEnd.h.

◆ DllExport

#define DllExport

Definition at line 21 of file Adapter_BackEnd.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
DDR_MAX_OFFSET 

All offsets must from 0 to 1 less than this value.

DDR_INVALID_HANDLE 

Value indicating the handle is invalid.

Definition at line 38 of file Adapter_BackEnd.h.

◆ DDR_ErrorCode

Represents the possible errors that can be returned from the memory block access functions.

Enumerator
DDR_ErrorCode_Success 

Operation succeeded.

DDR_ErrorCode_Block_Already_Opened 

Memory block is already open and cannot be opened again.

DDR_ErrorCode_Block_Not_Opened 

Memory block is closed and cannot be accessed.

DDR_ErrorCode_Invalid_Block_Name 

The given name is not a recognized memory block name.

DDR_ErrorCode_Invalid_Handle 

The handle argument does not correspond to a valid open memory block.

DDR_ErrorCode_Invalid_Offset 

The given offset is out of bounds.

DDR_ErrorCode_Null_Argument 

The block name pointer or return handle pointer argument is NULL.

Definition at line 48 of file Adapter_BackEnd.h.

Function Documentation

◆ DDR_CloseMemoryBlock()

DllExport DDR_ErrorCode DDR_CloseMemoryBlock ( int  dataHandle)

Close access to a previously opened memory block, thus releasing it for others to open.

Parameters
dataHandleHandle to a previously opened memory block as obtained from the DDR_OpenMemoryBlock() function.
Returns
Returns a value from the DDR_ErrorCode enumeration indicating success or failure.

Definition at line 150 of file Adapter_BackEnd.c.

References _ConvertHandleToBlockIndex(), DDR_ErrorCode_Block_Not_Opened, DDR_ErrorCode_Invalid_Handle, DDR_ErrorCode_Success, MemoryBlock::locked, and memory_blocks.

Referenced by Adapter_CloseMemory(), and DataReaderWriter::~DataReaderWriter().

◆ DDR_GetDataChunk()

DllExport DDR_ErrorCode DDR_GetDataChunk ( int  dataHandle,
int  chunkOffset,
uint32_t *  value 
)

Read a single 32-bit value at the given offset in the memory block indicated by the specified handle.

Parameters
dataHandleHandle to a previously opened memory block as obtained from the DDR_OpenMemoryBlock() function.
chunkOffsetOffset into the memory block from which to get the value (range is 0 to DDR_MAX_OFFSET-1).
valueReturns the requested value.
Returns
Returns a value from the DDR_ErrorCode enumeration indicating success or failure.

Definition at line 191 of file Adapter_BackEnd.c.

References _ConvertHandleToBlockIndex(), _IsValidOffset(), MemoryBlock::data, DDR_ErrorCode_Block_Not_Opened, DDR_ErrorCode_Invalid_Offset, DDR_ErrorCode_Null_Argument, DDR_ErrorCode_Success, and memory_blocks.

Referenced by Adapter_ReadMemory(), Adapter_WriteMemory(), DataReaderWriter::Read(), and DataReaderWriter::Write().

◆ DDR_GetMemorySize()

DllExport DDR_ErrorCode DDR_GetMemorySize ( int  dataHandle,
int *  memorySizeInChunks 
)

Retrieve the number of chunks in the memory block indicated by the handle to the successfully opened memory block.

Parameters
dataHandleHandle to a previously opened memory block as obtained from the DDR_OpenMemoryBlock() function.
memorySizeInChunksReturns the number of 32-bit chunks in the memory block.
Returns
Returns a value from the DDR_ErrorCode enumeration indicating success or failure.

Definition at line 171 of file Adapter_BackEnd.c.

References _ConvertHandleToBlockIndex(), DDR_ErrorCode_Invalid_Handle, DDR_ErrorCode_Null_Argument, DDR_ErrorCode_Success, and MAX_DATA_SIZE.

Referenced by Adapter_GetMemorySize(), and DataReaderWriter::DataReaderWriter().

◆ DDR_OpenMemoryBlock()

DllExport DDR_ErrorCode DDR_OpenMemoryBlock ( const char *  blockName,
int *  dataHandle 
)

Open access to a memory block for exclusive use, given the name of the memory block.

Parameters
blockNameName of the block to access (one of the predefined names, BLOCK_NAME_0, BLOCK_NAME_1, or BLOCK_NAME_2)
dataHandleReturns a handle to be used for accessing the specific memory block.
Returns
Returns a value from the DDR_ErrorCode enumeration indicating success or failure.

Definition at line 121 of file Adapter_BackEnd.c.

References _FindBlock(), DDR_ErrorCode_Block_Already_Opened, DDR_ErrorCode_Invalid_Block_Name, DDR_ErrorCode_Null_Argument, DDR_ErrorCode_Success, DDR_INVALID_HANDLE, MemoryBlock::locked, and memory_blocks.

Referenced by Adapter_OpenMemory(), and DataReaderWriter::DataReaderWriter().

◆ DDR_SetDataChunk()

DllExport DDR_ErrorCode DDR_SetDataChunk ( int  dataHandle,
int  chunkOffset,
uint32_t  value 
)

Writes a single 32-bit value to the given offset in the memory block indicated by the specified handle.

Parameters
dataHandleHandle to a previously opened memory block as obtained from the DDR_OpenMemoryBlock() function.
chunkOffsetOffset into the memory block to which to set the value (range is 0 to DDR_MAX_OFFSET-1).
valueThe value to write to the memory block
Returns
Returns a value from the DDR_ErrorCode enumeration indicating success or failure.

Definition at line 219 of file Adapter_BackEnd.c.

References _ConvertHandleToBlockIndex(), _IsValidOffset(), MemoryBlock::data, DDR_ErrorCode_Block_Not_Opened, DDR_ErrorCode_Invalid_Handle, DDR_ErrorCode_Invalid_Offset, DDR_ErrorCode_Success, and memory_blocks.

Referenced by Adapter_WriteMemory(), and DataReaderWriter::Write().

Variable Documentation

◆ BLOCK_NAME_0

DllExport const char* BLOCK_NAME_0
extern

Name of the first block.

Definition at line 13 of file Adapter_BackEnd.c.

Referenced by DataReaderWriter::_GetBlockNameForBlockNumber(), and _GetBlockNameForBlockNumber().

◆ BLOCK_NAME_1

DllExport const char* BLOCK_NAME_1
extern

Name of the second block.

Definition at line 14 of file Adapter_BackEnd.c.

Referenced by DataReaderWriter::_GetBlockNameForBlockNumber(), and _GetBlockNameForBlockNumber().

◆ BLOCK_NAME_2

DllExport const char* BLOCK_NAME_2
extern

Name of the third block.

Definition at line 15 of file Adapter_BackEnd.c.

Referenced by DataReaderWriter::_GetBlockNameForBlockNumber(), and _GetBlockNameForBlockNumber().