DUNE: Uniform Navigational Environment  2019.02.1
DUNE::Utils::RawFifo Class Reference

Detailed Description

Implementation of a First In First Out data structure, that can hold raw data (byte streams).

Data is stored internally in a circular buffer. This structure can be accessed without locks when there is only one concurrent writer and one concurrent reader.

Public Member Functions

 RawFifo (uint32_t size)
 
 RawFifo (uint8_t *data, uint32_t size)
 
 ~RawFifo (void)
 
void reset (void)
 
uint32_t size (void)
 
uint32_t put (const uint8_t *buffer, uint32_t length)
 
uint32_t get (uint8_t *buffer, uint32_t length)
 
uint32_t getHead (uint8_t *buffer, uint32_t length)
 
uint32_t discard (uint32_t length)
 

Constructor & Destructor Documentation

DUNE::Utils::RawFifo::RawFifo ( uint32_t  size)

Creates a new FIFO, allocating necessary space.

Parameters
sizesize of the FIFO data (will be transformed to the nearest power of two).

References DUNE::Math::computeNextPowerOfTwo().

DUNE::Utils::RawFifo::RawFifo ( uint8_t *  data,
uint32_t  size 
)

Creates a FIFO from an existing array.

Parameters
dataarray of data.
sizesize of the array (must be a power of two).
DUNE::Utils::RawFifo::~RawFifo ( void  )
inline

Class destructor.

Member Function Documentation

uint32_t DUNE::Utils::RawFifo::discard ( uint32_t  length)

Discards data from the FIFO.

Parameters
lengthamount of bytes to discard.
Returns
amount of bytes discarded.

Referenced by get().

uint32_t DUNE::Utils::RawFifo::get ( uint8_t *  buffer,
uint32_t  length 
)
inline

Retrieves data from the FIFO.

Parameters
bufferbuffer that will hold the retrieved data.
lengthamount of bytes to retrieve.
Returns
amount of bytes retrieved.

References discard(), and getHead().

uint32_t DUNE::Utils::RawFifo::getHead ( uint8_t *  buffer,
uint32_t  length 
)

Retrieves the head of the FIFO.

Parameters
bufferbuffer that will hold the retrieved data.
lengthamount of bytes to retrieve.
Returns
amount of bytes retrieved.

Referenced by get().

uint32_t DUNE::Utils::RawFifo::put ( const uint8_t *  buffer,
uint32_t  length 
)

Inserts data into the FIFO.

Parameters
bufferdata to be inserted.
lengthlength of the data to be inserted.
Returns
amount of bytes inserted.

Referenced by size().

void DUNE::Utils::RawFifo::reset ( void  )
inline

Resets the FIFO contents.

uint32_t DUNE::Utils::RawFifo::size ( void  )
inline

Computes the FIFO size.

Returns
FIFO size in bytes.

References put().

Collaboration diagram for DUNE::Utils::RawFifo:
Collaboration graph