convert the message in the reporter

This commit is contained in:
Sven Czarnian
2021-08-19 08:20:20 +02:00
parent d06ec49b2e
commit 9e15b72c54
3 changed files with 8 additions and 7 deletions

View File

@@ -48,5 +48,6 @@ namespace aman {
bool send(zmq::message_t& message); bool send(zmq::message_t& message);
static AircraftReporter& instance(); static AircraftReporter& instance();
bool send(const aman::AircraftReport& report);
}; };
} }

View File

@@ -193,12 +193,7 @@ void PlugIn::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget radarTarg
report.set_allocated_dynamics(dynamics); report.set_allocated_dynamics(dynamics);
report.set_allocated_position(coordinate); 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 */ /* 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); this->DisplayUserMessage(PLUGIN_NAME, "ERROR", ("Unable to send a report for " + aircraft->callsign()).c_str(), true, true, true, true, true);
} }

View File

@@ -57,10 +57,15 @@ bool AircraftReporter::deinitialize() {
return true; return true;
} }
bool AircraftReporter::send(zmq::message_t& message) { bool AircraftReporter::send(const aman::AircraftReport& report) {
bool retval = false; bool retval = false;
if (nullptr != this->m_socket) { 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 { try {
auto size = message.size(); auto size = message.size();
auto result = this->m_socket->send(message, zmq::send_flags::none); auto result = this->m_socket->send(message, zmq::send_flags::none);