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

#include <Connection.hpp>

Collaboration diagram for Connection:
Collaboration graph

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 Packetnext_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)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Connection()

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.

Parameters
nameThe name of the connection, should be the device string for a serial connection or the IP address and port number for a UDP connection.
filterThe packet filter to use for determining whether and with what priority to add a packet to the queue for transmission.
mirrorSet 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.
poolThe AddressPool to use for keeping track of the addresses reachable by the connection. A default address pool will be used if none is given.
queueThe PacketQueue to use to hold packets awaiting transmission. A default packet queue will be used if none is given.
Exceptions
std::invalid_argumentif the given any of the filter, pool, or queue pointers are null.
Remarks
If the given AddressPool and PacketQueue are threadsafe then the connection will also be threadsafe.

Definition at line 244 of file Connection.cpp.

◆ ~Connection()

TEST_VIRTUAL Connection::~Connection ( )
default

Member Function Documentation

◆ add_address()

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.

Note
Addresses will be removed after the timeout set in the AddressPool given in the constructor. Re-adding the address (even before this time runs out) will reset the timeout.
Parameters
addressThe MAVLink address to add, or update the timeout for.

Definition at line 281 of file Connection.cpp.

References Logger::level(), Logger::log(), and str().

Here is the call graph for this function:

◆ next_packet()

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.

Parameters
timeoutHow long to block waiting for a packet. Set to 0s for non blocking.
Returns
The next packet to send. Or nullptr if the call times out waiting on a packet.

Definition at line 303 of file Connection.cpp.

◆ send()

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.

Note
If the packet has a destination address that is not 0.0 (the broadcast address) it will only be sent if that system is reachable on this connection. It will still be sent even if the particular component cannot be found.
If this is a mirror connection then the destination address of the packet is ignored.
Parameters
packetThe packet to send.
Exceptions
std::invalid_argumentif the packet pointer is null.

Definition at line 327 of file Connection.cpp.

References MAVAddress::component(), and MAVAddress::system().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const Connection connection 
)
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.


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