Diag-Client-Lib
doip_vehicle_discovery_handler.cpp
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 
10 
11 #include "common/logger.h"
12 #include "utility/state.h"
13 
14 namespace doip_client {
15 namespace channel {
16 namespace udp_channel {
17 namespace {
21 enum class VehicleDiscoveryState : std::uint8_t {
22  kIdle = 0U,
25 };
26 
30 class kIdle final : public utility::state::State<VehicleDiscoveryState> {
31  public:
38 
42  void Start() override {}
43 
47  void Stop() override {}
48 };
49 
53 class kWaitForVehicleAnnouncement final : public utility::state::State<VehicleDiscoveryState> {
54  public:
61  : State<VehicleDiscoveryState>(state) {}
62 
66  void Start() override {}
67 
71  void Stop() override {}
72 };
73 
77 class kDoIPCtrlTimeout final : public utility::state::State<VehicleDiscoveryState> {
78  public:
85 
89  void Start() override {}
90 
94  void Stop() override {}
95 };
96 
97 } // namespace
98 
103  public:
108 
115  : udp_socket_handler_{udp_socket_handler},
116  state_context_{} {
117  // create and add state for vehicle discovery
118  // kIdle
119  state_context_.AddState(VehicleDiscoveryState::kIdle,
120  std::make_unique<kIdle>(VehicleDiscoveryState::kIdle));
121  // kWaitForVehicleAnnouncement
122  state_context_.AddState(VehicleDiscoveryState::kWaitForVehicleAnnouncement,
123  std::make_unique<kWaitForVehicleAnnouncement>(
124  VehicleDiscoveryState::kWaitForVehicleAnnouncement));
125  // kDoIPCtrlTimeout
127  VehicleDiscoveryState::kDoIPCtrlTimeout,
128  std::make_unique<kDoIPCtrlTimeout>(VehicleDiscoveryState::kDoIPCtrlTimeout));
129  // Transit to wait for vehicle announcement
130  state_context_.TransitionTo(VehicleDiscoveryState::kWaitForVehicleAnnouncement);
131  }
132 
138 
143  auto GetSocketHandler() noexcept -> sockets::UdpSocketHandler & { return udp_socket_handler_; }
144 
145  private:
150 
155 };
156 
158  sockets::UdpSocketHandler &udp_socket_handler, DoipUdpChannel &)
159  : handler_impl_{std::make_unique<VehicleDiscoveryHandlerImpl>(udp_socket_handler)} {}
160 
162 
164  if (handler_impl_->GetStateContext().GetActiveState().GetState() ==
165  VehicleDiscoveryState::kWaitForVehicleAnnouncement) {
166  // Deserialize and Add to task executor
167  logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogWarn(
168  FILE_NAME, __LINE__, __func__, [](std::stringstream &msg) {
169  msg << "Processing of vehicle announcement is not implemented";
170  });
171  } else {
172  // ignore
173  }
174 }
175 
176 } // namespace udp_channel
177 } // namespace channel
178 } // namespace doip_client
Immutable class to store received doip message.
Definition: doip_message.h:21
Class to manage a udp channel as per DoIP protocol.
VehicleDiscoveryHandlerImpl(sockets::UdpSocketHandler &udp_socket_handler)
Constructs an instance of VehicleDiscoveryHandlerImpl.
auto GetSocketHandler() noexcept -> sockets::UdpSocketHandler &
Function to get the socket handler.
auto GetStateContext() noexcept -> VehicleDiscoveryStateContext &
Function to get the Vehicle Discovery State context.
~VehicleDiscoveryHandler()
Destruct an instance of VehicleDiscoveryHandler.
void ProcessVehicleAnnouncementResponse(DoipMessage &doip_payload) noexcept
Function to process received vehicle announcement response.
VehicleDiscoveryHandler(sockets::UdpSocketHandler &udp_socket_handler, DoipUdpChannel &channel)
Constructs an instance of VehicleDiscoveryHandler.
static auto GetDiagClientLogger() noexcept -> DoipClientLogger &
Definition: logger.h:20
Handler class to manage different socket of various client (Udp / Tcp)
void TransitionTo(EnumState state)
Definition: state.h:70
void AddState(EnumState state, std::unique_ptr< State< EnumState >> state_ptr)
Definition: state.h:58
#define FILE_NAME
Definition: file_path.h:14
SocketHandler< boost_support::client::udp::UdpClient > UdpSocketHandler
Type alias of Udp socket handler.
State
Definitions of different connection state.
Definition: tls_client.cpp:56