12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- //
- // Created by zx on 2020/7/9.
- //
- #ifndef NNXX_TESTS_PARKSPACE_COMMUNICATOR_H
- #define NNXX_TESTS_PARKSPACE_COMMUNICATOR_H
- #include <parkspace_allocation_message.pb.h>
- #include "communication_socket_base.h"
- #include "singleton.h"
- #include "thread_safe_map.h"
- namespace message
- {
- bool operator<(const message::Parkspace_allocation_request_msg& msg1,const message::Parkspace_allocation_request_msg& msg2);
- bool operator==(const message::Parkspace_allocation_request_msg& msg1,const message::Parkspace_allocation_request_msg& msg2);
- bool operator<(const message::Parkspace_search_request_msg& msg1,const message::Parkspace_search_request_msg& msg2);
- bool operator==(const message::Parkspace_search_request_msg& msg1,const message::Parkspace_search_request_msg& msg2);
- bool operator<(const message::Parkspace_release_request_msg& msg1,const message::Parkspace_release_request_msg& msg2);
- bool operator==(const message::Parkspace_release_request_msg& msg1,const message::Parkspace_release_request_msg& msg2);
- }
- class Parkspace_communicator :public Singleton<Parkspace_communicator>, public Communication_socket_base
- {
- friend Singleton<Parkspace_communicator>;
- public:
- virtual ~Parkspace_communicator();
- /*
- * 请求分配车位
- */
- Error_manager alloc_request(message::Parkspace_allocation_request_msg& request,message::Parkspace_allocation_response_msg& result);
- /*
- * 查询车辆所在位置请求
- */
- Error_manager search_request(message::Parkspace_search_request_msg& request,message::Parkspace_search_response_msg& response);
- /*
- * 释放车位请求(停车失败或者取车完成时调用)
- */
- Error_manager release_request(message::Parkspace_release_request_msg& request,message::Parkspace_release_response_msg& response);
- 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);
- /*
- * 根据接收到的response,生成对应的 request
- */
- message::Parkspace_allocation_request_msg create_request_by_response(message::Parkspace_allocation_response_msg& msg);
- message::Parkspace_search_request_msg create_request_by_response(message::Parkspace_search_response_msg& msg);
- message::Parkspace_release_request_msg create_request_by_response(message::Parkspace_release_response_msg& msg);
- protected:
- thread_safe_map<message::Parkspace_allocation_request_msg,message::Parkspace_allocation_response_msg> m_alloc_table;
- thread_safe_map<message::Parkspace_search_request_msg,message::Parkspace_search_response_msg> m_search_table;
- thread_safe_map<message::Parkspace_release_request_msg,message::Parkspace_release_response_msg> m_release_table;
- Communication_message m_parkspace_status_msg;
- };
- #endif //NNXX_TESTS_PARKSPACE_COMMUNICATOR_H
|