BlueToe
an alternative GATT/BLE implementation
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
bluetoe::link_layer::pdu_ring_buffer< Size, Buffer, Layout > Class Template Reference

structure, able to store variable sized link layer PDUs in a fixed size ring. More...

#include <bluetoe/link_layer/include/bluetoe/ring_buffer.hpp>

Public Member Functions

 pdu_ring_buffer (std::uint8_t *buffer)
 sets up the ring to be empty
 
void reset (std::uint8_t *buffer)
 resets the ring to be empty
 
Buffer alloc_front (std::uint8_t *buffer, std::size_t size) const
 return a writeable PDU buffer of at least size bytes at the front of the ring
 
void push_front (std::uint8_t *buffer, const Buffer &pdu)
 stores the allocated PDU in the ring.
 
Buffer next_end () const
 returns the next PDU from the ring.
 
void pop_end (std::uint8_t *buffer)
 frees the last PDU at the end of the ring
 
bool more_than_one () const
 returns true, if the buffer contains at least 2 elements
 

Static Public Attributes

static constexpr std::size_t size = Size
 the size of the buffer in bytes
 

Detailed Description

template<std::size_t Size, typename Buffer = read_buffer, typename Layout = default_pdu_layout>
class bluetoe::link_layer::pdu_ring_buffer< Size, Buffer, Layout >

structure, able to store variable sized link layer PDUs in a fixed size ring.

The buffer uses the size field of the stored PDUs as pointers to the next PDU stored in the buffer.

Elements are inserted at the front and removed from the end. When the ring buffer is empty it is garantied that the buffer can store one elemente of at least Size - 1 in size.

The Layout is used to access the header field of the PDU and to determin the in memory length of stored PDUs.

Constructor & Destructor Documentation

◆ pdu_ring_buffer()

template<std::size_t Size, typename Buffer , typename Layout >
bluetoe::link_layer::pdu_ring_buffer< Size, Buffer, Layout >::pdu_ring_buffer ( std::uint8_t *  buffer)
explicit

sets up the ring to be empty

Precondition
next_end().size == 0
buffer must point to an array of at least Size bytes

Member Function Documentation

◆ alloc_front()

template<std::size_t Size, typename Buffer , typename Layout >
Buffer bluetoe::link_layer::pdu_ring_buffer< Size, Buffer, Layout >::alloc_front ( std::uint8_t *  buffer,
std::size_t  size 
) const

return a writeable PDU buffer of at least size bytes at the front of the ring

The function is idempotent and will yield the same results as long as the state of the buffer is not changed and the parameters are the same.

If there is not enough room for size bytes in the ring buffer, the function will return an empty read_buffer.

Precondition
size > Layout::data_channel_pdu_memory_size( 0 )
buffer must point to an array of at least Size bytes

◆ next_end()

template<std::size_t Size, typename Buffer , typename Layout >
Buffer bluetoe::link_layer::pdu_ring_buffer< Size, Buffer, Layout >::next_end

returns the next PDU from the ring.

If no PDU is stored in the ring, the function will return an empty write_buffer.

◆ pop_end()

template<std::size_t Size, typename Buffer , typename Layout >
void bluetoe::link_layer::pdu_ring_buffer< Size, Buffer, Layout >::pop_end ( std::uint8_t *  buffer)

frees the last PDU at the end of the ring

Precondition
next_end().size == 0

◆ push_front()

template<std::size_t Size, typename Buffer , typename Layout >
void bluetoe::link_layer::pdu_ring_buffer< Size, Buffer, Layout >::push_front ( std::uint8_t *  buffer,
const Buffer &  pdu 
)

stores the allocated PDU in the ring.

The length field of the PDU must contain the actual size of the PDU - 2. Now the stored PDU can be read through the ring.

Precondition
pdu.size >= Layout::data_channel_pdu_memory_size( Layout::header( pdu ) >> 8 )
Layout::header( pdu ) >> 8 != 0
Postcondition
next_end().size != 0

◆ reset()

template<std::size_t Size, typename Buffer , typename Layout >
void bluetoe::link_layer::pdu_ring_buffer< Size, Buffer, Layout >::reset ( std::uint8_t *  buffer)

resets the ring to be empty

Precondition
next_end().size == 0
buffer must point to an array of at least Size bytes

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