communication_manager.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "tool/error_code.hpp"
  2. #include "rabbitmq/rabbitmq_communication.h"
  3. #include "grpc/streamServer.h"
  4. #include "mqtt/mqtt_communication.h"
  5. #include "proto/communication.pb.h"
  6. class CommunicationManager {
  7. public:
  8. static CommunicationManager *iter() {
  9. static CommunicationManager *instance = nullptr;
  10. if (instance == nullptr) {
  11. instance = new CommunicationManager();
  12. }
  13. return instance;
  14. }
  15. ~CommunicationManager() = default;
  16. Error_manager Init(const CommunicationManagerConfig &config);
  17. protected:
  18. void run();
  19. MeasureStatu getMeasureData(DetectManager::DetectResult &detect_measure_info);
  20. Error_manager sendGrpcData(const MeasureStatu &measure_statu, DetectManager::DetectResult &measure_result);
  21. Error_manager sendMqttData(const MeasureStatu &measure_statu, DetectManager::DetectResult &measure_result);
  22. Error_manager sendRabbitmqData(const MeasureStatu &measure_statu, DetectManager::DetectResult &measure_result);
  23. Range_status outOfRangeDetection(const MeasureStatu &measure_statu, DetectManager::DetectResult &measure_result, bool isPlc);
  24. Error_manager addOffset(DetectManager::DetectResult &measure_result);
  25. Error_manager removeOffset(DetectManager::DetectResult &measure_result);
  26. private:
  27. StreamRpcServer *m_grpc_server = nullptr;
  28. Thread_condition *condition = nullptr;
  29. std::thread *run_t = nullptr;
  30. CommunicationManagerConfig m_config;
  31. int last_range_statu = 0;
  32. int heart = 0;
  33. };