use only one backend and adapt to the new communication structure
avoid empty messages
This commit is contained in:
76
include/aman/com/Backend.h
Normal file
76
include/aman/com/Backend.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* @brief Defines the backend module to communicate with the backend
|
||||
* @file aman/com/Backend.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)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <zmq.hpp>
|
||||
|
||||
#include <aman/types/Communication.h>
|
||||
|
||||
#pragma warning(push, 0)
|
||||
#include <protobuf/Communication.pb.h>
|
||||
#pragma warning(pop)
|
||||
|
||||
namespace aman {
|
||||
/**
|
||||
* @brief Defines the bakcend class which sends and receives aircraft information to and from the backend
|
||||
* @ingroup com
|
||||
*/
|
||||
class Backend {
|
||||
private:
|
||||
std::unique_ptr<zmq::socket_t> m_socket;
|
||||
|
||||
Backend() noexcept;
|
||||
|
||||
template <typename T>
|
||||
bool setSocketKey(const std::string& key, T entry) {
|
||||
try {
|
||||
this->m_socket->set(entry, key);
|
||||
return true;
|
||||
}
|
||||
catch (std::exception&) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<aman::AircraftSequence> receiveSequence();
|
||||
|
||||
public:
|
||||
Backend(const Backend&) = delete;
|
||||
Backend(Backend&&) = delete;
|
||||
Backend& operator=(const Backend&) = delete;
|
||||
Backend& operator=(Backend&&) = delete;
|
||||
|
||||
/**
|
||||
* @brief Initializes the aircraft reporter
|
||||
* @param[in] configuration The current AMAM communication configuration
|
||||
* @return True if the initialization is done, else false
|
||||
*/
|
||||
bool initialize(const Communication& configuration);
|
||||
/**
|
||||
* @brief Terminates the reporter connection
|
||||
*/
|
||||
bool deinitialize();
|
||||
/**
|
||||
* @brief Checks if the reporter is initialized
|
||||
* @return True if it is initialized, else false
|
||||
*/
|
||||
bool initialized() const noexcept;
|
||||
/**
|
||||
* @brief Sends a new message to the backend
|
||||
* @param[in] report The new aircraft update
|
||||
* @return Receives the current sequence of the airport
|
||||
*/
|
||||
std::shared_ptr<aman::AircraftSequence> update(aman::AircraftUpdate& report);
|
||||
/**
|
||||
* @brief Returns the reporter instance
|
||||
* @return The system-wide instance
|
||||
*/
|
||||
static Backend& instance() noexcept;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user