parkspace_allocation_communicator.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //
  2. // Created by zx on 2020/6/18.
  3. //
  4. #ifndef PARKSPACE_ALLOCATION_COMMUNICATOR_H
  5. #define PARKSPACE_ALLOCATION_COMMUNICATOR_H
  6. #include <mutex>
  7. #include "communication_socket_base.h"
  8. #include "singleton.h"
  9. #include "parkspace_allocation_message.pb.h"
  10. #include "error_code.h"
  11. class Parkspace_allocation_communicator: public Singleton<Parkspace_allocation_communicator>, public Communication_socket_base
  12. {
  13. friend Singleton<Parkspace_allocation_communicator>;
  14. public:
  15. virtual ~Parkspace_allocation_communicator();
  16. //外部调用,反馈结果消息
  17. Error_manager send_response(Communication_message* message);
  18. //更新所有车位状态,现有状态将被全部覆盖,车位数量可能变动
  19. Error_manager update_parkspace_status(message::Parkspace_allocation_status_msg message);
  20. //更新某个车位状态,不修改车位数量,车位按编号从0开始
  21. Error_manager update_parkspace_status(int parkspace_id, message::Parkspace_info parkspace_info);
  22. //获取所有车位状态
  23. message::Parkspace_allocation_status_msg get_status();
  24. protected:
  25. Parkspace_allocation_communicator();
  26. //封装反馈消息,加入队列父类自行发送
  27. virtual Error_manager encapsulate_msg(Communication_message* message);
  28. //解析车位分配请求消息具体内容,激活车位分配单例处理函数(不可阻塞),获得结果后由车位分配单例封装消息发送
  29. virtual Error_manager execute_msg(Communication_message* p_msg);
  30. //检查是否接收到本模块需要的消息,重载后父类自行调用判断
  31. virtual Error_manager check_msg(Communication_message* p_msg);
  32. //重载检查执行者函数,判断执行者状态
  33. virtual Error_manager check_executer(Communication_message* p_msg);
  34. //心跳与车位实时信息
  35. virtual Error_manager encapsulate_send_data();
  36. protected:
  37. message::Parkspace_allocation_status_msg m_parkspace_status_msg;
  38. std::mutex m_status_mutex;
  39. };
  40. #endif //PARKSPACE_ALLOCATION_COMMUNICATOR_H