mavtables  0.2.1
MAVLink router and firewall.
ConfigParser.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 CONFIGPARSER_HPP_
19 #define CONFIGPARSER_HPP_
20 
21 
22 #include <map>
23 #include <memory>
24 #include <ostream>
25 #include <string>
26 
27 #include <pegtl.hpp>
28 
29 #include "App.hpp"
30 #include "Chain.hpp"
31 #include "Filter.hpp"
32 #include "parse_tree.hpp"
33 #include "SerialInterface.hpp"
34 #include "UDPInterface.hpp"
35 
36 
37 std::map<std::string, std::shared_ptr<Chain>> init_chains(
38  const config::parse_tree::node &root);
39 
40 std::unique_ptr<Rule> parse_action(
41  const config::parse_tree::node &root,
42  std::optional<int> priority,
43  std::optional<If> condition,
44  const std::map<std::string, std::shared_ptr<Chain>> &chains);
45 
46 void parse_chain(
47  Chain &chain,
48  const config::parse_tree::node &root,
49  const std::map<std::string, std::shared_ptr<Chain>> &chains);
50 
51 If parse_condition(const config::parse_tree::node &root);
52 
53 std::unique_ptr<Filter> parse_filter(const config::parse_tree::node &root);
54 
55 std::vector<std::unique_ptr<Interface>> parse_interfaces(
56  const config::parse_tree::node &root, std::unique_ptr<Filter> filter);
57 
58 std::unique_ptr<SerialInterface> parse_serial(
59  const config::parse_tree::node &root,
60  std::shared_ptr<Filter> filter,
61  std::shared_ptr<ConnectionPool> pool);
62 
63 std::unique_ptr<UDPInterface> parse_udp(
64  const config::parse_tree::node &root,
65  std::shared_ptr<Filter> filter,
66  std::shared_ptr<ConnectionPool> pool);
67 
68 
69 /** Configuration file parser.
70  *
71  * Used to parse a configuration file and create an instance of the mavtables
72  * application.
73  */
75 {
76  public:
77  ConfigParser(std::string filename);
78  ConfigParser(const ConfigParser &other) = delete;
79  ConfigParser(ConfigParser &&other) = delete;
80  std::unique_ptr<App> make_app();
81  ConfigParser &operator=(const ConfigParser &other) = delete;
82  ConfigParser &operator=(ConfigParser &&other) = delete;
83 
84  friend std::ostream &operator<<(
85  std::ostream &os, const ConfigParser &config_parser);
86 
87  protected:
88  tao::pegtl::read_input<> in_;
89  std::unique_ptr<config::parse_tree::node> root_;
90 };
91 
92 
93 std::ostream &operator<<(std::ostream &os, const ConfigParser &config_parser);
94 
95 
96 #endif // CONFIGPARSER_HPP_
tao::pegtl::read_input in_
If parse_condition(const config::parse_tree::node &root)
std::unique_ptr< App > make_app()
Definition: If.hpp:35
std::unique_ptr< Filter > parse_filter(const config::parse_tree::node &root)
friend std::ostream & operator<<(std::ostream &os, const ConfigParser &config_parser)
std::unique_ptr< UDPInterface > parse_udp(const config::parse_tree::node &root, std::shared_ptr< Filter > filter, std::shared_ptr< ConnectionPool > pool)
std::unique_ptr< SerialInterface > parse_serial(const config::parse_tree::node &root, std::shared_ptr< Filter > filter, std::shared_ptr< ConnectionPool > pool)
ConfigParser & operator=(const ConfigParser &other)=delete
std::ostream & operator<<(std::ostream &os, const Action &action)
Definition: Action.cpp:188
std::unique_ptr< config::parse_tree::node > root_
ConfigParser(std::string filename)
std::vector< std::unique_ptr< Interface > > parse_interfaces(const config::parse_tree::node &root, std::unique_ptr< Filter > filter)
Definition: Chain.hpp:37
void parse_chain(Chain &chain, const config::parse_tree::node &root, const std::map< std::string, std::shared_ptr< Chain >> &chains)
std::map< std::string, std::shared_ptr< Chain > > init_chains(const config::parse_tree::node &root)
std::unique_ptr< Rule > parse_action(const config::parse_tree::node &root, std::optional< int > priority, std::optional< If > condition, const std::map< std::string, std::shared_ptr< Chain >> &chains)