2019-01-21 10:59:29 +00:00
|
|
|
/*!
|
|
|
|
* \file monitor_pvt_udp_sink.cc
|
|
|
|
* \brief Implementation of a class that sends serialized Monitor_Pvt
|
|
|
|
* objects over udp to one or multiple endpoints
|
|
|
|
* \author Álvaro Cebrián Juan, 2019. acebrianjuan(at)gmail.com
|
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2019-01-21 10:59:29 +00:00
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
|
2019-01-21 10:59:29 +00:00
|
|
|
*
|
|
|
|
* GNSS-SDR is a software defined Global Navigation
|
|
|
|
* Satellite Systems receiver
|
|
|
|
*
|
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
2020-02-08 00:20:02 +00:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2019-01-21 10:59:29 +00:00
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2019-01-21 10:59:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "monitor_pvt_udp_sink.h"
|
|
|
|
#include <boost/archive/binary_oarchive.hpp>
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
|
2019-02-14 21:49:36 +00:00
|
|
|
|
2019-06-29 20:04:03 +00:00
|
|
|
Monitor_Pvt_Udp_Sink::Monitor_Pvt_Udp_Sink(const std::vector<std::string>& addresses, const uint16_t& port, bool protobuf_enabled) : socket{io_context}
|
2019-01-21 10:59:29 +00:00
|
|
|
{
|
2019-02-12 00:25:27 +00:00
|
|
|
for (const auto& address : addresses)
|
2019-01-21 10:59:29 +00:00
|
|
|
{
|
|
|
|
boost::asio::ip::udp::endpoint endpoint(boost::asio::ip::address::from_string(address, error), port);
|
|
|
|
endpoints.push_back(endpoint);
|
|
|
|
}
|
2019-04-20 16:50:22 +00:00
|
|
|
|
2019-04-21 11:30:59 +00:00
|
|
|
use_protobuf = protobuf_enabled;
|
|
|
|
if (use_protobuf)
|
|
|
|
{
|
|
|
|
serdes = Serdes_Monitor_Pvt();
|
|
|
|
}
|
2019-01-21 10:59:29 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 21:49:36 +00:00
|
|
|
|
2020-07-26 21:56:36 +00:00
|
|
|
bool Monitor_Pvt_Udp_Sink::write_monitor_pvt(const Monitor_Pvt* const monitor_pvt)
|
2019-01-21 10:59:29 +00:00
|
|
|
{
|
2019-04-20 16:50:22 +00:00
|
|
|
std::string outbound_data;
|
2019-04-21 11:30:59 +00:00
|
|
|
if (use_protobuf == false)
|
2019-04-20 16:50:22 +00:00
|
|
|
{
|
|
|
|
std::ostringstream archive_stream;
|
|
|
|
boost::archive::binary_oarchive oa{archive_stream};
|
2020-06-18 18:40:53 +00:00
|
|
|
oa << *monitor_pvt;
|
2019-04-20 16:50:22 +00:00
|
|
|
outbound_data = archive_stream.str();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-18 18:40:53 +00:00
|
|
|
outbound_data = serdes.createProtobuffer(monitor_pvt);
|
2019-04-20 16:50:22 +00:00
|
|
|
}
|
2019-01-21 10:59:29 +00:00
|
|
|
|
2019-02-12 00:25:27 +00:00
|
|
|
for (const auto& endpoint : endpoints)
|
2019-01-21 10:59:29 +00:00
|
|
|
{
|
|
|
|
socket.open(endpoint.protocol(), error);
|
|
|
|
socket.connect(endpoint, error);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
socket.send(boost::asio::buffer(outbound_data));
|
|
|
|
}
|
|
|
|
catch (boost::system::system_error const& e)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|