Core Library 1.7.0.0 Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.

SimpleUdpSender.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 SIMPLEUDPSENDER
28 #define SIMPLEUDPSENDER
29
30 #include "UdpTypedSender.h"
31
33 namespace core_lib
34 {
36 namespace asio
37 {
39 namespace udp
40 {
42 class CORE_LIBRARY_DLL_SHARED_API SimpleUdpSender final
43 {
44 public:
46 SimpleUdpSender() = delete;
59 SimpleUdpSender(boost_iocontext_t& ioContext, const defs::connection_t& receiver,
60 eUdpOption sendOption = eUdpOption::broadcast,
61 size_t sendBufferSize = DEFAULT_UDP_BUF_SIZE);
73 explicit SimpleUdpSender(const defs::connection_t& receiver,
74 eUdpOption sendOption = eUdpOption::broadcast,
75 size_t sendBufferSize = DEFAULT_UDP_BUF_SIZE);
77 SimpleUdpSender(const SimpleUdpSender&) = delete;
79 SimpleUdpSender& operator=(const SimpleUdpSender&) = delete;
81 SimpleUdpSender(SimpleUdpSender&&) = delete;
83 SimpleUdpSender& operator=(SimpleUdpSender&&) = delete;
85 ~SimpleUdpSender() = default;
90 defs::connection_t ReceiverConnection() const;
101 bool SendMessage(int32_t messageId,
102 const defs::connection_t& responseAddress = defs::NULL_CONNECTION);
112 bool SendMessage(const defs::char_buffer_t& message, int32_t messageId,
113 const defs::connection_t& responseAddress = defs::NULL_CONNECTION);
124 template <typename T, typename A = serialize::archives::out_port_bin_t>
125 bool SendMessage(const T& message, int32_t messageId,
126 const defs::connection_t& responseAddress = defs::NULL_CONNECTION)
127 {
128 return m_udpTypedSender.SendMessage<T, A>(message, messageId, responseAddress);
129 }
135 bool SendMessage(const defs::char_buffer_t& message);
136
137 private:
139 messages::MessageBuilder m_messageBuilder;
141 UdpTypedSender<messages::MessageBuilder> m_udpTypedSender;
142 };
143
144 } // namespace udp
145 } // namespace asio
146 } // namespace core_lib
147
148 #endif // SIMPLEUDPSENDER
core_lib::asio::udp::eUdpOption
eUdpOption
The udp options enumeration.
Definition: AsioDefines.h:98
core_lib::asio::udp::SimpleUdpSender
A simplified UDP sender.
Definition: SimpleUdpSender.h:42
core_lib::asio::udp::SimpleUdpSender::m_messageBuilder
messages::MessageBuilder m_messageBuilder
Default message builder object of type core_lib::asio::messages::MessageBuilder.
Definition: SimpleUdpSender.h:139
core_lib
The core_lib namespace.
Definition: AsioDefines.h:59
core_lib::asio::udp::SimpleUdpSender::SendMessage
bool SendMessage(const T &message, int32_t messageId, const defs::connection_t &responseAddress=defs::NULL_CONNECTION)
Send a full message to the server.
Definition: SimpleUdpSender.h:125
core_lib::asio::defs::connection_t
std::pair< std::string, uint16_t > connection_t
Typedef describing a network connection as (address, port).
Definition: AsioDefines.h:152
core_lib::asio::udp::UdpTypedSender
A generic UDP sender.
Definition: UdpTypedSender.h:55
core_lib::asio::udp::SimpleUdpSender::m_udpTypedSender
UdpTypedSender< messages::MessageBuilder > m_udpTypedSender
Our actual typed UDP sender object.
Definition: SimpleUdpSender.h:141
boost_iocontext_t
boost_asio::io_context boost_iocontext_t
Boost IO context convenience typedef.
Definition: AsioDefines.h:46
core_lib::asio::udp::eUdpOption::broadcast
udp broadcasts.
core_lib::asio::messages::MessageBuilder
Default message builder class.
Definition: MessageUtils.h:268
core_lib::asio::defs::char_buffer_t
std::vector< char > char_buffer_t
Typedef to generic char buffer based on s std::vector<char>.
Definition: AsioDefines.h:239
UdpTypedSender.h
File containing UDP typed sender class declaration.
core_lib::asio::defs::NULL_CONNECTION
const connection_t NULL_CONNECTION
Constant defining a null network connection as ("0.0.0.0", 0).