rename the files and use the new interface to communicate with the backend

This commit is contained in:
Sven Czarnian
2021-11-13 22:59:04 +01:00
parent 50bb565229
commit 8b1292c95a
4 changed files with 28 additions and 34 deletions

View File

@@ -1,6 +1,6 @@
/* /*
* @brief Defines the aircraft reporter module to communicate with the backend * @brief Defines the backend notification module to communicate with the backend
* @file aman/com/AircraftReporter.h * @file aman/com/BackendNotification.h
* @author Sven Czarnian <devel@svcz.de> * @author Sven Czarnian <devel@svcz.de>
* @copyright Copyright 2021 Sven Czarnian * @copyright Copyright 2021 Sven Czarnian
* @license This project is published under the GNU General Public License v3 (GPLv3) * @license This project is published under the GNU General Public License v3 (GPLv3)
@@ -13,19 +13,19 @@
#include <aman/types/Communication.h> #include <aman/types/Communication.h>
#pragma warning(push, 0) #pragma warning(push, 0)
#include "protobuf/AircraftReport.pb.h" #include <protobuf/Communication.pb.h>
#pragma warning(pop) #pragma warning(pop)
namespace aman { namespace aman {
/** /**
* @brief Defines the aircraft reporter class which sends aircraft information to the backend * @brief Defines the bakcend notification class which sends aircraft information to the backend
* @ingroup com * @ingroup com
*/ */
class AircraftReporter { class BackendNotification {
private: private:
std::unique_ptr<zmq::socket_t> m_socket; std::unique_ptr<zmq::socket_t> m_socket;
AircraftReporter() noexcept; BackendNotification() noexcept;
template <typename T> template <typename T>
bool setSocketKey(const std::string& key, T entry) { bool setSocketKey(const std::string& key, T entry) {
@@ -39,10 +39,10 @@ namespace aman {
} }
public: public:
AircraftReporter(const AircraftReporter&) = delete; BackendNotification(const BackendNotification&) = delete;
AircraftReporter(AircraftReporter&&) = delete; BackendNotification(BackendNotification&&) = delete;
AircraftReporter& operator=(const AircraftReporter&) = delete; BackendNotification& operator=(const BackendNotification&) = delete;
AircraftReporter& operator=(AircraftReporter&&) = delete; BackendNotification& operator=(BackendNotification&&) = delete;
/** /**
* @brief Initializes the aircraft reporter * @brief Initializes the aircraft reporter
@@ -61,14 +61,14 @@ namespace aman {
bool initialized() const noexcept; bool initialized() const noexcept;
/** /**
* @brief Sends a new message to the backend * @brief Sends a new message to the backend
* @param[in] report The new aircraft report * @param[in] report The new aircraft update
* @return True if the report is sent, else false * @return True if the report is sent, else false
*/ */
bool send(aman::AircraftReport& report); bool send(aman::AircraftUpdate& report);
/** /**
* @brief Returns the reporter instance * @brief Returns the reporter instance
* @return The system-wide instance * @return The system-wide instance
*/ */
static AircraftReporter& instance() noexcept; static BackendNotification& instance() noexcept;
}; };
} }

View File

@@ -32,7 +32,7 @@ SET(SOURCE_FILES
) )
SET(SOURCE_COM_FILES SET(SOURCE_COM_FILES
com/AircraftReporter.cpp com/BackendNotification.cpp
com/AircraftScheduler.cpp com/AircraftScheduler.cpp
com/ZmqContext.cpp com/ZmqContext.cpp
com/ZmqContext.h com/ZmqContext.h
@@ -51,7 +51,7 @@ SET(SOURCE_FILES_RES
) )
SET(INCLUDE_COM_FILES SET(INCLUDE_COM_FILES
${CMAKE_SOURCE_DIR}/include/aman/com/AircraftReporter.h ${CMAKE_SOURCE_DIR}/include/aman/com/BackendNotification.h
${CMAKE_SOURCE_DIR}/include/aman/com/AircraftScheduler.h ${CMAKE_SOURCE_DIR}/include/aman/com/AircraftScheduler.h
) )

View File

@@ -15,8 +15,8 @@
#include <Shlwapi.h> #include <Shlwapi.h>
#include <Windows.h> #include <Windows.h>
#include <aman/com/AircraftReporter.h>
#include <aman/com/AircraftScheduler.h> #include <aman/com/AircraftScheduler.h>
#include <aman/com/BackendNotification.h>
#include <aman/config/CommunicationFileFormat.h> #include <aman/config/CommunicationFileFormat.h>
#include <aman/config/IdentifierFileFormat.h> #include <aman/config/IdentifierFileFormat.h>
#include <aman/helper/String.h> #include <aman/helper/String.h>
@@ -76,7 +76,7 @@ PlugIn::PlugIn() :
PlugIn::~PlugIn() noexcept { PlugIn::~PlugIn() noexcept {
AircraftScheduler::instance().deinitialize(); AircraftScheduler::instance().deinitialize();
AircraftReporter::instance().deinitialize(); BackendNotification::instance().deinitialize();
ZmqContext::instance().deinitialize(); ZmqContext::instance().deinitialize();
google::protobuf::ShutdownProtobufLibrary(); google::protobuf::ShutdownProtobufLibrary();
} }
@@ -260,6 +260,6 @@ void PlugIn::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget radarTarg
report.set_allocated_position(coordinate); report.set_allocated_position(coordinate);
/* send the report */ /* send the report */
if (false == AircraftReporter::instance().send(report)) if (false == BackendNotification::instance().send(update))
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 new aircraft report update", true, true, true, true, true);
} }

View File

@@ -2,24 +2,24 @@
* Author: * Author:
* Sven Czarnian <devel@svcz.de> * Sven Czarnian <devel@svcz.de>
* Brief: * Brief:
* Implements the aircraft reporter * Implements the backend notification
* Copyright: * Copyright:
* 2021 Sven Czarnian * 2021 Sven Czarnian
* License: * License:
* GNU General Public License v3 (GPLv3) * GNU General Public License v3 (GPLv3)
*/ */
#include <aman/com/AircraftReporter.h> #include <aman/com/BackendNotification.h>
#include <aman/helper/String.h> #include <aman/helper/String.h>
#include "ZmqContext.h" #include "ZmqContext.h"
using namespace aman; using namespace aman;
AircraftReporter::AircraftReporter() noexcept : BackendNotification::BackendNotification() noexcept :
m_socket() { } m_socket() { }
bool AircraftReporter::initialize(const Communication& configuration) { bool BackendNotification::initialize(const Communication& configuration) {
if (nullptr != this->m_socket) if (nullptr != this->m_socket)
return true; return true;
if (false == configuration.valid) if (false == configuration.valid)
@@ -48,7 +48,7 @@ bool AircraftReporter::initialize(const Communication& configuration) {
return true; return true;
} }
bool AircraftReporter::deinitialize() { bool BackendNotification::deinitialize() {
if (nullptr == this->m_socket) if (nullptr == this->m_socket)
return true; return true;
@@ -58,20 +58,14 @@ bool AircraftReporter::deinitialize() {
return true; return true;
} }
bool AircraftReporter::initialized() const noexcept { bool BackendNotification::initialized() const noexcept {
return nullptr != this->m_socket; return nullptr != this->m_socket;
} }
bool AircraftReporter::send(aman::AircraftReport& report) { bool BackendNotification::send(aman::AircraftUpdate& report) {
bool retval = false; bool retval = false;
if (nullptr != this->m_socket) { if (nullptr != this->m_socket) {
/* set the report time */
std::stringstream stream;
auto reportTime = std::chrono::utc_clock::now();
stream << std::format("{0:%Y%m%d%H%M%S}", reportTime);
report.set_reporttime(String::splitString(stream.str(), ".")[0]);
/* serialize the report */ /* serialize the report */
std::string serialized = report.SerializeAsString(); std::string serialized = report.SerializeAsString();
zmq::message_t message(serialized.size()); zmq::message_t message(serialized.size());
@@ -90,7 +84,7 @@ bool AircraftReporter::send(aman::AircraftReport& report) {
return retval; return retval;
} }
AircraftReporter& AircraftReporter::instance() noexcept { BackendNotification& BackendNotification::instance() noexcept {
static AircraftReporter __instance; static BackendNotification __instance;
return __instance; return __instance;
} }