Diag-Client-Lib
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
udp_client.h
Go to the documentation of this file.
1 /* Diagnostic Client library
2  * Copyright (C) 2024 Avijit Dey
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 #ifndef DIAG_CLIENT_LIB_LIB_BOOST_SUPPORT_INCLUDE_BOOST_SUPPORT_CLIENT_UDP_UDP_CLIENT_H_
9 #define DIAG_CLIENT_LIB_LIB_BOOST_SUPPORT_INCLUDE_BOOST_SUPPORT_CLIENT_UDP_UDP_CLIENT_H_
10 
11 #include <functional>
12 #include <string_view>
13 
15 #include "core/include/result.h"
16 
17 namespace boost_support {
18 namespace client {
19 namespace udp {
20 
24 class UdpClient final {
25  public:
30 
35 
40 
44  using HandlerRead = std::function<void(MessagePtr)>;
45 
46  public:
54  UdpClient(std::string_view local_ip_address, std::uint16_t local_port_num) noexcept;
55 
59  UdpClient(const UdpClient &other) noexcept = delete;
60  UdpClient &operator=(const UdpClient &other) noexcept = delete;
61 
65  UdpClient(UdpClient &&other) noexcept;
66  UdpClient &operator=(UdpClient &&other) noexcept;
67 
71  ~UdpClient() noexcept;
72 
76  void Initialize() noexcept;
77 
81  void DeInitialize() noexcept;
82 
89  void SetReadHandler(HandlerRead read_handler) noexcept;
90 
97  core_type::Result<void> Transmit(MessageConstPtr udp_message);
98 
99  private:
103  class UdpClientImpl;
104 
108  std::unique_ptr<UdpClientImpl> udp_client_impl_;
109 };
110 
111 } // namespace udp
112 } // namespace client
113 } // namespace boost_support
114 #endif // DIAG_CLIENT_LIB_LIB_BOOST_SUPPORT_INCLUDE_BOOST_SUPPORT_CLIENT_UDP_UDP_CLIENT_H_
Class to provide implementation of udp client.
Definition: udp_client.cpp:22
Client that manages udp connection.
Definition: udp_client.h:24
std::unique_ptr< UdpClientImpl > udp_client_impl_
Unique pointer to udp client implementation.
Definition: udp_client.h:103
core_type::Result< void > Transmit(MessageConstPtr udp_message)
Function to transmit the provided tcp message.
Definition: udp_client.cpp:128
void SetReadHandler(HandlerRead read_handler) noexcept
Function to set the read handler that is invoked when message is received.
Definition: udp_client.cpp:124
boost_support::message::udp::UdpMessageConstPtr MessageConstPtr
Type alias for Tcp message const pointer.
Definition: udp_client.h:39
void DeInitialize() noexcept
De-initialize the client.
Definition: udp_client.cpp:122
UdpClient(std::string_view local_ip_address, std::uint16_t local_port_num) noexcept
Constructs an instance of UdpClient.
Definition: udp_client.cpp:111
void Initialize() noexcept
Initialize the client.
Definition: udp_client.cpp:120
UdpClient & operator=(UdpClient &&other) noexcept
std::function< void(MessagePtr)> HandlerRead
Tcp function template used for reception.
Definition: udp_client.h:44
boost_support::message::udp::UdpMessagePtr MessagePtr
Type alias for Tcp message pointer.
Definition: udp_client.h:34
UdpClient & operator=(const UdpClient &other) noexcept=delete
UdpClient(const UdpClient &other) noexcept=delete
Deleted copy assignment and copy constructor.
~UdpClient() noexcept
Destruct an instance of UdpClient.
UdpClient(UdpClient &&other) noexcept
Move assignment and move constructor.
Immutable class to store received udp message.
Definition: udp_message.h:32
std::unique_ptr< UdpMessage > UdpMessagePtr
The unique pointer to UdpMessage.
Definition: udp_message.h:110
std::unique_ptr< UdpMessage const > UdpMessageConstPtr
The unique pointer to const UdpMessage.
Definition: udp_message.h:105
core_type::Result< T, E > Result
Class type to contains a value (of type ValueType), or an error (of type ErrorType)