1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- //
- // Created by zx on 2020/7/13.
- //
- #ifndef NNXX_TESTS_TERMINAL_COMMUNICATION_H
- #define NNXX_TESTS_TERMINAL_COMMUNICATION_H
- #include "thread_safe_queue.h"
- #include <process_message.pb.h>
- #include "../tool/singleton.h"
- #include "../communication/communication_socket_base.h"
- #include "terminal_message.pb.h"
- #include "parkspace_allocation_message.pb.h"
- #include "thread_safe_map.h"
- class Terminal_communication :public Singleton<Terminal_communication>, public Communication_socket_base{
- friend class Singleton<Terminal_communication>;
- private:
- // 父类的构造函数必须保护,子类的构造函数必须私有。
- Terminal_communication();
- public:
- //必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
- Terminal_communication(const Terminal_communication& other) = delete;
- Terminal_communication& operator =(const Terminal_communication& other) = delete;
- ~Terminal_communication();
- /*
- * 设置终端id
- */
- Error_manager set_terminal_id(int id);
- /*
- * 发送停车指令请求
- */
- Error_manager store_request(message::Store_command_request_msg& request,message::Store_command_response_msg& response);
- /*
- * 发送取车指令请求
- */
- Error_manager pickup_request(message::Pickup_command_request_msg& request,message::Pickup_command_response_msg& response);
- /*
- * 获取停车流程状态
- */
- Error_manager get_storing_statu(std::string terminal_id,message::Storing_process_statu_msg& msg);
- /*
- * 获取取车流程状态
- */
- Error_manager get_picking_statu(std::string terminal_id,message::Picking_process_statu_msg& msg);
- protected:
- //重载函数
- virtual Error_manager encapsulate_msg(Communication_message* message);
- virtual Error_manager execute_msg(Communication_message* p_msg);
- /*
- * 检测消息是否可被处理
- */
- virtual Error_manager check_msg(Communication_message* p_msg);
- /*
- * 心跳发送函数,重载
- */
- virtual Error_manager encapsulate_send_data();
- //检查消息是否可以被解析, 需要重载
- virtual Error_manager check_executer(Communication_message* p_msg);
- static void thread_update_map_function(Terminal_communication* terminal);
- void update_map();
- private:
- message::Store_command_response_msg m_store_response_msg;
- message::Pickup_command_response_msg m_pickup_response_msg;
- thread_safe_map<std::string ,message::Storing_process_statu_msg> m_storing_statu_map;
- thread_safe_map<std::string ,std::chrono::system_clock::time_point> m_storing_statu_time_point_map;
- Thread_safe_queue<std::string> m_storing_license_queue;
- thread_safe_map<std::string ,message::Picking_process_statu_msg> m_picking_statu_map;
- thread_safe_map<std::string ,std::chrono::system_clock::time_point> m_picking_statu_time_point_map;
- Thread_safe_queue<std::string> m_picking_license_queue;
- std::thread* m_update_msg_map_thread;
- Thread_condition m_publish_exit_condition;
- };
- #endif //NNXX_TESTS_TERMINAL_COMMUNICATION_H
|