Diag-Client-Lib
|
Class used to create a udp socket for handling transmission and reception of udp message from driver. More...
#include <udp_client.h>
Public Types | |
enum class | UdpErrorCode : std::uint8_t { kOpenFailed , kBindingFailed , kGenericError } |
Udp error code. More... | |
enum class | PortType : std::uint8_t { kUdp_Broadcast = 0 , kUdp_Unicast } |
Type of udp port to be used underneath. More... | |
using | UdpHandlerRead = std::function< void(UdpMessagePtr)> |
Udp function template used for reception. More... | |
Public Member Functions | |
UdpClientSocket (std::string_view local_ip_address, std::uint16_t local_port_num, PortType port_type, UdpHandlerRead udp_handler_read) | |
Constructs an instance of UdpClientSocket. More... | |
virtual | ~UdpClientSocket () |
Destruct an instance of UdpClientSocket. More... | |
core_type::Result< void, UdpErrorCode > | Open () |
Function to Open the socket. More... | |
core_type::Result< void, UdpErrorCode > | Transmit (UdpMessageConstPtr udp_message) |
Function to trigger transmission. More... | |
core_type::Result< void, UdpErrorCode > | Destroy () |
Function to destroy the socket. More... | |
Private Types | |
using | Udp = boost::asio::ip::udp |
Type alias for udp protocol. More... | |
using | UdpSocket = Udp::socket |
Type alias for udp socket. More... | |
using | UdpIpAddress = boost::asio::ip::address |
Type alias for udp ip address. More... | |
using | UdpErrorCodeType = boost::system::error_code |
Type alias for udp error codes. More... | |
Private Member Functions | |
void | HandleMessage (const UdpErrorCodeType &error, std::size_t bytes_received) |
Function to handle the reception of tcp message. More... | |
Private Attributes | |
std::string | local_ip_address_ |
Store local ip address. More... | |
std::uint16_t | local_port_num_ |
Store local port number. More... | |
boost::asio::io_context | io_context_ |
boost io context More... | |
UdpSocket | udp_socket_ |
Store tcp socket. More... | |
std::atomic_bool | exit_request_ |
Flag to terminate the thread. More... | |
std::atomic_bool | running_ |
Flag to start the thread. More... | |
std::condition_variable | cond_var_ |
Conditional variable to block the thread. More... | |
std::thread | thread_ |
The thread itself. More... | |
std::mutex | mutex_ |
mutex to lock critical section More... | |
Udp::endpoint | remote_endpoint_ |
Store the remote endpoint. More... | |
PortType | port_type_ |
Store the port type - broadcast / unicast. More... | |
UdpHandlerRead | udp_handler_read_ |
Store the handler. More... | |
std::array< std::uint8_t, kDoipUdpResSize > | rx_buffer_ |
Reception buffer needed for async reception of udp data. More... | |
Class used to create a udp socket for handling transmission and reception of udp message from driver.
Definition at line 27 of file udp_client.h.
|
private |
Type alias for udp protocol.
Definition at line 88 of file udp_client.h.
|
private |
Type alias for udp error codes.
Definition at line 103 of file udp_client.h.
using boost_support::socket::udp::UdpClientSocket::UdpHandlerRead = std::function<void(UdpMessagePtr)> |
Udp function template used for reception.
Definition at line 42 of file udp_client.h.
|
private |
Type alias for udp ip address.
Definition at line 98 of file udp_client.h.
|
private |
Type alias for udp socket.
Definition at line 93 of file udp_client.h.
|
strong |
Type of udp port to be used underneath.
Enumerator | |
---|---|
kUdp_Broadcast | |
kUdp_Unicast |
Definition at line 37 of file udp_client.h.
|
strong |
Udp error code.
Enumerator | |
---|---|
kOpenFailed | |
kBindingFailed | |
kGenericError |
Definition at line 32 of file udp_client.h.
boost_support::socket::udp::UdpClientSocket::UdpClientSocket | ( | std::string_view | local_ip_address, |
std::uint16_t | local_port_num, | ||
PortType | port_type, | ||
UdpHandlerRead | udp_handler_read | ||
) |
Constructs an instance of UdpClientSocket.
[in] | local_ip_address | The local ip address |
[in] | local_port_num | The local port number |
[in] | port_type | The type of socket port |
[in] | UdpHandlerRead | The handler to send received data to user |
Definition at line 17 of file udp_client.cpp.
References cond_var_, exit_request_, io_context_, mutex_, running_, and thread_.
|
virtual |
Destruct an instance of UdpClientSocket.
Definition at line 47 of file udp_client.cpp.
References cond_var_, exit_request_, running_, and thread_.
core_type::Result< void, UdpClientSocket::UdpErrorCode > boost_support::socket::udp::UdpClientSocket::Destroy | ( | ) |
Function to destroy the socket.
Definition at line 147 of file udp_client.cpp.
References core_type::Result< T, E >::EmplaceValue().
|
private |
Function to handle the reception of tcp message.
Definition at line 158 of file udp_client.cpp.
References boost_support::common::logger::LibBoostLogger::GetLibBoostLogger().
Referenced by Open(), and Transmit().
core_type::Result< void, UdpClientSocket::UdpErrorCode > boost_support::socket::udp::UdpClientSocket::Open | ( | ) |
Function to Open the socket.
Definition at line 54 of file udp_client.cpp.
References cond_var_, boost_support::common::logger::LibBoostLogger::GetLibBoostLogger(), HandleMessage(), kGenericError, kUdp_Broadcast, local_ip_address_, local_port_num_, mutex_, port_type_, remote_endpoint_, running_, rx_buffer_, and udp_socket_.
core_type::Result< void, UdpClientSocket::UdpErrorCode > boost_support::socket::udp::UdpClientSocket::Transmit | ( | UdpMessageConstPtr | udp_message | ) |
Function to trigger transmission.
[in] | udp_message | The udp message to be transmitted |
Definition at line 109 of file udp_client.cpp.
References boost_support::common::logger::LibBoostLogger::GetLibBoostLogger(), HandleMessage(), kGenericError, remote_endpoint_, rx_buffer_, and udp_socket_.
|
private |
Conditional variable to block the thread.
Definition at line 138 of file udp_client.h.
Referenced by Open(), UdpClientSocket(), and ~UdpClientSocket().
|
private |
Flag to terminate the thread.
Definition at line 128 of file udp_client.h.
Referenced by UdpClientSocket(), and ~UdpClientSocket().
|
private |
|
private |
|
private |
|
private |
mutex to lock critical section
Definition at line 148 of file udp_client.h.
Referenced by Open(), and UdpClientSocket().
|
private |
Store the port type - broadcast / unicast.
Definition at line 158 of file udp_client.h.
Referenced by Open().
|
private |
Store the remote endpoint.
Definition at line 153 of file udp_client.h.
Referenced by Open(), and Transmit().
|
private |
Flag to start the thread.
Definition at line 133 of file udp_client.h.
Referenced by Open(), UdpClientSocket(), and ~UdpClientSocket().
|
private |
Reception buffer needed for async reception of udp data.
Definition at line 168 of file udp_client.h.
Referenced by Open(), and Transmit().
|
private |
The thread itself.
Definition at line 143 of file udp_client.h.
Referenced by UdpClientSocket(), and ~UdpClientSocket().
|
private |
Store the handler.
Definition at line 163 of file udp_client.h.
|
private |
Store tcp socket.
Definition at line 123 of file udp_client.h.
Referenced by Open(), and Transmit().