mavtables  0.2.1
MAVLink router and firewall.
mavtables.cpp
Go to the documentation of this file.
1 // MAVLink router and firewall.
2 // Copyright (C) 2017 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 #include <cstdlib>
19 #include <exception>
20 #include <iostream>
21 #include <string>
22 
23 #include <boost/program_options.hpp>
24 
25 #include "config.hpp"
26 #include "config_grammar.hpp"
27 #include "ConfigParser.hpp"
28 #include "Logger.hpp"
29 #include "Options.hpp"
30 #include "utility.hpp"
31 
32 
33 /** mavtables: A MAVLink router and firewall.
34  *
35  * See the README for further documentation.
36  */
37 int main(int argc, const char *argv[])
38 {
39  try
40  {
41  Options options(argc, argv);
42 
43  if (options)
44  {
45  auto config = std::make_unique<ConfigParser>(options.config_file());
46 
47  if (options.ast())
48  {
49  std::cout << "===== " << options.config_file()
50  << " =====" << std::endl;
51  std::cout << *config;
52  }
53 
54  if (options.run())
55  {
56  Logger::level(options.loglevel());
57  auto app = config->make_app();
58  app->run();
59  }
60  }
61  }
62  catch (const std::exception &e)
63  {
64  std::cerr << "error: " << e.what() << std::endl;
65  return EXIT_FAILURE;
66  }
67 
68  return EXIT_SUCCESS;
69 }
bool run()
Definition: Options.cpp:167
bool ast()
Definition: Options.cpp:135
static unsigned int level()
Definition: Logger.cpp:96
unsigned int loglevel()
Definition: Options.cpp:156
int main(int argc, const char *argv[])
Definition: mavtables.cpp:37
std::string config_file()
Definition: Options.cpp:146