5G-MAG Reference Tools - MBMS Middleware
Classes | Functions | Variables
main.cpp File Reference

Contains the program entry point, command line parameter handling, and the main runloop for data processing. More...

#include <argp.h>
#include <cstdlib>
#include <string>
#include <filesystem>
#include <libconfig.h++>
#include <boost/asio.hpp>
#include "Version.h"
#include "spdlog/async.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/syslog_sink.h"
#include "Middleware.h"
Include dependency graph for main.cpp:

Go to the source code of this file.

Classes

struct  mw_arguments
 Holds all options passed on the command line. More...
 

Functions

static void print_version (FILE *stream, struct argp_state *)
 Print the program version in MAJOR.MINOR.PATCH format. More...
 
static auto parse_opt (int key, char *arg, struct argp_state *state) -> error_t
 Parses the command line options into the arguments struct. More...
 
auto main (int argc, char **argv) -> int
 Main entry point for the program. More...
 

Variables

void(* argp_program_version_hook )(FILE *, struct argp_state *) = print_version
 
const char * argp_program_bug_address = "5G-MAG Reference Tools <reference-tools@5g-mag.com>"
 
static char doc [] = "5G-MAG-RT MBMS Middleware Process"
 
static struct argp_option options []
 
static struct argp argp
 
static Config cfg
 Global configuration object. More...
 

Detailed Description

Contains the program entry point, command line parameter handling, and the main runloop for data processing.

Definition in file main.cpp.

Function Documentation

◆ main()

auto main ( int  argc,
char **  argv 
) -> int

Main entry point for the program.

Parameters
argcCommand line agument count
argvCommand line arguments
Returns
0 on clean exit, -1 on failure

Definition at line 120 of file main.cpp.

120  {
121  struct mw_arguments arguments;
122  /* Default values */
123  arguments.config_file = "/etc/5gmag-rt.conf";
124  arguments.flute_interface= "0.0.0.0";
125 
126  argp_parse(&argp, argc, argv, 0, nullptr, &arguments);
127 
128  // Read and parse the configuration file
129  try {
130  cfg.readFile(arguments.config_file);
131  } catch(const FileIOException &fioex) {
132  spdlog::error("I/O error while reading config file at {}. Exiting.", arguments.config_file);
133  exit(1);
134  } catch(const ParseException &pex) {
135  spdlog::error("Config parse error at {}:{} - {}. Exiting.",
136  pex.getFile(), pex.getLine(), pex.getError());
137  exit(1);
138  }
139 
140  // Set up logging
141  std::string ident = "mw";
142  auto syslog_logger = spdlog::syslog_logger_mt("syslog", ident, LOG_PID | LOG_PERROR | LOG_CONS );
143 
144  spdlog::set_level(
145  static_cast<spdlog::level::level_enum>(arguments.log_level));
146  spdlog::set_pattern("[%H:%M:%S.%f %z] [%^%l%$] [thr %t] %v");
147 
148  spdlog::set_default_logger(syslog_logger);
149  spdlog::info("5g-mag-rt mw v{}.{}.{} starting up", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
150 
151  std::string uri = "http://0.0.0.0:3020/";
152  cfg.lookupValue("mw.http_server.uri", uri);
153 
154  try {
155  boost::asio::io_service io;
156  MBMS_RT::Middleware mw(io, cfg, uri, arguments.flute_interface);
157  io.run();
158  } catch (const std::exception& ex) {
159  spdlog::error("BUG ALERT: Unhandled exception in main: {}", ex.what());
160  }
161 
162 exit:
163  return 0;
164 }
static Config cfg
Global configuration object.
Definition: main.cpp:111
static struct argp argp
Definition: main.cpp:97
Holds all options passed on the command line.
Definition: main.cpp:70
const char * config_file
file path of the config file.
Definition: main.cpp:71

◆ parse_opt()

static auto parse_opt ( int  key,
char *  arg,
struct argp_state *  state 
) -> error_t
static

Parses the command line options into the arguments struct.

Definition at line 79 of file main.cpp.

79  {
80  auto arguments = static_cast<struct mw_arguments *>(state->input);
81  switch (key) {
82  case 'c':
83  arguments->config_file = arg;
84  break;
85  case 'i':
86  arguments->flute_interface = arg;
87  break;
88  case 'l':
89  arguments->log_level = static_cast<unsigned>(strtoul(arg, nullptr, 10));
90  break;
91  default:
92  return ARGP_ERR_UNKNOWN;
93  }
94  return 0;
95 }

◆ print_version()

void print_version ( FILE *  stream,
struct argp_state *  state 
)
static

Print the program version in MAJOR.MINOR.PATCH format.

Definition at line 103 of file main.cpp.

103  {
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());
107 }

Variable Documentation

◆ argp

struct argp argp
static
Initial value:
= {options, parse_opt, nullptr, doc,
nullptr, nullptr, nullptr}
static struct argp_option options[]
Definition: main.cpp:58
static auto parse_opt(int key, char *arg, struct argp_state *state) -> error_t
Parses the command line options into the arguments struct.
Definition: main.cpp:79
static char doc[]
Definition: main.cpp:56

Definition at line 79 of file main.cpp.

◆ argp_program_bug_address

const char* argp_program_bug_address = "5G-MAG Reference Tools <reference-tools@5g-mag.com>"

Definition at line 55 of file main.cpp.

◆ argp_program_version_hook

void(* argp_program_version_hook) (FILE *, struct argp_state *) ( FILE *  ,
struct argp_state *   
) = print_version

Definition at line 54 of file main.cpp.

◆ cfg

Config cfg
static

Global configuration object.

Definition at line 111 of file main.cpp.

◆ doc

char doc[] = "5G-MAG-RT MBMS Middleware Process"
static

Definition at line 56 of file main.cpp.

◆ options

struct argp_option options[]
static
Initial value:
= {
{"config", 'c', "FILE", 0, "Configuration file (default: /etc/5gmag-rt.conf)", 0},
{"interface", 'i', "IF", 0, "IP address of the interface to bind flute receivers to (default: 192.168.180.10)", 0},
{"log-level", 'l', "LEVEL", 0,
"Log verbosity: 0 = trace, 1 = debug, 2 = info, 3 = warn, 4 = error, 5 = "
"critical, 6 = none. Default: 2.",
0},
{nullptr, 0, nullptr, 0, nullptr, 0}}

Definition at line 56 of file main.cpp.