AircraftScheduler.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * @brief Defines the aircraft scheduling notifier module to receive plans from the backend
  3. * @file aman/com/AircraftScheduler.h
  4. * @author Sven Czarnian <devel@svcz.de>
  5. * @copyright Copyright 2021 Sven Czarnian
  6. * @license This project is published under the GNU General Public License v3 (GPLv3)
  7. */
  8. #pragma once
  9. #include <thread>
  10. #include <zmq.hpp>
  11. #include <aman/types/Communication.h>
  12. #include "protobuf/AircraftSchedule.pb.h"
  13. namespace aman {
  14. /**
  15. * @brief Defines the aircraft scheduling notification class to receive scheduling sequences
  16. * @ingroup com
  17. */
  18. class AircraftScheduler {
  19. private:
  20. std::unique_ptr<zmq::socket_t> m_socket;
  21. std::thread m_receiverThread;
  22. std::atomic_bool m_stopReceiver;
  23. AircraftScheduler() noexcept;
  24. template <typename T>
  25. bool setSocketKey(const std::string& key, T entry) {
  26. try {
  27. this->m_socket->set(entry, key);
  28. return true;
  29. }
  30. catch (std::exception&) {
  31. return false;
  32. }
  33. }
  34. void run();
  35. public:
  36. AircraftScheduler(const AircraftScheduler&) = delete;
  37. AircraftScheduler(AircraftScheduler&&) = delete;
  38. AircraftScheduler& operator=(const AircraftScheduler&) = delete;
  39. AircraftScheduler& operator=(AircraftScheduler&&) = delete;
  40. /**
  41. * @brief Initializes the aircraft scheduler
  42. * @param[in] configuration The current AMAM communication configuration
  43. * @return True if the initialization is done, else false
  44. */
  45. bool initialize(const Communication& configuration);
  46. /**
  47. * @brief Terminates the scheduler connection
  48. */
  49. bool deinitialize();
  50. /**
  51. * @brief Checks if the scheduler is initialized
  52. * @return True if it is initialized, else false
  53. */
  54. bool initialized() const noexcept;
  55. /**
  56. * @brief Receives a new scheduling message
  57. * @return The new scheduling message or a nullptr
  58. */
  59. std::unique_ptr<aman::AircraftSchedule> receive();
  60. /**
  61. * @brief Returns the scheduling instance
  62. * @return The system-wide instance
  63. */
  64. static AircraftScheduler& instance() noexcept;
  65. };
  66. }