/* * @brief Defines the aircraft scheduling notifier module to receive plans from the backend * @file aman/com/BackendReceiver.h * @author Sven Czarnian * @copyright Copyright 2021 Sven Czarnian * @license This project is published under the GNU General Public License v3 (GPLv3) */ #pragma once #include #include #include #include #pragma warning(push, 0) #include "protobuf/Communication.pb.h" #pragma warning(pop) namespace aman { /** * @brief Defines the aircraft scheduling notification class to receive scheduling sequences * @ingroup com */ class BackendReceiver { private: std::unique_ptr m_socket; std::thread m_receiverThread; std::atomic_bool m_stopReceiver; std::list> m_sequences; std::mutex m_sequencesLock; BackendReceiver() noexcept; template bool setSocketKey(const std::string& key, T entry) { try { this->m_socket->set(entry, key); return true; } catch (std::exception&) { return false; } } void receiveSequence(); void run(); public: BackendReceiver(const BackendReceiver&) = delete; BackendReceiver(BackendReceiver&&) = delete; BackendReceiver& operator=(const BackendReceiver&) = delete; BackendReceiver& operator=(BackendReceiver&&) = delete; /** * @brief Initializes the aircraft scheduler * @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 scheduler connection */ bool deinitialize(); /** * @brief Checks if the scheduler is initialized * @return True if it is initialized, else false */ bool initialized() const noexcept; /** * @brief Returns the current sequence of the receiver queue * @return The sequence queue */ std::shared_ptr receive(); /** * @brief Returns the scheduling instance * @return The system-wide instance */ static BackendReceiver& instance() noexcept; }; }