Diag-Client-Lib
udp_socket_handler.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_DOIP_CLIENT_SOCKETS_UDP_SOCKET_HANDLER_H_
9 #define DIAG_CLIENT_LIB_LIB_DOIP_CLIENT_SOCKETS_UDP_SOCKET_HANDLER_H_
10 //includes
11 #include <string>
12 #include <string_view>
13 
14 #include "core/include/result.h"
15 #include "socket/udp/udp_client.h"
16 
17 namespace doip_client {
18 // forward declaration
19 namespace channel {
20 namespace udp_channel {
21 class DoipUdpChannel;
22 } // namespace udp_channel
23 } // namespace channel
24 
25 namespace sockets {
26 
30 class UdpSocketHandler final {
31  public:
36 
41 
46 
51 
56 
57  public:
65  UdpSocketHandler(std::string_view local_ip_address, std::uint16_t port_num, PortType port_type,
66  DoipUdpChannel &channel);
67 
71  ~UdpSocketHandler() = default;
72 
76  void Start();
77 
81  void Stop();
82 
90 
91  private:
96 
100  std::string local_ip_address_;
101 
105  std::uint16_t local_port_num_;
106 
111 
115  std::unique_ptr<UdpSocket> udp_socket_;
116 
121 };
122 } // namespace sockets
123 } // namespace doip_client
124 #endif // DIAG_CLIENT_LIB_LIB_DOIP_CLIENT_SOCKETS_UDP_SOCKET_HANDLER_H_
Class used to create a udp socket for handling transmission and reception of udp message from driver.
Definition: udp_client.h:27
PortType
Type of udp port to be used underneath.
Definition: udp_client.h:37
Immutable class to store received udp message.
Definition: udp_message.h:31
Class type to contains a value (of type ValueType), or an error (of type ErrorType)
Definition: result.h:29
Class to manage a udp channel as per DoIP protocol.
Class used to create a udp socket for handling transmission and reception of udp message from driver.
UdpSocketHandler(std::string_view local_ip_address, std::uint16_t port_num, PortType port_type, DoipUdpChannel &channel)
Constructs an instance of UdpSocketHandler.
core_type::Result< void > Transmit(UdpMessageConstPtr udp_message)
Function to transmit the provided udp message.
boost_support::socket::udp::UdpMessagePtr UdpMessagePtr
Type alias for Udp message pointer.
std::uint16_t local_port_num_
Store the local port number.
boost_support::socket::udp::UdpMessageConstPtr UdpMessageConstPtr
Type alias for Udp message const pointer.
std::string local_ip_address_
Store the local ip address.
DoipUdpChannel & channel_
Store the reference to tcp channel.
~UdpSocketHandler()=default
Destruct an instance of UdpSocketHandler.
std::unique_ptr< UdpSocket > udp_socket_
Store the socket object.
void Stop()
Function to stop the socket handler.
void Start()
Function to start the socket handler.
UdpSocket::PortType port_type_
Store the port type.
std::unique_ptr< const UdpMessage > UdpMessageConstPtr
The unique pointer to const UdpMessage.
Definition: udp_message.h:134
std::unique_ptr< UdpMessage > UdpMessagePtr
The unique pointer to UdpMessage.
Definition: udp_message.h:139