123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- //
- // 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()
- {
- 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;
- }
- std::chrono::system_clock::time_point Communication_message::get_receive_time()
- {
- return m_receive_time;
- }
|