Core Library  1.7.0.0
Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.
core_lib::asio::messages::MessageHandler Class Referencefinal

Default message handler class. More...

#include <MessageUtils.h>

Public Member Functions

 MessageHandler ()=default
 Default constructor.
 
 MessageHandler (const defs::default_message_dispatcher_t &messageDispatcher, const std::string &magicString, size_t memPoolMsgCount=0, size_t defaultMsgSize=udp::DEFAULT_UDP_BUF_SIZE)
 Initialisation constructor. More...
 
 ~MessageHandler ()=default
 Default destructor.
 
 MessageHandler (const MessageHandler &)=default
 Default copy constructor.
 
MessageHandleroperator= (const MessageHandler &)=default
 Default copy assignment operator.
 
 MessageHandler (MessageHandler &&)=default
 Default move constructor.
 
MessageHandleroperator= (MessageHandler &&)=default
 Default move assignment operator.
 
size_t CheckBytesLeftToRead (const defs::char_buffer_t &message) const
 Check bytes left to read method. More...
 
void MessageReceivedHandler (const defs::char_buffer_t &message) const
 Message received handler method. More...
 

Private Member Functions

void InitialiseMsgPool (size_t memPoolMsgCount, size_t defaultMsgSize)
 Initialise message pool. More...
 
defs::default_received_message_ptr_t GetNewMessgeObject () const
 Initialise message pool. More...
 

Static Private Member Functions

static bool CheckMessage (const defs::char_buffer_t &message)
 Check message method. More...
 

Private Attributes

defs::default_message_dispatcher_t m_messageDispatcher
 Message dispatcher function object.
 
std::string m_magicString {static_cast<char const*>(defs::DEFAULT_MAGIC_STRING)}
 Magic string.
 
size_t m_msgPoolIndex {0}
 
std::vector< defs::default_received_message_ptr_tm_msgPool
 

Detailed Description

Default message handler class.

This is an example of a message handler functor that can be used by the network classes to handle a received network message with header type MessageHeader and is used in the simple network classes: SimpleTcpClient, SimpleTcpServer etc.

Constructor & Destructor Documentation

◆ MessageHandler()

core_lib::asio::messages::MessageHandler::MessageHandler ( const defs::default_message_dispatcher_t messageDispatcher,
const std::string &  magicString,
size_t  memPoolMsgCount = 0,
size_t  defaultMsgSize = udp::DEFAULT_UDP_BUF_SIZE 
)

Initialisation constructor.

Parameters
[in]messageDispatcher- Function object defining the message dispatcher callback
[in]magicString- Magic string used to identify the start of valid messages.
[in]memPoolMsgCount- (Optional) Pool size as number of messages.
[in]defaultMsgSize- (Optional) Initial size of a message in the pool.

If you want to use a memory pool rather that dynamic allocations then set memPoolMsgCount > 0 and the pool will allow for the specified number of messages. If memPollMsgCount == 0 then dynamic memory allocation is used when handling each new message.

Member Function Documentation

◆ CheckBytesLeftToRead()

size_t core_lib::asio::messages::MessageHandler::CheckBytesLeftToRead ( const defs::char_buffer_t message) const

Check bytes left to read method.

Parameters
[in]message- A received message buffer.

◆ CheckMessage()

bool core_lib::asio::messages::MessageHandler::CheckMessage ( const defs::char_buffer_t message)
staticprivate

Check message method.

Parameters
[in]message- A received message buffer.

◆ GetNewMessgeObject()

defs::default_received_message_ptr_t core_lib::asio::messages::MessageHandler::GetNewMessgeObject ( ) const
private

Initialise message pool.

Returns
A new message object or a one from the pool.

◆ InitialiseMsgPool()

void core_lib::asio::messages::MessageHandler::InitialiseMsgPool ( size_t  memPoolMsgCount,
size_t  defaultMsgSize 
)
private

Initialise message pool.

Parameters
[in]memPoolMsgCount- Pool size as number of messages..
[in]defaultMsgSize- Initial size of a message in the pool.

◆ MessageReceivedHandler()

void core_lib::asio::messages::MessageHandler::MessageReceivedHandler ( const defs::char_buffer_t message) const

Message received handler method.

Parameters
[in]message- A received message buffer.

The documentation for this class was generated from the following files: