mavtables  0.2.1
MAVLink router and firewall.
Public Member Functions | List of all members
PacketQueue Class Reference

#include <PacketQueue.hpp>

Collaboration diagram for PacketQueue:
Collaboration graph

Public Member Functions

 PacketQueue (std::optional< std::function< void(void)>> callback={})
 
TEST_VIRTUAL ~PacketQueue ()=default
 
TEST_VIRTUAL void close ()
 
TEST_VIRTUAL bool empty ()
 
TEST_VIRTUAL std::shared_ptr< const Packetpop ()
 
TEST_VIRTUAL std::shared_ptr< const Packetpop (const std::chrono::nanoseconds &timeout)
 
TEST_VIRTUAL void push (std::shared_ptr< const Packet > packet, int priority=0)
 

Detailed Description

A threadsafe priority queue for MAVLink packets.

This priority queue will order packets based on priority but also maintains insertion order among packets of the same priority.

This is used to implement the packet priority of the firewall and to provide a queueing mechanism for packets when consumers are slower than the producers.

See also
QueuedPacket

Definition at line 45 of file PacketQueue.hpp.

Constructor & Destructor Documentation

◆ PacketQueue()

PacketQueue::PacketQueue ( std::optional< std::function< void(void)>>  callback = {})

Construct a packet queue.

Parameters
callbackA function to call whenever a new packet is added to the queue. This allows the queue to signal when it has become non empty. The default is no callback {}.

Definition at line 58 of file PacketQueue.cpp.

◆ ~PacketQueue()

TEST_VIRTUAL PacketQueue::~PacketQueue ( )
default

Member Function Documentation

◆ close()

void PacketQueue::close ( )

Close the queue.

This will release any blocking calls to pop.

Remarks
Threadsafe (locking).

Definition at line 70 of file PacketQueue.cpp.

◆ empty()

bool PacketQueue::empty ( )

Determine if the packet queue is empty or not.

retval true There are no packets in the queue. retval false There is at least one packet in the queue.

Remarks
Threadsafe (locking).

Definition at line 87 of file PacketQueue.cpp.

◆ pop() [1/2]

std::shared_ptr< const Packet > PacketQueue::pop ( )

Remove and return the packet at the front of the queue.

This version will block on an empty queue and will not return until the queue becomes non empty or is closed with close.

Returns
The packet that was at the front of the queue, or nullptr if the queue was closed.
Remarks
Threadsafe (locking).
See also
pop(const std::chrono::nanoseconds &)

Definition at line 105 of file PacketQueue.cpp.

◆ pop() [2/2]

std::shared_ptr< const Packet > PacketQueue::pop ( const std::chrono::nanoseconds &  timeout)

Remove and return the packet at the front of the queue.

This version will block on an empty queue and will not return until the queue becomes non empty, is closed with close, or the timeout has expired.

Parameters
timeoutHow long to block waiting for an empty queue. Set to 0s for non blocking.
Returns
The packet that was at the front of the queue, or nullptr if the queue was closed or the timeout expired.
Remarks
Threadsafe (locking).
See also
pop()

Definition at line 132 of file PacketQueue.cpp.

◆ push()

void PacketQueue::push ( std::shared_ptr< const Packet packet,
int  priority = 0 
)

Add a new packet to the queue, with a priority.

A higher priority will result in the packet being pushed to the front of the queue. When priorities are equal the order in which the packets were added to the queue is maintained.

Parameters
packetThe packet to add to the queue. It must not be nullptr.
priorityThe priority to use when adding it to the queue. The default is 0.
Exceptions
std::invalid_argumentif the packet pointer is null.
Remarks
Threadsafe (locking).

Definition at line 164 of file PacketQueue.cpp.


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