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::MulticastTypedSender< MsgBldr > Class Template Referencefinal

A generic UDP sender. More...

#include <MulticastTypedSender.h>

Public Member Functions

 MulticastTypedSender ()=delete
 Default constructor - deleted.
 
 MulticastTypedSender (boost_iocontext_t &ioContext, const defs::connection_t &multicastConnection, const MsgBldr &messageBuilder, const std::string &interfaceAddress="", bool enableLoopback=true, eMulticastTTL ttl=eMulticastTTL::sameSubnet, size_t sendBufferSize=DEFAULT_UDP_BUF_SIZE)
 Initialisation constructor. More...
 
 MulticastTypedSender (const defs::connection_t &multicastConnection, const MsgBldr &messageBuilder, const std::string &interfaceAddress="", bool enableLoopback=true, eMulticastTTL ttl=eMulticastTTL::sameSubnet, size_t sendBufferSize=DEFAULT_UDP_BUF_SIZE)
 Initialisation constructor. More...
 
 MulticastTypedSender (const MulticastTypedSender &)=delete
 Copy constructor - deleted.
 
MulticastTypedSenderoperator= (const MulticastTypedSender &)=delete
 Copy assignment operator - deleted.
 
 MulticastTypedSender (MulticastTypedSender &&)=delete
 Move constructor - deleted.
 
MulticastTypedSenderoperator= (MulticastTypedSender &&)=delete
 Move assignment operator - deleted.
 
 ~MulticastTypedSender ()=default
 Default destructor.
 
defs::connection_t MulticastConnection () const
 Retrieve multicast connection details. More...
 
std::string InterfaceAddress () const
 Retrieve interface IP address. More...
 
bool SendMessage (int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION)
 Send a header-only message to the receiver. More...
 
bool SendMessage (const defs::char_buffer_t &message, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION)
 Send a header plus message buffer to the receiver. More...
 
template<typename T , class A = serialize::archives::out_port_bin_t>
bool SendMessage (const T &message, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION)
 Send a full message to the server. More...
 
bool SendMessage (const defs::char_buffer_t &message)
 Send a message buffer to the receiver. More...
 

Private Attributes

std::mutex m_sendMutex
 Send message mutex.
 
const MsgBldr & m_messageBuilder
 Const reference to message builder object.
 
MulticastSender m_multicastSender
 Underlying UDP sender object.
 

Detailed Description

template<typename MsgBldr>
class core_lib::asio::udp::MulticastTypedSender< MsgBldr >

A generic UDP sender.

The template argument defines a message builder object that must have an interface compatible with that of the class core_lib::asio::messages::MessageBuilder.

This class forms the underpinnings of the SimpleMulticastSender class.

This is also the class to be used when the user wants to specify their own message builder type and message header type.

Constructor & Destructor Documentation

◆ MulticastTypedSender() [1/2]

template<typename MsgBldr>
core_lib::asio::udp::MulticastTypedSender< MsgBldr >::MulticastTypedSender ( boost_iocontext_t ioContext,
const defs::connection_t multicastConnection,
const MsgBldr &  messageBuilder,
const std::string &  interfaceAddress = "",
bool  enableLoopback = true,
eMulticastTTL  ttl = eMulticastTTL::sameSubnet,
size_t  sendBufferSize = DEFAULT_UDP_BUF_SIZE 
)
inline

Initialisation constructor.

Parameters
[in]ioContext- External boost IO context to manage ASIO.
[in]multicastConnection- Connection object describing target multicast group address and port.
[in]interfaceAddress- Optional interface IP address for outgoing network messages.
[in]messageBuilder- Message builder object reference.
[in]enableLoopback- Optional allow multicasts to loopback on same adapter.
[in]ttl- Optional time-to-live for multicast messages.
[in]sendBufferSize- Socket send option to control send buffer size.

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.

◆ MulticastTypedSender() [2/2]

template<typename MsgBldr>
core_lib::asio::udp::MulticastTypedSender< MsgBldr >::MulticastTypedSender ( const defs::connection_t multicastConnection,
const MsgBldr &  messageBuilder,
const std::string &  interfaceAddress = "",
bool  enableLoopback = true,
eMulticastTTL  ttl = eMulticastTTL::sameSubnet,
size_t  sendBufferSize = DEFAULT_UDP_BUF_SIZE 
)
inline

Initialisation constructor.

Parameters
[in]multicastConnection- Connection object describing target multicast group address and port.
[in]interfaceAddress- Optional interface IP address for outgoing network messages.
[in]messageBuilder- Message builder object reference.
[in]enableLoopback- Optional allow multicasts to loopback on same adapter.
[in]ttl- Optional time-to-live for multicast messages.
[in]sendBufferSize- Socket send option to control send buffer size.

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.

Member Function Documentation

◆ InterfaceAddress()

template<typename MsgBldr>
std::string core_lib::asio::udp::MulticastTypedSender< MsgBldr >::InterfaceAddress ( ) const
inline

Retrieve interface IP address.

Returns
- Interface IP address.

◆ MulticastConnection()

template<typename MsgBldr>
defs::connection_t core_lib::asio::udp::MulticastTypedSender< MsgBldr >::MulticastConnection ( ) const
inline

Retrieve multicast connection details.

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

◆ SendMessage() [1/4]

template<typename MsgBldr>
bool core_lib::asio::udp::MulticastTypedSender< MsgBldr >::SendMessage ( int32_t  messageId,
const defs::connection_t responseAddress = defs::NULL_CONNECTION 
)
inline

Send a header-only message to the receiver.

Parameters
[in]messageId- Unique message ID to insert into message header.
[in]responseAddress- (Optional) The address and port where the receiver should send the response, the default value will mean the response address will point to this client socket.
Returns
Returns the success state of the send as a boolean.

◆ SendMessage() [2/4]

template<typename MsgBldr>
bool core_lib::asio::udp::MulticastTypedSender< MsgBldr >::SendMessage ( const defs::char_buffer_t message,
int32_t  messageId,
const defs::connection_t responseAddress = defs::NULL_CONNECTION 
)
inline

Send a header plus message buffer to the receiver.

Parameters
[in]message- The message buffer.
[in]messageId- Unique message ID to insert into message header.
[in]responseAddress- (Optional) The address and port where the receiver should send the response, the default value will mean the response address will point to this client socket.
Returns
Returns the success state of the send as a boolean.

◆ SendMessage() [3/4]

template<typename MsgBldr>
template<typename T , class A = serialize::archives::out_port_bin_t>
bool core_lib::asio::udp::MulticastTypedSender< MsgBldr >::SendMessage ( const T &  message,
int32_t  messageId,
const defs::connection_t responseAddress = defs::NULL_CONNECTION 
)
inline

Send a full message to the server.

Parameters
[in]message- The message of type T to send behind the header serialized to an boost::serialization-compatible archive of type A.
[in]messageId- Unique message ID to insert into message header.
[in]responseAddress- (Optional) The address and port where the receiver should send the response, the default value will mean the response address will point to this client socket.
Returns
Returns the success state of the send as a boolean.

◆ SendMessage() [4/4]

template<typename MsgBldr>
bool core_lib::asio::udp::MulticastTypedSender< MsgBldr >::SendMessage ( const defs::char_buffer_t message)
inline

Send a message buffer to the receiver.

Parameters
[in]message- The message buffer.
Returns
Returns the success state of the send as a boolean.

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