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.
69 lines
1.1 KiB
69 lines
1.1 KiB
13 years ago
|
#ifndef MESSAGE_HPP
|
||
|
#define MESSAGE_HPP
|
||
|
|
||
13 years ago
|
#include "Logger.hpp"
|
||
|
|
||
13 years ago
|
|
||
13 years ago
|
#include <string>
|
||
13 years ago
|
#include <stddef.h> // size_t
|
||
13 years ago
|
|
||
13 years ago
|
/** Append msgParts with buildMessage() to m_buffer.
|
||
13 years ago
|
* Call onMessageReady() if the length of the buffer equals the value from
|
||
|
* getExpectedLength().
|
||
|
*/
|
||
|
|
||
13 years ago
|
class Connection;
|
||
13 years ago
|
|
||
|
|
||
13 years ago
|
class Message
|
||
|
{
|
||
|
public:
|
||
|
|
||
13 years ago
|
Message( Connection *connection,
|
||
13 years ago
|
void *msgParam = 0 )
|
||
13 years ago
|
: m_connection(connection)
|
||
|
, m_param(msgParam)
|
||
|
, m_buffer()
|
||
13 years ago
|
{
|
||
|
TRACE;
|
||
|
};
|
||
|
|
||
|
Message( void *msgParam = 0 )
|
||
|
: m_connection(0)
|
||
|
, m_param(msgParam)
|
||
|
, m_buffer()
|
||
|
{
|
||
|
TRACE;
|
||
|
};
|
||
13 years ago
|
|
||
13 years ago
|
virtual ~Message() {};
|
||
13 years ago
|
virtual Message* clone() = 0;
|
||
13 years ago
|
|
||
13 years ago
|
virtual bool buildMessage( const void *msgPart,
|
||
|
const size_t msgLen ) = 0;
|
||
13 years ago
|
virtual void onMessageReady() = 0;
|
||
|
|
||
13 years ago
|
void setConnection(Connection* conn )
|
||
13 years ago
|
{
|
||
|
TRACE;
|
||
|
m_connection = conn;
|
||
|
}
|
||
|
|
||
13 years ago
|
protected:
|
||
|
|
||
13 years ago
|
virtual size_t getExpectedLength() = 0;
|
||
13 years ago
|
|
||
|
|
||
13 years ago
|
Connection *m_connection;
|
||
13 years ago
|
void *m_param;
|
||
|
std::string m_buffer;
|
||
13 years ago
|
|
||
|
private:
|
||
|
|
||
13 years ago
|
Message(const Message &);
|
||
|
Message& operator=(const Message &);
|
||
13 years ago
|
};
|
||
|
|
||
|
|
||
|
#endif // MESSAGE_HPP
|