diff --git a/include/aman/com/AircraftReporter.h b/include/aman/com/BackendNotification.h similarity index 66% rename from include/aman/com/AircraftReporter.h rename to include/aman/com/BackendNotification.h index 0c8bf4b..6cf7ec5 100644 --- a/include/aman/com/AircraftReporter.h +++ b/include/aman/com/BackendNotification.h @@ -1,6 +1,6 @@ /* - * @brief Defines the aircraft reporter module to communicate with the backend - * @file aman/com/AircraftReporter.h + * @brief Defines the backend notification module to communicate with the backend + * @file aman/com/BackendNotification.h * @author Sven Czarnian * @copyright Copyright 2021 Sven Czarnian * @license This project is published under the GNU General Public License v3 (GPLv3) @@ -13,19 +13,19 @@ #include #pragma warning(push, 0) -#include "protobuf/AircraftReport.pb.h" +#include #pragma warning(pop) 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 */ - class AircraftReporter { + class BackendNotification { private: std::unique_ptr m_socket; - AircraftReporter() noexcept; + BackendNotification() noexcept; template bool setSocketKey(const std::string& key, T entry) { @@ -39,10 +39,10 @@ namespace aman { } public: - AircraftReporter(const AircraftReporter&) = delete; - AircraftReporter(AircraftReporter&&) = delete; - AircraftReporter& operator=(const AircraftReporter&) = delete; - AircraftReporter& operator=(AircraftReporter&&) = delete; + BackendNotification(const BackendNotification&) = delete; + BackendNotification(BackendNotification&&) = delete; + BackendNotification& operator=(const BackendNotification&) = delete; + BackendNotification& operator=(BackendNotification&&) = delete; /** * @brief Initializes the aircraft reporter @@ -61,14 +61,14 @@ namespace aman { bool initialized() const noexcept; /** * @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 */ - bool send(aman::AircraftReport& report); + bool send(aman::AircraftUpdate& report); /** * @brief Returns the reporter instance * @return The system-wide instance */ - static AircraftReporter& instance() noexcept; + static BackendNotification& instance() noexcept; }; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 038de14..5345ccc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,7 +32,7 @@ SET(SOURCE_FILES ) SET(SOURCE_COM_FILES - com/AircraftReporter.cpp + com/BackendNotification.cpp com/AircraftScheduler.cpp com/ZmqContext.cpp com/ZmqContext.h @@ -51,7 +51,7 @@ SET(SOURCE_FILES_RES ) 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 ) diff --git a/src/PlugIn.cpp b/src/PlugIn.cpp index c8803af..206db73 100644 --- a/src/PlugIn.cpp +++ b/src/PlugIn.cpp @@ -15,8 +15,8 @@ #include #include -#include #include +#include #include #include #include @@ -76,7 +76,7 @@ PlugIn::PlugIn() : PlugIn::~PlugIn() noexcept { AircraftScheduler::instance().deinitialize(); - AircraftReporter::instance().deinitialize(); + BackendNotification::instance().deinitialize(); ZmqContext::instance().deinitialize(); google::protobuf::ShutdownProtobufLibrary(); } @@ -260,6 +260,6 @@ void PlugIn::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget radarTarg report.set_allocated_position(coordinate); /* send the report */ - 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); + if (false == BackendNotification::instance().send(update)) + this->DisplayUserMessage(PLUGIN_NAME, "ERROR", "Unable to send a new aircraft report update", true, true, true, true, true); } diff --git a/src/com/AircraftReporter.cpp b/src/com/BackendNotification.cpp similarity index 74% rename from src/com/AircraftReporter.cpp rename to src/com/BackendNotification.cpp index 22e5e31..511b726 100644 --- a/src/com/AircraftReporter.cpp +++ b/src/com/BackendNotification.cpp @@ -2,24 +2,24 @@ * Author: * Sven Czarnian * Brief: - * Implements the aircraft reporter + * Implements the backend notification * Copyright: * 2021 Sven Czarnian * License: * GNU General Public License v3 (GPLv3) */ -#include +#include #include #include "ZmqContext.h" using namespace aman; -AircraftReporter::AircraftReporter() noexcept : +BackendNotification::BackendNotification() noexcept : m_socket() { } -bool AircraftReporter::initialize(const Communication& configuration) { +bool BackendNotification::initialize(const Communication& configuration) { if (nullptr != this->m_socket) return true; if (false == configuration.valid) @@ -48,7 +48,7 @@ bool AircraftReporter::initialize(const Communication& configuration) { return true; } -bool AircraftReporter::deinitialize() { +bool BackendNotification::deinitialize() { if (nullptr == this->m_socket) return true; @@ -58,20 +58,14 @@ bool AircraftReporter::deinitialize() { return true; } -bool AircraftReporter::initialized() const noexcept { +bool BackendNotification::initialized() const noexcept { return nullptr != this->m_socket; } -bool AircraftReporter::send(aman::AircraftReport& report) { +bool BackendNotification::send(aman::AircraftUpdate& report) { bool retval = false; 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 */ std::string serialized = report.SerializeAsString(); zmq::message_t message(serialized.size()); @@ -90,7 +84,7 @@ bool AircraftReporter::send(aman::AircraftReport& report) { return retval; } -AircraftReporter& AircraftReporter::instance() noexcept { - static AircraftReporter __instance; +BackendNotification& BackendNotification::instance() noexcept { + static BackendNotification __instance; return __instance; }