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

#include <QueuedPacket.hpp>

Collaboration diagram for QueuedPacket:
Collaboration graph

Public Member Functions

 QueuedPacket (const QueuedPacket &other)=default
 
 QueuedPacket (QueuedPacket &&other)=default
 
 QueuedPacket (std::shared_ptr< const Packet > packet, int priority, unsigned long long ticket_number)
 
std::shared_ptr< const Packetpacket () const
 
QueuedPacketoperator= (const QueuedPacket &other)=default
 
QueuedPacketoperator= (QueuedPacket &&other)=default
 

Friends

bool operator== (const QueuedPacket &lhs, const QueuedPacket &rhs)
 
bool operator!= (const QueuedPacket &lhs, const QueuedPacket &rhs)
 
bool operator< (const QueuedPacket &lhs, const QueuedPacket &rhs)
 
bool operator> (const QueuedPacket &lhs, const QueuedPacket &rhs)
 
bool operator<= (const QueuedPacket &lhs, const QueuedPacket &rhs)
 
bool operator>= (const QueuedPacket &lhs, const QueuedPacket &rhs)
 
std::ostream & operator<< (std::ostream &os, const QueuedPacket &queued_packet)
 

Detailed Description

A packet in the queue to be sent out.

Forms a node in the PacketQueue class.

This is the data structure used in the priority queues used by the Connection class. It stores a MAVLink packet as well as a priority and ticket number used to maintain packet order in the priority queue when packets have the same priority.

See also
PacketQueue

Definition at line 39 of file QueuedPacket.hpp.

Constructor & Destructor Documentation

◆ QueuedPacket() [1/3]

QueuedPacket::QueuedPacket ( const QueuedPacket other)
default

Copy constructor.

Parameters
otherQueuedPacket to copy from.

◆ QueuedPacket() [2/3]

QueuedPacket::QueuedPacket ( QueuedPacket &&  other)
default

Move constructor.

Parameters
otherQueuedPacket to move from.

◆ QueuedPacket() [3/3]

QueuedPacket::QueuedPacket ( std::shared_ptr< const Packet packet,
int  priority,
unsigned long long  ticket_number 
)

Construct a queued packet.

Parameters
packetThe packet to store in the queue.
priorityThe priority to send the packet with, higher numbers result in a higher priority.
ticket_numberA number that should always be incremented for each queued packet created per packet queue, even if this increment causes an unsigned integer wraparound.
Exceptions
std::invalid_argumentif the given packet pointer is nullptr.

Definition at line 36 of file QueuedPacket.cpp.

Member Function Documentation

◆ operator=() [1/2]

QueuedPacket& QueuedPacket::operator= ( const QueuedPacket other)
default

Assignment operator.

Parameters
otherQueuedPacket to copy from.

◆ operator=() [2/2]

QueuedPacket& QueuedPacket::operator= ( QueuedPacket &&  other)
default

Assignment operator (by move semantics).

Parameters
otherQueuedPacket to move from.

◆ packet()

std::shared_ptr< const Packet > QueuedPacket::packet ( ) const

Return the contained packet.

Returns
The contained MAVLink packet.

Definition at line 53 of file QueuedPacket.cpp.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const QueuedPacket lhs,
const QueuedPacket rhs 
)
friend

Inequality comparison.

Note
It should never be the case that two queued packets have the same ticket number and thus two queued packets should never be equal.
Parameters
lhsThe left hand side queued packet.
rhsThe right hand side queued packet.
Return values
trueif lhs and rhs do not have the same priority and ticket number.
falseif lhs and rhs have the same priority and ticket number.

Definition at line 90 of file QueuedPacket.cpp.

◆ operator<

bool operator< ( const QueuedPacket lhs,
const QueuedPacket rhs 
)
friend

Less than comparison.

The priority is considered first, followed by the ticket number in reverse order (lower ticket number is greater).

Note
The ticket number is considered to be a wrapping integer and thus numbers that are within std::numeric_limits<unsigned long long>::max()/2 of each other are considered in the same range. In this way 0 is greater than std::numeric_limits<unsigned long long>::max(). Because of this it is important that anything relying on ordering must not contain a range of ticket numbers equal to or grater than std::numeric_limits<unsigned long long>::max()/2.
Parameters
lhsThe left hand side queued packet.
rhsThe right hand side queued packet.
Return values
trueif lhs is less than rhs.
falseif lhs is not less than rhs.

Definition at line 116 of file QueuedPacket.cpp.

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const QueuedPacket queued_packet 
)
friend

Print the packet to the given output stream.

Some examples are:

  • HEARTBEAT (#1) from 16.8 (v1.0) with priority -3
  • PING (#4) from 128.4 to 16.8 (v2.0) with priority 0
  • DATA_TRANSMISSION_HANDSHAKE (#130) from 16.8 (v2.0) with priority 3
  • ENCAPSULATED_DATA (#131) from 128.4 (v2.0) with priority 1
Parameters
osThe output stream to print to.
queued_packetThe queued packet to print.
Returns
The output stream.

Definition at line 192 of file QueuedPacket.cpp.

◆ operator<=

bool operator<= ( const QueuedPacket lhs,
const QueuedPacket rhs 
)
friend

Less than or equal comparison.

Parameters
lhsThe left hand side queued packet.
rhsThe right hand side queued packet.
Return values
trueif lhs is less than or eqaul to rhs.
falseif lhs is greater than rhs.

Definition at line 159 of file QueuedPacket.cpp.

◆ operator==

bool operator== ( const QueuedPacket lhs,
const QueuedPacket rhs 
)
friend

Equality comparison.

Note
It should never be the case that two queued packets have the same ticket number and thus two queued packets should never be equal.
Parameters
lhsThe left hand side queued packet.
rhsThe right hand side queued packet.
Return values
trueif lhs and rhs have the same priority and ticket number.
falseif lhs and rhs do not have the same priority and ticket number.

Definition at line 71 of file QueuedPacket.cpp.

◆ operator>

bool operator> ( const QueuedPacket lhs,
const QueuedPacket rhs 
)
friend

Greater than comparison.

The priority is considered first, followed by the ticket number in reverse order (lower ticket number is greater).

Note
The ticket number is considered to be a wrapping integer and thus numbers that are within std::numeric_limits<unsigned long long>::max()/2 of each other are considered in the same range. In this way 0 is greater than std::numeric_limits<unsigned long long>::max(). Because of this it is important that anything relying on ordering must not contain a range of ticket numbers equal to or grater than std::numeric_limits<unsigned long long>::max()/2.
Parameters
lhsThe left hand side queued packet.
rhsThe right hand side queued packet.
Return values
trueif lhs is less than rhs.
falseif lhs is not less than rhs.

Definition at line 143 of file QueuedPacket.cpp.

◆ operator>=

bool operator>= ( const QueuedPacket lhs,
const QueuedPacket rhs 
)
friend

Greater than or equal comparison.

Parameters
lhsThe left hand side queued packet.
rhsThe right hand side queued packet.
Return values
trueif lhs is greater than or equal to rhs.
falseif lhs is less than rhs.

Definition at line 173 of file QueuedPacket.cpp.


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