AircraftReporter.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * @brief Defines the aircraft reporter module to communicate with the backend
  3. * @file aman/com/AircraftReporter.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. namespace aman {
  12. /**
  13. * @brief Defines the aircraft reporter class which sends aircraft information to the backend
  14. * @ingroup com
  15. */
  16. class AircraftReporter {
  17. private:
  18. std::unique_ptr<zmq::socket_t> m_socket;
  19. AircraftReporter() noexcept;
  20. template <typename T>
  21. bool setSocketKey(const std::string& key, T entry) {
  22. try {
  23. this->m_socket->set(entry, key);
  24. return true;
  25. }
  26. catch (std::exception&) {
  27. return false;
  28. }
  29. }
  30. public:
  31. AircraftReporter(const AircraftReporter&) = delete;
  32. AircraftReporter(AircraftReporter&&) = delete;
  33. AircraftReporter& operator=(const AircraftReporter&) = delete;
  34. AircraftReporter& operator=(AircraftReporter&&) = delete;
  35. /**
  36. * @brief Initializes the aircraft reporter
  37. * @param[in] configuration The current AMAM communication configuration
  38. * @return True if the initialization is done, else false
  39. */
  40. bool initialize(const Communication& configuration);
  41. /**
  42. * @brief Terminates the reporter connection
  43. */
  44. bool deinitialize();
  45. /**
  46. * @brief Sends a new message to the backend
  47. * @param[in] report The new aircraft report
  48. * @return True if the report is sent, else false
  49. */
  50. bool send(const aman::AircraftReport& report);
  51. /**
  52. * @brief Returns the reporter instance
  53. * @return The system-wide instance
  54. */
  55. static AircraftReporter& instance() noexcept;
  56. };
  57. }