AircraftReporter.h 2.2 KB

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