mavtables
0.2.1
MAVLink router and firewall.
|
#include <Connection.hpp>
Public Member Functions | |
Connection (std::string name, std::shared_ptr< Filter > filter, bool mirror=false, std::unique_ptr< AddressPool<>> pool=std::make_unique< AddressPool<>>(), std::unique_ptr< PacketQueue > queue=std::make_unique< PacketQueue >()) | |
TEST_VIRTUAL | ~Connection ()=default |
TEST_VIRTUAL void | add_address (MAVAddress address) |
TEST_VIRTUAL std::shared_ptr< const Packet > | next_packet (const std::chrono::nanoseconds &timeout=std::chrono::nanoseconds(0)) |
TEST_VIRTUAL void | send (std::shared_ptr< const Packet > packet) |
Friends | |
std::ostream & | operator<< (std::ostream &os, const Connection &connection) |
Represents a connection that packets can be sent over.
The connection class does not actually send anything. It filters and sorts packets in a queue for sending by an Interface. It also maintains a list of MAVLink addresses reachable on this connection.
Definition at line 39 of file Connection.hpp.
Connection::Connection | ( | std::string | name, |
std::shared_ptr< Filter > | filter, | ||
bool | mirror = false , |
||
std::unique_ptr< AddressPool<>> | pool = std::make_unique<AddressPool<>>() , |
||
std::unique_ptr< PacketQueue > | queue = std::make_unique<PacketQueue>() |
||
) |
Construct a connection.
name | The name of the connection, should be the device string for a serial connection or the IP address and port number for a UDP connection. |
filter | The packet filter to use for determining whether and with what priority to add a packet to the queue for transmission. |
mirror | Set to true if this is to be a mirror connection. A mirror connection is one that will receive all packets, regardless of destination address. The default is false. |
pool | The AddressPool to use for keeping track of the addresses reachable by the connection. A default address pool will be used if none is given. |
queue | The PacketQueue to use to hold packets awaiting transmission. A default packet queue will be used if none is given. |
std::invalid_argument | if the given any of the filter , pool , or queue pointers are null. |
Definition at line 244 of file Connection.cpp.
|
default |
void Connection::add_address | ( | MAVAddress | address | ) |
Add a MAVLink address to the connection.
This adds an address to the list of systems/components that can be reached on this connection.
address | The MAVLink address to add, or update the timeout for. |
Definition at line 281 of file Connection.cpp.
References Logger::level(), Logger::log(), and str().
std::shared_ptr< const Packet > Connection::next_packet | ( | const std::chrono::nanoseconds & | timeout = std::chrono::nanoseconds(0) | ) |
Get next packet to send.
Blocks until a packet is ready to be sent or the timeout
expires. Returns nullptr in the later case.
timeout | How long to block waiting for a packet. Set to 0s for non blocking. |
Definition at line 303 of file Connection.cpp.
void Connection::send | ( | std::shared_ptr< const Packet > | packet | ) |
Send a packet out on the connection.
Packets are ran through the contained Filter before being placed into the PacketQueue given in the constructor. Packets are read from the queue (for sending) by using the next_packet method.
packet | The packet to send. |
std::invalid_argument | if the packet pointer is null. |
Definition at line 327 of file Connection.cpp.
References MAVAddress::component(), and MAVAddress::system().
|
friend |
Print the connection name to the given output stream.
Some examples are:
/dev/ttyUSB0
127.0.0.1:8000
127.0.0.1:14550
Definition at line 368 of file Connection.cpp.