-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
82 lines (66 loc) · 1.92 KB
/
main.cpp
File metadata and controls
82 lines (66 loc) · 1.92 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* (C) 2016, Richard G. Roman <richard.roman@gmx.de>
* Created on 2016-01-17 15:52:02
*
*/
#include <cstdint>
#include <boost/asio/io_service.hpp>
#include <boost/program_options.hpp>
#include <iostream>
#include "CommandParser.h"
#include "Lirc.h"
#include "Logger.h"
#include "UdpServer.h"
void
parseArgs(int argc, char** argv, uint32_t* portNumber)
{
using namespace boost::program_options;
options_description options {
"Options"
};
std::string logfile;
std::string configFile = std::string(getenv("HOME")) + "/.udpirsendrc";
options.add_options()
("help,h", "Help Screen")
("port,p", value<uint32_t>(portNumber)->default_value(6969),
"Port Number to Listen On")
("logfile,l", value<std::string>(&logfile),
"Logfile name, tilde is replaced with $HOME")
("config", value<std::string>(&configFile)->default_value(configFile),
"Configuration File");
variables_map vm;
try {
store(parse_command_line(argc, argv, options), vm);
if (vm.count("config")) {
std::ifstream ifs(vm["config"].as<std::string>().c_str());
if (ifs)
store(parse_config_file(ifs, options), vm);
}
} catch (const error& ex) {
std::cerr << ex.what() << std::endl;
}
notify(vm);
if (!logfile.empty() && logfile[0] == '~') // note: ~username/ is not handled.
logfile = std::string(getenv("HOME")) + logfile.substr(1);
Logger::Instance().initWithFilename(logfile.c_str());
if (vm.count("help"))
std::cout << options << std::endl;
}
int
main(int argc, char** argv)
{
uint32_t portNumber;
parseArgs(argc, argv, &portNumber);
boost::asio::io_service io_service;
Lirc lirc(&io_service);
CommandParser commandParser(&lirc);
UdpServer udpServer(&io_service, portNumber, &commandParser);
try {
io_service.run();
L("Exiting");
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
L("Exception:" << e.what());
}
return 0;
}