HDLC-Daemon
main-hdlcd.cpp
Go to the documentation of this file.
1 
22 #include "Config.h"
23 #include <iostream>
24 #include <boost/asio.hpp>
25 #include <boost/program_options.hpp>
28 
29 int main(int argc, char **argv) {
30  try {
31  // Declare the supported options.
32  boost::program_options::options_description l_Description("Allowed options");
33  l_Description.add_options()
34  ("help,h", "produce this help message")
35  ("version,v", "show version information")
36  ("port,p", boost::program_options::value<uint16_t>(),
37  "the TCP port to accept clients on")
38  ;
39 
40  // Parse the command line
41  boost::program_options::variables_map l_VariablesMap;
42  boost::program_options::store(boost::program_options::parse_command_line(argc, argv, l_Description), l_VariablesMap);
43  boost::program_options::notify(l_VariablesMap);
44  if (l_VariablesMap.count("version")) {
45  std::cerr << "HDLC daemon version " << HDLCD_VERSION_MAJOR << "." << HDLCD_VERSION_MINOR
46  << " built with hdlcd-devel version " << HDLCD_DEVEL_VERSION_MAJOR << "." << HDLCD_DEVEL_VERSION_MINOR << std::endl;
47  } // if
48 
49  if (l_VariablesMap.count("help")) {
50  std::cout << l_Description << std::endl;
51  std::cout << "The HDLC Daemon is Copyright (C) 2016, and GNU GPL'd, by Florian Evers." << std::endl;
52  std::cout << "Bug reports, feedback, admiration, abuse, etc, to: https://github.com/Strunzdesign/hdlcd" << std::endl;
53  return 1;
54  } // if
55 
56  if (!l_VariablesMap.count("port")) {
57  std::cout << "hdlcd: you have to specify the TCP listener port" << std::endl;
58  std::cout << "hdlcd: Use --help for more information." << std::endl;
59  return 1;
60  } // if
61 
62  // Install signal handlers
63  boost::asio::io_service l_IoService;
64  boost::asio::signal_set l_Signals(l_IoService);
65  l_Signals.add(SIGINT);
66  l_Signals.add(SIGTERM);
67  l_Signals.async_wait([&l_IoService](boost::system::error_code, int){ l_IoService.stop(); });
68 
69  // Create and initialize components
70  auto l_SerialPortHandlerCollection = std::make_shared<SerialPortHandlerCollection> (l_IoService);
71  auto l_HdlcdServerHandlerCollection = std::make_shared<HdlcdServerHandlerCollection>(l_IoService, l_SerialPortHandlerCollection, l_VariablesMap["port"].as<uint16_t>());
72 
73  // Start event processing
74  l_IoService.run();
75 
76  // Shutdown
77  l_HdlcdServerHandlerCollection->Shutdown();
78  l_SerialPortHandlerCollection->Shutdown();
79 
80  } catch (std::exception& a_Error) {
81  std::cerr << "Exception: " << a_Error.what() << "\n";
82  return 1;
83  } // catch
84 
85  return 0;
86 }
The HDLC Deamon implements the HDLC protocol to easily talk to devices connected via serial communica...
#define HDLCD_DEVEL_VERSION_MINOR
Definition: HdlcdConfig.h:41
int main(int argc, char **argv)
Definition: main-hdlcd.cpp:29
The HDLC Deamon implements the HDLC protocol to easily talk to devices connected via serial communica...
#define HDLCD_DEVEL_VERSION_MAJOR
Definition: HdlcdConfig.h:40