Terminal_communication.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 <process_message.pb.h>
  7. #include "../tool/singleton.h"
  8. #include "../communication/communication_socket_base.h"
  9. #include "terminal_message.pb.h"
  10. #include "parkspace_allocation_message.pb.h"
  11. #include "message_compare.h"
  12. class Terminal_communication :public Singleton<Terminal_communication>, public Communication_socket_base{
  13. friend class Singleton<Terminal_communication>;
  14. private:
  15. // 父类的构造函数必须保护,子类的构造函数必须私有。
  16. Terminal_communication();
  17. public:
  18. //必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
  19. Terminal_communication(const Terminal_communication& other) = delete;
  20. Terminal_communication& operator =(const Terminal_communication& other) = delete;
  21. ~Terminal_communication();
  22. /*
  23. * 设置终端id
  24. */
  25. Error_manager set_terminal_id(int id);
  26. /*
  27. * 发送停车指令请求
  28. */
  29. Error_manager store_request(message::Store_command_request_msg& request,message::Store_command_response_msg& response);
  30. /*
  31. * 发送取车指令请求
  32. */
  33. Error_manager pickup_request(message::Pickup_command_request_msg& request,message::Pickup_command_response_msg& response);
  34. protected:
  35. //重载函数
  36. virtual Error_manager encapsulate_msg(Communication_message* message);
  37. virtual Error_manager execute_msg(Communication_message* p_msg);
  38. /*
  39. * 检测消息是否可被处理
  40. */
  41. virtual Error_manager check_msg(Communication_message* p_msg);
  42. /*
  43. * 心跳发送函数,重载
  44. */
  45. virtual Error_manager encapsulate_send_data();
  46. //检查消息是否可以被解析, 需要重载
  47. virtual Error_manager check_executer(Communication_message* p_msg);
  48. private:
  49. message::Store_command_response_msg m_store_response_msg;
  50. message::Pickup_command_response_msg m_pickup_response_msg;
  51. int m_terminal_id;
  52. };
  53. #endif //NNXX_TESTS_TERMINAL_COMMUNICATION_H