AircraftScheduler.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #pragma warning(push, 0)
  13. #include "protobuf/AircraftSchedule.pb.h"
  14. #pragma warning(pop)
  15. namespace aman {
  16. /**
  17. * @brief Defines the aircraft scheduling notification class to receive scheduling sequences
  18. * @ingroup com
  19. */
  20. class AircraftScheduler {
  21. private:
  22. std::unique_ptr<zmq::socket_t> m_socket;
  23. std::thread m_receiverThread;
  24. std::atomic_bool m_stopReceiver;
  25. AircraftScheduler() noexcept;
  26. template <typename T>
  27. bool setSocketKey(const std::string& key, T entry) {
  28. try {
  29. this->m_socket->set(entry, key);
  30. return true;
  31. }
  32. catch (std::exception&) {
  33. return false;
  34. }
  35. }
  36. void run();
  37. public:
  38. AircraftScheduler(const AircraftScheduler&) = delete;
  39. AircraftScheduler(AircraftScheduler&&) = delete;
  40. AircraftScheduler& operator=(const AircraftScheduler&) = delete;
  41. AircraftScheduler& operator=(AircraftScheduler&&) = delete;
  42. /**
  43. * @brief Initializes the aircraft scheduler
  44. * @param[in] configuration The current AMAM communication configuration
  45. * @return True if the initialization is done, else false
  46. */
  47. bool initialize(const Communication& configuration);
  48. /**
  49. * @brief Terminates the scheduler connection
  50. */
  51. bool deinitialize();
  52. /**
  53. * @brief Checks if the scheduler is initialized
  54. * @return True if it is initialized, else false
  55. */
  56. bool initialized() const noexcept;
  57. /**
  58. * @brief Receives a new scheduling message
  59. * @return The new scheduling message or a nullptr
  60. */
  61. std::unique_ptr<aman::AircraftSchedule> receive();
  62. /**
  63. * @brief Returns the scheduling instance
  64. * @return The system-wide instance
  65. */
  66. static AircraftScheduler& instance() noexcept;
  67. };
  68. }