You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.0 KiB

#ifndef EchoMessage_HPP
#define EchoMessage_HPP
#include <cpp_utils/Message.hpp>
/// @brief echoes back the message to the sender
class EchoMessage : public Message
{
public:
EchoMessage( void *msgParam = 0)
: Message(msgParam)
{
TRACE;
}
bool buildMessage( const void *msgPart,
const size_t msgLen )
{
TRACE;
m_buffer = std::string( (const char*) msgPart, msgLen );
// not using getExpectedLength
onMessageReady();
return true;
}
void onMessageReady()
{
TRACE;
LOG_BEGIN(Logger::INFO)
LOG_PROP("message", m_buffer)
LOG_PROP("host", m_connection->getHost())
LOG_PROP("port", m_connection->getPort())
LOG_END("Got message.");
m_connection->send(m_buffer.c_str(), m_buffer.length());
m_buffer.clear();
}
Message* clone()
{
TRACE;
return new EchoMessage(m_param);
}
std::string getBuffer()
{
TRACE;
return m_buffer;
}
protected:
size_t getExpectedLength()
{
TRACE;
return 0;
}
};
#endif // EchoMessage_HPP