18 #include "spdlog/spdlog.h"
28 const std::string &api_url,
29 const std::string &iface)
30 : _rp(
cfg), _control(
cfg), _cache(
cfg, io_service), _api(
cfg, api_url, _cache, &_service_announcement, _services),
31 _tick_interval(1), _timer(io_service, _tick_interval), _control_timer(io_service, _control_tick_interval),
32 _cfg(
cfg), _interface(iface), _io_service(io_service) {
33 cfg.lookupValue(
"mw.seamless_switching.enabled",
_seamless);
35 spdlog::info(
"Seamless switching mode enabled");
40 cfg.lookupValue(
"mw.control_system.interval", secs);
42 spdlog::info(
"Control System API enabled");
56 bool local_service_enabled =
false;
57 std::string local_bootstrap_file;
59 _cfg.lookupValue(
"mw.local_service.enabled", local_service_enabled);
60 _cfg.lookupValue(
"mw.local_service.bootstrap_file", local_bootstrap_file);
62 if (local_service_enabled && local_bootstrap_file !=
"") {
63 spdlog::info(
"Reading service announcement from file at {}", local_bootstrap_file);
64 std::ifstream ifs(local_bootstrap_file);
65 std::string sa_multipart((std::istreambuf_iterator<char>(ifs)),
66 (std::istreambuf_iterator<char>()));
67 std::string tmgi =
"";
68 _cfg.lookupValue(
"mw.local_service.tmgi", tmgi);
69 std::string mcast_address =
"";
70 _cfg.lookupValue(
"mw.local_service.mcast_address", mcast_address);
72 _service_announcement = std::make_unique<MBMS_RT::ServiceAnnouncement>(_cfg, tmgi, mcast_address, 0, _interface,
73 _io_service, _cache, _seamless,
78 _service_announcement->parse_bootstrap(sa_multipart);
92 auto mchs = _rp.getMchInfo();
93 for (
auto const &mch: mchs.as_array()) {
94 for (
auto const &mtch: mch.at(
"mtchs").as_array()) {
95 auto tmgi = mtch.at(
"tmgi").as_string();
96 auto dest = mtch.at(
"dest").as_string();
98 _cfg.lookupValue(
"mw.service_announcement_tsi", tsi);
99 auto is_service_announcement = std::stoul(tmgi.substr(0, 6),
nullptr, 16) < 0xF;
100 if (!dest.empty() && is_service_announcement && !_service_announcement) {
103 _service_announcement = std::make_unique<MBMS_RT::ServiceAnnouncement>(_cfg, tmgi, dest, tsi, _interface,
110 _service_announcement->start_flute_receiver(dest);
115 _cache.check_file_expiry_and_cache_size();
117 _timer.expires_at(_timer.expires_at() + _tick_interval);
125 if (_control_system) {
127 auto status = _rp.getStatus();
128 auto cinr = status.at(
"cinr_db").as_double();
129 spdlog::debug(
"CINR ist {}", cinr);
131 std::vector<std::string> tmgis;
132 auto services = _control.sendHello(cinr, tmgis);
133 for (
const auto &ctrl_service: services.as_array()) {
134 spdlog::debug(
"control system sent service: {}", ctrl_service.serialize());
140 _control_timer.expires_at(_control_timer.expires_at() + _control_tick_interval);
150 if (_services.find(service_id) != _services.end()) {
151 return _services[service_id];
boost::posix_time::seconds _control_tick_interval
Middleware(boost::asio::io_service &io_service, const libconfig::Config &cfg, const std::string &api_url, const std::string &iface)
std::shared_ptr< Service > get_service(const std::string &service_id)
void set_service(const std::string &service_id, std::shared_ptr< Service > service)
void control_tick_handler()
bool _handle_local_service_announcement()
boost::asio::deadline_timer _control_timer
boost::asio::deadline_timer _timer
static Config cfg
Global configuration object.