Backend.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * @brief Defines the backend module to communicate with the backend
  3. * @file aman/com/Backend.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 <zmq.hpp>
  10. #include <aman/types/Communication.h>
  11. #pragma warning(push, 0)
  12. #include <protobuf/Communication.pb.h>
  13. #pragma warning(pop)
  14. namespace aman {
  15. /**
  16. * @brief Defines the bakcend class which sends and receives aircraft information to and from the backend
  17. * @ingroup com
  18. */
  19. class Backend {
  20. private:
  21. std::unique_ptr<zmq::socket_t> m_socket;
  22. Backend() noexcept;
  23. template <typename T>
  24. bool setSocketKey(const std::string& key, T entry) {
  25. try {
  26. this->m_socket->set(entry, key);
  27. return true;
  28. }
  29. catch (std::exception&) {
  30. return false;
  31. }
  32. }
  33. std::shared_ptr<aman::AircraftSequence> receiveSequence();
  34. public:
  35. Backend(const Backend&) = delete;
  36. Backend(Backend&&) = delete;
  37. Backend& operator=(const Backend&) = delete;
  38. Backend& operator=(Backend&&) = delete;
  39. /**
  40. * @brief Initializes the aircraft reporter
  41. * @param[in] configuration The current AMAM communication configuration
  42. * @return True if the initialization is done, else false
  43. */
  44. bool initialize(const Communication& configuration);
  45. /**
  46. * @brief Terminates the reporter connection
  47. */
  48. bool deinitialize();
  49. /**
  50. * @brief Checks if the reporter is initialized
  51. * @return True if it is initialized, else false
  52. */
  53. bool initialized() const noexcept;
  54. /**
  55. * @brief Sends a new message to the backend
  56. * @param[in] report The new aircraft update
  57. * @return Receives the current sequence of the airport
  58. */
  59. std::shared_ptr<aman::AircraftSequence> update(aman::AircraftUpdate& report);
  60. /**
  61. * @brief Returns the reporter instance
  62. * @return The system-wide instance
  63. */
  64. static Backend& instance() noexcept;
  65. };
  66. }