mavtables
0.2.1
MAVLink router and firewall.
|
#include <PacketQueue.hpp>
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 Packet > | pop () |
TEST_VIRTUAL std::shared_ptr< const Packet > | pop (const std::chrono::nanoseconds &timeout) |
TEST_VIRTUAL void | push (std::shared_ptr< const Packet > packet, int priority=0) |
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.
Definition at line 45 of file PacketQueue.hpp.
PacketQueue::PacketQueue | ( | std::optional< std::function< void(void)>> | callback = {} | ) |
Construct a packet queue.
callback | A 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.
|
default |
void PacketQueue::close | ( | ) |
Close the queue.
This will release any blocking calls to pop.
Definition at line 70 of file PacketQueue.cpp.
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.
Definition at line 87 of file PacketQueue.cpp.
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.
Definition at line 105 of file PacketQueue.cpp.
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.
timeout | How long to block waiting for an empty queue. Set to 0s for non blocking. |
Definition at line 132 of file PacketQueue.cpp.
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.
packet | The packet to add to the queue. It must not be nullptr. |
priority | The priority to use when adding it to the queue. The default is 0. |
std::invalid_argument | if the packet pointer is null. |
Definition at line 164 of file PacketQueue.cpp.