libflute
Classes | Functions | Variables
flute-receiver.cpp File Reference
#include <cstdio>
#include <iostream>
#include <argp.h>
#include <cstdlib>
#include <fstream>
#include <string>
#include <filesystem>
#include <libconfig.h++>
#include <boost/asio.hpp>
#include "spdlog/async.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/syslog_sink.h"
#include "Receiver.h"
#include "File.h"
Include dependency graph for flute-receiver.cpp:

Go to the source code of this file.

Classes

struct  ft_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 = "Austrian Broadcasting Services <obeca@ors.at>"
 
static char doc [] = "FLUTE/ALC receiver demo"
 
static struct argp_option options []
 
static struct argp argp
 

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 106 of file flute-receiver.cpp.

106  {
107  struct ft_arguments arguments;
108  /* Default values */
109  arguments.mcast_target = "238.1.1.95";
110  arguments.flute_interface= "0.0.0.0";
111 
112  // Parse the arguments
113  argp_parse(&argp, argc, argv, 0, nullptr, &arguments);
114 
115  // Set up logging
116  std::string ident = "flute-receiver";
117  auto syslog_logger = spdlog::syslog_logger_mt("syslog", ident, LOG_PID | LOG_PERROR | LOG_CONS );
118 
119  spdlog::set_level(
120  static_cast<spdlog::level::level_enum>(arguments.log_level));
121  spdlog::set_pattern("[%H:%M:%S.%f %z] [%^%l%$] [thr %t] %v");
122 
123  spdlog::set_default_logger(syslog_logger);
124  spdlog::info("FLUTE receiver demo starting up");
125 
126  // Create a Boost io_service
127  boost::asio::io_service io;
128 
129  // Create the receiver
130  LibFlute::Receiver receiver(
131  arguments.flute_interface,
132  arguments.mcast_target,
133  arguments.mcast_port,
134  0,
135  io);
136 
137  // Configure IPSEC, if enabled
138  if (arguments.enable_ipsec)
139  {
140  receiver.enable_ipsec(1, arguments.aes_key);
141  }
142 
143  receiver.register_completion_callback(
144  [](std::shared_ptr<LibFlute::File> file) {
145  spdlog::info("{} (TOI {}) has been received",
146  file->meta().content_location, file->meta().toi);
147  FILE* fd = fopen(file->meta().content_location.c_str(), "wb");
148  fwrite(file->buffer(), 1, file->length(), fd);
149  fclose(fd);
150  });
151 
152  // Start the IO service
153  io.run();
154 
155 exit:
156  return 0;
157 }
FLUTE receiver class.
Definition: Receiver.h:32
static struct argp argp
Holds all options passed on the command line.
const char * mcast_target

◆ 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 62 of file flute-receiver.cpp.

62  {
63  auto arguments = static_cast<struct ft_arguments *>(state->input);
64  switch (key) {
65  case 'm':
66  arguments->mcast_target = arg;
67  break;
68  case 'i':
69  arguments->flute_interface = arg;
70  break;
71  case 'k':
72  arguments->aes_key = arg;
73  arguments->enable_ipsec = true;
74  break;
75  case 'p':
76  arguments->mcast_port = static_cast<unsigned short>(strtoul(arg, nullptr, 10));
77  break;
78  case 'l':
79  arguments->log_level = static_cast<unsigned>(strtoul(arg, nullptr, 10));
80  break;
81  default:
82  return ARGP_ERR_UNKNOWN;
83  }
84  return 0;
85 }

◆ print_version()

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

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

Definition at line 93 of file flute-receiver.cpp.

93  {
94  fprintf(stream, "1.0.0\n");
95 }

Variable Documentation

◆ argp

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

Definition at line 62 of file flute-receiver.cpp.

◆ argp_program_bug_address

const char* argp_program_bug_address = "Austrian Broadcasting Services <obeca@ors.at>"

Definition at line 32 of file flute-receiver.cpp.

◆ argp_program_version_hook

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

Definition at line 31 of file flute-receiver.cpp.

◆ doc

char doc[] = "FLUTE/ALC receiver demo"
static

Definition at line 33 of file flute-receiver.cpp.

◆ options

struct argp_option options[]
static
Initial value:
= {
{"interface", 'i', "IF", 0, "IP address of the interface to bind flute receivers to (default: 0.0.0.0)", 0},
{"target", 'm', "IP", 0, "Multicast address to receive on (default: 238.1.1.95)", 0},
{"port", 'p', "PORT", 0, "Multicast port (default: 40085)", 0},
{"ipsec-key", 'k', "KEY", 0, "To enable IPSec/ESP decryption of packets, provide a hex-encoded AES key here", 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 33 of file flute-receiver.cpp.