From 9e15b72c5436e0c4e4dd62910e64ae6826a2a544 Mon Sep 17 00:00:00 2001 From: Sven Czarnian Date: Thu, 19 Aug 2021 08:20:20 +0200 Subject: [PATCH] convert the message in the reporter --- include/aman/com/AircraftReporter.h | 1 + src/PlugIn.cpp | 7 +------ src/com/AircraftReporter.cpp | 7 ++++++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/aman/com/AircraftReporter.h b/include/aman/com/AircraftReporter.h index 23a949a..19d52af 100644 --- a/include/aman/com/AircraftReporter.h +++ b/include/aman/com/AircraftReporter.h @@ -48,5 +48,6 @@ namespace aman { bool send(zmq::message_t& message); static AircraftReporter& instance(); + bool send(const aman::AircraftReport& report); }; } diff --git a/src/PlugIn.cpp b/src/PlugIn.cpp index b5edce1..bb32315 100644 --- a/src/PlugIn.cpp +++ b/src/PlugIn.cpp @@ -193,12 +193,7 @@ void PlugIn::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget radarTarg report.set_allocated_dynamics(dynamics); report.set_allocated_position(coordinate); - /* serialize the report */ - std::string serialized = report.SerializeAsString(); - zmq::message_t message(serialized.size()); - std::memcpy(message.data(), serialized.c_str(), serialized.size()); - /* send the report */ - if (false == AircraftReporter::instance().send(message)) + if (false == AircraftReporter::instance().send(report)) this->DisplayUserMessage(PLUGIN_NAME, "ERROR", ("Unable to send a report for " + aircraft->callsign()).c_str(), true, true, true, true, true); } diff --git a/src/com/AircraftReporter.cpp b/src/com/AircraftReporter.cpp index 42bf85d..a64476c 100644 --- a/src/com/AircraftReporter.cpp +++ b/src/com/AircraftReporter.cpp @@ -57,10 +57,15 @@ bool AircraftReporter::deinitialize() { return true; } -bool AircraftReporter::send(zmq::message_t& message) { +bool AircraftReporter::send(const aman::AircraftReport& report) { bool retval = false; if (nullptr != this->m_socket) { + /* serialize the report */ + std::string serialized = report.SerializeAsString(); + zmq::message_t message(serialized.size()); + std::memcpy(message.data(), serialized.c_str(), serialized.size()); + try { auto size = message.size(); auto result = this->m_socket->send(message, zmq::send_flags::none);