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
* @file aman/com/AircraftReporter.h
* @brief Defines the backend notification module to communicate with the backend
* @file aman/com/BackendNotification.h
* @author Sven Czarnian <devel@svcz.de>
* @copyright Copyright 2021 Sven Czarnian
* @license This project is published under the GNU General Public License v3 (GPLv3)
@@ -13,19 +13,19 @@
#include <aman/types/Communication.h>
#pragma warning(push, 0)
#include "protobuf/AircraftReport.pb.h"
#include <protobuf/Communication.pb.h>
#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<zmq::socket_t> m_socket;
AircraftReporter() noexcept;
BackendNotification() noexcept;
template <typename T>
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;
};
}

View File

@@ -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
)

View File

@@ -15,8 +15,8 @@
#include <Shlwapi.h>
#include <Windows.h>
#include <aman/com/AircraftReporter.h>
#include <aman/com/AircraftScheduler.h>
#include <aman/com/BackendNotification.h>
#include <aman/config/CommunicationFileFormat.h>
#include <aman/config/IdentifierFileFormat.h>
#include <aman/helper/String.h>
@@ -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);
}

View File

@@ -2,24 +2,24 @@
* Author:
* Sven Czarnian <devel@svcz.de>
* Brief:
* Implements the aircraft reporter
* Implements the backend notification
* Copyright:
* 2021 Sven Czarnian
* License:
* GNU General Public License v3 (GPLv3)
*/
#include <aman/com/AircraftReporter.h>
#include <aman/com/BackendNotification.h>
#include <aman/helper/String.h>
#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;
}