Class CMemBufferAccessorBase#

Nested Relationships#

Nested Types#

Inheritance Relationships#

Derived Types#

Class Documentation#

class CMemBufferAccessorBase#

Memory buffer accessor.

Lock-free memory buffer accessor. This buffer allows the writing and reading of memory packets in a circular buffer.

Remark

This class doesn’t provide any handshaking. This is the task of the objects using this class.

Attention

This class does not synchronize calls! It works if only one thread at the time writes data and only one thread at the time reads data. Reading and writing can occur simulateously.

Attention

No protection is implemented to monitor the lifetime of the buffer. It is assumed that during any call this buffer is valid.

Subclassed by CMemBufferAccessorRx, CMemBufferAccessorTx

Public Functions

CMemBufferAccessorBase() = default#

Constructor.

virtual void Attach(uint8_t *pBuffer, uint32_t uiSize = 0)#

Attach the buffer to the accessor.

Parameters:
  • pBuffer[in] Pointer to the buffer that should be accessed.

  • uiSize[in] Size of the buffer when still uninitialized (during buffer creation); otherwise 0.

virtual void Detach()#

Detach the buffer from the accessor.

bool IsValid() const#

Is valid.

Returns:

Returns ‘true’ when valid; otherwise ‘false’.

const uint8_t *GetBufferPointer() const#

Get the buffer pointer.

Returns:

Returns a pointer to the buffer or NULL when there is no buffer.

inline void ResetRx()#

Reset the Rx position to skip any sent data. Typically needed when a reconnect should take place.

inline void CancelSend()#

Cancel send operation.

inline bool Canceled() const#

Canceled?

Returns:

Returns ‘true’ when the currend send job has been canceled; ‘false’ when not.

Protected Functions

SPacketHdr *GetPacketHdr(uint32_t uiPos) const#

Providing the position, return the packet header preceding the data.

Parameters:

uiPos[in] The position in the buffer

Returns:

Pointer to the packet header or NULL when the position isn’t within the buffer.

uint8_t *GetPacketData(uint32_t uiPos) const#

Providing the position, return the packet data following the header.

Parameters:

uiPos[in] The position in the buffer

Returns:

Pointer to the packet data or NULL when the position isn’t within the buffer.

inline virtual bool HasUnreadData() const#

Has unread data.

Returns:

Returns ‘true’ when unread data is still available; otherwise returns ‘false’.

virtual void TriggerDataSend() = 0#

Trigger listener that a write operation was completed.

virtual bool WaitForData(uint32_t uiTimeoutMs) const = 0#

Wait for a write operation to be completed.

Parameters:

uiTimeoutMs[in] The amount of time (in ms) to wait for a trigger.

Returns:

Returns ‘true’ when data was stored, ‘false’ when a timeout occurred.

virtual void TriggerDataReceive() = 0#

Trigger listener that a read operation was completed.

virtual bool WaitForFreeSpace(uint32_t uiTimeoutMs) const = 0#

Wait for a read operation to be completed.

Parameters:

uiTimeoutMs[in] The amount of time (in ms) to wait for a trigger.

Returns:

Returns ‘true’ when data was stored, ‘false’ when a timeout occurred.

template<typename T>
inline uint32_t Align(T tSize)#

Align to 64 bits.

Template Parameters:

T – The type of the size argument.

Parameters:

tSize[in] The current size.

Returns:

The 64-bit aligned size.

Protected Attributes

uint8_t *m_pBuffer = nullptr#

Buffer pointer.

SBufferHdr *m_pHdr = nullptr#

Buffer header.

bool m_bCancel = false#

Cancel the send operation.

struct SBufferHdr#

Memory buffer header.

Public Members

uint32_t uiVersion = SDVFrameworkInterfaceVersion#

Check for compatible communication channel.

uint32_t uiSize = 0u#

The size of the buffer.

uint32_t uiTxPos = 0u#

Current write position.

uint32_t uiRxPos = 0u#

Current read position.

struct SPacketHdr#

Packet header.

The packet header is placed in front of every packet and describes the packet type as well as the size of the packet.

Remark

Packets are always starting at a 64-bit boundary.

Public Types

enum class EType : uint16_t#

Packet types.

Values:

enumerator data#

The packet contains data.

enumerator stuffing#

The packet doesn’t contain data and is used to fill up space.

enum class EState : uint16_t#

Packet state.

Values:

enumerator free#

Packet is not reserved; overwriting is allowed.

enumerator reserved#

Space is reserved but not committed.

enumerator commit#

Packet is committed and available for reading.

enumerator read#

Packet is currently being read.

Public Members

enum CMemBufferAccessorBase::SPacketHdr::EType eType#

Packet type.

enum CMemBufferAccessorBase::SPacketHdr::EState eState#

The packet state.

uint32_t uiSize#

Packet size.