Diag-Client-Lib
Classes | Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
doip_client::channel::tcp_channel::RoutingActivationHandler Class Referencefinal

Class used as a handler to process routing activation messages. More...

#include <doip_routing_activation_handler.h>

Classes

class  RoutingActivationHandlerImpl
 Class implements routing activation handler. More...
 

Public Types

using TcpMessagePtr = sockets::TcpSocketHandler::TcpMessagePtr
 Type alias for Tcp message pointer. More...
 
using TcpMessage = sockets::TcpSocketHandler::TcpMessage
 Type alias for Tcp message. More...
 

Public Member Functions

 RoutingActivationHandler (sockets::TcpSocketHandler &tcp_socket_handler)
 Constructs an instance of RoutingActivationHandler. More...
 
 ~RoutingActivationHandler ()
 Destruct an instance of RoutingActivationHandler. More...
 
void Start ()
 Function to start the handler. More...
 
void Stop ()
 Function to stop the handler. More...
 
void Reset ()
 Function to reset the handler. More...
 
void ProcessDoIPRoutingActivationResponse (DoipMessage &doip_payload) noexcept
 Function to process received routing activation response. More...
 
auto HandleRoutingActivationRequest (uds_transport::UdsMessageConstPtr routing_activation_request) noexcept -> uds_transport::UdsTransportProtocolMgr::ConnectionResult
 Function to handle sending of routing activation request. More...
 
auto IsRoutingActivated () noexcept -> bool
 Check if routing activation is active for this handler. More...
 

Private Member Functions

auto SendRoutingActivationRequest (uds_transport::UdsMessageConstPtr routing_activation_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult
 Function to send routing activation request. More...
 

Static Private Member Functions

static void CreateDoipGenericHeader (std::vector< std::uint8_t > &doip_header, std::uint16_t payload_type, std::uint32_t payload_len)
 Function to create doip generic header. More...
 

Private Attributes

std::unique_ptr< RoutingActivationHandlerImplhandler_impl_
 Stores the Handler implementation. More...
 

Detailed Description

Class used as a handler to process routing activation messages.

Definition at line 29 of file doip_routing_activation_handler.h.

Member Typedef Documentation

◆ TcpMessage

Type alias for Tcp message.

Definition at line 39 of file doip_routing_activation_handler.h.

◆ TcpMessagePtr

Type alias for Tcp message pointer.

Definition at line 34 of file doip_routing_activation_handler.h.

Constructor & Destructor Documentation

◆ RoutingActivationHandler()

doip_client::channel::tcp_channel::RoutingActivationHandler::RoutingActivationHandler ( sockets::TcpSocketHandler tcp_socket_handler)
explicit

Constructs an instance of RoutingActivationHandler.

Parameters
[in]tcp_socket_handlerThe reference to socket handler

Definition at line 310 of file doip_routing_activation_handler.cpp.

311  : handler_impl_{std::make_unique<RoutingActivationHandlerImpl>(tcp_socket_handler)} {}
std::unique_ptr< RoutingActivationHandlerImpl > handler_impl_
Stores the Handler implementation.

◆ ~RoutingActivationHandler()

doip_client::channel::tcp_channel::RoutingActivationHandler::~RoutingActivationHandler ( )
default

Destruct an instance of RoutingActivationHandler.

Member Function Documentation

◆ CreateDoipGenericHeader()

void doip_client::channel::tcp_channel::RoutingActivationHandler::CreateDoipGenericHeader ( std::vector< std::uint8_t > &  doip_header,
std::uint16_t  payload_type,
std::uint32_t  payload_len 
)
staticprivate

Function to create doip generic header.

Parameters
[in,out]doip_headerThe doip header
[in]payload_typeThe type of payload
[in]payload_lenThe length of payload

Definition at line 443 of file doip_routing_activation_handler.cpp.

444  {
445  doip_header_buffer.emplace_back(kDoip_ProtocolVersion);
446  doip_header_buffer.emplace_back(~(static_cast<std::uint8_t>(kDoip_ProtocolVersion)));
447  doip_header_buffer.emplace_back(static_cast<std::uint8_t>((payload_type & 0xFF00) >> 8));
448  doip_header_buffer.emplace_back(static_cast<std::uint8_t>(payload_type & 0x00FF));
449  doip_header_buffer.emplace_back(static_cast<std::uint8_t>((payload_len & 0xFF000000) >> 24));
450  doip_header_buffer.emplace_back(static_cast<std::uint8_t>((payload_len & 0x00FF0000) >> 16));
451  doip_header_buffer.emplace_back(static_cast<std::uint8_t>((payload_len & 0x0000FF00) >> 8));
452  doip_header_buffer.emplace_back(static_cast<std::uint8_t>(payload_len & 0x000000FF));
453 }
constexpr std::uint8_t kDoip_ProtocolVersion

References doip_client::kDoip_ProtocolVersion.

◆ HandleRoutingActivationRequest()

auto doip_client::channel::tcp_channel::RoutingActivationHandler::HandleRoutingActivationRequest ( uds_transport::UdsMessageConstPtr  routing_activation_request) -> uds_transport::UdsTransportProtocolMgr::ConnectionResult
noexcept

Function to handle sending of routing activation request.

Parameters
[in]routing_activation_requestThe routing activation request
Returns
Transmission result

Definition at line 359 of file doip_routing_activation_handler.cpp.

361  {
364  if (handler_impl_->GetStateContext().GetActiveState().GetState() == RoutingActivationState::kIdle) {
365  if (SendRoutingActivationRequest(std::move(routing_activation_request)) ==
367  // Wait for routing activation response
368  handler_impl_->GetStateContext().TransitionTo(RoutingActivationState::kWaitForRoutingActivationRes);
369  handler_impl_->GetSyncTimer().WaitForTimeout(
370  [this, &result]() {
372  handler_impl_->GetStateContext().TransitionTo(RoutingActivationState::kIdle);
373  logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogError(
374  __FILE__, __LINE__, "", [](std::stringstream &msg) {
375  msg << "RoutingActivation response timeout, no response received in: "
376  << kDoIPRoutingActivationTimeout << " milliseconds";
377  });
378  },
379  [this, &result]() {
380  if (handler_impl_->GetStateContext().GetActiveState().GetState() ==
381  RoutingActivationState::kRoutingActivationSuccessful) {
382  // success
384  logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogInfo(
385  __FILE__, __LINE__, "",
386  [](std::stringstream &msg) { msg << "RoutingActivation successful with remote server"; });
387  } else { // failed
388  handler_impl_->GetStateContext().TransitionTo(RoutingActivationState::kIdle);
389  logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogError(
390  __FILE__, __LINE__, "",
391  [](std::stringstream &msg) { msg << "RoutingActivation failed with remote server"; });
392  }
393  },
394  std::chrono::milliseconds{kDoIPRoutingActivationTimeout});
395  } else {
396  // failed, do nothing
397  handler_impl_->GetStateContext().TransitionTo(RoutingActivationState::kIdle);
398  logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogError(
399  __FILE__, __LINE__, "",
400  [](std::stringstream &msg) { msg << "RoutingActivation Request send failed with remote server"; });
401  }
402  } else {
403  // channel not free
404  logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogVerbose(
405  __FILE__, __LINE__, "", [](std::stringstream &msg) { msg << "RoutingActivation channel not free"; });
406  }
407  return result;
408 }
auto SendRoutingActivationRequest(uds_transport::UdsMessageConstPtr routing_activation_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult
Function to send routing activation request.
static auto GetDiagClientLogger() noexcept -> DoipClientLogger &
Definition: logger.h:20
constexpr std::uint32_t kDoIPRoutingActivationTimeout
The timeout value for a DoIP Routing Activation request.

References doip_client::logger::DoipClientLogger::GetDiagClientLogger(), uds_transport::UdsTransportProtocolMgr::kConnectionFailed, uds_transport::UdsTransportProtocolMgr::kConnectionOk, uds_transport::UdsTransportProtocolMgr::kConnectionTimeout, doip_client::channel::tcp_channel::anonymous_namespace{doip_routing_activation_handler.cpp}::kDoIPRoutingActivationTimeout, and uds_transport::UdsTransportProtocolMgr::kTransmitOk.

Here is the call graph for this function:

◆ IsRoutingActivated()

auto doip_client::channel::tcp_channel::RoutingActivationHandler::IsRoutingActivated ( ) -> bool
noexcept

Check if routing activation is active for this handler.

Returns
True if activated, otherwise False

Definition at line 410 of file doip_routing_activation_handler.cpp.

410  {
411  return (handler_impl_->GetStateContext().GetActiveState().GetState() ==
412  RoutingActivationState::kRoutingActivationSuccessful);
413 }

References handler_impl_.

Referenced by doip_client::channel::tcp_channel::DoipTcpChannelHandler::IsRoutingActivated().

Here is the caller graph for this function:

◆ ProcessDoIPRoutingActivationResponse()

auto doip_client::channel::tcp_channel::RoutingActivationHandler::ProcessDoIPRoutingActivationResponse ( DoipMessage doip_payload)
noexcept

Function to process received routing activation response.

Parameters
[in]doip_payloadThe doip message received

Definition at line 321 of file doip_routing_activation_handler.cpp.

321  {
322  RoutingActivationState final_state{RoutingActivationState::kRoutingActivationFailed};
323  if (handler_impl_->GetStateContext().GetActiveState().GetState() ==
324  RoutingActivationState::kWaitForRoutingActivationRes) {
325  // get the ack code
326  RoutingActivationAckType const rout_act_type{doip_payload.GetPayload()[0u]};
327  switch (rout_act_type.act_type_) {
329  // routing successful
330  final_state = RoutingActivationState::kRoutingActivationSuccessful;
331  logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogInfo(
332  __FILE__, __LINE__, __func__, [&doip_payload](std::stringstream &msg) {
333  msg << "RoutingActivation successfully activated in remote server with logical Address"
334  << " (0x" << std::hex << doip_payload.GetServerAddress() << ")";
335  });
336  } break;
338  // trigger routing activation after sometime, not implemented yet
339  logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogInfo(
340  __FILE__, __LINE__, __func__, [&doip_payload](std::stringstream &msg) {
341  msg << "RoutingActivation is activated, confirmation required in remote server with logical Address"
342  << " (0x" << std::hex << doip_payload.GetServerAddress() << ")";
343  });
344  } break;
345  default:
346  // failure, do nothing
347  logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogWarn(
348  __FILE__, __LINE__, __func__,
349  [&rout_act_type](std::stringstream &msg) { msg << "Routing activation denied due to " << rout_act_type; });
350  break;
351  }
352  handler_impl_->GetStateContext().TransitionTo(final_state);
353  handler_impl_->GetSyncTimer().CancelWait();
354  } else {
355  /* ignore */
356  }
357 }

References doip_client::logger::DoipClientLogger::GetDiagClientLogger(), doip_client::channel::tcp_channel::anonymous_namespace{doip_routing_activation_handler.cpp}::kDoip_RoutingActivation_ResCode_ConfirmtnRequired, and doip_client::channel::tcp_channel::anonymous_namespace{doip_routing_activation_handler.cpp}::kDoip_RoutingActivation_ResCode_RoutingSuccessful.

Here is the call graph for this function:

◆ Reset()

void doip_client::channel::tcp_channel::RoutingActivationHandler::Reset ( )

Function to reset the handler.

This will reset all the internal handler back to default state

Definition at line 319 of file doip_routing_activation_handler.cpp.

319 { handler_impl_->Reset(); }

References handler_impl_.

Referenced by doip_client::channel::tcp_channel::DoipTcpChannelHandler::Reset().

Here is the caller graph for this function:

◆ SendRoutingActivationRequest()

auto doip_client::channel::tcp_channel::RoutingActivationHandler::SendRoutingActivationRequest ( uds_transport::UdsMessageConstPtr  routing_activation_request) -> uds_transport::UdsTransportProtocolMgr::TransmissionResult
privatenoexcept

Function to send routing activation request.

Parameters
[in]routing_activation_requestThe routing activation request
Returns
Transmission result

Definition at line 415 of file doip_routing_activation_handler.cpp.

416  {
419  TcpMessagePtr doip_routing_act_req{std::make_unique<TcpMessage>()};
420  // reserve bytes in vector
421  doip_routing_act_req->GetTxBuffer().reserve(kDoipheadrSize + kDoip_RoutingActivation_ReqMinLen);
422  // create header
423  CreateDoipGenericHeader(doip_routing_act_req->GetTxBuffer(), kDoip_RoutingActivation_ReqType,
425  // Add source address
426  doip_routing_act_req->GetTxBuffer().emplace_back(static_cast<std::uint8_t>((message->GetSa() & 0xFF00) >> 8u));
427  doip_routing_act_req->GetTxBuffer().emplace_back(static_cast<std::uint8_t>(message->GetSa() & 0x00FF));
428  // Add activation type
429  doip_routing_act_req->GetTxBuffer().emplace_back(kDoip_RoutingActivation_ReqActType_Default);
430  // Add reservation byte , default zeroes
431  doip_routing_act_req->GetTxBuffer().emplace_back(0x00);
432  doip_routing_act_req->GetTxBuffer().emplace_back(0x00);
433  doip_routing_act_req->GetTxBuffer().emplace_back(0x00);
434  doip_routing_act_req->GetTxBuffer().emplace_back(0x00);
435 
436  // Initiate transmission
437  if (handler_impl_->GetSocketHandler().Transmit(std::move(doip_routing_act_req))) {
439  }
440  return ret_val;
441 }
sockets::TcpSocketHandler::TcpMessagePtr TcpMessagePtr
Type alias for Tcp message pointer.
static void CreateDoipGenericHeader(std::vector< std::uint8_t > &doip_header, std::uint16_t payload_type, std::uint32_t payload_len)
Function to create doip generic header.
constexpr std::uint8_t kDoip_RoutingActivation_ReqActType_Default
Routing Activation request activation types.
constexpr std::uint8_t kDoipheadrSize

References doip_client::channel::udp_channel::anonymous_namespace{doip_vehicle_identification_handler.cpp}::CreateDoipGenericHeader(), doip_client::channel::tcp_channel::anonymous_namespace{doip_routing_activation_handler.cpp}::kDoip_RoutingActivation_ReqActType_Default, doip_client::channel::tcp_channel::anonymous_namespace{doip_routing_activation_handler.cpp}::kDoip_RoutingActivation_ReqMinLen, doip_client::channel::tcp_channel::anonymous_namespace{doip_routing_activation_handler.cpp}::kDoip_RoutingActivation_ReqType, doip_client::kDoipheadrSize, uds_transport::UdsTransportProtocolMgr::kTransmitFailed, and uds_transport::UdsTransportProtocolMgr::kTransmitOk.

Here is the call graph for this function:

◆ Start()

void doip_client::channel::tcp_channel::RoutingActivationHandler::Start ( )

Function to start the handler.

Definition at line 315 of file doip_routing_activation_handler.cpp.

315 { handler_impl_->Start(); }

References handler_impl_.

Referenced by doip_client::channel::tcp_channel::DoipTcpChannelHandler::Start().

Here is the caller graph for this function:

◆ Stop()

void doip_client::channel::tcp_channel::RoutingActivationHandler::Stop ( )

Function to stop the handler.

This will reset all the internal handler back to default state

Definition at line 317 of file doip_routing_activation_handler.cpp.

317 { handler_impl_->Stop(); }

References handler_impl_.

Referenced by doip_client::channel::tcp_channel::DoipTcpChannelHandler::Stop().

Here is the caller graph for this function:

Member Data Documentation

◆ handler_impl_

std::unique_ptr<RoutingActivationHandlerImpl> doip_client::channel::tcp_channel::RoutingActivationHandler::handler_impl_
private

Stores the Handler implementation.

Definition at line 124 of file doip_routing_activation_handler.h.

Referenced by IsRoutingActivated(), Reset(), Start(), and Stop().


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