parent
cb4766eb62
commit
fab6d0b6e6
@ -1,35 +1,64 @@
|
||||
#ifndef ECHO_MESSAGE_HPP
|
||||
#define ECHO_MESSAGE_HPP
|
||||
#ifndef EchoMessage_HPP
|
||||
#define EchoMessage_HPP
|
||||
|
||||
#include "Message.hpp"
|
||||
#include "Connection.hpp"
|
||||
#include "ThreadPool.hpp"
|
||||
#include "MysqlConnectionPool.hpp"
|
||||
#include <cpp_utils/Message.hpp>
|
||||
|
||||
struct MsgParam
|
||||
{
|
||||
MysqlConnectionPool *m_cp;
|
||||
ThreadPool *m_tp;
|
||||
MsgParam(MysqlConnectionPool *cp, ThreadPool *tp) : m_cp(cp), m_tp(tp) {};
|
||||
};
|
||||
|
||||
|
||||
class EchoMessage : public Message<EchoMessage>
|
||||
/// @brief echoes back the message to the sender
|
||||
class EchoMessage : public Message
|
||||
{
|
||||
public:
|
||||
|
||||
EchoMessage( Connection<EchoMessage> *connection,
|
||||
void *msgParam = 0);
|
||||
EchoMessage( void *msgParam = 0)
|
||||
: Message(msgParam)
|
||||
{
|
||||
TRACE;
|
||||
}
|
||||
|
||||
bool buildMessage( const void *msgPart,
|
||||
const size_t msgLen );
|
||||
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);
|
||||
}
|
||||
|
||||
void onMessageReady();
|
||||
std::string getBuffer()
|
||||
{
|
||||
TRACE;
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
size_t getExpectedLength();
|
||||
size_t getExpectedLength()
|
||||
{
|
||||
TRACE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // ECHO_MESSAGE_HPP
|
||||
#endif // EchoMessage_HPP
|
||||
|
@ -0,0 +1,35 @@
|
||||
#ifndef ECHO_MESSAGE_HPP
|
||||
#define ECHO_MESSAGE_HPP
|
||||
|
||||
#include "Message.hpp"
|
||||
#include "Connection.hpp"
|
||||
#include "ThreadPool.hpp"
|
||||
#include "MysqlConnectionPool.hpp"
|
||||
|
||||
struct MsgParam
|
||||
{
|
||||
MysqlConnectionPool *m_cp;
|
||||
ThreadPool *m_tp;
|
||||
MsgParam(MysqlConnectionPool *cp, ThreadPool *tp) : m_cp(cp), m_tp(tp) {};
|
||||
};
|
||||
|
||||
|
||||
class EchoMessage : public Message<EchoMessage>
|
||||
{
|
||||
public:
|
||||
|
||||
EchoMessage( Connection<EchoMessage> *connection,
|
||||
void *msgParam = 0);
|
||||
|
||||
bool buildMessage( const void *msgPart,
|
||||
const size_t msgLen );
|
||||
|
||||
void onMessageReady();
|
||||
|
||||
protected:
|
||||
|
||||
size_t getExpectedLength();
|
||||
|
||||
};
|
||||
|
||||
#endif // ECHO_MESSAGE_HPP
|
Loading…
Reference in new issue