Diag-Client-Lib
Public Types | Public Member Functions | Private Types | Private Attributes | List of all members
doip_client::sockets::UdpSocketHandler Class Referencefinal

Class used to create a udp socket for handling transmission and reception of udp message from driver. More...

#include <udp_socket_handler.h>

Collaboration diagram for doip_client::sockets::UdpSocketHandler:
Collaboration graph
[legend]

Public Types

using PortType = boost_support::socket::udp::UdpClientSocket::PortType
 Type alias for port type. More...
 
using UdpMessage = boost_support::socket::udp::UdpMessage
 Type alias for Udp message. More...
 
using UdpMessagePtr = boost_support::socket::udp::UdpMessagePtr
 Type alias for Udp message pointer. More...
 
using UdpMessageConstPtr = boost_support::socket::udp::UdpMessageConstPtr
 Type alias for Udp message const pointer. More...
 
using DoipUdpChannel = channel::udp_channel::DoipUdpChannel
 Type alias for Udp message. More...
 

Public Member Functions

 UdpSocketHandler (std::string_view local_ip_address, std::uint16_t port_num, PortType port_type, DoipUdpChannel &channel)
 Constructs an instance of UdpSocketHandler. More...
 
 ~UdpSocketHandler ()=default
 Destruct an instance of UdpSocketHandler. More...
 
void Start ()
 Function to start the socket handler. More...
 
void Stop ()
 Function to stop the socket handler. More...
 
core_type::Result< void > Transmit (UdpMessageConstPtr udp_message)
 Function to transmit the provided udp message. More...
 

Private Types

using UdpSocket = boost_support::socket::udp::UdpClientSocket
 Type alias for tcp client socket. More...
 

Private Attributes

std::string local_ip_address_
 Store the local ip address. More...
 
std::uint16_t local_port_num_
 Store the local port number. More...
 
UdpSocket::PortType port_type_
 Store the port type. More...
 
std::unique_ptr< UdpSocketudp_socket_
 Store the socket object. More...
 
DoipUdpChannelchannel_
 Store the reference to tcp channel. More...
 

Detailed Description

Class used to create a udp socket for handling transmission and reception of udp message from driver.

Definition at line 30 of file udp_socket_handler.h.

Member Typedef Documentation

◆ DoipUdpChannel

Type alias for Udp message.

Definition at line 55 of file udp_socket_handler.h.

◆ PortType

Type alias for port type.

Definition at line 35 of file udp_socket_handler.h.

◆ UdpMessage

Type alias for Udp message.

Definition at line 40 of file udp_socket_handler.h.

◆ UdpMessageConstPtr

Type alias for Udp message const pointer.

Definition at line 50 of file udp_socket_handler.h.

◆ UdpMessagePtr

Type alias for Udp message pointer.

Definition at line 45 of file udp_socket_handler.h.

◆ UdpSocket

Type alias for tcp client socket.

Definition at line 95 of file udp_socket_handler.h.

Constructor & Destructor Documentation

◆ UdpSocketHandler()

doip_client::sockets::UdpSocketHandler::UdpSocketHandler ( std::string_view  local_ip_address,
std::uint16_t  port_num,
PortType  port_type,
DoipUdpChannel channel 
)

Constructs an instance of UdpSocketHandler.

Parameters
[in]local_ip_addressThe local ip address
[in]channelThe reference to tcp transport handler

Definition at line 15 of file udp_socket_handler.cpp.

17  : local_ip_address_{local_ip_address},
18  local_port_num_{port_num},
19  port_type_{port_type},
20  channel_{channel} {
21  // create sockets and start receiving
22  if (port_type == UdpSocket::PortType::kUdp_Broadcast) {
23  udp_socket_ = std::make_unique<UdpSocket>(
25  [this](UdpMessagePtr udp_rx_message) { channel_.ProcessReceivedUdpBroadcast(std::move(udp_rx_message)); });
26  } else {
27  udp_socket_ = std::make_unique<UdpSocket>(
29  [this](UdpMessagePtr udp_rx_message) { channel_.ProcessReceivedUdpUnicast(std::move(udp_rx_message)); });
30  }
31 }
void ProcessReceivedUdpUnicast(UdpMessagePtr udp_rx_message)
Function to process the received Udp unicast message from socket layer.
void ProcessReceivedUdpBroadcast(UdpMessagePtr udp_rx_message)
Function to process the received Udp broadcast message from socket layer.
boost_support::socket::udp::UdpMessagePtr UdpMessagePtr
Type alias for Udp message pointer.
std::uint16_t local_port_num_
Store the local port number.
std::string local_ip_address_
Store the local ip address.
DoipUdpChannel & channel_
Store the reference to tcp channel.
std::unique_ptr< UdpSocket > udp_socket_
Store the socket object.
UdpSocket::PortType port_type_
Store the port type.

References channel_, boost_support::socket::udp::UdpClientSocket::kUdp_Broadcast, local_ip_address_, local_port_num_, port_type_, doip_client::channel::udp_channel::DoipUdpChannel::ProcessReceivedUdpBroadcast(), doip_client::channel::udp_channel::DoipUdpChannel::ProcessReceivedUdpUnicast(), and udp_socket_.

Here is the call graph for this function:

◆ ~UdpSocketHandler()

doip_client::sockets::UdpSocketHandler::~UdpSocketHandler ( )
default

Destruct an instance of UdpSocketHandler.

Member Function Documentation

◆ Start()

void doip_client::sockets::UdpSocketHandler::Start ( )

Function to start the socket handler.

Definition at line 33 of file udp_socket_handler.cpp.

33 { udp_socket_->Open(); }

References udp_socket_.

Referenced by doip_client::channel::udp_channel::DoipUdpChannel::Start().

Here is the caller graph for this function:

◆ Stop()

void doip_client::sockets::UdpSocketHandler::Stop ( )

Function to stop the socket handler.

Definition at line 35 of file udp_socket_handler.cpp.

35 { udp_socket_->Destroy(); }

References udp_socket_.

Referenced by doip_client::channel::udp_channel::DoipUdpChannel::Stop().

Here is the caller graph for this function:

◆ Transmit()

core_type::Result< void > doip_client::sockets::UdpSocketHandler::Transmit ( UdpMessageConstPtr  udp_message)

Function to transmit the provided udp message.

Parameters
[in]udp_messageThe udp message
Returns
The

Definition at line 37 of file udp_socket_handler.cpp.

37  {
39  if (udp_socket_->Transmit(std::move(udp_message)).HasValue()) { result.EmplaceValue(); }
40  return result;
41 }
Class type to contains a value (of type ValueType), or an error (of type ErrorType)
Definition: result.h:29
core_type::ErrorCode MakeErrorCode(DoipErrorErrc, core_type::ErrorDomain::SupportDataType data) noexcept
Create a new ErrorCode within DoipErrorDomain.

References doip_client::error_domain::kGenericError, doip_client::error_domain::MakeErrorCode(), and udp_socket_.

Here is the call graph for this function:

Member Data Documentation

◆ channel_

DoipUdpChannel& doip_client::sockets::UdpSocketHandler::channel_
private

Store the reference to tcp channel.

Definition at line 120 of file udp_socket_handler.h.

Referenced by UdpSocketHandler().

◆ local_ip_address_

std::string doip_client::sockets::UdpSocketHandler::local_ip_address_
private

Store the local ip address.

Definition at line 100 of file udp_socket_handler.h.

Referenced by UdpSocketHandler().

◆ local_port_num_

std::uint16_t doip_client::sockets::UdpSocketHandler::local_port_num_
private

Store the local port number.

Definition at line 105 of file udp_socket_handler.h.

Referenced by UdpSocketHandler().

◆ port_type_

UdpSocket::PortType doip_client::sockets::UdpSocketHandler::port_type_
private

Store the port type.

Definition at line 110 of file udp_socket_handler.h.

Referenced by UdpSocketHandler().

◆ udp_socket_

std::unique_ptr<UdpSocket> doip_client::sockets::UdpSocketHandler::udp_socket_
private

Store the socket object.

Definition at line 115 of file udp_socket_handler.h.

Referenced by Start(), Stop(), Transmit(), and UdpSocketHandler().


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