Core Library  1.7.0.0
Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.
SimpleMulticastSender.h
Go to the documentation of this file.
1 // This file is part of CoreLibrary containing useful reusable utility
2 // classes.
3 //
4 // Copyright (C) 2014 to present, Duncan Crutchley
5 // Contact <dac1976github@outlook.com>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published
9 // by the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License and GNU Lesser General Public License
16 // for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // and GNU Lesser General Public License along with this program. If
20 // not, see <http://www.gnu.org/licenses/>.
21 
27 #ifndef SIMPLEMULTICASTSENDER
28 #define SIMPLEMULTICASTSENDER
29 
30 #include "MulticastTypedSender.h"
31 
33 namespace core_lib
34 {
36 namespace asio
37 {
39 namespace udp
40 {
41 
44 class CORE_LIBRARY_DLL_SHARED_API SimpleMulticastSender final
45 {
46 public:
48  SimpleMulticastSender() = delete;
65  const defs::connection_t& multicastConnection,
66  const std::string& interfaceAddress = "", bool enableLoopback = true,
68  size_t sendBufferSize = DEFAULT_UDP_BUF_SIZE);
83  explicit SimpleMulticastSender(const defs::connection_t& multicastConnection,
84  const std::string& interfaceAddress = "",
85  bool enableLoopback = true,
87  size_t sendBufferSize = DEFAULT_UDP_BUF_SIZE);
91  SimpleMulticastSender& operator=(const SimpleMulticastSender&) = delete;
95  SimpleMulticastSender& operator=(SimpleMulticastSender&&) = delete;
97  ~SimpleMulticastSender() = default;
102  defs::connection_t MulticastConnection() const;
107  std::string InterfaceAddress() const;
116  bool SendMessage(int32_t messageId,
117  const defs::connection_t& responseAddress = defs::NULL_CONNECTION);
127  bool SendMessage(const defs::char_buffer_t& message, int32_t messageId,
128  const defs::connection_t& responseAddress = defs::NULL_CONNECTION);
139  template <typename T, class A = serialize::archives::out_port_bin_t>
140  bool SendMessage(const T& message, int32_t messageId,
141  const defs::connection_t& responseAddress = defs::NULL_CONNECTION)
142  {
143  return m_multicastTypedSender.SendMessage<T, A>(message, messageId, responseAddress);
144  }
150  bool SendMessage(const defs::char_buffer_t& message);
151 
152 private:
154  messages::MessageBuilder m_messageBuilder{};
157 };
158 
159 } // namespace udp
160 } // namespace asio
161 } // namespace core_lib
162 
163 #endif // SIMPLEMULTICASTSENDER
bool SendMessage(const T &message, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION)
Send a full message to the server.
Definition: SimpleMulticastSender.h:140
MulticastTypedSender< messages::MessageBuilder > m_multicastTypedSender
Our actual typed Multicast sender object.
Definition: SimpleMulticastSender.h:156
File containing UDP typed sender class declaration.
Multicast only to same subnet.
The core_lib namespace.
Definition: AsioDefines.h:59
eMulticastTTL
The multicast TTL enumeration.
Definition: AsioDefines.h:129
std::pair< std::string, uint16_t > connection_t
Typedef describing a network connection as (address, port).
Definition: AsioDefines.h:152
boost_asio::io_context boost_iocontext_t
Boost IO context convenience typedef.
Definition: AsioDefines.h:46
A generic UDP sender.
Definition: MulticastTypedSender.h:55
A simplified Multicast sender, which uses the class MessageHeader as the message header type...
Definition: SimpleMulticastSender.h:44
Default message builder class.
Definition: MessageUtils.h:268
std::vector< char > char_buffer_t
Typedef to generic char buffer based on s std::vector<char>.
Definition: AsioDefines.h:239
const connection_t NULL_CONNECTION
Constant defining a null network connection as ("0.0.0.0", 0).