Terminal_communication.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // Created by zx on 2020/7/13.
  3. //
  4. #ifndef NNXX_TESTS_TERMINAL_COMMUNICATION_H
  5. #define NNXX_TESTS_TERMINAL_COMMUNICATION_H
  6. #include "thread_safe_queue.h"
  7. #include <process_message.pb.h>
  8. #include "../tool/singleton.h"
  9. #include "../communication/communication_socket_base.h"
  10. #include "terminal_message.pb.h"
  11. #include "parkspace_allocation_message.pb.h"
  12. #include "thread_safe_map.h"
  13. class Terminal_communication :public Singleton<Terminal_communication>, public Communication_socket_base{
  14. friend class Singleton<Terminal_communication>;
  15. private:
  16. // 父类的构造函数必须保护,子类的构造函数必须私有。
  17. Terminal_communication();
  18. public:
  19. //必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
  20. Terminal_communication(const Terminal_communication& other) = delete;
  21. Terminal_communication& operator =(const Terminal_communication& other) = delete;
  22. ~Terminal_communication();
  23. /*
  24. * 设置终端id
  25. */
  26. Error_manager set_terminal_id(int id);
  27. /*
  28. * 发送停车指令请求
  29. */
  30. Error_manager store_request(message::Store_command_request_msg& request,message::Store_command_response_msg& response);
  31. /*
  32. * 发送取车指令请求
  33. */
  34. Error_manager pickup_request(message::Pickup_command_request_msg& request,message::Pickup_command_response_msg& response);
  35. /*
  36. * 获取停车流程状态
  37. */
  38. Error_manager get_storing_statu(std::string terminal_id,message::Storing_process_statu_msg& msg);
  39. /*
  40. * 获取取车流程状态
  41. */
  42. Error_manager get_picking_statu(std::string terminal_id,message::Picking_process_statu_msg& msg);
  43. protected:
  44. //重载函数
  45. virtual Error_manager encapsulate_msg(Communication_message* message);
  46. virtual Error_manager execute_msg(Communication_message* p_msg);
  47. /*
  48. * 检测消息是否可被处理
  49. */
  50. virtual Error_manager check_msg(Communication_message* p_msg);
  51. /*
  52. * 心跳发送函数,重载
  53. */
  54. virtual Error_manager encapsulate_send_data();
  55. //检查消息是否可以被解析, 需要重载
  56. virtual Error_manager check_executer(Communication_message* p_msg);
  57. static void thread_update_map_function(Terminal_communication* terminal);
  58. void update_map();
  59. private:
  60. message::Store_command_response_msg m_store_response_msg;
  61. message::Pickup_command_response_msg m_pickup_response_msg;
  62. thread_safe_map<std::string ,message::Storing_process_statu_msg> m_storing_statu_map;
  63. thread_safe_map<std::string ,std::chrono::system_clock::time_point> m_storing_statu_time_point_map;
  64. Thread_safe_queue<std::string> m_storing_license_queue;
  65. thread_safe_map<std::string ,message::Picking_process_statu_msg> m_picking_statu_map;
  66. thread_safe_map<std::string ,std::chrono::system_clock::time_point> m_picking_statu_time_point_map;
  67. Thread_safe_queue<std::string> m_picking_license_queue;
  68. std::thread* m_update_msg_map_thread;
  69. Thread_condition m_publish_exit_condition;
  70. };
  71. #endif //NNXX_TESTS_TERMINAL_COMMUNICATION_H