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::udp::SimpleMulticastReceiver Class Referencefinal

A simplified multicast receiver, which uses the class MessageHeader as the message header type. More...

#include <SimpleMulticastReceiver.h>

Public Member Functions

 SimpleMulticastReceiver ()=delete
 Default constructor - deleted.
 
 SimpleMulticastReceiver (boost_iocontext_t &ioContext, const defs::connection_t &multicastConnection, const defs::default_message_dispatcher_t &messageDispatcher, const std::string &interfaceAddress="", size_t receiveBufferSize=DEFAULT_UDP_BUF_SIZE, size_t memPoolMsgCount=0)
 Initialisation constructor. More...
 
 SimpleMulticastReceiver (const defs::connection_t &multicastConnection, const defs::default_message_dispatcher_t &messageDispatcher, const std::string &interfaceAddress="", size_t receiveBufferSize=DEFAULT_UDP_BUF_SIZE, size_t memPoolMsgCount=0)
 Initialisation constructor. More...
 
 SimpleMulticastReceiver (const SimpleMulticastReceiver &)=delete
 Copy constructor - deleted.
 
SimpleMulticastReceiveroperator= (SimpleMulticastReceiver &&)=delete
 Copy assignment operator - deleted.
 
 SimpleMulticastReceiver (SimpleMulticastReceiver &&)=delete
 Move constructor - deleted.
 
SimpleMulticastReceiveroperator= (const SimpleMulticastReceiver &)=delete
 Move assignment operator - deleted.
 
 ~SimpleMulticastReceiver ()=default
 Default destructor.
 
defs::connection_t MulticastConnection () const
 Retrieve multicast connection details. More...
 
std::string InterfaceAddress () const
 Retrieve interface IP address. More...
 

Private Attributes

messages::MessageHandler m_messageHandler {}
 Default message handler object of type core_lib::asio::messages::MessageHandler.
 
MulticastReceiver m_mcastReceiver
 Our actual typed multicast receiver object.
 

Detailed Description

A simplified multicast receiver, which uses the class MessageHeader as the message header type.

Constructor & Destructor Documentation

◆ SimpleMulticastReceiver() [1/2]

core_lib::asio::udp::SimpleMulticastReceiver::SimpleMulticastReceiver ( boost_iocontext_t ioContext,
const defs::connection_t multicastConnection,
const defs::default_message_dispatcher_t messageDispatcher,
const std::string &  interfaceAddress = "",
size_t  receiveBufferSize = DEFAULT_UDP_BUF_SIZE,
size_t  memPoolMsgCount = 0 
)

Initialisation constructor.

Parameters
[in]ioContext- External boost IO context to manage ASIO.
[in]multicastConnection- Connection object describing target multicast group address and port.
[in]messageDispatcher- Callback to use to dispatch received messages.
[in]interfaceAddress- Optional interface IP address for incoming network messages.
[in]receiveBufferSize- Optional socket receive option to control receive buffer size.
[in]memPoolMsgCount- Number of messages in pool for received message handling, defaults to 0, which implies no pool used.

Typically use this constructor when managing a pool of threads using an instance of core_lib::asio::IoContextThreadGroup in your application to manage a pool of std::threads. This means you can use a single thread pool and all ASIO operations will be executed using this thread pool managed by a single IO context. This is the recommended constructor.

NOTE: When the message pool feature is used then all messages passed to the the registered dispatcher are managed by the internal pool. Care must be taken in the dispatcher to process the messages as quickly as possibly so the pool doesn't fill and start overwriting older messages. If the messages need to be kept then it is the dispatchers job to make a suitable copy of the received message.

◆ SimpleMulticastReceiver() [2/2]

core_lib::asio::udp::SimpleMulticastReceiver::SimpleMulticastReceiver ( const defs::connection_t multicastConnection,
const defs::default_message_dispatcher_t messageDispatcher,
const std::string &  interfaceAddress = "",
size_t  receiveBufferSize = DEFAULT_UDP_BUF_SIZE,
size_t  memPoolMsgCount = 0 
)

Initialisation constructor.

Parameters
[in]multicastConnection- Connection object describing target multicast group address and port.
[in]messageDispatcher- Callback to use to dispatch received messages.
[in]interfaceAddress- Optional interface IP address for incoming network messages.
[in]receiveBufferSize- Optional socket receive option to control receive buffer size.
[in]memPoolMsgCount- Number of messages in pool for received message handling, defaults to 0, which implies no pool used.

This constructor does not require an external IO context to run instead it creates its own IO context object along with its own thread. For very simple cases this version will be fine but in more performance and resource critical situations the external IO context constructor is recommended.

NOTE: When the message pool feature is used then all messages passed to the the registered dispatcher are managed by the internal pool. Care must be taken in the dispatcher to process the messages as quickly as possibly so the pool doesn't fill and start overwriting older messages. If the messages need to be kept then it is the dispatchers job to make a suitable copy of the received message.

Member Function Documentation

◆ InterfaceAddress()

std::string core_lib::asio::udp::SimpleMulticastReceiver::InterfaceAddress ( ) const

Retrieve interface IP address.

Returns
- Interface IP address.

◆ MulticastConnection()

defs::connection_t core_lib::asio::udp::SimpleMulticastReceiver::MulticastConnection ( ) const

Retrieve multicast connection details.

Returns
- Connection object describing target multicast group address and port.

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