Satellite-Gateway
main-satellite-gateway.cpp
Go to the documentation of this file.
1 
24 #include "Config.h"
25 #include <iostream>
26 #include <boost/asio.hpp>
27 #include <boost/program_options.hpp>
31 
32 int main(int argc, char* argv[]) {
33  try {
34  // Declare the supported options.
35  boost::program_options::options_description l_Description("Allowed options");
36  l_Description.add_options()
37  ("help,h", "produce this help message")
38  ("version,v", "show version information")
39  ("port,p", boost::program_options::value<uint16_t>(),
40  "the TCP port to accept control connections on")
41  ("trace,t", "each relayed packet is dissected and printed")
42  ;
43 
44  // Parse the command line
45  boost::program_options::variables_map l_VariablesMap;
46  boost::program_options::store(boost::program_options::parse_command_line(argc, argv, l_Description), l_VariablesMap);
47  boost::program_options::notify(l_VariablesMap);
48  if (l_VariablesMap.count("version")) {
49  std::cerr << "s-net(r) satellite gateway version " << SATELLITE_GATEWAY_VERSION_MAJOR << "." << SATELLITE_GATEWAY_VERSION_MINOR
50  << " built with hdlcd-devel version " << HDLCD_DEVEL_VERSION_MAJOR << "." << HDLCD_DEVEL_VERSION_MINOR
51  << " and snet-devel version " << SNET_DEVEL_VERSION_MAJOR << "." << SNET_DEVEL_VERSION_MINOR << std::endl;
52  } // if
53 
54  if (l_VariablesMap.count("help")) {
55  std::cout << l_Description << std::endl;
56  std::cout << "The satellite gateway software for the HDLC Daemon is Copyright (C) 2016, and GNU GPL'd, by Florian Evers." << std::endl;
57  std::cout << "Bug reports, feedback, admiration, abuse, etc, to: https://github.com/Strunzdesign/satellite-gateway" << std::endl;
58  return 1;
59  } // if
60 
61  if (!l_VariablesMap.count("port")) {
62  std::cout << "satellite-gateway: you have to specify the TCP listener port to accept control connections on" << std::endl;
63  std::cout << "satellite-gateway: Use --help for more information." << std::endl;
64  return 1;
65  } // if
66 
67  // Install signal handlers
68  boost::asio::io_service l_IoService;
69  boost::asio::signal_set l_Signals(l_IoService);
70  l_Signals.add(SIGINT);
71  l_Signals.add(SIGTERM);
72  l_Signals.async_wait([&l_IoService](boost::system::error_code, int){ l_IoService.stop(); });
73 
74  // Create and initialize components
75  auto l_ConfigServerHandlerCollection = std::make_shared<ConfigServerHandlerCollection>(l_IoService, l_VariablesMap["port"].as<uint16_t>());
76  auto l_GatewayClientHandlerCollection = std::make_shared<GatewayClientHandlerCollection>(l_IoService);
77  auto l_HdlcdClientHandlerCollection = std::make_shared<HdlcdClientHandlerCollection>(l_IoService);
78  l_ConfigServerHandlerCollection->Initialize (l_GatewayClientHandlerCollection, l_HdlcdClientHandlerCollection);
79  l_GatewayClientHandlerCollection->Initialize(l_ConfigServerHandlerCollection, l_HdlcdClientHandlerCollection);
80  l_HdlcdClientHandlerCollection->Initialize (l_ConfigServerHandlerCollection, l_GatewayClientHandlerCollection);
81 
82  // Start event processing
83  l_IoService.run();
84 
85  // Shutdown
86  l_ConfigServerHandlerCollection->SystemShutdown();
87  l_GatewayClientHandlerCollection->SystemShutdown();
88  l_HdlcdClientHandlerCollection->SystemShutdown();
89 
90  } catch (std::exception& a_Error) {
91  std::cerr << "Exception: " << a_Error.what() << "\n";
92  return 1;
93  } // catch
94 
95  return 0;
96 }
#define HDLCD_DEVEL_VERSION_MINOR
Definition: HdlcdConfig.h:41
#define SNET_DEVEL_VERSION_MAJOR
Definition: SnetConfig.h:2
#define SNET_DEVEL_VERSION_MINOR
Definition: SnetConfig.h:3
#define HDLCD_DEVEL_VERSION_MAJOR
Definition: HdlcdConfig.h:40
int main(int argc, char *argv[])