-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
executable file
·49 lines (41 loc) · 1.5 KB
/
main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <string>
#include <boost/program_options.hpp>
#include "server.hpp"
#include "config.hpp"
#include "mqtt.hpp"
namespace po = boost::program_options;
/**
* @brief main
* @param argc
* @param argv
* @return
*/
int main(int argc, char* argv[])
{
try {
po::options_description desc("Allowed options");
desc.add_options()
(dashbutton::config::ARG_HELP, "produce help message")
(dashbutton::config::ARG_PORT, po::value<uint16_t>()->default_value(443)->required(), "port to listen on")
(dashbutton::config::ARG_CONFIG, po::value<std::string>()->default_value("dashbutton.xml"), "configuration file name")
(dashbutton::config::ARG_DEV, po::value<std::string>()->default_value("enp3s0"), "name of the device to resolve mac address");
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count(dashbutton::config::ARG_HELP)) {
std::cout << desc << std::endl;
return 1;
}
dashbutton::config config(vm[dashbutton::config::ARG_CONFIG].as<std::string>());
config.overrideConfigByCommandLine(vm);
dashbutton::mqtt mqtt(config.mqtt());
io::io_context io_context;
dashbutton::server srv(io_context, config, mqtt);
io_context.run();
}
catch (std::exception& ex) {
std::cerr << ex.what() << std::endl;
}
return 0;
}