mavtables  0.2.1
MAVLink router and firewall.
QueuedPacket.hpp
Go to the documentation of this file.
1 // MAVLink router and firewall.
2 // Copyright (C) 2018 Michael R. Shannon <mrshannon.aerospace@gmail.com>
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 
18 #ifndef QUEUEDPACKET_HPP_
19 #define QUEUEDPACKET_HPP_
20 
21 
22 #include <memory>
23 #include <ostream>
24 
25 #include "Packet.hpp"
26 
27 
28 /** A packet in the queue to be sent out.
29  *
30  * Forms a node in the \ref PacketQueue class.
31  *
32  * This is the data structure used in the priority queues used by the \ref
33  * Connection class. It stores a MAVLink packet as well as a priority and
34  * ticket number used to maintain packet order in the priority queue when
35  * packets have the same priority.
36  *
37  * \sa PacketQueue
38  */
40 {
41  public:
42  /** Copy constructor.
43  *
44  * \param other QueuedPacket to copy from.
45  */
46  QueuedPacket(const QueuedPacket &other) = default;
47  /** Move constructor.
48  *
49  * \param other QueuedPacket to move from.
50  */
51  QueuedPacket(QueuedPacket &&other) = default;
53  std::shared_ptr<const Packet> packet, int priority,
54  unsigned long long ticket_number);
55  std::shared_ptr<const Packet> packet() const;
56  /** Assignment operator.
57  *
58  * \param other QueuedPacket to copy from.
59  */
60  QueuedPacket &operator=(const QueuedPacket &other) = default;
61  /** Assignment operator (by move semantics).
62  *
63  * \param other QueuedPacket to move from.
64  */
65  QueuedPacket &operator=(QueuedPacket &&other) = default;
66 
67  friend bool operator==(
68  const QueuedPacket &lhs, const QueuedPacket &rhs);
69  friend bool operator!=(
70  const QueuedPacket &lhs, const QueuedPacket &rhs);
71  friend bool operator<(
72  const QueuedPacket &lhs, const QueuedPacket &rhs);
73  friend bool operator>(
74  const QueuedPacket &lhs, const QueuedPacket &rhs);
75  friend bool operator<=(
76  const QueuedPacket &lhs, const QueuedPacket &rhs);
77  friend bool operator>=(
78  const QueuedPacket &lhs, const QueuedPacket &rhs);
79  friend std::ostream &operator<<(
80  std::ostream &os, const QueuedPacket &queued_packet);
81 
82  private:
83  std::shared_ptr<const Packet> packet_;
84  int priority_;
85  unsigned long long ticket_number_;
86 };
87 
88 bool operator==(const QueuedPacket &lhs, const QueuedPacket &rhs);
89 bool operator!=(const QueuedPacket &lhs, const QueuedPacket &rhs);
90 bool operator<(const QueuedPacket &lhs, const QueuedPacket &rhs);
91 bool operator>(const QueuedPacket &lhs, const QueuedPacket &rhs);
92 bool operator<=(const QueuedPacket &lhs, const QueuedPacket &rhs);
93 bool operator>=(const QueuedPacket &lhs, const QueuedPacket &rhs);
94 std::ostream &operator<<(std::ostream &os, const QueuedPacket &queued_packet);
95 
96 
97 #endif // QUEUEDPACKET_HPP_
friend std::ostream & operator<<(std::ostream &os, const QueuedPacket &queued_packet)
QueuedPacket(const QueuedPacket &other)=default
friend bool operator<(const QueuedPacket &lhs, const QueuedPacket &rhs)
friend bool operator!=(const QueuedPacket &lhs, const QueuedPacket &rhs)
std::ostream & operator<<(std::ostream &os, const Action &action)
Definition: Action.cpp:188
friend bool operator>(const QueuedPacket &lhs, const QueuedPacket &rhs)
friend bool operator>=(const QueuedPacket &lhs, const QueuedPacket &rhs)
bool operator==(const Action &lhs, const Action &rhs)
Definition: Action.cpp:154
bool operator<=(const IPAddress &lhs, const IPAddress &rhs)
Definition: IPAddress.cpp:297
bool operator!=(const Action &lhs, const Action &rhs)
Definition: Action.cpp:168
bool operator>=(const IPAddress &lhs, const IPAddress &rhs)
Definition: IPAddress.cpp:313
bool operator>(const IPAddress &lhs, const IPAddress &rhs)
Definition: IPAddress.cpp:280
friend bool operator==(const QueuedPacket &lhs, const QueuedPacket &rhs)
bool operator<(const IPAddress &lhs, const IPAddress &rhs)
Definition: IPAddress.cpp:263
std::shared_ptr< const Packet > packet() const
friend bool operator<=(const QueuedPacket &lhs, const QueuedPacket &rhs)
QueuedPacket & operator=(const QueuedPacket &other)=default