introduce the aircraft scheduler to receive new messages from the backend
threading-concepts are used to avoid unnecessary main thread action
This commit is contained in:
75
include/aman/com/AircraftScheduler.h
Normal file
75
include/aman/com/AircraftScheduler.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* @brief Defines the aircraft scheduling notifier module to receive plans from the backend
|
||||
* @file aman/com/AircraftScheduler.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 <thread>
|
||||
#include <zmq.hpp>
|
||||
|
||||
#include <aman/types/Communication.h>
|
||||
|
||||
#include "protobuf/AircraftSchedule.pb.h"
|
||||
|
||||
namespace aman {
|
||||
/**
|
||||
* @brief Defines the aircraft scheduling notification class to receive scheduling sequences
|
||||
* @ingroup com
|
||||
*/
|
||||
class AircraftScheduler {
|
||||
private:
|
||||
std::unique_ptr<zmq::socket_t> m_socket;
|
||||
std::thread m_receiverThread;
|
||||
std::atomic_bool m_stopReceiver;
|
||||
|
||||
AircraftScheduler() 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;
|
||||
}
|
||||
}
|
||||
void run();
|
||||
|
||||
public:
|
||||
AircraftScheduler(const AircraftScheduler&) = delete;
|
||||
AircraftScheduler(AircraftScheduler&&) = delete;
|
||||
AircraftScheduler& operator=(const AircraftScheduler&) = delete;
|
||||
AircraftScheduler& operator=(AircraftScheduler&&) = 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 Receives a new scheduling message
|
||||
* @return The new scheduling message or a nullptr
|
||||
*/
|
||||
std::unique_ptr<aman::AircraftSchedule> receive();
|
||||
/**
|
||||
* @brief Returns the scheduling instance
|
||||
* @return The system-wide instance
|
||||
*/
|
||||
static AircraftScheduler& instance() noexcept;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user