AircraftReporter.h 2.2 KB

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