34 #include <libconfig.h++>
35 #include <boost/asio.hpp>
39 #include "spdlog/async.h"
40 #include "spdlog/spdlog.h"
41 #include "spdlog/sinks/syslog_sink.h"
45 using libconfig::Config;
46 using libconfig::FileIOException;
47 using libconfig::ParseException;
49 using std::placeholders::_1;
50 using std::placeholders::_2;
51 using std::placeholders::_3;
53 static void print_version(FILE *stream,
struct argp_state *state);
56 static char doc[] =
"5G-MAG-RT MBMS Middleware Process";
58 static struct argp_option
options[] = {
59 {
"config",
'c',
"FILE", 0,
"Configuration file (default: /etc/5gmag-rt.conf)", 0},
60 {
"interface",
'i',
"IF", 0,
"IP address of the interface to bind flute receivers to (default: 192.168.180.10)", 0},
61 {
"log-level",
'l',
"LEVEL", 0,
62 "Log verbosity: 0 = trace, 1 = debug, 2 = info, 3 = warn, 4 = error, 5 = "
63 "critical, 6 = none. Default: 2.",
65 {
nullptr, 0,
nullptr, 0,
nullptr, 0}};
79 static auto parse_opt(
int key,
char *arg,
struct argp_state *state) -> error_t {
80 auto arguments =
static_cast<struct
mw_arguments *
>(state->input);
86 arguments->flute_interface = arg;
89 arguments->log_level =
static_cast<unsigned>(strtoul(arg,
nullptr, 10));
92 return ARGP_ERR_UNKNOWN;
98 nullptr,
nullptr,
nullptr};
104 fprintf(stream,
"%s.%s.%s\n", std::to_string(VERSION_MAJOR).c_str(),
105 std::to_string(VERSION_MINOR).c_str(),
106 std::to_string(VERSION_PATCH).c_str());
120 auto main(
int argc,
char **argv) ->
int {
126 argp_parse(&
argp, argc, argv, 0,
nullptr, &arguments);
131 }
catch(
const FileIOException &fioex) {
132 spdlog::error(
"I/O error while reading config file at {}. Exiting.", arguments.
config_file);
134 }
catch(
const ParseException &pex) {
135 spdlog::error(
"Config parse error at {}:{} - {}. Exiting.",
136 pex.getFile(), pex.getLine(), pex.getError());
141 std::string ident =
"mw";
142 auto syslog_logger = spdlog::syslog_logger_mt(
"syslog", ident, LOG_PID | LOG_PERROR | LOG_CONS );
145 static_cast<spdlog::level::level_enum
>(arguments.
log_level));
146 spdlog::set_pattern(
"[%H:%M:%S.%f %z] [%^%l%$] [thr %t] %v");
148 spdlog::set_default_logger(syslog_logger);
149 spdlog::info(
"5g-mag-rt mw v{}.{}.{} starting up", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
151 std::string uri =
"http://0.0.0.0:3020/";
152 cfg.lookupValue(
"mw.http_server.uri", uri);
155 boost::asio::io_service io;
158 }
catch (
const std::exception& ex) {
159 spdlog::error(
"BUG ALERT: Unhandled exception in main: {}", ex.what());
static Config cfg
Global configuration object.
static void print_version(FILE *stream, struct argp_state *state)
Print the program version in MAJOR.MINOR.PATCH format.
auto main(int argc, char **argv) -> int
Main entry point for the program.
const char * argp_program_bug_address
static struct argp_option options[]
void(* argp_program_version_hook)(FILE *, struct argp_state *)
static auto parse_opt(int key, char *arg, struct argp_state *state) -> error_t
Parses the command line options into the arguments struct.
Holds all options passed on the command line.
unsigned log_level
log level
const char * config_file
file path of the config file.
const char * flute_interface
file path of the config file.