// // Created by zx on 2020/7/9. // #ifndef NNXX_TESTS_PARKSPACE_COMMUNICATOR_H #define NNXX_TESTS_PARKSPACE_COMMUNICATOR_H #include #include "communication_socket_base.h" #include "singleton.h" #include "thread_safe_map.h" class Parkspace_communicator :public Singleton, public Communication_socket_base { friend Singleton; public: virtual ~Parkspace_communicator(); /* * 请求分配车位 */ Error_manager alloc_request(message::Parkspace_allocation_request_msg& request, message::Parkspace_allocation_response_msg& result,Thread_condition& cancel_condition); /* * 查询车辆所在位置请求 */ Error_manager search_request(message::Parkspace_search_request_msg& request, message::Parkspace_search_response_msg& response,Thread_condition& cancel_condition); /* * 释放车位请求(停车失败或者取车完成时调用) */ Error_manager release_request(message::Parkspace_release_request_msg& request, message::Parkspace_release_response_msg& response,Thread_condition& cancel_condition); /* * 确认占用车位消息 */ Error_manager confirm_request(message::Parkspace_confirm_alloc_request_msg& request, message::Parkspace_confirm_alloc_response_msg& response,Thread_condition& cancel_condition); Error_manager check_statu(); protected: Parkspace_communicator(); 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); protected: thread_safe_map m_alloc_table; thread_safe_map m_search_table; thread_safe_map m_release_table; thread_safe_map m_confirm_table; message::Parkspace_allocation_status_msg m_parkspace_status_msg; std::chrono::system_clock::time_point m_parkspace_statu_time; }; #endif //NNXX_TESTS_PARKSPACE_COMMUNICATOR_H