12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- //
- // Created by huli on 2020/6/29.
- //
- #include "communication_message.h"
- Communication_message::Communication_message()
- {
- m_message_type = eBase_msg;
- m_receive_time = std::chrono::system_clock::now();
- m_timeout_ms = std::chrono::milliseconds(5000); //超时默认5秒
- m_sender = eEmpty;
- m_receiver = eEmpty;
- // m_message_buf = "";
- }
- Communication_message::Communication_message(std::string message_buf)
- {
- m_message_type = eBase_msg;
- m_receive_time = std::chrono::system_clock::now();
- m_timeout_ms = std::chrono::milliseconds(5000); //超时默认5秒
- m_sender = eEmpty;
- m_receiver = eEmpty;
- m_message_buf = message_buf;
- }
- Communication_message::Communication_message(char* p_buf, int size)
- {
- m_message_type = eBase_msg;
- m_receive_time = std::chrono::system_clock::now();
- m_timeout_ms = std::chrono::milliseconds(5000); //超时默认5秒
- m_sender = eEmpty;
- m_receiver = eEmpty;
- m_message_buf = std::string(p_buf, size);
- }
- Communication_message::~Communication_message()
- {
- }
- bool Communication_message::is_over_time()
- {
- std::cout<<"interval: "<<std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - m_receive_time).count()<<std::endl;
- std::cout<<"timeout: "<<m_timeout_ms.count()<<std::endl;
- if ( std::chrono::system_clock::now() - m_receive_time > m_timeout_ms)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- void Communication_message::reset(const message::Base_info& base_info, std::string receive_string)
- {
- m_message_type = (Message_type)(base_info.msg_type());
- m_receive_time = std::chrono::system_clock::now();
- m_timeout_ms = std::chrono::milliseconds(base_info.timeout_ms());
- m_sender = (Communicator)(base_info.sender());
- m_receiver = (Communicator)(base_info.receiver());
- m_message_buf = receive_string;
- }
- Communication_message::Message_type Communication_message::get_message_type()
- {
- return m_message_type;
- }
- Communication_message::Communicator Communication_message::get_sender()
- {
- return m_sender;
- }
- Communication_message::Communicator Communication_message::get_receiver()
- {
- return m_receiver;
- }
- std::string& Communication_message::get_message_buf()
- {
- return m_message_buf;
- }
|