mavtables  0.2.1
MAVLink router and firewall.
Interface.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 INTERFACE_HPP_
19 #define INTERFACE_HPP_
20 
21 
22 #include <chrono>
23 #include <memory>
24 
25 #include "ConnectionPool.hpp"
26 
27 
28 /** The base class for all interfaces.
29  *
30  * Derived classes should add one or more connections to queue packets for
31  * sending.
32  */
33 class Interface
34 {
35  public:
36  virtual ~Interface();
37  /** Send a packet from one of the interface's connections.
38  *
39  * \note Which connection to take this packet from is not defined but
40  * it must not starve any one of the \ref Interface's connections.
41  *
42  * \param timeout The maximum amount of time to wait for a packet to be
43  * available for sending.
44  */
45  virtual void send_packet(const std::chrono::nanoseconds &timeout) = 0;
46  /** Receive a packet on the interface.
47  *
48  * \param timeout The maximum amount of time to wait for incoming data.
49  */
50  virtual void receive_packet(
51  const std::chrono::nanoseconds &timeout) = 0;
52 
53  friend std::ostream &operator<<(
54  std::ostream &os, const Interface &interface);
55 
56  protected:
57  /** Print the interface to the given output stream.
58  *
59  * \param os The output stream to print to.
60  * \returns The output stream.
61  */
62  virtual std::ostream &print_(std::ostream &os) const = 0;
63 };
64 
65 
66 std::ostream &operator<<(std::ostream &os, const Interface &interface);
67 
68 
69 #endif // INTERFACE_HPP_
virtual std::ostream & print_(std::ostream &os) const =0
virtual void receive_packet(const std::chrono::nanoseconds &timeout)=0
virtual ~Interface()
Definition: Interface.cpp:27
virtual void send_packet(const std::chrono::nanoseconds &timeout)=0
std::ostream & operator<<(std::ostream &os, const Action &action)
Definition: Action.cpp:188
friend std::ostream & operator<<(std::ostream &os, const Interface &interface)
Definition: Interface.cpp:58