From d0cb1704d26223a4cc19544ae8ef39d8621263ae Mon Sep 17 00:00:00 2001 From: Avijit Dey Date: Thu, 8 Aug 2024 16:27:12 +0200 Subject: [PATCH] Linting after changing columnlimit to 100 --- .clang-format | 3 +- .../include/diag-client/diagnostic_client.h | 6 +- .../diagnostic_client_conversation.h | 21 +- .../dcm/config_parser/config_parser_type.cpp | 6 +- .../dcm/config_parser/config_parser_type.h | 3 +- .../uds_transport_protocol_manager.cpp | 8 +- .../dcm/conversation/conversation.h | 31 +- .../dcm/conversation/conversation_manager.cpp | 67 ++-- .../dcm/conversation/conversation_manager.h | 8 +- .../dcm/conversation/dm_conversation.cpp | 153 ++++---- .../dcm/conversation/dm_conversation.h | 19 +- .../dm_conversation_state_impl.cpp | 27 +- .../dcm/conversation/vd_conversation.cpp | 143 +++++--- .../dcm/conversation/vd_conversation.h | 22 +- .../appl/src/diag-client/dcm/dcm_client.cpp | 21 +- .../appl/src/diag-client/dcm/dcm_client.h | 4 +- .../dcm/error_domain/dm_error_domain.cpp | 3 +- .../dcm/error_domain/dm_error_domain.h | 5 +- .../dcm/service/dm_uds_message.cpp | 3 +- .../diag-client/dcm/service/dm_uds_message.h | 3 +- .../diag-client/dcm/service/vd_message.cpp | 3 +- .../src/diag-client/diagnostic_client.cpp | 27 +- .../diagnostic_client_conversation.cpp | 20 +- .../boost-support/client/tcp/tcp_client.h | 3 +- .../boost-support/client/tls/tls_client.h | 7 +- .../boost-support/message/tcp/tcp_message.h | 4 +- .../boost-support/message/udp/udp_message.h | 4 +- .../boost-support/server/tls/tls_acceptor.h | 5 +- .../boost-support/client/tcp/tcp_client.cpp | 42 ++- .../boost-support/client/tls/tls_client.cpp | 41 ++- .../boost-support/client/udp/udp_client.cpp | 7 +- .../connection/tcp/tcp_connection.h | 3 +- .../boost_support_error_domain.cpp | 7 +- .../error_domain/boost_support_error_domain.h | 4 +- .../src/boost-support/parser/json_parser.cpp | 5 +- .../boost-support/server/tcp/tcp_acceptor.cpp | 15 +- .../boost-support/server/tcp/tcp_server.cpp | 7 +- .../boost-support/server/tls/tls_acceptor.cpp | 30 +- .../boost-support/server/tls/tls_server.cpp | 7 +- .../src/boost-support/socket/io_context.cpp | 7 +- .../boost-support/socket/tcp/tcp_socket.cpp | 67 ++-- .../src/boost-support/socket/tcp/tcp_socket.h | 13 +- .../boost-support/socket/tcp/tls_client_.cpp | 92 ++--- .../boost-support/socket/tcp/tls_client_.h | 7 +- .../boost-support/socket/tcp/tls_server_.cpp | 58 +-- .../boost-support/socket/tls/tls_context.cpp | 23 +- .../boost-support/socket/tls/tls_context.h | 6 +- .../boost-support/socket/tls/tls_socket.cpp | 64 ++-- .../src/boost-support/socket/tls/tls_socket.h | 7 +- .../boost-support/socket/udp/udp_socket.cpp | 54 +-- .../doip_diagnostic_message_handler.cpp | 133 ++++--- .../doip_routing_activation_handler.cpp | 73 ++-- .../doip_routing_activation_handler.h | 6 +- .../channel/tcp_channel/doip_tcp_channel.cpp | 17 +- .../channel/tcp_channel/doip_tcp_channel.h | 18 +- .../tcp_channel/doip_tcp_channel_handler.cpp | 25 +- .../tcp_channel/doip_tcp_channel_handler.h | 6 +- .../channel/udp_channel/doip_udp_channel.cpp | 19 +- .../channel/udp_channel/doip_udp_channel.h | 18 +- .../udp_channel/doip_udp_channel_handler.cpp | 29 +- .../udp_channel/doip_udp_channel_handler.h | 13 +- .../doip_vehicle_discovery_handler.cpp | 32 +- .../doip_vehicle_identification_handler.cpp | 91 +++-- .../doip_vehicle_identification_handler.h | 9 +- .../lib/doip-client/common/doip_message.cpp | 17 +- .../lib/doip-client/common/doip_message.h | 4 +- .../connection/connection_manager.cpp | 49 +-- .../connection/connection_manager.h | 12 +- .../doip_transport_protocol_handler.cpp | 6 +- .../doip_transport_protocol_handler.h | 20 +- .../error_domain/doip_error_domain.cpp | 3 +- .../error_domain/doip_error_domain.h | 5 +- .../lib/doip-client/sockets/socket_handler.h | 7 +- .../platform-core/core/include/error_code.h | 3 +- .../lib/platform-core/core/include/result.h | 16 +- .../lib/platform-core/core/include/span.h | 113 +++--- .../lib/platform-core/core/src/error_code.cpp | 16 +- .../uds_transport/connection.h | 9 +- .../uds_transport/conversation_handler.h | 8 +- .../uds_transport/protocol_handler.h | 9 +- .../uds_transport/protocol_mgr.h | 6 +- .../lib/utility-support/utility/logger.h | 38 +- .../lib/utility-support/utility/state.h | 3 +- examples/example_1/src/main.cpp | 32 +- examples/example_1/src/uds_message.h | 7 +- examples/example_2/src/uds_message.h | 7 +- .../common/handler/doip_tcp_handler.cpp | 41 ++- .../common/handler/doip_tcp_handler.h | 9 +- .../common/handler/doip_udp_handler.cpp | 70 ++-- .../common/handler/doip_udp_handler.h | 12 +- test/component/main.h | 4 +- .../test_cases/diagnostic_message_test.cpp | 337 ++++++++++-------- .../test_cases/routing_activation_test.cpp | 73 ++-- test/component/test_cases/tls_test.cpp | 40 ++- .../test_cases/vehicle_discovery_test.cpp | 145 ++++---- test/test_case/diag_request_response_test.cpp | 145 +++++--- test/test_case/tls_test.cpp | 12 +- 97 files changed, 1782 insertions(+), 1180 deletions(-) diff --git a/.clang-format b/.clang-format index 033c6bc7..5c1494bf 100644 --- a/.clang-format +++ b/.clang-format @@ -1,4 +1,3 @@ -# Generated from CLion C/C++ Code Style settings BasedOnStyle: Google Standard: c++17 AccessModifierOffset: -1 @@ -35,7 +34,7 @@ BreakBeforeBinaryOperators: None BreakBeforeTernaryOperators: true BreakConstructorInitializers: BeforeColon BreakInheritanceList: BeforeColon -ColumnLimit: 120 +ColumnLimit: 100 ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 CommentPragmas: '^[^ ]' diff --git a/diag-client-lib/appl/include/diag-client/diagnostic_client.h b/diag-client-lib/appl/include/diag-client/diagnostic_client.h index 451045ae..29b9269e 100644 --- a/diag-client-lib/appl/include/diag-client/diagnostic_client.h +++ b/diag-client-lib/appl/include/diag-client/diagnostic_client.h @@ -84,7 +84,8 @@ class DiagClient final { * @return Result containing available vehicle information response on success, VehicleResponseErrorCode on error * @implements DiagClientLib-VehicleDiscovery */ - Result SendVehicleIdentificationRequest( + Result + SendVehicleIdentificationRequest( diag::client::vehicle_info::VehicleInfoListRequestType vehicle_info_request) noexcept; /** @@ -94,7 +95,8 @@ class DiagClient final { * @return Diag client conversation object * @implements DiagClientLib-MultipleTester-Connection, DiagClientLib-Conversation-Construction */ - conversation::DiagClientConversation GetDiagnosticClientConversation(std::string_view conversation_name) noexcept; + conversation::DiagClientConversation GetDiagnosticClientConversation( + std::string_view conversation_name) noexcept; private: /** diff --git a/diag-client-lib/appl/include/diag-client/diagnostic_client_conversation.h b/diag-client-lib/appl/include/diag-client/diagnostic_client_conversation.h index 9ae3b8fa..705c96d3 100644 --- a/diag-client-lib/appl/include/diag-client/diagnostic_client_conversation.h +++ b/diag-client-lib/appl/include/diag-client/diagnostic_client_conversation.h @@ -34,17 +34,20 @@ class DiagClientConversation final { */ enum class ConnectResult : std::uint8_t { kConnectSuccess = 0U, /**< Successfully connected to the Diagnostic Server */ - kConnectFailed = 1U, /**< Connection failure to the Diagnostic Server, check logs for more failure information */ + kConnectFailed = + 1U, /**< Connection failure to the Diagnostic Server, check logs for more failure information */ kConnectTimeout = 2U, /**< No Connection response received from the Diagnostic Server */ - kTlsRequired = 3U /**< The Diagnostic Server only accepts secured connections, open TLS connection */ + kTlsRequired = + 3U /**< The Diagnostic Server only accepts secured connections, open TLS connection */ }; /** * @brief Definitions of Disconnection results */ enum class DisconnectResult : std::uint8_t { - kDisconnectSuccess = 0U, /**< Successfully disconnected from Diagnostic Server */ - kDisconnectFailed = 1U, /**< Disconnection failure with Diagnostic Server, check logs for more information */ + kDisconnectSuccess = 0U, /**< Successfully disconnected from Diagnostic Server */ + kDisconnectFailed = + 1U, /**< Disconnection failure with Diagnostic Server, check logs for more information */ kAlreadyDisconnected = 2U /**< Not connected to Diagnostic Server */ }; @@ -54,11 +57,11 @@ class DiagClientConversation final { enum class DiagError : std::uint8_t { kDiagGenericFailure = 1U, /**< Generic Diagnostic Error, see logs for more information */ kDiagRequestSendFailed = 2U, /**< Diagnostic request message transmission failure */ - kDiagAckTimeout = 3U, /**< No diagnostic acknowledgement response received within 2 seconds */ - kDiagNegAckReceived = 4U, /**< Diagnostic negative acknowledgement received */ - kDiagResponseTimeout = 5U, /**< No diagnostic response message received within P2/P2Star time */ - kDiagInvalidParameter = 6U, /**< Passed parameter value is not valid */ - kDiagBusyProcessing = 7U /**< Conversation is already busy processing previous request */ + kDiagAckTimeout = 3U, /**< No diagnostic acknowledgement response received within 2 seconds */ + kDiagNegAckReceived = 4U, /**< Diagnostic negative acknowledgement received */ + kDiagResponseTimeout = 5U, /**< No diagnostic response message received within P2/P2Star time */ + kDiagInvalidParameter = 6U, /**< Passed parameter value is not valid */ + kDiagBusyProcessing = 7U /**< Conversation is already busy processing previous request */ }; /** diff --git a/diag-client-lib/appl/src/diag-client/dcm/config_parser/config_parser_type.cpp b/diag-client-lib/appl/src/diag-client/dcm/config_parser/config_parser_type.cpp index dc60b7c5..6db9f4f1 100644 --- a/diag-client-lib/appl/src/diag-client/dcm/config_parser/config_parser_type.cpp +++ b/diag-client-lib/appl/src/diag-client/dcm/config_parser/config_parser_type.cpp @@ -12,7 +12,8 @@ namespace diag { namespace client { namespace config_parser { -diag::client::config_parser::DcmClientConfig ReadDcmClientConfig(boost_support::parser::boost_tree &config_tree) { +diag::client::config_parser::DcmClientConfig ReadDcmClientConfig( + boost_support::parser::boost_tree &config_tree) { diag::client::config_parser::DcmClientConfig config{}; // get the udp info for vehicle discovery config.udp_ip_address = config_tree.get("UdpIpAddress"); @@ -28,7 +29,8 @@ diag::client::config_parser::DcmClientConfig ReadDcmClientConfig(boost_support:: conversation.p2_star_client_max = conversation_ptr.second.get("P2StarClientMax"); conversation.rx_buffer_size = conversation_ptr.second.get("RxBufferSize"); conversation.source_address = conversation_ptr.second.get("SourceAddress"); - conversation.network.tcp_ip_address = conversation_ptr.second.get("Network.TcpIpAddress"); + conversation.network.tcp_ip_address = + conversation_ptr.second.get("Network.TcpIpAddress"); conversation.network.tls_handling = conversation_ptr.second.get("Network.TlsHandling"); config.conversations.emplace_back(conversation); } diff --git a/diag-client-lib/appl/src/diag-client/dcm/config_parser/config_parser_type.h b/diag-client-lib/appl/src/diag-client/dcm/config_parser/config_parser_type.h index 83ecf6ce..5b9727df 100644 --- a/diag-client-lib/appl/src/diag-client/dcm/config_parser/config_parser_type.h +++ b/diag-client-lib/appl/src/diag-client/dcm/config_parser/config_parser_type.h @@ -58,7 +58,8 @@ struct DcmClientConfig { * The reference to config tree containing the configuration * @return The Dcm client configuration */ -diag::client::config_parser::DcmClientConfig ReadDcmClientConfig(boost_support::parser::boost_tree &config_tree); +diag::client::config_parser::DcmClientConfig ReadDcmClientConfig( + boost_support::parser::boost_tree &config_tree); } // namespace config_parser } // namespace client diff --git a/diag-client-lib/appl/src/diag-client/dcm/connection/uds_transport_protocol_manager.cpp b/diag-client-lib/appl/src/diag-client/dcm/connection/uds_transport_protocol_manager.cpp index 0b26c5c5..7b786387 100644 --- a/diag-client-lib/appl/src/diag-client/dcm/connection/uds_transport_protocol_manager.cpp +++ b/diag-client-lib/appl/src/diag-client/dcm/connection/uds_transport_protocol_manager.cpp @@ -16,8 +16,9 @@ namespace uds_transport { //ctor UdsTransportProtocolManager::UdsTransportProtocolManager( /* pass the protocol kind */) - : doip_transport_handler{std::make_unique( - handler_id_count, *this)} {} + : doip_transport_handler{ + std::make_unique( + handler_id_count, *this)} {} // initialize all the transport protocol handler void UdsTransportProtocolManager::Startup() { @@ -37,7 +38,8 @@ void UdsTransportProtocolManager::Shutdown() { doip_transport_handler->Stop(); } -::uds_transport::UdsTransportProtocolHandler& UdsTransportProtocolManager::GetTransportProtocolHandler() { +::uds_transport::UdsTransportProtocolHandler& +UdsTransportProtocolManager::GetTransportProtocolHandler() { return *doip_transport_handler; } } // namespace uds_transport diff --git a/diag-client-lib/appl/src/diag-client/dcm/conversation/conversation.h b/diag-client-lib/appl/src/diag-client/dcm/conversation/conversation.h index 81c559f1..35beef54 100644 --- a/diag-client-lib/appl/src/diag-client/dcm/conversation/conversation.h +++ b/diag-client-lib/appl/src/diag-client/dcm/conversation/conversation.h @@ -86,7 +86,8 @@ class Conversation { * @param[in] connection * The conversation connection object */ - virtual void RegisterConnection(std::unique_ptr<::uds_transport::Connection> connection) noexcept = 0; + virtual void RegisterConnection( + std::unique_ptr<::uds_transport::Connection> connection) noexcept = 0; /** * @brief Function to get the conversation handler from conversation object @@ -104,14 +105,18 @@ class Conversation { * @return ConnectResult * Connection result returned */ - virtual ConnectResult ConnectToDiagServer(std::uint16_t, IpAddress) noexcept { return ConnectResult::kConnectFailed; } + virtual ConnectResult ConnectToDiagServer(std::uint16_t, IpAddress) noexcept { + return ConnectResult::kConnectFailed; + } /** * @brief Function to disconnect from Diagnostic Server * @return DisconnectResult * Disconnection result returned */ - virtual DisconnectResult DisconnectFromDiagServer() noexcept { return DisconnectResult::kDisconnectFailed; } + virtual DisconnectResult DisconnectFromDiagServer() noexcept { + return DisconnectResult::kDisconnectFailed; + } /** * @brief Function to indicate a start of reception of message @@ -138,10 +143,13 @@ class Conversation { * The pair of IndicationResult and a pointer to UdsMessage owned/created by DM core and returned * to the handler to get filled */ - virtual std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, ::uds_transport::UdsMessagePtr> - IndicateMessage(::uds_transport::UdsMessage::Address source_addr, ::uds_transport::UdsMessage::Address target_addr, - ::uds_transport::UdsMessage::TargetAddressType type, ::uds_transport::ChannelID channel_id, - std::size_t size, ::uds_transport::Priority priority, ::uds_transport::ProtocolKind protocol_kind, + virtual std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, + ::uds_transport::UdsMessagePtr> + IndicateMessage(::uds_transport::UdsMessage::Address source_addr, + ::uds_transport::UdsMessage::Address target_addr, + ::uds_transport::UdsMessage::TargetAddressType type, + ::uds_transport::ChannelID channel_id, std::size_t size, + ::uds_transport::Priority priority, ::uds_transport::ProtocolKind protocol_kind, core_type::Span payload_info) noexcept = 0; /** @@ -163,7 +171,8 @@ class Conversation { */ virtual Result SendDiagnosticRequest( uds_message::UdsRequestMessageConstPtr) noexcept { - return Result::FromError(DiagError::kDiagRequestSendFailed); + return Result::FromError( + DiagError::kDiagRequestSendFailed); } /** @@ -175,9 +184,9 @@ class Conversation { virtual core_type::Result SendVehicleIdentificationRequest(vehicle_info::VehicleInfoListRequestType) noexcept { - return core_type::Result< - diag::client::vehicle_info::VehicleInfoMessageResponseUniquePtr, - DiagClient::VehicleInfoResponseError>::FromError(DiagClient::VehicleInfoResponseError::kTransmitFailed); + return core_type::Result:: + FromError(DiagClient::VehicleInfoResponseError::kTransmitFailed); } /** diff --git a/diag-client-lib/appl/src/diag-client/dcm/conversation/conversation_manager.cpp b/diag-client-lib/appl/src/diag-client/dcm/conversation/conversation_manager.cpp index 39dd5938..bcafa676 100644 --- a/diag-client-lib/appl/src/diag-client/dcm/conversation/conversation_manager.cpp +++ b/diag-client-lib/appl/src/diag-client/dcm/conversation/conversation_manager.cpp @@ -40,7 +40,8 @@ void ConversationManager::Startup() noexcept {} void ConversationManager::Shutdown() noexcept { // Loop through available conversation and check if already in shutdown state - for (std::unordered_map::value_type const &conversation: conversation_map_) { + for (std::unordered_map::value_type const &conversation: + conversation_map_) { if (conversation.second.conversation != nullptr) { if (conversation.second.conversation->GetActivityStatus() != conversation::Conversation::ActivityStatusType::kInactive) { @@ -63,45 +64,54 @@ diag::client::conversation::Conversation &ConversationManager::GetDiagnosticClie auto it = conversation_map_.find(std::string{conversation_name}); if (it != conversation_map_.end()) { std::string const conversation_name_in_map{it->first}; - it->second.conversation = std::visit( - core_type::visit::overloaded{ - [this, &conversation_name_in_map](conversation::DMConversationType conversation_type) noexcept { - // Create the conversation - std::unique_ptr conversation{ - std::make_unique(conversation_name_in_map, - conversation_type)}; - // Register the connection - conversation->RegisterConnection(uds_transport_mgr_.GetTransportProtocolHandler().CreateTcpConnection( - conversation->GetConversationHandler(), conversation_type.tcp_address, conversation_type.port_num)); - return conversation; - }, - [this, &conversation_name_in_map](conversation::VDConversationType conversation_type) noexcept { - // Create the conversation - std::unique_ptr conversation{ - std::make_unique(conversation_name_in_map, - conversation_type)}; - // Register the connection - conversation->RegisterConnection(uds_transport_mgr_.GetTransportProtocolHandler().CreateUdpConnection( - conversation->GetConversationHandler(), conversation_type.udp_address, conversation_type.port_num)); - return conversation; - }}, - it->second.conversation_type); + it->second.conversation = + std::visit(core_type::visit::overloaded{ + [this, &conversation_name_in_map]( + conversation::DMConversationType conversation_type) noexcept { + // Create the conversation + std::unique_ptr conversation{ + std::make_unique( + conversation_name_in_map, conversation_type)}; + // Register the connection + conversation->RegisterConnection( + uds_transport_mgr_.GetTransportProtocolHandler().CreateTcpConnection( + conversation->GetConversationHandler(), + conversation_type.tcp_address, conversation_type.port_num)); + return conversation; + }, + [this, &conversation_name_in_map]( + conversation::VDConversationType conversation_type) noexcept { + // Create the conversation + std::unique_ptr conversation{ + std::make_unique( + conversation_name_in_map, conversation_type)}; + // Register the connection + conversation->RegisterConnection( + uds_transport_mgr_.GetTransportProtocolHandler().CreateUdpConnection( + conversation->GetConversationHandler(), + conversation_type.udp_address, conversation_type.port_num)); + return conversation; + }}, + it->second.conversation_type); } else { logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogFatal( __FILE__, __LINE__, __func__, [conversation_name](std::stringstream &msg) { - msg << "Invalid conversation name: '" << conversation_name << "', provide correct name as per config file"; + msg << "Invalid conversation name: '" << conversation_name + << "', provide correct name as per config file"; }); } return *(it->second.conversation); } -void ConversationManager::StoreConversationConfig(diag::client::config_parser::DcmClientConfig &config) noexcept { +void ConversationManager::StoreConversationConfig( + diag::client::config_parser::DcmClientConfig &config) noexcept { { // Create Vehicle discovery config conversation::VDConversationType conversion_identifier{}; conversion_identifier.udp_address = config.udp_ip_address; conversion_identifier.udp_broadcast_address = config.udp_broadcast_address; conversion_identifier.port_num = kRandomPortNumber; // random selection of port number - conversation_map_.emplace(kVdConversationName, ConversationStorage{conversion_identifier, nullptr}); + conversation_map_.emplace(kVdConversationName, + ConversationStorage{conversion_identifier, nullptr}); } { // Create Conversation config @@ -109,7 +119,8 @@ void ConversationManager::StoreConversationConfig(diag::client::config_parser::D conversation::DMConversationType conversion_identifier{}; conversion_identifier.rx_buffer_size = config.conversations[conv_count].rx_buffer_size; conversion_identifier.p2_client_max = config.conversations[conv_count].p2_client_max; - conversion_identifier.p2_star_client_max = config.conversations[conv_count].p2_star_client_max; + conversion_identifier.p2_star_client_max = + config.conversations[conv_count].p2_star_client_max; conversion_identifier.source_address = config.conversations[conv_count].source_address; conversion_identifier.tcp_address = config.conversations[conv_count].network.tcp_ip_address; conversion_identifier.port_num = kRandomPortNumber; // random selection of port number diff --git a/diag-client-lib/appl/src/diag-client/dcm/conversation/conversation_manager.h b/diag-client-lib/appl/src/diag-client/dcm/conversation/conversation_manager.h index 3d76c165..7e584483 100644 --- a/diag-client-lib/appl/src/diag-client/dcm/conversation/conversation_manager.h +++ b/diag-client-lib/appl/src/diag-client/dcm/conversation/conversation_manager.h @@ -35,8 +35,9 @@ class ConversationManager final { * @param[in] uds_transport_mgr * The reference to Uds transport manger */ - ConversationManager(diag::client::config_parser::DcmClientConfig config, - diag::client::uds_transport::UdsTransportProtocolManager &uds_transport_mgr) noexcept; + ConversationManager( + diag::client::config_parser::DcmClientConfig config, + diag::client::uds_transport::UdsTransportProtocolManager &uds_transport_mgr) noexcept; /** * @brief Destructs an instance of ConversationManager @@ -70,7 +71,8 @@ class ConversationManager final { /** * @brief Store conversation type */ - std::variant conversation_type{}; + std::variant + conversation_type{}; /** * @brief Store pointer to conversation object diff --git a/diag-client-lib/appl/src/diag-client/dcm/conversation/dm_conversation.cpp b/diag-client-lib/appl/src/diag-client/dcm/conversation/dm_conversation.cpp index 983cc017..aaed5c65 100644 --- a/diag-client-lib/appl/src/diag-client/dcm/conversation/dm_conversation.cpp +++ b/diag-client-lib/appl/src/diag-client/dcm/conversation/dm_conversation.cpp @@ -75,13 +75,16 @@ class DmConversationHandler final : public ::uds_transport::ConversionHandler { * The pair of IndicationResult and a pointer to UdsMessage owned/created by DM core and returned * to the handler to get filled */ - std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, ::uds_transport::UdsMessagePtr> IndicateMessage( - ::uds_transport::UdsMessage::Address source_addr, ::uds_transport::UdsMessage::Address target_addr, - ::uds_transport::UdsMessage::TargetAddressType type, ::uds_transport::ChannelID channel_id, std::size_t size, - ::uds_transport::Priority priority, ::uds_transport::ProtocolKind protocol_kind, - core_type::Span payload_info) const noexcept override { - return (dm_conversation_.IndicateMessage(source_addr, target_addr, type, channel_id, size, priority, protocol_kind, - payload_info)); + std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, + ::uds_transport::UdsMessagePtr> + IndicateMessage(::uds_transport::UdsMessage::Address source_addr, + ::uds_transport::UdsMessage::Address target_addr, + ::uds_transport::UdsMessage::TargetAddressType type, + ::uds_transport::ChannelID channel_id, std::size_t size, + ::uds_transport::Priority priority, ::uds_transport::ProtocolKind protocol_kind, + core_type::Span payload_info) const noexcept override { + return (dm_conversation_.IndicateMessage(source_addr, target_addr, type, channel_id, size, + priority, protocol_kind, payload_info)); } /** @@ -101,7 +104,8 @@ class DmConversationHandler final : public ::uds_transport::ConversionHandler { DmConversation &dm_conversation_; }; -DmConversation::DmConversation(std::string_view conversion_name, DMConversationType &conversion_identifier) +DmConversation::DmConversation(std::string_view conversion_name, + DMConversationType &conversion_identifier) : Conversation{}, active_session_{SessionControlType::kDefaultSession}, active_security_level_{SecurityLevelType::kLocked}, @@ -111,7 +115,8 @@ DmConversation::DmConversation(std::string_view conversion_name, DMConversationT source_address_{conversion_identifier.source_address}, target_address_{}, conversation_name_{conversion_name}, - dm_conversion_handler_{std::make_unique(conversion_identifier.handler_id, *this)} {} + dm_conversion_handler_{ + std::make_unique(conversion_identifier.handler_id, *this)} {} DmConversation::~DmConversation() = default; @@ -122,12 +127,12 @@ void DmConversation::Startup() noexcept { connection_->Start(); // Change the state to Active activity_status_ = ActivityStatusType::kActive; - logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo(__FILE__, __LINE__, __func__, - [&](std::stringstream &msg) { - msg << "'" << conversation_name_ << "'" - << "-> " - << "Startup completed"; - }); + logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo( + __FILE__, __LINE__, __func__, [&](std::stringstream &msg) { + msg << "'" << conversation_name_ << "'" + << "-> " + << "Startup completed"; + }); } void DmConversation::Shutdown() noexcept { @@ -136,24 +141,25 @@ void DmConversation::Shutdown() noexcept { connection_->Stop(); // Change the state to InActive activity_status_ = ActivityStatusType::kInactive; - logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo(__FILE__, __LINE__, __func__, - [&](std::stringstream &msg) { - msg << "'" << conversation_name_ << "'" - << "-> " - << "Shutdown completed"; - }); + logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo( + __FILE__, __LINE__, __func__, [&](std::stringstream &msg) { + msg << "'" << conversation_name_ << "'" + << "-> " + << "Shutdown completed"; + }); } } -DiagClientConversation::ConnectResult DmConversation::ConnectToDiagServer(std::uint16_t const target_address, - IpAddress const host_ip_addr) noexcept { +DiagClientConversation::ConnectResult DmConversation::ConnectToDiagServer( + std::uint16_t const target_address, IpAddress const host_ip_addr) noexcept { // create an uds message just to get the port number // source address required for Routing Activation uds_transport::ByteVector payload{}; // empty payload // Send Connect request to doip layer - DiagClientConversation::ConnectResult const connection_result{static_cast( - connection_->ConnectToHost(std::make_unique( - source_address_, target_address, host_ip_addr, payload)))}; + DiagClientConversation::ConnectResult const connection_result{ + static_cast( + connection_->ConnectToHost(std::make_unique( + source_address_, target_address, host_ip_addr, payload)))}; remote_address_ = host_ip_addr; target_address_ = target_address; if (connection_result == DiagClientConversation::ConnectResult::kConnectSuccess) { @@ -177,11 +183,13 @@ DiagClientConversation::ConnectResult DmConversation::ConnectToDiagServer(std::u } DiagClientConversation::DisconnectResult DmConversation::DisconnectFromDiagServer() noexcept { - DiagClientConversation::DisconnectResult ret_val{DiagClientConversation::DisconnectResult::kDisconnectFailed}; + DiagClientConversation::DisconnectResult ret_val{ + DiagClientConversation::DisconnectResult::kDisconnectFailed}; // Check if already connected before disconnecting if (connection_->IsConnectToHost()) { // Send disconnect request to doip layer - ret_val = static_cast(connection_->DisconnectFromHost()); + ret_val = + static_cast(connection_->DisconnectFromHost()); if (ret_val == DiagClientConversation::DisconnectResult::kDisconnectSuccess) { logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo( __FILE__, __LINE__, __func__, [this](std::stringstream &msg) { @@ -204,8 +212,8 @@ DiagClientConversation::DisconnectResult DmConversation::DisconnectFromDiagServe return ret_val; } -Result DmConversation::SendDiagnosticRequest( - uds_message::UdsRequestMessageConstPtr message) noexcept { +Result +DmConversation::SendDiagnosticRequest(uds_message::UdsRequestMessageConstPtr message) noexcept { Result result{ Result::FromError( DiagClientConversation::DiagError::kDiagRequestSendFailed)}; @@ -216,7 +224,8 @@ Result Dm uds_transport::UdsTransportProtocolMgr::TransmissionResult const transmission_result{ connection_->Transmit(std::make_unique( source_address_, target_address_, message->GetHostIpAddress(), payload))}; - if (transmission_result == uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitOk) { + if (transmission_result == + uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitOk) { // Diagnostic Request Sent successful logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo( __FILE__, __LINE__, __func__, [&](std::stringstream &msg) { @@ -224,17 +233,20 @@ Result Dm << "-> " << "Diagnostic Request Sent & Positive Ack received"; }); - conversation_state_.GetConversationStateContext().TransitionTo(ConversationState::kDiagWaitForRes); + conversation_state_.GetConversationStateContext().TransitionTo( + ConversationState::kDiagWaitForRes); // Wait P6Max / P2ClientMax sync_timer_.WaitForTimeout( [this, &result]() { result.EmplaceError(DiagClientConversation::DiagError::kDiagResponseTimeout); - conversation_state_.GetConversationStateContext().TransitionTo(ConversationState::kIdle); + conversation_state_.GetConversationStateContext().TransitionTo( + ConversationState::kIdle); logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo( __FILE__, __LINE__, "", [&](std::stringstream &msg) { msg << "'" << conversation_name_ << "'" << "-> " - << "Diagnostic Response P2 Timeout happened after " << p2_client_max_ << " milliseconds"; + << "Diagnostic Response P2 Timeout happened after " << p2_client_max_ + << " milliseconds"; }); }, [this]() { @@ -242,10 +254,12 @@ Result Dm if (conversation_state_.GetConversationStateContext().GetActiveState().GetState() == ConversationState::kDiagRecvdFinalRes) { // pos/neg response received - } else if (conversation_state_.GetConversationStateContext().GetActiveState().GetState() == - ConversationState::kDiagRecvdPendingRes) { + } else if (conversation_state_.GetConversationStateContext() + .GetActiveState() + .GetState() == ConversationState::kDiagRecvdPendingRes) { // first pending received - conversation_state_.GetConversationStateContext().TransitionTo(ConversationState::kDiagStartP2StarTimer); + conversation_state_.GetConversationStateContext().TransitionTo( + ConversationState::kDiagStartP2StarTimer); } }, std::chrono::milliseconds{p2_client_max_}); @@ -256,7 +270,8 @@ Result Dm // Check the active state switch (conversation_state_.GetConversationStateContext().GetActiveState().GetState()) { case ConversationState::kDiagRecvdPendingRes: - conversation_state_.GetConversationStateContext().TransitionTo(ConversationState::kDiagStartP2StarTimer); + conversation_state_.GetConversationStateContext().TransitionTo( + ConversationState::kDiagStartP2StarTimer); break; case ConversationState::kDiagRecvdFinalRes: // do nothing @@ -274,15 +289,18 @@ Result Dm << p2_star_client_max_ << " milliseconds"; }); result.EmplaceError(DiagClientConversation::DiagError::kDiagResponseTimeout); - conversation_state_.GetConversationStateContext().TransitionTo(ConversationState::kIdle); + conversation_state_.GetConversationStateContext().TransitionTo( + ConversationState::kIdle); }, [this]() { // pending or pos/neg response - if (conversation_state_.GetConversationStateContext().GetActiveState().GetState() == - ConversationState::kDiagRecvdFinalRes) { + if (conversation_state_.GetConversationStateContext() + .GetActiveState() + .GetState() == ConversationState::kDiagRecvdFinalRes) { // pos/neg response received - } else if (conversation_state_.GetConversationStateContext().GetActiveState().GetState() == - ConversationState::kDiagRecvdPendingRes) { + } else if (conversation_state_.GetConversationStateContext() + .GetActiveState() + .GetState() == ConversationState::kDiagRecvdPendingRes) { // pending received again conversation_state_.GetConversationStateContext().TransitionTo( ConversationState::kDiagStartP2StarTimer); @@ -292,8 +310,10 @@ Result Dm break; case ConversationState::kDiagSuccess: // change state to idle, form the uds response and return - result.EmplaceValue(std::make_unique(payload_rx_buffer_)); - conversation_state_.GetConversationStateContext().TransitionTo(ConversationState::kIdle); + result.EmplaceValue( + std::make_unique(payload_rx_buffer_)); + conversation_state_.GetConversationStateContext().TransitionTo( + ConversationState::kIdle); break; default: // nothing @@ -306,17 +326,18 @@ Result Dm } } else { result.EmplaceError(DiagClientConversation::DiagError::kDiagInvalidParameter); - logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogWarn(__FILE__, __LINE__, "", - [&](std::stringstream &msg) { - msg << "'" << conversation_name_ << "'" - << "-> " - << "Diagnostic Request message is empty"; - }); + logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogWarn( + __FILE__, __LINE__, "", [&](std::stringstream &msg) { + msg << "'" << conversation_name_ << "'" + << "-> " + << "Diagnostic Request message is empty"; + }); } return result; } -void DmConversation::RegisterConnection(std::unique_ptr connection) noexcept { +void DmConversation::RegisterConnection( + std::unique_ptr connection) noexcept { connection_ = std::move(connection); } @@ -325,12 +346,14 @@ ::uds_transport::ConversionHandler &DmConversation::GetConversationHandler() noe } std::pair -DmConversation::IndicateMessage(uds_transport::UdsMessage::Address, uds_transport::UdsMessage::Address, - uds_transport::UdsMessage::TargetAddressType, uds_transport::ChannelID, - std::size_t size, uds_transport::Priority, uds_transport::ProtocolKind, +DmConversation::IndicateMessage(uds_transport::UdsMessage::Address, + uds_transport::UdsMessage::Address, + uds_transport::UdsMessage::TargetAddressType, + uds_transport::ChannelID, std::size_t size, uds_transport::Priority, + uds_transport::ProtocolKind, core_type::Span payload_info) noexcept { - std::pair ret_val{ - uds_transport::UdsTransportProtocolMgr::IndicationResult::kIndicationNOk, nullptr}; + std::pair + ret_val{uds_transport::UdsTransportProtocolMgr::IndicationResult::kIndicationNOk, nullptr}; // Verify the payload received :- if (!payload_info.empty()) { // Check for size, else kIndicationOverflow @@ -344,8 +367,10 @@ DmConversation::IndicateMessage(uds_transport::UdsMessage::Address, uds_transpor << "-> " << "Diagnostic pending response received in Conversation"; }); - ret_val.first = uds_transport::UdsTransportProtocolMgr::IndicationResult::kIndicationPending; - conversation_state_.GetConversationStateContext().TransitionTo(ConversationState::kDiagRecvdPendingRes); + ret_val.first = + uds_transport::UdsTransportProtocolMgr::IndicationResult::kIndicationPending; + conversation_state_.GetConversationStateContext().TransitionTo( + ConversationState::kDiagRecvdPendingRes); } else { logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogDebug( __FILE__, __LINE__, "", [this](std::stringstream &msg) { @@ -357,9 +382,10 @@ DmConversation::IndicateMessage(uds_transport::UdsMessage::Address, uds_transpor // resize the global rx buffer payload_rx_buffer_.resize(size); ret_val.first = uds_transport::UdsTransportProtocolMgr::IndicationResult::kIndicationOk; - ret_val.second = std::make_unique(source_address_, target_address_, "", - payload_rx_buffer_); - conversation_state_.GetConversationStateContext().TransitionTo(ConversationState::kDiagRecvdFinalRes); + ret_val.second = std::make_unique( + source_address_, target_address_, "", payload_rx_buffer_); + conversation_state_.GetConversationStateContext().TransitionTo( + ConversationState::kDiagRecvdFinalRes); } sync_timer_.CancelWait(); } else { @@ -390,7 +416,8 @@ void DmConversation::HandleMessage(uds_transport::UdsMessagePtr message) noexcep DiagClientConversation::DiagError DmConversation::ConvertResponseType( uds_transport::UdsTransportProtocolMgr::TransmissionResult result_type) { - DiagClientConversation::DiagError ret_result{DiagClientConversation::DiagError::kDiagGenericFailure}; + DiagClientConversation::DiagError ret_result{ + DiagClientConversation::DiagError::kDiagGenericFailure}; switch (result_type) { case uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitFailed: ret_result = DiagClientConversation::DiagError::kDiagRequestSendFailed; diff --git a/diag-client-lib/appl/src/diag-client/dcm/conversation/dm_conversation.h b/diag-client-lib/appl/src/diag-client/dcm/conversation/dm_conversation.h index 590f909e..2b47fa74 100644 --- a/diag-client-lib/appl/src/diag-client/dcm/conversation/dm_conversation.h +++ b/diag-client-lib/appl/src/diag-client/dcm/conversation/dm_conversation.h @@ -78,7 +78,8 @@ class DmConversation final : public Conversation { * @param[in] connection * The conversation connection object */ - void RegisterConnection(std::unique_ptr<::uds_transport::Connection> connection) noexcept override; + void RegisterConnection( + std::unique_ptr<::uds_transport::Connection> connection) noexcept override; /** * @brief Function to get the conversation handler from conversation object @@ -96,7 +97,8 @@ class DmConversation final : public Conversation { * @return ConnectResult * Connection result returned */ - ConnectResult ConnectToDiagServer(std::uint16_t target_address, IpAddress host_ip_addr) noexcept override; + ConnectResult ConnectToDiagServer(std::uint16_t target_address, + IpAddress host_ip_addr) noexcept override; /** * @brief Function to disconnect from Diagnostic Server @@ -130,11 +132,14 @@ class DmConversation final : public Conversation { * The pair of IndicationResult and a pointer to UdsMessage owned/created by DM core and returned * to the handler to get filled */ - std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, ::uds_transport::UdsMessagePtr> IndicateMessage( - ::uds_transport::UdsMessage::Address source_addr, ::uds_transport::UdsMessage::Address target_addr, - ::uds_transport::UdsMessage::TargetAddressType type, ::uds_transport::ChannelID channel_id, std::size_t size, - ::uds_transport::Priority priority, ::uds_transport::ProtocolKind protocol_kind, - core_type::Span payload_info) noexcept override; + std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, + ::uds_transport::UdsMessagePtr> + IndicateMessage(::uds_transport::UdsMessage::Address source_addr, + ::uds_transport::UdsMessage::Address target_addr, + ::uds_transport::UdsMessage::TargetAddressType type, + ::uds_transport::ChannelID channel_id, std::size_t size, + ::uds_transport::Priority priority, ::uds_transport::ProtocolKind protocol_kind, + core_type::Span payload_info) noexcept override; /** * @brief Function to Hands over a valid received Uds message diff --git a/diag-client-lib/appl/src/diag-client/dcm/conversation/dm_conversation_state_impl.cpp b/diag-client-lib/appl/src/diag-client/dcm/conversation/dm_conversation_state_impl.cpp index c086033e..f0268499 100644 --- a/diag-client-lib/appl/src/diag-client/dcm/conversation/dm_conversation_state_impl.cpp +++ b/diag-client-lib/appl/src/diag-client/dcm/conversation/dm_conversation_state_impl.cpp @@ -14,10 +14,12 @@ ConversationStateImpl::ConversationStateImpl() : conversation_state_{std::make_unique>()} { // create and add state // kIdle - GetConversationStateContext().AddState(ConversationState::kIdle, std::make_unique(ConversationState::kIdle)); + GetConversationStateContext().AddState(ConversationState::kIdle, + std::make_unique(ConversationState::kIdle)); // kDiagWaitForRes - GetConversationStateContext().AddState(ConversationState::kDiagWaitForRes, - std::make_unique(ConversationState::kDiagWaitForRes)); + GetConversationStateContext().AddState( + ConversationState::kDiagWaitForRes, + std::make_unique(ConversationState::kDiagWaitForRes)); // kDiagStartP2StarTimer GetConversationStateContext().AddState( ConversationState::kDiagStartP2StarTimer, @@ -27,16 +29,19 @@ ConversationStateImpl::ConversationStateImpl() ConversationState::kDiagRecvdPendingRes, std::make_unique(ConversationState::kDiagRecvdPendingRes)); // kDiagRecvdFinalRes - GetConversationStateContext().AddState(ConversationState::kDiagRecvdFinalRes, - std::make_unique(ConversationState::kDiagRecvdFinalRes)); + GetConversationStateContext().AddState( + ConversationState::kDiagRecvdFinalRes, + std::make_unique(ConversationState::kDiagRecvdFinalRes)); // kDiagSuccess - GetConversationStateContext().AddState(ConversationState::kDiagSuccess, - std::make_unique(ConversationState::kDiagSuccess)); + GetConversationStateContext().AddState( + ConversationState::kDiagSuccess, + std::make_unique(ConversationState::kDiagSuccess)); // transit to idle state GetConversationStateContext().TransitionTo(ConversationState::kIdle); } -auto ConversationStateImpl::GetConversationStateContext() noexcept -> StateContext& { +auto ConversationStateImpl::GetConversationStateContext() noexcept + -> StateContext& { return *conversation_state_; } @@ -56,7 +61,8 @@ void kDiagWaitForRes::Stop() {} void kDiagWaitForRes::HandleMessage() {} -kDiagStartP2StarTimer::kDiagStartP2StarTimer(ConversationState state) : State(state) {} +kDiagStartP2StarTimer::kDiagStartP2StarTimer(ConversationState state) + : State(state) {} void kDiagStartP2StarTimer::Start() {} @@ -64,7 +70,8 @@ void kDiagStartP2StarTimer::Stop() {} void kDiagStartP2StarTimer::HandleMessage() {} -kDiagRecvdPendingRes::kDiagRecvdPendingRes(ConversationState state) : State(state) {} +kDiagRecvdPendingRes::kDiagRecvdPendingRes(ConversationState state) + : State(state) {} void kDiagRecvdPendingRes::Start() {} diff --git a/diag-client-lib/appl/src/diag-client/dcm/conversation/vd_conversation.cpp b/diag-client-lib/appl/src/diag-client/dcm/conversation/vd_conversation.cpp index 4273bb6e..c0a1e28a 100644 --- a/diag-client-lib/appl/src/diag-client/dcm/conversation/vd_conversation.cpp +++ b/diag-client-lib/appl/src/diag-client/dcm/conversation/vd_conversation.cpp @@ -24,7 +24,8 @@ std::string ConvertToHexString(std::uint8_t char_start, std::uint8_t char_count, std::string hex_string{}; std::uint8_t total_char_count{static_cast(char_start + char_count)}; - for (std::uint8_t char_start_count = char_start; char_start_count < total_char_count; char_start_count++) { + for (std::uint8_t char_start_count = char_start; char_start_count < total_char_count; + char_start_count++) { std::stringstream vehicle_info_data_eid{}; int payload_byte{input_buffer[char_start_count]}; if ((payload_byte <= 15)) { @@ -43,7 +44,8 @@ std::string ConvertToAsciiString(std::uint8_t char_start, std::uint8_t char_coun std::string ascii_string{}; std::uint8_t total_char_count{static_cast(char_start + char_count)}; - for (std::uint8_t char_start_count = char_start; char_start_count < total_char_count; char_start_count++) { + for (std::uint8_t char_start_count = char_start; char_start_count < total_char_count; + char_start_count++) { std::stringstream vehicle_info_data_vin{}; vehicle_info_data_vin << input_buffer[char_start_count]; ascii_string.append(vehicle_info_data_vin.str()); @@ -51,11 +53,12 @@ std::string ConvertToAsciiString(std::uint8_t char_start, std::uint8_t char_coun return ascii_string; } -void SerializeEIDGIDFromString(std::string &input_string, std::vector &output_buffer, std::uint8_t total_size, - std::uint8_t substring_range) { +void SerializeEIDGIDFromString(std::string &input_string, std::vector &output_buffer, + std::uint8_t total_size, std::uint8_t substring_range) { for (auto char_count = 0U; char_count < total_size; char_count += substring_range) { - std::string input_string_new{input_string.substr(char_count, static_cast(substring_range))}; + std::string input_string_new{ + input_string.substr(char_count, static_cast(substring_range))}; std::stringstream input_string_stream{input_string_new}; int get_byte; input_string_stream >> std::hex >> get_byte; @@ -63,11 +66,12 @@ void SerializeEIDGIDFromString(std::string &input_string, std::vector & } } -void SerializeVINFromString(std::string &input_string, std::vector &output_buffer, std::uint8_t total_size, - std::uint8_t substring_range) { +void SerializeVINFromString(std::string &input_string, std::vector &output_buffer, + std::uint8_t total_size, std::uint8_t substring_range) { for (auto char_count = 0U; char_count < total_size; char_count += substring_range) { - std::string input_string_new{input_string.substr(char_count, static_cast(substring_range))}; + std::string input_string_new{ + input_string.substr(char_count, static_cast(substring_range))}; std::stringstream input_string_stream{input_string_new}; int get_byte{input_string_stream.get()}; output_buffer.emplace_back(static_cast(get_byte)); @@ -80,7 +84,8 @@ class VehicleInfoMessageImpl final : public vehicle_info::VehicleInfoMessage { explicit VehicleInfoMessageImpl( std::map &vehicle_info_collection) : vehicle_info_messages_{} { - for (std::pair vehicle_info: vehicle_info_collection) { + for (std::pair vehicle_info: + vehicle_info_collection) { Push(vehicle_info.second); } } @@ -158,13 +163,16 @@ class VdConversationHandler final : public ::uds_transport::ConversionHandler { * The pair of IndicationResult and a pointer to UdsMessage owned/created by DM core and returned * to the handler to get filled */ - std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, ::uds_transport::UdsMessagePtr> IndicateMessage( - ::uds_transport::UdsMessage::Address source_addr, ::uds_transport::UdsMessage::Address target_addr, - ::uds_transport::UdsMessage::TargetAddressType type, ::uds_transport::ChannelID channel_id, std::size_t size, - ::uds_transport::Priority priority, ::uds_transport::ProtocolKind protocol_kind, - core_type::Span payloadInfo) const noexcept override { - return (vd_conversation_.IndicateMessage(source_addr, target_addr, type, channel_id, size, priority, protocol_kind, - payloadInfo)); + std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, + ::uds_transport::UdsMessagePtr> + IndicateMessage(::uds_transport::UdsMessage::Address source_addr, + ::uds_transport::UdsMessage::Address target_addr, + ::uds_transport::UdsMessage::TargetAddressType type, + ::uds_transport::ChannelID channel_id, std::size_t size, + ::uds_transport::Priority priority, ::uds_transport::ProtocolKind protocol_kind, + core_type::Span payloadInfo) const noexcept override { + return (vd_conversation_.IndicateMessage(source_addr, target_addr, type, channel_id, size, + priority, protocol_kind, payloadInfo)); } /** @@ -185,8 +193,10 @@ class VdConversationHandler final : public ::uds_transport::ConversionHandler { }; // Conversation class -VdConversation::VdConversation(std::string_view conversion_name, VDConversationType &conversion_identifier) - : vd_conversion_handler_{std::make_unique(conversion_identifier.handler_id, *this)}, +VdConversation::VdConversation(std::string_view conversion_name, + VDConversationType &conversion_identifier) + : vd_conversion_handler_{std::make_unique( + conversion_identifier.handler_id, *this)}, conversation_name_{conversion_name}, broadcast_address_{conversion_identifier.udp_broadcast_address}, connection_ptr_{}, @@ -202,12 +212,12 @@ void VdConversation::Startup() noexcept { connection_ptr_->Start(); // Change the state to Active activity_status_ = ActivityStatusType::kActive; - logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo(__FILE__, __LINE__, __func__, - [&](std::stringstream &msg) { - msg << "'" << conversation_name_ << "'" - << "-> " - << "Startup completed"; - }); + logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo( + __FILE__, __LINE__, __func__, [&](std::stringstream &msg) { + msg << "'" << conversation_name_ << "'" + << "-> " + << "Startup completed"; + }); } void VdConversation::Shutdown() noexcept { @@ -216,38 +226,42 @@ void VdConversation::Shutdown() noexcept { connection_ptr_->Stop(); // Change the state to InActive activity_status_ = ActivityStatusType::kInactive; - logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo(__FILE__, __LINE__, __func__, - [&](std::stringstream &msg) { - msg << "'" << conversation_name_ << "'" - << "-> " - << "Shutdown completed"; - }); + logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo( + __FILE__, __LINE__, __func__, [&](std::stringstream &msg) { + msg << "'" << conversation_name_ << "'" + << "-> " + << "Shutdown completed"; + }); } } -void VdConversation::RegisterConnection(std::unique_ptr connection) noexcept { +void VdConversation::RegisterConnection( + std::unique_ptr connection) noexcept { connection_ptr_ = std::move(connection); } -core_type::Result +core_type::Result VdConversation::SendVehicleIdentificationRequest( vehicle_info::VehicleInfoListRequestType vehicle_info_request) noexcept { using VehicleIdentificationResponseResult = core_type::Result; - VehicleIdentificationResponseResult result{ - VehicleIdentificationResponseResult::FromError(DiagClient::VehicleInfoResponseError::kTransmitFailed)}; + VehicleIdentificationResponseResult result{VehicleIdentificationResponseResult::FromError( + DiagClient::VehicleInfoResponseError::kTransmitFailed)}; // Deserialize first , Todo: Add optional when deserialize fails std::pair vehicle_info_request_deserialized_value{ DeserializeVehicleInfoRequest(vehicle_info_request)}; - if (VerifyVehicleInfoRequest(vehicle_info_request_deserialized_value.first, - static_cast(vehicle_info_request_deserialized_value.second.size()))) { + if (VerifyVehicleInfoRequest( + vehicle_info_request_deserialized_value.first, + static_cast(vehicle_info_request_deserialized_value.second.size()))) { if (connection_ptr_->Transmit(std::make_unique( - vehicle_info_request_deserialized_value.first, vehicle_info_request_deserialized_value.second, - broadcast_address_)) != uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitFailed) { + vehicle_info_request_deserialized_value.first, + vehicle_info_request_deserialized_value.second, broadcast_address_)) != + uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitFailed) { // Check if any response received if (vehicle_info_collection_.empty()) { // no response received @@ -271,17 +285,22 @@ VdConversation::SendVehicleIdentificationRequest( return result; } -vehicle_info::VehicleInfoMessageResponseUniquePtr VdConversation::GetDiagnosticServerList() { return nullptr; } +vehicle_info::VehicleInfoMessageResponseUniquePtr VdConversation::GetDiagnosticServerList() { + return nullptr; +} -std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, ::uds_transport::UdsMessagePtr> +std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, + ::uds_transport::UdsMessagePtr> VdConversation::IndicateMessage(uds_transport::UdsMessage::Address /* source_addr */, uds_transport::UdsMessage::Address /* target_addr */, - uds_transport::UdsMessage::TargetAddressType /* type */, uds_transport::ChannelID, - std::size_t size, uds_transport::Priority, uds_transport::ProtocolKind, + uds_transport::UdsMessage::TargetAddressType /* type */, + uds_transport::ChannelID, std::size_t size, uds_transport::Priority, + uds_transport::ProtocolKind, core_type::Span payload_info) noexcept { - using IndicationResult = - std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, ::uds_transport::UdsMessagePtr>; - IndicationResult ret_val{::uds_transport::UdsTransportProtocolMgr::IndicationResult::kIndicationNOk, nullptr}; + using IndicationResult = std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, + ::uds_transport::UdsMessagePtr>; + IndicationResult ret_val{ + ::uds_transport::UdsTransportProtocolMgr::IndicationResult::kIndicationNOk, nullptr}; if (!payload_info.empty()) { ret_val.first = ::uds_transport::UdsTransportProtocolMgr::IndicationResult::kIndicationOk; ret_val.second = std::make_unique(); @@ -336,17 +355,19 @@ VdConversation::DeserializeVehicleInfoResponse(uds_transport::UdsMessagePtr mess std::string const vehicle_info_data_gid{ ConvertToHexString(start_index_gid, total_eid_gid_length, message->GetPayload())}; - LogicalAddress const logical_address{ - (static_cast(((message->GetPayload()[17U] & 0xFF) << 8) | (message->GetPayload()[18U] & 0xFF)))}; + LogicalAddress const logical_address{(static_cast( + ((message->GetPayload()[17U] & 0xFF) << 8) | (message->GetPayload()[18U] & 0xFF)))}; // Create the structure out of the extracted string - VehicleAddrInfoResponseStruct const vehicle_addr_info{std::string{message->GetHostIpAddress()}, // remote ip address - logical_address, // logical address - vehicle_info_data_vin, // vin - vehicle_info_data_eid, // eid - vehicle_info_data_gid}; // gid - - return std::pair{logical_address, vehicle_addr_info}; + VehicleAddrInfoResponseStruct const vehicle_addr_info{ + std::string{message->GetHostIpAddress()}, // remote ip address + logical_address, // logical address + vehicle_info_data_vin, // vin + vehicle_info_data_eid, // eid + vehicle_info_data_gid}; // gid + + return std::pair{logical_address, + vehicle_addr_info}; } ::uds_transport::ConversionHandler &VdConversation::GetConversationHandler() noexcept { @@ -354,7 +375,8 @@ ::uds_transport::ConversionHandler &VdConversation::GetConversationHandler() noe } std::pair -VdConversation::DeserializeVehicleInfoRequest(vehicle_info::VehicleInfoListRequestType &vehicle_info_request) { +VdConversation::DeserializeVehicleInfoRequest( + vehicle_info::VehicleInfoListRequestType &vehicle_info_request) { std::pair ret_val{}; ret_val.first = vehicle_info_request.preselection_mode; @@ -362,14 +384,17 @@ VdConversation::DeserializeVehicleInfoRequest(vehicle_info::VehicleInfoListReque if (ret_val.first == 1U) { // 1U : DoIP Entities with given VIN SerializeVINFromString(vehicle_info_request.preselection_value, ret_val.second, - static_cast(vehicle_info_request.preselection_value.length()), 1U); + static_cast(vehicle_info_request.preselection_value.length()), + 1U); } else if (ret_val.first == 2U) { // 2U : DoIP Entities with given EID vehicle_info_request.preselection_value.erase( - remove(vehicle_info_request.preselection_value.begin(), vehicle_info_request.preselection_value.end(), ':'), + remove(vehicle_info_request.preselection_value.begin(), + vehicle_info_request.preselection_value.end(), ':'), vehicle_info_request.preselection_value.end()); - SerializeEIDGIDFromString(vehicle_info_request.preselection_value, ret_val.second, - static_cast(vehicle_info_request.preselection_value.length()), 2U); + SerializeEIDGIDFromString( + vehicle_info_request.preselection_value, ret_val.second, + static_cast(vehicle_info_request.preselection_value.length()), 2U); } else { // log failure } diff --git a/diag-client-lib/appl/src/diag-client/dcm/conversation/vd_conversation.h b/diag-client-lib/appl/src/diag-client/dcm/conversation/vd_conversation.h index d12cd46b..a65c850d 100644 --- a/diag-client-lib/appl/src/diag-client/dcm/conversation/vd_conversation.h +++ b/diag-client-lib/appl/src/diag-client/dcm/conversation/vd_conversation.h @@ -94,7 +94,8 @@ class VdConversation final : public Conversation { * @param[in] connection * The conversation connection object */ - void RegisterConnection(std::unique_ptr<::uds_transport::Connection> connection) noexcept override; + void RegisterConnection( + std::unique_ptr<::uds_transport::Connection> connection) noexcept override; /** * @brief Function to get the conversation handler from conversation object @@ -128,11 +129,14 @@ class VdConversation final : public Conversation { * The pair of IndicationResult and a pointer to UdsMessage owned/created by DM core and returned * to the handler to get filled */ - std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, ::uds_transport::UdsMessagePtr> IndicateMessage( - ::uds_transport::UdsMessage::Address source_addr, ::uds_transport::UdsMessage::Address target_addr, - ::uds_transport::UdsMessage::TargetAddressType type, ::uds_transport::ChannelID channel_id, std::size_t size, - ::uds_transport::Priority priority, ::uds_transport::ProtocolKind protocol_kind, - core_type::Span payloadInfo) noexcept override; + std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, + ::uds_transport::UdsMessagePtr> + IndicateMessage(::uds_transport::UdsMessage::Address source_addr, + ::uds_transport::UdsMessage::Address target_addr, + ::uds_transport::UdsMessage::TargetAddressType type, + ::uds_transport::ChannelID channel_id, std::size_t size, + ::uds_transport::Priority priority, ::uds_transport::ProtocolKind protocol_kind, + core_type::Span payloadInfo) noexcept override; /** * @brief Function to Hands over a valid received Uds message @@ -150,7 +154,8 @@ class VdConversation final : public Conversation { */ core_type::Result - SendVehicleIdentificationRequest(vehicle_info::VehicleInfoListRequestType vehicle_info_request) noexcept override; + SendVehicleIdentificationRequest( + vehicle_info::VehicleInfoListRequestType vehicle_info_request) noexcept override; /** * @brief Function to get the list of available diagnostic server @@ -167,7 +172,8 @@ class VdConversation final : public Conversation { * The length of preselection value * @return True on success, else false */ - bool VerifyVehicleInfoRequest(PreselectionMode preselection_mode, std::uint8_t preselection_value_length); + bool VerifyVehicleInfoRequest(PreselectionMode preselection_mode, + std::uint8_t preselection_value_length); /** * @brief Function to deserialize the received Vehicle Identification Response/ Announcement diff --git a/diag-client-lib/appl/src/diag-client/dcm/dcm_client.cpp b/diag-client-lib/appl/src/diag-client/dcm/dcm_client.cpp index f72f59ec..4b66d0a3 100644 --- a/diag-client-lib/appl/src/diag-client/dcm/dcm_client.cpp +++ b/diag-client-lib/appl/src/diag-client/dcm/dcm_client.cpp @@ -20,7 +20,8 @@ namespace { /** * @brief Store the conversation manager reference optionally */ -std::optional> conversation_manager_ref{}; +std::optional> + conversation_manager_ref{}; /** * @brief String representing of vehicle discovery conversation name @@ -32,7 +33,8 @@ DCMClient::DCMClient(config_parser::DcmClientConfig dcm_client_config) : DiagnosticManager{}, uds_transport_protocol_mgr_{std::make_unique()}, conversation_mgr_{std::move(dcm_client_config), *uds_transport_protocol_mgr_}, - vehicle_discovery_conversation_{conversation_mgr_.GetDiagnosticClientConversation(VehicleDiscoveryConversation)} { + vehicle_discovery_conversation_{ + conversation_mgr_.GetDiagnosticClientConversation(VehicleDiscoveryConversation)} { // make the conversation manager reference available externally conversation_manager_ref.emplace(conversation_mgr_); } @@ -48,14 +50,16 @@ void DCMClient::Initialize() noexcept { vehicle_discovery_conversation_.Startup(); logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo( - __FILE__, __LINE__, __func__, [](std::stringstream &msg) { msg << "Dcm Client Initialized"; }); + __FILE__, __LINE__, __func__, + [](std::stringstream &msg) { msg << "Dcm Client Initialized"; }); } void DCMClient::Run() noexcept { // run udsTransportProtocol layer uds_transport_protocol_mgr_->Run(); logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo( - __FILE__, __LINE__, __func__, [](std::stringstream &msg) { msg << "Dcm Client is ready to serve"; }); + __FILE__, __LINE__, __func__, + [](std::stringstream &msg) { msg << "Dcm Client is ready to serve"; }); } void DCMClient::Shutdown() noexcept { @@ -67,7 +71,8 @@ void DCMClient::Shutdown() noexcept { conversation_mgr_.Shutdown(); logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo( - __FILE__, __LINE__, __func__, [](std::stringstream &msg) { msg << "Dcm Client Shutdown completed"; }); + __FILE__, __LINE__, __func__, + [](std::stringstream &msg) { msg << "Dcm Client Shutdown completed"; }); } conversation::DiagClientConversation DCMClient::GetDiagnosticClientConversation( @@ -75,7 +80,8 @@ conversation::DiagClientConversation DCMClient::GetDiagnosticClientConversation( return conversation::DiagClientConversation{conversation_name}; } -core_type::Result +core_type::Result DCMClient::SendVehicleIdentificationRequest( diag::client::vehicle_info::VehicleInfoListRequestType vehicle_info_request) noexcept { return vehicle_discovery_conversation_.SendVehicleIdentificationRequest(vehicle_info_request); @@ -84,7 +90,8 @@ DCMClient::SendVehicleIdentificationRequest( auto GetConversationManager() noexcept -> conversation_manager::ConversationManager & { if (!conversation_manager_ref.has_value()) { logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogFatal( - __FILE__, __LINE__, "", [](std::stringstream &msg) { msg << "DiagClient is not Initialized"; }); + __FILE__, __LINE__, "", + [](std::stringstream &msg) { msg << "DiagClient is not Initialized"; }); } return conversation_manager_ref.value(); } diff --git a/diag-client-lib/appl/src/diag-client/dcm/dcm_client.h b/diag-client-lib/appl/src/diag-client/dcm/dcm_client.h index 76de2a74..b127ad44 100644 --- a/diag-client-lib/appl/src/diag-client/dcm/dcm_client.h +++ b/diag-client-lib/appl/src/diag-client/dcm/dcm_client.h @@ -81,8 +81,8 @@ class DCMClient final : public diag::client::common::DiagnosticManager { */ core_type::Result - SendVehicleIdentificationRequest( - diag::client::vehicle_info::VehicleInfoListRequestType vehicle_info_request) noexcept override; + SendVehicleIdentificationRequest(diag::client::vehicle_info::VehicleInfoListRequestType + vehicle_info_request) noexcept override; private: /** diff --git a/diag-client-lib/appl/src/diag-client/dcm/error_domain/dm_error_domain.cpp b/diag-client-lib/appl/src/diag-client/dcm/error_domain/dm_error_domain.cpp index c2945ddd..df793013 100644 --- a/diag-client-lib/appl/src/diag-client/dcm/error_domain/dm_error_domain.cpp +++ b/diag-client-lib/appl/src/diag-client/dcm/error_domain/dm_error_domain.cpp @@ -53,7 +53,8 @@ const char* DmErrorDomain::Message(core_type::ErrorDomain::CodeType error_code) return message_.c_str(); } -core_type::ErrorCode MakeErrorCode(DmErrorErrc, core_type::ErrorDomain::SupportDataType data) noexcept { +core_type::ErrorCode MakeErrorCode(DmErrorErrc, + core_type::ErrorDomain::SupportDataType data) noexcept { return core_type::ErrorCode{data, dm_error_domain}; } diff --git a/diag-client-lib/appl/src/diag-client/dcm/error_domain/dm_error_domain.h b/diag-client-lib/appl/src/diag-client/dcm/error_domain/dm_error_domain.h index c8f43e46..fe5ad457 100644 --- a/diag-client-lib/appl/src/diag-client/dcm/error_domain/dm_error_domain.h +++ b/diag-client-lib/appl/src/diag-client/dcm/error_domain/dm_error_domain.h @@ -82,8 +82,9 @@ class DmErrorDomain final : public core_type::ErrorDomain { * @return ErrorCode * A new ErrorCode instance */ -core_type::ErrorCode MakeErrorCode(DmErrorErrc code, core_type::ErrorDomain::SupportDataType data = - core_type::ErrorDomain::SupportDataType{}) noexcept; +core_type::ErrorCode MakeErrorCode(DmErrorErrc code, + core_type::ErrorDomain::SupportDataType data = + core_type::ErrorDomain::SupportDataType{}) noexcept; } // namespace error_domain } // namespace client diff --git a/diag-client-lib/appl/src/diag-client/dcm/service/dm_uds_message.cpp b/diag-client-lib/appl/src/diag-client/dcm/service/dm_uds_message.cpp index 0412b79e..db15d80d 100644 --- a/diag-client-lib/appl/src/diag-client/dcm/service/dm_uds_message.cpp +++ b/diag-client-lib/appl/src/diag-client/dcm/service/dm_uds_message.cpp @@ -10,7 +10,8 @@ namespace diag { namespace client { namespace uds_message { -DmUdsMessage::DmUdsMessage(Address sa, Address ta, IpAddress host_ip_address, uds_transport::ByteVector &payload) +DmUdsMessage::DmUdsMessage(Address sa, Address ta, IpAddress host_ip_address, + uds_transport::ByteVector &payload) : uds_transport::UdsMessage(), source_address_{sa}, target_address_{ta}, diff --git a/diag-client-lib/appl/src/diag-client/dcm/service/dm_uds_message.h b/diag-client-lib/appl/src/diag-client/dcm/service/dm_uds_message.h index 2f35e426..95a7e357 100644 --- a/diag-client-lib/appl/src/diag-client/dcm/service/dm_uds_message.h +++ b/diag-client-lib/appl/src/diag-client/dcm/service/dm_uds_message.h @@ -19,7 +19,8 @@ namespace uds_message { class DmUdsMessage final : public uds_transport::UdsMessage { public: // ctor - DmUdsMessage(Address sa, Address ta, IpAddress host_ip_address, uds_transport::ByteVector &payload); + DmUdsMessage(Address sa, Address ta, IpAddress host_ip_address, + uds_transport::ByteVector &payload); // dtor ~DmUdsMessage() noexcept override = default; diff --git a/diag-client-lib/appl/src/diag-client/dcm/service/vd_message.cpp b/diag-client-lib/appl/src/diag-client/dcm/service/vd_message.cpp index 701325d7..3f86c9da 100644 --- a/diag-client-lib/appl/src/diag-client/dcm/service/vd_message.cpp +++ b/diag-client-lib/appl/src/diag-client/dcm/service/vd_message.cpp @@ -14,7 +14,8 @@ namespace diag { namespace client { namespace vd_message { -auto SerializeVehicleInfoList(std::uint8_t preselection_mode, uds_transport::ByteVector& preselection_value) noexcept +auto SerializeVehicleInfoList(std::uint8_t preselection_mode, + uds_transport::ByteVector& preselection_value) noexcept -> uds_transport::ByteVector { constexpr std::uint8_t VehicleIdentificationHandler{0U}; diff --git a/diag-client-lib/appl/src/diag-client/diagnostic_client.cpp b/diag-client-lib/appl/src/diag-client/diagnostic_client.cpp index dcd4dc6a..1c3698aa 100644 --- a/diag-client-lib/appl/src/diag-client/diagnostic_client.cpp +++ b/diag-client-lib/appl/src/diag-client/diagnostic_client.cpp @@ -65,23 +65,27 @@ class DiagClient::DiagClientImpl final { */ Result Initialize() noexcept { logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo( - __FILE__, __LINE__, __func__, [](std::stringstream &msg) { msg << "DiagClient Initialization started"; }); + __FILE__, __LINE__, __func__, + [](std::stringstream &msg) { msg << "DiagClient Initialization started"; }); // read configuration return boost_support::parser::Read(diag_client_config_path_) .AndThen([this](boost_support::parser::boost_tree config) { // Create single dcm instance and pass the configuration - dcm_instance_ = std::make_unique(config_parser::ReadDcmClientConfig(config)); + dcm_instance_ = std::make_unique( + config_parser::ReadDcmClientConfig(config)); // Start dcm client main thread dcm_thread_ = std::thread([this]() noexcept { dcm_instance_->Main(); }); pthread_setname_np(dcm_thread_.native_handle(), "DcmClientMain"); logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo( - __FILE__, __LINE__, "", [](std::stringstream &msg) { msg << "DiagClient Initialization completed"; }); + __FILE__, __LINE__, "", + [](std::stringstream &msg) { msg << "DiagClient Initialization completed"; }); return Result::FromValue(); }) .MapError([](boost_support::parser::ParsingErrorCode const &) noexcept { logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogError( - __FILE__, __LINE__, "", [](std::stringstream &msg) { msg << "DiagClient Initialization failed"; }); + __FILE__, __LINE__, "", + [](std::stringstream &msg) { msg << "DiagClient Initialization failed"; }); return error_domain::MakeErrorCode(error_domain::DmErrorErrc::kInitializationFailed); }); } @@ -95,13 +99,15 @@ class DiagClient::DiagClientImpl final { */ Result DeInitialize() noexcept { logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo( - __FILE__, __LINE__, __func__, [](std::stringstream &msg) { msg << "DiagClient De-Initialization started"; }); + __FILE__, __LINE__, __func__, + [](std::stringstream &msg) { msg << "DiagClient De-Initialization started"; }); // shutdown DCM module here return dcm_instance_->SignalShutdown() .AndThen([this]() { if (dcm_thread_.joinable()) { dcm_thread_.join(); } logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo( - __FILE__, __LINE__, "", [](std::stringstream &msg) { msg << "DiagClient De-Initialization completed"; }); + __FILE__, __LINE__, "", + [](std::stringstream &msg) { msg << "DiagClient De-Initialization completed"; }); }) .OrElse([](core_type::ErrorCode const &) { return error_domain::MakeErrorCode(error_domain::DmErrorErrc::kDeInitializationFailed); @@ -115,10 +121,12 @@ class DiagClient::DiagClientImpl final { * @return Diag client conversation object as per passed conversation name * @implements DiagClientLib-MultipleTester-Connection, DiagClientLib-Conversation-Construction */ - conversation::DiagClientConversation GetDiagnosticClientConversation(std::string_view conversation_name) noexcept { + conversation::DiagClientConversation GetDiagnosticClientConversation( + std::string_view conversation_name) noexcept { if (!dcm_instance_) { logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogFatal( - __FILE__, __LINE__, "", [](std::stringstream &msg) { msg << "DiagClient is not Initialized"; }); + __FILE__, __LINE__, "", + [](std::stringstream &msg) { msg << "DiagClient is not Initialized"; }); } return dcm_instance_->GetDiagnosticClientConversation(conversation_name); } @@ -135,7 +143,8 @@ class DiagClient::DiagClientImpl final { diag::client::vehicle_info::VehicleInfoListRequestType vehicle_info_request) noexcept { if (!dcm_instance_) { logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogFatal( - __FILE__, __LINE__, "", [](std::stringstream &msg) { msg << "DiagClient is not Initialized"; }); + __FILE__, __LINE__, "", + [](std::stringstream &msg) { msg << "DiagClient is not Initialized"; }); } return dcm_instance_->SendVehicleIdentificationRequest(std::move(vehicle_info_request)); } diff --git a/diag-client-lib/appl/src/diag-client/diagnostic_client_conversation.cpp b/diag-client-lib/appl/src/diag-client/diagnostic_client_conversation.cpp index 45a037b2..f66186a0 100644 --- a/diag-client-lib/appl/src/diag-client/diagnostic_client_conversation.cpp +++ b/diag-client-lib/appl/src/diag-client/diagnostic_client_conversation.cpp @@ -24,7 +24,8 @@ class DiagClientConversation::DiagClientConversationImpl final { * The name of conversation configured as json parameter under "ConversationName" */ explicit DiagClientConversationImpl(std::string_view conversation_name) noexcept - : internal_conversation_{dcm::GetConversationManager().GetDiagnosticClientConversation(conversation_name)} {} + : internal_conversation_{ + dcm::GetConversationManager().GetDiagnosticClientConversation(conversation_name)} {} /** * @brief Destructor an instance of DiagClientConversationImpl @@ -62,7 +63,9 @@ class DiagClientConversation::DiagClientConversationImpl final { * @return DisconnectResult * Disconnection result returned */ - DisconnectResult DisconnectFromDiagServer() noexcept { return internal_conversation_.DisconnectFromDiagServer(); } + DisconnectResult DisconnectFromDiagServer() noexcept { + return internal_conversation_.DisconnectFromDiagServer(); + } /** * @brief Function to send Diagnostic Request and get Diagnostic Response @@ -73,8 +76,8 @@ class DiagClientConversation::DiagClientConversationImpl final { * @return uds_message::UdsResponseMessagePtr * Diagnostic Response message received, null_ptr in case of error */ - Result SendDiagnosticRequest( - uds_message::UdsRequestMessageConstPtr message) noexcept { + Result + SendDiagnosticRequest(uds_message::UdsRequestMessageConstPtr message) noexcept { return internal_conversation_.SendDiagnosticRequest(std::move(message)); } @@ -86,7 +89,8 @@ class DiagClientConversation::DiagClientConversationImpl final { }; DiagClientConversation::DiagClientConversation(std::string_view conversation_name) noexcept - : diag_client_conversation_impl_{std::make_unique(conversation_name)} {} + : diag_client_conversation_impl_{ + std::make_unique(conversation_name)} {} DiagClientConversation::~DiagClientConversation() noexcept = default; @@ -99,12 +103,14 @@ DiagClientConversation::ConnectResult DiagClientConversation::ConnectToDiagServe return diag_client_conversation_impl_->ConnectToDiagServer(target_address, host_ip_addr); } -DiagClientConversation::DisconnectResult DiagClientConversation::DisconnectFromDiagServer() noexcept { +DiagClientConversation::DisconnectResult +DiagClientConversation::DisconnectFromDiagServer() noexcept { return diag_client_conversation_impl_->DisconnectFromDiagServer(); } Result -DiagClientConversation::SendDiagnosticRequest(uds_message::UdsRequestMessageConstPtr message) noexcept { +DiagClientConversation::SendDiagnosticRequest( + uds_message::UdsRequestMessageConstPtr message) noexcept { return diag_client_conversation_impl_->SendDiagnosticRequest(std::move(message)); } diff --git a/diag-client-lib/lib/boost-support/include/boost-support/client/tcp/tcp_client.h b/diag-client-lib/lib/boost-support/include/boost-support/client/tcp/tcp_client.h index d9c7a54c..c7873acd 100644 --- a/diag-client-lib/lib/boost-support/include/boost-support/client/tcp/tcp_client.h +++ b/diag-client-lib/lib/boost-support/include/boost-support/client/tcp/tcp_client.h @@ -96,7 +96,8 @@ class TcpClient final { * The host port number * @return Empty void on success, otherwise error is returned */ - core_type::Result ConnectToHost(std::string_view host_ip_address, std::uint16_t host_port_num); + core_type::Result ConnectToHost(std::string_view host_ip_address, + std::uint16_t host_port_num); /** * @brief Function to disconnect from remote host if already connected diff --git a/diag-client-lib/lib/boost-support/include/boost-support/client/tls/tls_client.h b/diag-client-lib/lib/boost-support/include/boost-support/client/tls/tls_client.h index 7a2316ec..d7d2dcd1 100644 --- a/diag-client-lib/lib/boost-support/include/boost-support/client/tls/tls_client.h +++ b/diag-client-lib/lib/boost-support/include/boost-support/client/tls/tls_client.h @@ -71,8 +71,8 @@ class TlsClient final { * @param[in] ca_certification_path * The path to root ca certificate */ - TlsClient(std::string_view local_ip_address, std::uint16_t local_port_num, std::string_view ca_certification_path, - TlsVersion tls_version) noexcept; + TlsClient(std::string_view local_ip_address, std::uint16_t local_port_num, + std::string_view ca_certification_path, TlsVersion tls_version) noexcept; /** * @brief Deleted copy assignment and copy constructor @@ -117,7 +117,8 @@ class TlsClient final { * The host port number * @return Empty void on success, otherwise error is returned */ - core_type::Result ConnectToHost(std::string_view host_ip_address, std::uint16_t host_port_num); + core_type::Result ConnectToHost(std::string_view host_ip_address, + std::uint16_t host_port_num); /** * @brief Function to disconnect from remote host if already connected diff --git a/diag-client-lib/lib/boost-support/include/boost-support/message/tcp/tcp_message.h b/diag-client-lib/lib/boost-support/include/boost-support/message/tcp/tcp_message.h index cf453f06..c9d11ca6 100644 --- a/diag-client-lib/lib/boost-support/include/boost-support/message/tcp/tcp_message.h +++ b/diag-client-lib/lib/boost-support/include/boost-support/message/tcp/tcp_message.h @@ -97,7 +97,9 @@ class TcpMessage final { * @brief Get the readable view on received payload * @return The view on payload */ - core_type::Span GetPayload() const { return core_type::Span{payload_}; } + core_type::Span GetPayload() const { + return core_type::Span{payload_}; + } /** * @brief Get the state of underlying socket diff --git a/diag-client-lib/lib/boost-support/include/boost-support/message/udp/udp_message.h b/diag-client-lib/lib/boost-support/include/boost-support/message/udp/udp_message.h index 27c46250..4654d4a5 100644 --- a/diag-client-lib/lib/boost-support/include/boost-support/message/udp/udp_message.h +++ b/diag-client-lib/lib/boost-support/include/boost-support/message/udp/udp_message.h @@ -78,7 +78,9 @@ class UdpMessage final { * @brief Get the readable view on received payload * @return The view on payload */ - core_type::Span GetPayload() const { return core_type::Span{payload_}; } + core_type::Span GetPayload() const { + return core_type::Span{payload_}; + } private: /** diff --git a/diag-client-lib/lib/boost-support/include/boost-support/server/tls/tls_acceptor.h b/diag-client-lib/lib/boost-support/include/boost-support/server/tls/tls_acceptor.h index 66b0c43b..5dbbfe3b 100644 --- a/diag-client-lib/lib/boost-support/include/boost-support/server/tls/tls_acceptor.h +++ b/diag-client-lib/lib/boost-support/include/boost-support/server/tls/tls_acceptor.h @@ -47,8 +47,9 @@ class TlsAcceptor final { * @param[in] maximum_connection * The maximum number of accepted connection allowed */ - TlsAcceptor(std::string_view local_ip_address, std::uint16_t local_port_num, std::uint8_t maximum_connection, - TlsVersion tls_version, std::string_view certificate_path, std::string_view private_key_path) noexcept; + TlsAcceptor(std::string_view local_ip_address, std::uint16_t local_port_num, + std::uint8_t maximum_connection, TlsVersion tls_version, + std::string_view certificate_path, std::string_view private_key_path) noexcept; /** * @brief Destruct an instance of TcpAcceptor diff --git a/diag-client-lib/lib/boost-support/src/boost-support/client/tcp/tcp_client.cpp b/diag-client-lib/lib/boost-support/src/boost-support/client/tcp/tcp_client.cpp index d34db8d5..5e2e24b3 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/client/tcp/tcp_client.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/client/tcp/tcp_client.cpp @@ -30,8 +30,8 @@ class TcpClient::TcpClientImpl final { /** * @brief Type alias for unsecured tcp connection */ - using TcpConnection = - connection::tcp::TcpConnection; + using TcpConnection = connection::tcp::TcpConnection; /** * @brief Definitions of different connection state @@ -92,7 +92,9 @@ class TcpClient::TcpClientImpl final { * @param[in] read_handler * The handler to be set */ - void SetReadHandler(HandlerRead read_handler) noexcept { tcp_connection_.SetReadHandler(std::move(read_handler)); } + void SetReadHandler(HandlerRead read_handler) noexcept { + tcp_connection_.SetReadHandler(std::move(read_handler)); + } /** * @brief Function to connect to remote ip address and port number @@ -102,8 +104,10 @@ class TcpClient::TcpClientImpl final { * The host port number * @return Empty void on success, otherwise error is returned */ - core_type::Result ConnectToHost(std::string_view host_ip_address, std::uint16_t host_port_num) { - core_type::Result result{error_domain::MakeErrorCode(error_domain::BoostSupportErrorErrc::kSocketError)}; + core_type::Result ConnectToHost(std::string_view host_ip_address, + std::uint16_t host_port_num) { + core_type::Result result{ + error_domain::MakeErrorCode(error_domain::BoostSupportErrorErrc::kSocketError)}; if (connection_state_.load(std::memory_order_seq_cst) != State::kConnected) { if (tcp_connection_.ConnectToHost(host_ip_address, host_port_num)) { connection_state_.store(State::kConnected, std::memory_order_seq_cst); @@ -113,7 +117,8 @@ class TcpClient::TcpClientImpl final { // already connected result.EmplaceValue(); common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogVerbose( - __FILE__, __LINE__, __func__, [](std::stringstream &msg) { msg << "Tcp client is already connected"; }); + __FILE__, __LINE__, __func__, + [](std::stringstream &msg) { msg << "Tcp client is already connected"; }); } return result; } @@ -123,7 +128,8 @@ class TcpClient::TcpClientImpl final { * @return Empty void on success, otherwise error is returned */ core_type::Result DisconnectFromHost() { - core_type::Result result{error_domain::MakeErrorCode(error_domain::BoostSupportErrorErrc::kSocketError)}; + core_type::Result result{ + error_domain::MakeErrorCode(error_domain::BoostSupportErrorErrc::kSocketError)}; if (connection_state_.load(std::memory_order_seq_cst) == State::kConnected) { tcp_connection_.DisconnectFromHost(); connection_state_.store(State::kDisconnected, std::memory_order_seq_cst); @@ -131,7 +137,8 @@ class TcpClient::TcpClientImpl final { } else { // Not connected common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug( - __FILE__, __LINE__, __func__, [](std::stringstream &msg) { msg << "Tcp client is in disconnected state"; }); + __FILE__, __LINE__, __func__, + [](std::stringstream &msg) { msg << "Tcp client is in disconnected state"; }); } return result; } @@ -151,14 +158,16 @@ class TcpClient::TcpClientImpl final { * @return Empty void on success, otherwise error is returned */ core_type::Result Transmit(MessageConstPtr tcp_message) { - core_type::Result result{error_domain::MakeErrorCode(error_domain::BoostSupportErrorErrc::kGenericError)}; + core_type::Result result{ + error_domain::MakeErrorCode(error_domain::BoostSupportErrorErrc::kGenericError)}; if (connection_state_.load(std::memory_order_seq_cst) == State::kConnected) { if (tcp_connection_.Transmit(std::move(tcp_message))) { result.EmplaceValue(); } } else { // not connected common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [](std::stringstream &msg) { msg << "Tcp client is Offline, please connect to server first"; }); + __FILE__, __LINE__, __func__, [](std::stringstream &msg) { + msg << "Tcp client is Offline, please connect to server first"; + }); } return result; } @@ -197,13 +206,18 @@ void TcpClient::SetReadHandler(TcpClient::HandlerRead read_handler) noexcept { tcp_client_impl_->SetReadHandler(std::move(read_handler)); } -core_type::Result TcpClient::ConnectToHost(std::string_view host_ip_address, std::uint16_t host_port_num) { +core_type::Result TcpClient::ConnectToHost(std::string_view host_ip_address, + std::uint16_t host_port_num) { return tcp_client_impl_->ConnectToHost(host_ip_address, host_port_num); } -core_type::Result TcpClient::DisconnectFromHost() { return tcp_client_impl_->DisconnectFromHost(); } +core_type::Result TcpClient::DisconnectFromHost() { + return tcp_client_impl_->DisconnectFromHost(); +} -auto TcpClient::IsConnectedToHost() const noexcept -> bool { return tcp_client_impl_->IsConnectedToHost(); } +auto TcpClient::IsConnectedToHost() const noexcept -> bool { + return tcp_client_impl_->IsConnectedToHost(); +} core_type::Result TcpClient::Transmit(MessageConstPtr tcp_message) { return tcp_client_impl_->Transmit(std::move(tcp_message)); diff --git a/diag-client-lib/lib/boost-support/src/boost-support/client/tls/tls_client.cpp b/diag-client-lib/lib/boost-support/src/boost-support/client/tls/tls_client.cpp index 14d7be31..dd67125f 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/client/tls/tls_client.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/client/tls/tls_client.cpp @@ -33,7 +33,8 @@ class TlsClient::TlsClientImpl final { /** * @brief Type alias for secured tcp connection */ - using TcpConnectionSecured = connection::tcp::TcpConnection; + using TcpConnectionSecured = + connection::tcp::TcpConnection; /** * @brief Definitions of different connection state @@ -61,8 +62,8 @@ class TlsClient::TlsClientImpl final { * @param[in] local_port_num * The local port number of client */ - TlsClientImpl(std::string_view local_ip_address, std::uint16_t local_port_num, std::string_view ca_certification_path, - TlsVersion tls_version) noexcept + TlsClientImpl(std::string_view local_ip_address, std::uint16_t local_port_num, + std::string_view ca_certification_path, TlsVersion tls_version) noexcept : io_context_{}, tls_context_{tls_version, ca_certification_path}, connection_state_{State::kDisconnected}, @@ -101,7 +102,9 @@ class TlsClient::TlsClientImpl final { * @param[in] read_handler * The handler to be set */ - void SetReadHandler(HandlerRead read_handler) noexcept { tcp_connection_.SetReadHandler(std::move(read_handler)); } + void SetReadHandler(HandlerRead read_handler) noexcept { + tcp_connection_.SetReadHandler(std::move(read_handler)); + } /** * @brief Function to connect to remote ip address and port number @@ -111,8 +114,10 @@ class TlsClient::TlsClientImpl final { * The host port number * @return Empty void on success, otherwise error is returned */ - core_type::Result ConnectToHost(std::string_view host_ip_address, std::uint16_t host_port_num) { - core_type::Result result{error_domain::MakeErrorCode(error_domain::BoostSupportErrorErrc::kSocketError)}; + core_type::Result ConnectToHost(std::string_view host_ip_address, + std::uint16_t host_port_num) { + core_type::Result result{ + error_domain::MakeErrorCode(error_domain::BoostSupportErrorErrc::kSocketError)}; if (connection_state_.load(std::memory_order_seq_cst) != State::kConnected) { if (tcp_connection_.ConnectToHost(host_ip_address, host_port_num)) { connection_state_.store(State::kConnected, std::memory_order_seq_cst); @@ -122,7 +127,8 @@ class TlsClient::TlsClientImpl final { // already connected result.EmplaceValue(); common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogVerbose( - __FILE__, __LINE__, __func__, [](std::stringstream &msg) { msg << "Tcp client is already connected"; }); + __FILE__, __LINE__, __func__, + [](std::stringstream &msg) { msg << "Tcp client is already connected"; }); } return result; } @@ -132,7 +138,8 @@ class TlsClient::TlsClientImpl final { * @return Empty void on success, otherwise error is returned */ core_type::Result DisconnectFromHost() { - core_type::Result result{error_domain::MakeErrorCode(error_domain::BoostSupportErrorErrc::kSocketError)}; + core_type::Result result{ + error_domain::MakeErrorCode(error_domain::BoostSupportErrorErrc::kSocketError)}; if (connection_state_.load(std::memory_order_seq_cst) == State::kConnected) { tcp_connection_.DisconnectFromHost(); connection_state_.store(State::kDisconnected, std::memory_order_seq_cst); @@ -140,7 +147,8 @@ class TlsClient::TlsClientImpl final { } else { // Not connected common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug( - __FILE__, __LINE__, __func__, [](std::stringstream &msg) { msg << "Tcp client is in disconnected state"; }); + __FILE__, __LINE__, __func__, + [](std::stringstream &msg) { msg << "Tcp client is in disconnected state"; }); } return result; } @@ -160,14 +168,16 @@ class TlsClient::TlsClientImpl final { * @return Empty void on success, otherwise error is returned */ core_type::Result Transmit(MessageConstPtr tcp_message) { - core_type::Result result{error_domain::MakeErrorCode(error_domain::BoostSupportErrorErrc::kGenericError)}; + core_type::Result result{ + error_domain::MakeErrorCode(error_domain::BoostSupportErrorErrc::kGenericError)}; if (connection_state_.load(std::memory_order_seq_cst) == State::kConnected) { if (tcp_connection_.Transmit(std::move(tcp_message))) { result.EmplaceValue(); } } else { // not connected common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [](std::stringstream &msg) { msg << "Tcp client is Offline, please connect to server first"; }); + __FILE__, __LINE__, __func__, [](std::stringstream &msg) { + msg << "Tcp client is Offline, please connect to server first"; + }); } return result; } @@ -196,9 +206,10 @@ class TlsClient::TlsClientImpl final { template TlsClient::TlsClient(std::string_view local_ip_address, std::uint16_t local_port_num, - std::string_view ca_certification_path, TlsVersion tls_version) noexcept - : tls_client_impl_{std::make_unique(local_ip_address, local_port_num, ca_certification_path, - std::move(tls_version))} {} + std::string_view ca_certification_path, + TlsVersion tls_version) noexcept + : tls_client_impl_{std::make_unique( + local_ip_address, local_port_num, ca_certification_path, std::move(tls_version))} {} template TlsClient::TlsClient(TlsClient &&other) noexcept = default; diff --git a/diag-client-lib/lib/boost-support/src/boost-support/client/udp/udp_client.cpp b/diag-client-lib/lib/boost-support/src/boost-support/client/udp/udp_client.cpp index edf711c5..11c7e275 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/client/udp/udp_client.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/client/udp/udp_client.cpp @@ -30,7 +30,8 @@ class UdpClient::UdpClientImpl final { */ UdpClientImpl(std::string_view local_ip_address, std::uint16_t local_port_num) noexcept : io_context_{}, - udp_connection_{socket::udp::UdpSocket{local_ip_address, local_port_num, io_context_.GetContext()}} {} + udp_connection_{ + socket::udp::UdpSocket{local_ip_address, local_port_num, io_context_.GetContext()}} {} /** * @brief Deleted copy assignment and copy constructor @@ -71,7 +72,9 @@ class UdpClient::UdpClientImpl final { * @param[in] read_handler * The handler to be set */ - void SetReadHandler(HandlerRead read_handler) noexcept { udp_connection_.SetReadHandler(std::move(read_handler)); } + void SetReadHandler(HandlerRead read_handler) noexcept { + udp_connection_.SetReadHandler(std::move(read_handler)); + } /** * @brief Function to transmit the provided udp message diff --git a/diag-client-lib/lib/boost-support/src/boost-support/connection/tcp/tcp_connection.h b/diag-client-lib/lib/boost-support/src/boost-support/connection/tcp/tcp_connection.h index d440a6dc..e4c69deb 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/connection/tcp/tcp_connection.h +++ b/diag-client-lib/lib/boost-support/src/boost-support/connection/tcp/tcp_connection.h @@ -150,7 +150,8 @@ class TcpConnection final { * The host port number * @return Empty result on success otherwise error code */ - auto ConnectToHost(std::string_view host_ip_address, std::uint16_t host_port_num) noexcept -> bool { + auto ConnectToHost(std::string_view host_ip_address, std::uint16_t host_port_num) noexcept + -> bool { return socket_.Connect(host_ip_address, host_port_num) .AndThen([this]() noexcept { { // start reading diff --git a/diag-client-lib/lib/boost-support/src/boost-support/error_domain/boost_support_error_domain.cpp b/diag-client-lib/lib/boost-support/src/boost-support/error_domain/boost_support_error_domain.cpp index 80ecc36f..fda5c1dc 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/error_domain/boost_support_error_domain.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/error_domain/boost_support_error_domain.cpp @@ -48,7 +48,8 @@ auto ConvertErrorCodeToString(core_type::ErrorDomain::CodeType error_code) noexc } // namespace -BoostSupportErrorDomain::BoostSupportErrorDomain() noexcept : core_type::ErrorDomain(unique_identifier) {} +BoostSupportErrorDomain::BoostSupportErrorDomain() noexcept + : core_type::ErrorDomain(unique_identifier) {} const char* BoostSupportErrorDomain::Name() const noexcept { return domain_name_.c_str(); } @@ -58,8 +59,8 @@ const char* BoostSupportErrorDomain::Message(core_type::ErrorDomain::CodeType er return message_.c_str(); } -auto MakeErrorCode(BoostSupportErrorDomain::Errc code, BoostSupportErrorDomain::SupportDataType data) noexcept - -> core_type::ErrorCode { +auto MakeErrorCode(BoostSupportErrorDomain::Errc code, + BoostSupportErrorDomain::SupportDataType data) noexcept -> core_type::ErrorCode { return {static_cast(code), boost_support_error_domain, data}; } diff --git a/diag-client-lib/lib/boost-support/src/boost-support/error_domain/boost_support_error_domain.h b/diag-client-lib/lib/boost-support/src/boost-support/error_domain/boost_support_error_domain.h index b35e6695..80a62c72 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/error_domain/boost_support_error_domain.h +++ b/diag-client-lib/lib/boost-support/src/boost-support/error_domain/boost_support_error_domain.h @@ -83,8 +83,8 @@ class BoostSupportErrorDomain final : public core_type::ErrorDomain { * @return ErrorCode * A new ErrorCode instance */ -auto MakeErrorCode(BoostSupportErrorDomain::Errc code, BoostSupportErrorDomain::SupportDataType data) noexcept - -> core_type::ErrorCode; +auto MakeErrorCode(BoostSupportErrorDomain::Errc code, + BoostSupportErrorDomain::SupportDataType data) noexcept -> core_type::ErrorCode; /** * @brief Create a new ErrorCode within DoipErrorDomain. diff --git a/diag-client-lib/lib/boost-support/src/boost-support/parser/json_parser.cpp b/diag-client-lib/lib/boost-support/src/boost-support/parser/json_parser.cpp index 8a9443e6..018de7b5 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/parser/json_parser.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/parser/json_parser.cpp @@ -23,8 +23,9 @@ core_type::Result Read(std::string_view config_pat } catch (boost::property_tree::json_parser_error &error) { parse_result.EmplaceError(ParsingErrorCode::kError); common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [&error](std::stringstream &msg) { msg << "Reading of config failed with error: " << error.message(); }); + __FILE__, __LINE__, __func__, [&error](std::stringstream &msg) { + msg << "Reading of config failed with error: " << error.message(); + }); } return parse_result; } diff --git a/diag-client-lib/lib/boost-support/src/boost-support/server/tcp/tcp_acceptor.cpp b/diag-client-lib/lib/boost-support/src/boost-support/server/tcp/tcp_acceptor.cpp index 76d90769..0b701de6 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/server/tcp/tcp_acceptor.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/server/tcp/tcp_acceptor.cpp @@ -52,7 +52,8 @@ class TcpAcceptor::TcpAcceptorImpl final { std::uint8_t maximum_connection) noexcept : io_context_{}, acceptor_{io_context_, - Tcp::endpoint(TcpIpAddress::from_string(std::string{local_ip_address}.c_str()), local_port_num)} { + Tcp::endpoint(TcpIpAddress::from_string(std::string{local_ip_address}.c_str()), + local_port_num)} { acceptor_.listen(maximum_connection); } @@ -78,8 +79,9 @@ class TcpAcceptor::TcpAcceptorImpl final { }); } else { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Tcp socket accept failed with error: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Tcp socket accept failed with error: " << ec.message(); + }); } return tcp_server; } @@ -103,11 +105,14 @@ class TcpAcceptor::TcpAcceptorImpl final { TcpAcceptor::TcpAcceptor(std::string_view local_ip_address, std::uint16_t local_port_num, std::uint8_t maximum_connection) noexcept - : tcp_acceptor_impl_{std::make_unique(local_ip_address, local_port_num, maximum_connection)} {} + : tcp_acceptor_impl_{std::make_unique(local_ip_address, local_port_num, + maximum_connection)} {} TcpAcceptor::~TcpAcceptor() noexcept = default; -std::optional TcpAcceptor::GetTcpServer() noexcept { return tcp_acceptor_impl_->GetTcpServer(); } +std::optional TcpAcceptor::GetTcpServer() noexcept { + return tcp_acceptor_impl_->GetTcpServer(); +} } // namespace tcp } // namespace server diff --git a/diag-client-lib/lib/boost-support/src/boost-support/server/tcp/tcp_server.cpp b/diag-client-lib/lib/boost-support/src/boost-support/server/tcp/tcp_server.cpp index b6a734dd..37a04632 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/server/tcp/tcp_server.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/server/tcp/tcp_server.cpp @@ -20,7 +20,8 @@ class TcpServer::TcpServerImpl final { /** * @brief Type alias for tcp server connection */ - using TcpConnection = connection::tcp::TcpConnection; + using TcpConnection = + connection::tcp::TcpConnection; /** * @brief Constructs an instance of TcpServerImpl @@ -62,7 +63,9 @@ class TcpServer::TcpServerImpl final { * @param[in] read_handler * The handler to be set */ - void SetReadHandler(HandlerRead read_handler) noexcept { tcp_connection_.SetReadHandler(std::move(read_handler)); } + void SetReadHandler(HandlerRead read_handler) noexcept { + tcp_connection_.SetReadHandler(std::move(read_handler)); + } /** * @brief Function to transmit the provided tcp message diff --git a/diag-client-lib/lib/boost-support/src/boost-support/server/tls/tls_acceptor.cpp b/diag-client-lib/lib/boost-support/src/boost-support/server/tls/tls_acceptor.cpp index 28e709c0..3e0312ad 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/server/tls/tls_acceptor.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/server/tls/tls_acceptor.cpp @@ -56,12 +56,14 @@ class TlsAcceptor::TlsAcceptorImpl final { * @param[in] maximum_connection * The maximum number of accepted connection */ - TlsAcceptorImpl(std::string_view local_ip_address, std::uint16_t local_port_num, std::uint8_t maximum_connection, - TlsVersion tls_version, std::string_view certificate_path, std::string_view private_key_path) noexcept + TlsAcceptorImpl(std::string_view local_ip_address, std::uint16_t local_port_num, + std::uint8_t maximum_connection, TlsVersion tls_version, + std::string_view certificate_path, std::string_view private_key_path) noexcept : io_context_{}, tls_context_{std::forward(tls_version), certificate_path, private_key_path}, acceptor_{io_context_, - Tcp::endpoint(TcpIpAddress::from_string(std::string{local_ip_address}.c_str()), local_port_num)} { + Tcp::endpoint(TcpIpAddress::from_string(std::string{local_ip_address}.c_str()), + local_port_num)} { acceptor_.listen(maximum_connection); } @@ -82,13 +84,14 @@ class TlsAcceptor::TlsAcceptorImpl final { tls_server.emplace(TlsSocket{std::move(accepted_socket), tls_context_}); common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug( __FILE__, __LINE__, __func__, [&endpoint](std::stringstream &msg) { - msg << "Tls socket connection received from client " << "<" << endpoint.address().to_string() << "," - << endpoint.port() << ">"; + msg << "Tls socket connection received from client " + << "<" << endpoint.address().to_string() << "," << endpoint.port() << ">"; }); } else { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Tcp socket accept failed with error: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Tcp socket accept failed with error: " << ec.message(); + }); } return tls_server; } @@ -116,12 +119,13 @@ class TlsAcceptor::TlsAcceptorImpl final { }; template -TlsAcceptor::TlsAcceptor(std::string_view local_ip_address, std::uint16_t local_port_num, - std::uint8_t maximum_connection, TlsVersion tls_version, - std::string_view certificate_path, std::string_view private_key_path) noexcept - : tls_acceptor_impl_{std::make_unique(local_ip_address, local_port_num, maximum_connection, - std::move(tls_version), certificate_path, - private_key_path)} {} +TlsAcceptor::TlsAcceptor(std::string_view local_ip_address, + std::uint16_t local_port_num, std::uint8_t maximum_connection, + TlsVersion tls_version, std::string_view certificate_path, + std::string_view private_key_path) noexcept + : tls_acceptor_impl_{std::make_unique( + local_ip_address, local_port_num, maximum_connection, std::move(tls_version), + certificate_path, private_key_path)} {} template TlsAcceptor::~TlsAcceptor() noexcept = default; diff --git a/diag-client-lib/lib/boost-support/src/boost-support/server/tls/tls_server.cpp b/diag-client-lib/lib/boost-support/src/boost-support/server/tls/tls_server.cpp index acc1e90e..ecd6c6c8 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/server/tls/tls_server.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/server/tls/tls_server.cpp @@ -25,7 +25,8 @@ class TlsServer::TlsServerImpl final { /** * @brief Type alias for secured tcp connection */ - using TcpConnectionSecured = connection::tcp::TcpConnection; + using TcpConnectionSecured = + connection::tcp::TcpConnection; /** * @brief Constructs an instance of TcpServerImpl @@ -67,7 +68,9 @@ class TlsServer::TlsServerImpl final { * @param[in] read_handler * The handler to be set */ - void SetReadHandler(HandlerRead read_handler) noexcept { tcp_connection_.SetReadHandler(std::move(read_handler)); } + void SetReadHandler(HandlerRead read_handler) noexcept { + tcp_connection_.SetReadHandler(std::move(read_handler)); + } /** * @brief Function to transmit the provided tcp message diff --git a/diag-client-lib/lib/boost-support/src/boost-support/socket/io_context.cpp b/diag-client-lib/lib/boost-support/src/boost-support/socket/io_context.cpp index 44205ea1..84223d19 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/socket/io_context.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/socket/io_context.cpp @@ -11,7 +11,12 @@ namespace boost_support { namespace socket { -IoContext::IoContext() noexcept : io_context_{}, exit_request_{false}, running_{false}, cond_var_{}, mutex_{} { +IoContext::IoContext() noexcept + : io_context_{}, + exit_request_{false}, + running_{false}, + cond_var_{}, + mutex_{} { // start thread to execute async tasks thread_ = std::thread([this]() { std::unique_lock lck(mutex_); diff --git a/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tcp_socket.cpp b/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tcp_socket.cpp index 25a05317..ff4e146f 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tcp_socket.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tcp_socket.cpp @@ -16,7 +16,8 @@ namespace boost_support { namespace socket { namespace tcp { -TcpSocket::TcpSocket(std::string_view local_ip_address, std::uint16_t local_port_num, IoContext &io_context) noexcept +TcpSocket::TcpSocket(std::string_view local_ip_address, std::uint16_t local_port_num, + IoContext &io_context) noexcept : tcp_socket_{io_context.GetContext()}, local_endpoint_{boost::asio::ip::make_address(local_ip_address), local_port_num} {} @@ -53,26 +54,29 @@ core_type::Result TcpSocket::Open() noexcept { } else { // Socket binding failed common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Tcp Socket binding failed with message: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Tcp Socket binding failed with message: " << ec.message(); + }); result.EmplaceError(SocketError::kBindingFailed); } } else { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Tcp Socket opening failed with error: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Tcp Socket opening failed with error: " << ec.message(); + }); result.EmplaceError(SocketError::kOpenFailed); } return result; } -core_type::Result TcpSocket::Connect(std::string_view host_ip_address, - std::uint16_t host_port_num) noexcept { +core_type::Result TcpSocket::Connect( + std::string_view host_ip_address, std::uint16_t host_port_num) noexcept { core_type::Result result{SocketError::kGenericError}; TcpErrorCodeType ec{}; // Connect to provided Ip address - tcp_socket_.connect(Tcp::endpoint(TcpIpAddress::from_string(std::string{host_ip_address}), host_port_num), ec); + tcp_socket_.connect( + Tcp::endpoint(TcpIpAddress::from_string(std::string{host_ip_address}), host_port_num), ec); if (ec.value() == boost::system::errc::success) { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug( __FILE__, __LINE__, __func__, [this](std::stringstream &msg) { @@ -83,8 +87,9 @@ core_type::Result TcpSocket::Connect(std::string_v result.EmplaceValue(); } else { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Tcp Socket connect to host failed with error: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Tcp Socket connect to host failed with error: " << ec.message(); + }); } return result; } @@ -107,12 +112,14 @@ core_type::Result TcpSocket::Disconnect() noexcept return result; } -core_type::Result TcpSocket::Transmit(TcpMessageConstPtr tcp_message) noexcept { +core_type::Result TcpSocket::Transmit( + TcpMessageConstPtr tcp_message) noexcept { core_type::Result result{SocketError::kGenericError}; TcpErrorCodeType ec{}; - boost::asio::write(tcp_socket_, - boost::asio::buffer(tcp_message->GetPayload().data(), tcp_message->GetPayload().size()), ec); + boost::asio::write( + tcp_socket_, + boost::asio::buffer(tcp_message->GetPayload().data(), tcp_message->GetPayload().size()), ec); // Check for error if (ec.value() == boost::system::errc::success) { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug( @@ -124,8 +131,9 @@ core_type::Result TcpSocket::Transmit(TcpMessageCo result.EmplaceValue(); } else { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Tcp message sending failed with error: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Tcp message sending failed with error: " << ec.message(); + }); } return result; } @@ -146,30 +154,34 @@ core_type::Result TcpSocket::R TcpMessage::BufferType rx_buffer{}; rx_buffer.resize(message::tcp::kDoipheadrSize); // start blocking read to read Header first - boost::asio::read(tcp_socket_, boost::asio::buffer(&rx_buffer[0u], message::tcp::kDoipheadrSize), ec); + boost::asio::read(tcp_socket_, boost::asio::buffer(&rx_buffer[0u], message::tcp::kDoipheadrSize), + ec); // Check for error if (ec.value() == boost::system::errc::success) { // read the next bytes to read std::uint32_t const read_next_bytes = [&rx_buffer]() noexcept -> std::uint32_t { - return static_cast((static_cast(rx_buffer[4u] << 24u) & 0xFF000000) | - (static_cast(rx_buffer[5u] << 16u) & 0x00FF0000) | - (static_cast(rx_buffer[6u] << 8u) & 0x0000FF00) | - (static_cast(rx_buffer[7u] & 0x000000FF))); + return static_cast( + (static_cast(rx_buffer[4u] << 24u) & 0xFF000000) | + (static_cast(rx_buffer[5u] << 16u) & 0x00FF0000) | + (static_cast(rx_buffer[6u] << 8u) & 0x0000FF00) | + (static_cast(rx_buffer[7u] & 0x000000FF))); }(); if (read_next_bytes != 0u) { // reserve the buffer rx_buffer.resize(message::tcp::kDoipheadrSize + std::size_t(read_next_bytes)); - boost::asio::read(tcp_socket_, boost::asio::buffer(&rx_buffer[message::tcp::kDoipheadrSize], read_next_bytes), - ec); + boost::asio::read( + tcp_socket_, + boost::asio::buffer(&rx_buffer[message::tcp::kDoipheadrSize], read_next_bytes), ec); Tcp::endpoint const remote_endpoint{tcp_socket_.remote_endpoint()}; - TcpMessagePtr tcp_rx_message{std::make_unique(remote_endpoint.address().to_string(), - remote_endpoint.port(), std::move(rx_buffer))}; + TcpMessagePtr tcp_rx_message{std::make_unique( + remote_endpoint.address().to_string(), remote_endpoint.port(), std::move(rx_buffer))}; common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug( __FILE__, __LINE__, __func__, [&remote_endpoint](std::stringstream &msg) { msg << "Tcp Message received from " - << "<" << remote_endpoint.address().to_string() << "," << remote_endpoint.port() << ">"; + << "<" << remote_endpoint.address().to_string() << "," << remote_endpoint.port() + << ">"; }); result.EmplaceValue(std::move(tcp_rx_message)); } else { @@ -183,8 +195,9 @@ core_type::Result TcpSocket::R [ec](std::stringstream &msg) { msg << "Remote Disconnected with: " << ec.message(); }); } else { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Remote Disconnected with undefined error: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Remote Disconnected with undefined error: " << ec.message(); + }); } return result; } diff --git a/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tcp_socket.h b/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tcp_socket.h index cb2d1aeb..00d70fe7 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tcp_socket.h +++ b/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tcp_socket.h @@ -26,7 +26,12 @@ class TcpSocket final { /** * @brief Socket error code */ - enum class SocketError : std::uint8_t { kOpenFailed, kBindingFailed, kRemoteDisconnected, kGenericError }; + enum class SocketError : std::uint8_t { + kOpenFailed, + kBindingFailed, + kRemoteDisconnected, + kGenericError + }; /** * @brief Type alias for Tcp message @@ -63,7 +68,8 @@ class TcpSocket final { * @param[in] io_context * The I/O context required to create socket */ - TcpSocket(std::string_view local_ip_address, std::uint16_t local_port_num, IoContext &io_context) noexcept; + TcpSocket(std::string_view local_ip_address, std::uint16_t local_port_num, + IoContext &io_context) noexcept; /** * @brief Constructs an instance of TcpSocket @@ -103,7 +109,8 @@ class TcpSocket final { * The host port number * @return Empty result on success otherwise error code */ - core_type::Result Connect(std::string_view host_ip_address, std::uint16_t host_port_num) noexcept; + core_type::Result Connect(std::string_view host_ip_address, + std::uint16_t host_port_num) noexcept; /** * @brief Function to Disconnect from host diff --git a/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tls_client_.cpp b/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tls_client_.cpp index f139c591..0b1f6041 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tls_client_.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tls_client_.cpp @@ -49,7 +49,8 @@ void print_cn_name(const char *label, X509_NAME *const name) { } // namespace TlsClientSocket::TlsClientSocket(std::string_view local_ip_address, std::uint16_t local_port_num, - TcpHandlerRead tcp_handler_read, std::string_view ca_certification_path) + TcpHandlerRead tcp_handler_read, + std::string_view ca_certification_path) : local_ip_address_{local_ip_address}, local_port_num_{local_port_num}, io_context_{}, @@ -64,21 +65,22 @@ TlsClientSocket::TlsClientSocket(std::string_view local_ip_address, std::uint16_ // Set verification mode tls_socket_.set_verify_mode(boost::asio::ssl::verify_peer); // Set the verification callback - tls_socket_.set_verify_callback([](bool pre_verified, boost::asio::ssl::verify_context &ctx) noexcept -> bool { - X509 *cert = X509_STORE_CTX_get_current_cert(ctx.native_handle()); - int depth = X509_STORE_CTX_get_error_depth(ctx.native_handle()); - - fprintf(stdout, "verify_callback (depth=%d)(preverify=%d)\n", depth, pre_verified); - - X509_NAME *iname = cert ? X509_get_issuer_name(cert) : nullptr; - X509_NAME *sname = cert ? X509_get_subject_name(cert) : nullptr; - - /* Issuer is the authority we trust that warrants nothing useful */ - print_cn_name("Issuer (cn)", iname); - /* Subject is who the certificate is issued to by the authority */ - print_cn_name("Subject (cn)", sname); - return true; - }); + tls_socket_.set_verify_callback( + [](bool pre_verified, boost::asio::ssl::verify_context &ctx) noexcept -> bool { + X509 *cert = X509_STORE_CTX_get_current_cert(ctx.native_handle()); + int depth = X509_STORE_CTX_get_error_depth(ctx.native_handle()); + + fprintf(stdout, "verify_callback (depth=%d)(preverify=%d)\n", depth, pre_verified); + + X509_NAME *iname = cert ? X509_get_issuer_name(cert) : nullptr; + X509_NAME *sname = cert ? X509_get_subject_name(cert) : nullptr; + + /* Issuer is the authority we trust that warrants nothing useful */ + print_cn_name("Issuer (cn)", iname); + /* Subject is who the certificate is issued to by the authority */ + print_cn_name("Subject (cn)", sname); + return true; + }); // Load the root CA certificates io_ssl_context_.load_verify_file(std::string{ca_certification_path}); @@ -126,7 +128,8 @@ core_type::Result TlsClientSocket::Open() { // Set socket to non blocking GetNativeTcpSocket().non_blocking(false); // Bind to local ip address and random port - GetNativeTcpSocket().bind(Tcp::endpoint(TcpIpAddress::from_string(local_ip_address_), local_port_num_), ec); + GetNativeTcpSocket().bind( + Tcp::endpoint(TcpIpAddress::from_string(local_ip_address_), local_port_num_), ec); if (ec.value() == boost::system::errc::success) { // Socket binding success @@ -140,27 +143,29 @@ core_type::Result TlsClientSocket::Open() { } else { // Socket binding failed common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Tcp Socket binding failed with message: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Tcp Socket binding failed with message: " << ec.message(); + }); result.EmplaceError(TlsErrorCode::kBindingFailed); } } else { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Tcp Socket opening failed with error: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Tcp Socket opening failed with error: " << ec.message(); + }); result.EmplaceError(TlsErrorCode::kOpenFailed); } return result; } -core_type::Result TlsClientSocket::ConnectToHost(std::string_view host_ip_address, - std::uint16_t host_port_num) { +core_type::Result TlsClientSocket::ConnectToHost( + std::string_view host_ip_address, std::uint16_t host_port_num) { core_type::Result result{TlsErrorCode::kGenericError}; TcpErrorCodeType ec{}; // Connect to provided Ip address - GetNativeTcpSocket().connect(Tcp::endpoint(TcpIpAddress::from_string(std::string{host_ip_address}), host_port_num), - ec); + GetNativeTcpSocket().connect( + Tcp::endpoint(TcpIpAddress::from_string(std::string{host_ip_address}), host_port_num), ec); if (ec.value() == boost::system::errc::success) { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug( __FILE__, __LINE__, __func__, [this](std::stringstream &msg) { @@ -187,8 +192,9 @@ core_type::Result TlsClientSocket::ConnectT } } else { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Tcp Socket connect to host failed with error: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Tcp Socket connect to host failed with error: " << ec.message(); + }); result.EmplaceError(TlsErrorCode::kConnectFailed); } return result; @@ -224,8 +230,9 @@ core_type::Result TlsClientSocket::Transmit core_type::Result result{TlsErrorCode::kGenericError}; TcpErrorCodeType ec{}; - boost::asio::write(tls_socket_, - boost::asio::buffer(tcp_message->GetPayload().data(), tcp_message->GetPayload().size()), ec); + boost::asio::write( + tls_socket_, + boost::asio::buffer(tcp_message->GetPayload().data(), tcp_message->GetPayload().size()), ec); // Check for error if (ec.value() == boost::system::errc::success) { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug( @@ -237,8 +244,9 @@ core_type::Result TlsClientSocket::Transmit result.EmplaceValue(); } else { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Tcp message sending failed with error: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Tcp message sending failed with error: " << ec.message(); + }); } return result; } @@ -257,22 +265,25 @@ void TlsClientSocket::HandleMessage() { message::tcp::TcpMessage::BufferType rx_buffer{}; rx_buffer.resize(message::tcp::kDoipheadrSize); // start blocking read to read Header first - boost::asio::read(tls_socket_, boost::asio::buffer(&rx_buffer[0u], message::tcp::kDoipheadrSize), ec); + boost::asio::read(tls_socket_, boost::asio::buffer(&rx_buffer[0u], message::tcp::kDoipheadrSize), + ec); // Check for error if (ec.value() == boost::system::errc::success) { // read the next bytes to read std::uint32_t const read_next_bytes = [&rx_buffer]() noexcept -> std::uint32_t { - return static_cast((static_cast(rx_buffer[4u] << 24u) & 0xFF000000) | - (static_cast(rx_buffer[5u] << 16u) & 0x00FF0000) | - (static_cast(rx_buffer[6u] << 8u) & 0x0000FF00) | - (static_cast(rx_buffer[7u] & 0x000000FF))); + return static_cast( + (static_cast(rx_buffer[4u] << 24u) & 0xFF000000) | + (static_cast(rx_buffer[5u] << 16u) & 0x00FF0000) | + (static_cast(rx_buffer[6u] << 8u) & 0x0000FF00) | + (static_cast(rx_buffer[7u] & 0x000000FF))); }(); if (read_next_bytes != 0u) { // reserve the buffer rx_buffer.resize(message::tcp::kDoipheadrSize + std::size_t(read_next_bytes)); - boost::asio::read(tls_socket_, boost::asio::buffer(&rx_buffer[message::tcp::kDoipheadrSize], read_next_bytes), - ec); + boost::asio::read( + tls_socket_, + boost::asio::buffer(&rx_buffer[message::tcp::kDoipheadrSize], read_next_bytes), ec); // all message received, transfer to upper layer Tcp::endpoint const endpoint_{GetNativeTcpSocket().remote_endpoint()}; @@ -298,8 +309,9 @@ void TlsClientSocket::HandleMessage() { } else { running_ = false; common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Remote Disconnected with undefined error: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Remote Disconnected with undefined error: " << ec.message(); + }); } } diff --git a/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tls_client_.h b/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tls_client_.h index b39c778c..8f52f711 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tls_client_.h +++ b/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tls_client_.h @@ -54,8 +54,8 @@ class TlsClientSocket final { * @param[in] ca_certification_path * The path to root ca certificate */ - TlsClientSocket(std::string_view local_ip_address, std::uint16_t local_port_num, TcpHandlerRead tcp_handler_read, - std::string_view ca_certification_path); + TlsClientSocket(std::string_view local_ip_address, std::uint16_t local_port_num, + TcpHandlerRead tcp_handler_read, std::string_view ca_certification_path); /** * @brief Destruct an instance of TcpClientSocket @@ -76,7 +76,8 @@ class TlsClientSocket final { * The host port number * @return Empty result on success otherwise error code */ - core_type::Result ConnectToHost(std::string_view host_ip_address, std::uint16_t host_port_num); + core_type::Result ConnectToHost(std::string_view host_ip_address, + std::uint16_t host_port_num); /** * @brief Function to Disconnect from host diff --git a/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tls_server_.cpp b/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tls_server_.cpp index 7b502bc9..c352412e 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tls_server_.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/socket/tcp/tls_server_.cpp @@ -31,11 +31,14 @@ TlsServerSocket::TlsServerSocket(std::string_view local_ip_address, std::uint16_ }); // Load certificate and private key from provided locations io_ssl_context_.use_certificate_chain_file("../../../openssl/DiagClientLib.crt"); - io_ssl_context_.use_private_key_file("../../../openssl/DiagClientLib.key", boost::asio::ssl::context::pem); - SSL_CTX_set_ciphersuites(io_ssl_context_.native_handle(), "TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256"); + io_ssl_context_.use_private_key_file("../../../openssl/DiagClientLib.key", + boost::asio::ssl::context::pem); + SSL_CTX_set_ciphersuites(io_ssl_context_.native_handle(), + "TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256"); } -std::optional TlsServerSocket::GetTcpServerConnection(TcpHandlerRead tcp_handler_read) { +std::optional TlsServerSocket::GetTcpServerConnection( + TcpHandlerRead tcp_handler_read) { std::optional tcp_connection{std::nullopt}; TcpErrorCodeType ec{}; Tcp::endpoint endpoint{}; @@ -52,8 +55,9 @@ std::optional TlsServerSocket::GetTcpServerConnection(TcpHa }); } else { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "TLS Socket Connect to client failed with error: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "TLS Socket Connect to client failed with error: " << ec.message(); + }); } return tcp_connection; } @@ -71,9 +75,10 @@ core_type::Result TcpServerConnection:: TcpErrorCodeType ec{}; core_type::Result result{TcpErrorCode::kGenericError}; - boost::asio::write( - tls_socket_, - boost::asio::buffer(tcp_tx_message->GetPayload().data(), std::size_t(tcp_tx_message->GetPayload().size())), ec); + boost::asio::write(tls_socket_, + boost::asio::buffer(tcp_tx_message->GetPayload().data(), + std::size_t(tcp_tx_message->GetPayload().size())), + ec); // Check for error if (ec.value() == boost::system::errc::success) { Tcp::endpoint endpoint_{GetNativeTcpSocket().remote_endpoint()}; @@ -85,8 +90,9 @@ core_type::Result TcpServerConnection:: result.EmplaceValue(); } else { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Tcp message sending failed with error: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Tcp message sending failed with error: " << ec.message(); + }); } return result; } @@ -103,20 +109,23 @@ bool TcpServerConnection::TryReceivingMessage() { message::tcp::TcpMessage::BufferType rx_buffer{}; rx_buffer.resize(message::tcp::kDoipheadrSize); // Start blocking read to read Header first - boost::asio::read(tls_socket_, boost::asio::buffer(&rx_buffer[0], message::tcp::kDoipheadrSize), ec); + boost::asio::read(tls_socket_, boost::asio::buffer(&rx_buffer[0], message::tcp::kDoipheadrSize), + ec); // Check for error if (ec.value() == boost::system::errc::success) { // Read the next bytes to read std::uint32_t const read_next_bytes = [&rx_buffer]() noexcept -> std::uint32_t { - return static_cast((static_cast(rx_buffer[4u] << 24u) & 0xFF000000) | - (static_cast(rx_buffer[5u] << 16u) & 0x00FF0000) | - (static_cast(rx_buffer[6u] << 8u) & 0x0000FF00) | - (static_cast(rx_buffer[7u] & 0x000000FF))); + return static_cast( + (static_cast(rx_buffer[4u] << 24u) & 0xFF000000) | + (static_cast(rx_buffer[5u] << 16u) & 0x00FF0000) | + (static_cast(rx_buffer[6u] << 8u) & 0x0000FF00) | + (static_cast(rx_buffer[7u] & 0x000000FF))); }(); // reserve the buffer rx_buffer.resize(message::tcp::kDoipheadrSize + std::size_t(read_next_bytes)); - boost::asio::read(tls_socket_, boost::asio::buffer(&rx_buffer[message::tcp::kDoipheadrSize], read_next_bytes), - ec); + boost::asio::read( + tls_socket_, + boost::asio::buffer(&rx_buffer[message::tcp::kDoipheadrSize], read_next_bytes), ec); // all message received, transfer to upper layer Tcp::endpoint endpoint_{GetNativeTcpSocket().remote_endpoint()}; @@ -136,14 +145,16 @@ bool TcpServerConnection::TryReceivingMessage() { connection_closed = true; } else { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Remote Disconnected with undefined error: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Remote Disconnected with undefined error: " << ec.message(); + }); connection_closed = true; } } else { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Tls server handshake with host failed with error: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Tls server handshake with host failed with error: " << ec.message(); + }); connection_closed = true; } return connection_closed; @@ -164,8 +175,9 @@ core_type::Result TcpServerConnection:: result.EmplaceValue(); } else { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Tcp Socket Disconnection failed with error: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Tcp Socket Disconnection failed with error: " << ec.message(); + }); } GetNativeTcpSocket().close(); } diff --git a/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_context.cpp b/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_context.cpp index 9e7d395b..bf0cc129 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_context.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_context.cpp @@ -117,9 +117,10 @@ auto ToOpenSslString(server::tls::Tls13CipherSuites cipher) noexcept -> std::str template auto ConvertCipherListToString(std::initializer_list ciphers) noexcept -> std::string { - return std::accumulate( - ciphers.begin(), ciphers.end(), std::string{}, - [](std::string const& result, CipherType const& cipher) { return result + ':' + ToOpenSslString(cipher); }); + return std::accumulate(ciphers.begin(), ciphers.end(), std::string{}, + [](std::string const& result, CipherType const& cipher) { + return result + ':' + ToOpenSslString(cipher); + }); } } // namespace @@ -128,8 +129,8 @@ TlsContext::TlsContext(Tls12VersionClient client, std::string_view ca_certificat // Load the root CA certificates ssl_context_.load_verify_file(std::string{ca_certification_path}); // Load the cipher suites - if (SSL_CTX_set_cipher_list(ssl_context_.native_handle(), ConvertCipherListToString(client.cipher_suites).c_str()) == - 0) { + if (SSL_CTX_set_cipher_list(ssl_context_.native_handle(), + ConvertCipherListToString(client.cipher_suites).c_str()) == 0) { // Failure } } @@ -139,8 +140,8 @@ TlsContext::TlsContext(Tls13VersionClient client, std::string_view ca_certificat // Load the root CA certificates ssl_context_.load_verify_file(std::string{ca_certification_path}); // Load the cipher suites - if (SSL_CTX_set_ciphersuites(ssl_context_.native_handle(), ConvertCipherListToString(client.cipher_suites).c_str()) == - 0) { + if (SSL_CTX_set_ciphersuites(ssl_context_.native_handle(), + ConvertCipherListToString(client.cipher_suites).c_str()) == 0) { // Failure } } @@ -152,8 +153,8 @@ TlsContext::TlsContext(Tls12VersionServer server, std::string_view certificate_p ssl_context_.use_certificate_chain_file(std::string{certificate_path}); ssl_context_.use_private_key_file(std::string{private_key_path}, boost::asio::ssl::context::pem); // Load the cipher suites - if (SSL_CTX_set_ciphersuites(ssl_context_.native_handle(), ConvertCipherListToString(server.cipher_suites).c_str()) == - 0) { + if (SSL_CTX_set_ciphersuites(ssl_context_.native_handle(), + ConvertCipherListToString(server.cipher_suites).c_str()) == 0) { // Failure } } @@ -165,8 +166,8 @@ TlsContext::TlsContext(Tls13VersionServer server, std::string_view certificate_p ssl_context_.use_certificate_chain_file(std::string{certificate_path}); ssl_context_.use_private_key_file(std::string{private_key_path}, boost::asio::ssl::context::pem); // Load the cipher suites - if (SSL_CTX_set_ciphersuites(ssl_context_.native_handle(), ConvertCipherListToString(server.cipher_suites).c_str()) == - 0) { + if (SSL_CTX_set_ciphersuites(ssl_context_.native_handle(), + ConvertCipherListToString(server.cipher_suites).c_str()) == 0) { // Failure } } diff --git a/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_context.h b/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_context.h index 13ba6fc5..669a5115 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_context.h +++ b/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_context.h @@ -76,7 +76,8 @@ class TlsContext final { * @param[in] private_key_path * The path to private key */ - TlsContext(Tls12VersionServer server, std::string_view certificate_path, std::string_view private_key_path) noexcept; + TlsContext(Tls12VersionServer server, std::string_view certificate_path, + std::string_view private_key_path) noexcept; /** * @brief Constructs an instance of TlsContext @@ -87,7 +88,8 @@ class TlsContext final { * @param[in] private_key_path * The path to private key */ - TlsContext(Tls13VersionServer server, std::string_view certificate_path, std::string_view private_key_path) noexcept; + TlsContext(Tls13VersionServer server, std::string_view certificate_path, + std::string_view private_key_path) noexcept; /** * @brief Deleted copy assignment and copy constructor diff --git a/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_socket.cpp b/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_socket.cpp index 842ee9a0..c99613cd 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_socket.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_socket.cpp @@ -16,8 +16,8 @@ namespace boost_support { namespace socket { namespace tls { -TlsSocket::TlsSocket(std::string_view local_ip_address, std::uint16_t local_port_num, TlsContext &tls_context, - IoContext &io_context) noexcept +TlsSocket::TlsSocket(std::string_view local_ip_address, std::uint16_t local_port_num, + TlsContext &tls_context, IoContext &io_context) noexcept : ssl_stream_{io_context.GetContext(), tls_context.GetContext()}, local_endpoint_{boost::asio::ip::make_address(local_ip_address), local_port_num} {} @@ -56,26 +56,29 @@ core_type::Result TlsSocket::Open() noexcept { } else { // Socket binding failed common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Tls Socket binding failed with message: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Tls Socket binding failed with message: " << ec.message(); + }); result.EmplaceError(SocketError::kBindingFailed); } } else { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Tls Socket opening failed with error: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Tls Socket opening failed with error: " << ec.message(); + }); result.EmplaceError(SocketError::kOpenFailed); } return result; } -core_type::Result TlsSocket::Connect(std::string_view host_ip_address, - std::uint16_t host_port_num) noexcept { +core_type::Result TlsSocket::Connect( + std::string_view host_ip_address, std::uint16_t host_port_num) noexcept { core_type::Result result{SocketError::kGenericError}; TcpErrorCodeType ec{}; // Connect to provided Ip address - GetNativeTcpSocket().connect(Tcp::endpoint{boost::asio::ip::make_address(host_ip_address), host_port_num}, ec); + GetNativeTcpSocket().connect( + Tcp::endpoint{boost::asio::ip::make_address(host_ip_address), host_port_num}, ec); if (ec.value() == boost::system::errc::success) { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug( __FILE__, __LINE__, __func__, [this](std::stringstream &msg) { @@ -124,12 +127,14 @@ core_type::Result TlsSocket::Disconnect() noexcept return result; } -core_type::Result TlsSocket::Transmit(TcpMessageConstPtr tcp_message) noexcept { +core_type::Result TlsSocket::Transmit( + TcpMessageConstPtr tcp_message) noexcept { core_type::Result result{SocketError::kGenericError}; TcpErrorCodeType ec{}; - boost::asio::write(ssl_stream_, - boost::asio::buffer(tcp_message->GetPayload().data(), tcp_message->GetPayload().size()), ec); + boost::asio::write( + ssl_stream_, + boost::asio::buffer(tcp_message->GetPayload().data(), tcp_message->GetPayload().size()), ec); // Check for error if (ec.value() == boost::system::errc::success) { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug( @@ -141,8 +146,9 @@ core_type::Result TlsSocket::Transmit(TcpMessageCo result.EmplaceValue(); } else { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Tcp message sending failed with error: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Tcp message sending failed with error: " << ec.message(); + }); } return result; } @@ -162,27 +168,30 @@ core_type::Result TlsSocket::R TcpMessage::BufferType rx_buffer{}; rx_buffer.resize(message::tcp::kDoipheadrSize); // start blocking read to read Header first - boost::asio::read(ssl_stream_, boost::asio::buffer(&rx_buffer[0u], message::tcp::kDoipheadrSize), ec); + boost::asio::read(ssl_stream_, boost::asio::buffer(&rx_buffer[0u], message::tcp::kDoipheadrSize), + ec); // Check for error if (ec.value() == boost::system::errc::success) { // read the next bytes to read std::uint32_t const read_next_bytes = [&rx_buffer]() noexcept -> std::uint32_t { - return static_cast((static_cast(rx_buffer[4u] << 24u) & 0xFF000000) | - (static_cast(rx_buffer[5u] << 16u) & 0x00FF0000) | - (static_cast(rx_buffer[6u] << 8u) & 0x0000FF00) | - (static_cast(rx_buffer[7u] & 0x000000FF))); + return static_cast( + (static_cast(rx_buffer[4u] << 24u) & 0xFF000000) | + (static_cast(rx_buffer[5u] << 16u) & 0x00FF0000) | + (static_cast(rx_buffer[6u] << 8u) & 0x0000FF00) | + (static_cast(rx_buffer[7u] & 0x000000FF))); }(); if (read_next_bytes != 0u) { // reserve the buffer rx_buffer.resize(message::tcp::kDoipheadrSize + std::size_t(read_next_bytes)); - boost::asio::read(ssl_stream_, boost::asio::buffer(&rx_buffer[message::tcp::kDoipheadrSize], read_next_bytes), - ec); + boost::asio::read( + ssl_stream_, + boost::asio::buffer(&rx_buffer[message::tcp::kDoipheadrSize], read_next_bytes), ec); // all message received, transfer to upper layer Tcp::endpoint const endpoint_{GetNativeTcpSocket().remote_endpoint()}; - TcpMessagePtr tcp_rx_message{ - std::make_unique(endpoint_.address().to_string(), endpoint_.port(), std::move(rx_buffer))}; + TcpMessagePtr tcp_rx_message{std::make_unique( + endpoint_.address().to_string(), endpoint_.port(), std::move(rx_buffer))}; common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug( __FILE__, __LINE__, __func__, [endpoint_](std::stringstream &msg) { msg << "Tcp Message received from " @@ -201,13 +210,16 @@ core_type::Result TlsSocket::R [ec](std::stringstream &msg) { msg << "Remote Disconnected with: " << ec.message(); }); } else { common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Remote Disconnected with undefined error: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Remote Disconnected with undefined error: " << ec.message(); + }); } return result; } -TlsSocket::SslStream::lowest_layer_type &TlsSocket::GetNativeTcpSocket() { return ssl_stream_.lowest_layer(); } +TlsSocket::SslStream::lowest_layer_type &TlsSocket::GetNativeTcpSocket() { + return ssl_stream_.lowest_layer(); +} } // namespace tls } // namespace socket diff --git a/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_socket.h b/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_socket.h index a52ccfd1..a4fda73a 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_socket.h +++ b/diag-client-lib/lib/boost-support/src/boost-support/socket/tls/tls_socket.h @@ -70,8 +70,8 @@ class TlsSocket final { * @param[in] io_context * The I/O context required to create socket */ - TlsSocket(std::string_view local_ip_address, std::uint16_t local_port_num, TlsContext &tls_context, - IoContext &io_context) noexcept; + TlsSocket(std::string_view local_ip_address, std::uint16_t local_port_num, + TlsContext &tls_context, IoContext &io_context) noexcept; /** * @brief Constructs an instance of TcpSocket @@ -115,7 +115,8 @@ class TlsSocket final { * The host port number * @return Empty result on success otherwise error code */ - core_type::Result Connect(std::string_view host_ip_address, std::uint16_t host_port_num) noexcept; + core_type::Result Connect(std::string_view host_ip_address, + std::uint16_t host_port_num) noexcept; /** * @brief Function to Disconnect from host diff --git a/diag-client-lib/lib/boost-support/src/boost-support/socket/udp/udp_socket.cpp b/diag-client-lib/lib/boost-support/src/boost-support/socket/udp/udp_socket.cpp index 1c039aa9..74f12fed 100644 --- a/diag-client-lib/lib/boost-support/src/boost-support/socket/udp/udp_socket.cpp +++ b/diag-client-lib/lib/boost-support/src/boost-support/socket/udp/udp_socket.cpp @@ -26,7 +26,9 @@ UdpSocket::UdpSocket(std::string_view local_ip_address, std::uint16_t local_port UdpSocket::~UdpSocket() noexcept = default; -void UdpSocket::SetReadHandler(UdpSocket::UdpHandlerRead read_handler) { udp_handler_read_ = std::move(read_handler); } +void UdpSocket::SetReadHandler(UdpSocket::UdpHandlerRead read_handler) { + udp_handler_read_ = std::move(read_handler); +} core_type::Result UdpSocket::Open() noexcept { core_type::Result result{SocketError::kOpenFailed}; @@ -53,8 +55,9 @@ core_type::Result UdpSocket::Open() noexcept { // Socket binding failed result.EmplaceError(SocketError::kBindingFailed); common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [ec](std::stringstream &msg) { msg << "Udp Socket Bind failed with message: " << ec.message(); }); + __FILE__, __LINE__, __func__, [ec](std::stringstream &msg) { + msg << "Udp Socket Bind failed with message: " << ec.message(); + }); } return result; } @@ -67,7 +70,8 @@ core_type::Result UdpSocket::Transmit( // Transmit to remote endpoints std::size_t const send_size{udp_socket_.send_to( boost::asio::buffer(udp_message->GetPayload().data(), udp_message->GetPayload().size()), - Udp::endpoint{boost::asio::ip::make_address(udp_message->GetHostIpAddress()), udp_message->GetHostPortNumber()}, + Udp::endpoint{boost::asio::ip::make_address(udp_message->GetHostIpAddress()), + udp_message->GetHostPortNumber()}, {}, ec)}; // Check for error if (ec.value() == boost::system::errc::success && send_size == udp_message->GetPayload().size()) { @@ -77,7 +81,8 @@ core_type::Result UdpSocket::Transmit( msg << "Udp message sent : " << "<" << local_endpoint_.address() << "," << local_endpoint_.port() << ">" << " -> " - << "<" << udp_message->GetHostIpAddress() << "," << udp_message->GetHostPortNumber() << ">"; + << "<" << udp_message->GetHostIpAddress() << "," << udp_message->GetHostPortNumber() + << ">"; }); result.EmplaceValue(); // start async receive @@ -115,8 +120,8 @@ core_type::Result UdpSocket::Read(std::size_t total_by received_data.insert(received_data.begin(), rx_buffer_.begin(), rx_buffer_.begin() + static_cast(total_bytes_received)); - UdpMessagePtr udp_rx_message{std::make_unique(remote_endpoint_.address().to_string(), - remote_endpoint_.port(), std::move(received_data))}; + UdpMessagePtr udp_rx_message{std::make_unique( + remote_endpoint_.address().to_string(), remote_endpoint_.port(), std::move(received_data))}; common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogInfo( __FILE__, __LINE__, __func__, [this](std::stringstream &msg) { @@ -140,23 +145,24 @@ core_type::Result UdpSocket::Read(std::size_t total_by void UdpSocket::StartReceivingMessage() { // start async receive - udp_socket_.async_receive_from(boost::asio::buffer(rx_buffer_), remote_endpoint_, - [this](const UdpErrorCodeType &error, std::size_t bytes_received) { - if (error.value() == boost::system::errc::success) { - static_cast(Read(bytes_received).AndThen([this](UdpMessagePtr udp_message) { - // send data to upper layer - if (udp_handler_read_) { udp_handler_read_(std::move(udp_message)); } - return core_type::Result::FromValue(); - })); - } else { - if (error.value() != boost::asio::error::operation_aborted) { - common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, [error](std::stringstream &msg) { - msg << "Remote Disconnected with undefined error: " << error.message(); - }); - } - } - }); + udp_socket_.async_receive_from( + boost::asio::buffer(rx_buffer_), remote_endpoint_, + [this](const UdpErrorCodeType &error, std::size_t bytes_received) { + if (error.value() == boost::system::errc::success) { + static_cast(Read(bytes_received).AndThen([this](UdpMessagePtr udp_message) { + // send data to upper layer + if (udp_handler_read_) { udp_handler_read_(std::move(udp_message)); } + return core_type::Result::FromValue(); + })); + } else { + if (error.value() != boost::asio::error::operation_aborted) { + common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogError( + __FILE__, __LINE__, __func__, [error](std::stringstream &msg) { + msg << "Remote Disconnected with undefined error: " << error.message(); + }); + } + } + }); } } // namespace udp diff --git a/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_diagnostic_message_handler.cpp b/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_diagnostic_message_handler.cpp index ab20791a..9f847949 100644 --- a/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_diagnostic_message_handler.cpp +++ b/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_diagnostic_message_handler.cpp @@ -108,7 +108,8 @@ class kSendDiagnosticReqFailed final : public utility::state::State(state) {} + explicit kSendDiagnosticReqFailed(DiagnosticMessageState state) + : State(state) {} /** * @brief Function to start the current state @@ -131,7 +132,8 @@ class kWaitForDiagnosticAck final : public utility::state::State(state) {} + explicit kWaitForDiagnosticAck(DiagnosticMessageState state) + : State(state) {} /** * @brief Function to start the current state @@ -154,7 +156,8 @@ class kDiagnosticPositiveAckRecvd final : public utility::state::State(state) {} + explicit kDiagnosticPositiveAckRecvd(DiagnosticMessageState state) + : State(state) {} /** * @brief Function to start the current state @@ -177,7 +180,8 @@ class kDiagnosticNegativeAckRecvd final : public utility::state::State(state) {} + explicit kDiagnosticNegativeAckRecvd(DiagnosticMessageState state) + : State(state) {} /** * @brief Function to start the current state @@ -200,7 +204,8 @@ class kWaitForDiagnosticResponse final : public utility::state::State(state) {} + explicit kWaitForDiagnosticResponse(DiagnosticMessageState state) + : State(state) {} /** * @brief Function to start the current state @@ -298,33 +303,36 @@ class DiagnosticMessageHandler::DiagnosticMessageHandlerImpl { * @param[in] channel * The reference to doip channel */ - DiagnosticMessageHandlerImpl(sockets::TcpSocketHandler &tcp_socket_handler, DoipTcpChannel &channel) + DiagnosticMessageHandlerImpl(sockets::TcpSocketHandler &tcp_socket_handler, + DoipTcpChannel &channel) : tcp_socket_handler_{tcp_socket_handler}, channel_{channel}, state_context_{}, sync_timer_{} { // create and add state for Diagnostic State // kIdle - state_context_.AddState(DiagnosticMessageState::kIdle, std::make_unique(DiagnosticMessageState::kIdle)); + state_context_.AddState(DiagnosticMessageState::kIdle, + std::make_unique(DiagnosticMessageState::kIdle)); // kSendDiagnosticReqFailed - state_context_.AddState( - DiagnosticMessageState::kSendDiagnosticReqFailed, - std::make_unique(DiagnosticMessageState::kSendDiagnosticReqFailed)); + state_context_.AddState(DiagnosticMessageState::kSendDiagnosticReqFailed, + std::make_unique( + DiagnosticMessageState::kSendDiagnosticReqFailed)); // kWaitForDiagnosticAck - state_context_.AddState(DiagnosticMessageState::kWaitForDiagnosticAck, - std::make_unique(DiagnosticMessageState::kWaitForDiagnosticAck)); - // kDiagnosticPositiveAckRecvd state_context_.AddState( - DiagnosticMessageState::kDiagnosticPositiveAckRecvd, - std::make_unique(DiagnosticMessageState::kDiagnosticPositiveAckRecvd)); + DiagnosticMessageState::kWaitForDiagnosticAck, + std::make_unique(DiagnosticMessageState::kWaitForDiagnosticAck)); + // kDiagnosticPositiveAckRecvd + state_context_.AddState(DiagnosticMessageState::kDiagnosticPositiveAckRecvd, + std::make_unique( + DiagnosticMessageState::kDiagnosticPositiveAckRecvd)); // kDiagnosticNegativeAckRecvd - state_context_.AddState( - DiagnosticMessageState::kDiagnosticNegativeAckRecvd, - std::make_unique(DiagnosticMessageState::kDiagnosticNegativeAckRecvd)); + state_context_.AddState(DiagnosticMessageState::kDiagnosticNegativeAckRecvd, + std::make_unique( + DiagnosticMessageState::kDiagnosticNegativeAckRecvd)); // kWaitForDiagnosticResponse - state_context_.AddState( - DiagnosticMessageState::kWaitForDiagnosticResponse, - std::make_unique(DiagnosticMessageState::kWaitForDiagnosticResponse)); + state_context_.AddState(DiagnosticMessageState::kWaitForDiagnosticResponse, + std::make_unique( + DiagnosticMessageState::kWaitForDiagnosticResponse)); // Transit to idle state state_context_.TransitionTo(DiagnosticMessageState::kIdle); } @@ -407,9 +415,11 @@ void DiagnosticMessageHandler::Stop() { handler_impl_->Stop(); } void DiagnosticMessageHandler::Reset() { handler_impl_->Reset(); } -auto DiagnosticMessageHandler::ProcessDoIPDiagnosticAckMessageResponse(DoipMessage &doip_payload) noexcept -> void { +auto DiagnosticMessageHandler::ProcessDoIPDiagnosticAckMessageResponse( + DoipMessage &doip_payload) noexcept -> void { DiagnosticMessageState final_state{DiagnosticMessageState::kDiagnosticNegativeAckRecvd}; - if (handler_impl_->GetStateContext().GetActiveState().GetState() == DiagnosticMessageState::kWaitForDiagnosticAck) { + if (handler_impl_->GetStateContext().GetActiveState().GetState() == + DiagnosticMessageState::kWaitForDiagnosticAck) { // get the ack code DiagAckType const diag_ack_type{doip_payload.GetPayload()[0u]}; if (doip_payload.GetPayloadType() == kDoipDiagMessagePosAck) { @@ -426,8 +436,9 @@ auto DiagnosticMessageHandler::ProcessDoIPDiagnosticAckMessageResponse(DoipMessa } } else if (doip_payload.GetPayloadType() == kDoipDiagMessageNegAck) { logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogWarn( - __FILE__, __LINE__, __func__, - [&diag_ack_type](std::stringstream &msg) { msg << "Diagnostic request denied due to " << diag_ack_type; }); + __FILE__, __LINE__, __func__, [&diag_ack_type](std::stringstream &msg) { + msg << "Diagnostic request denied due to " << diag_ack_type; + }); } else { // do nothing } @@ -438,20 +449,24 @@ auto DiagnosticMessageHandler::ProcessDoIPDiagnosticAckMessageResponse(DoipMessa } } -auto DiagnosticMessageHandler::ProcessDoIPDiagnosticMessageResponse(DoipMessage &doip_payload) noexcept -> void { +auto DiagnosticMessageHandler::ProcessDoIPDiagnosticMessageResponse( + DoipMessage &doip_payload) noexcept -> void { if (handler_impl_->GetStateContext().GetActiveState().GetState() == DiagnosticMessageState::kWaitForDiagnosticResponse) { // Indicate upper layer about incoming data - std::pair ret_val{ - handler_impl_->GetDoipChannel().IndicateMessage( + std::pair + ret_val{handler_impl_->GetDoipChannel().IndicateMessage( doip_payload.GetServerAddress(), doip_payload.GetClientAddress(), - uds_transport::UdsMessage::TargetAddressType::kPhysical, 0U, doip_payload.GetPayload().size(), 0u, - "DoIPTcp", doip_payload.GetPayload())}; - if (ret_val.first == uds_transport::UdsTransportProtocolMgr::IndicationResult::kIndicationPending) { + uds_transport::UdsMessage::TargetAddressType::kPhysical, 0U, + doip_payload.GetPayload().size(), 0u, "DoIPTcp", doip_payload.GetPayload())}; + if (ret_val.first == + uds_transport::UdsTransportProtocolMgr::IndicationResult::kIndicationPending) { // keep channel alive since pending request received, do not change channel state } else { // Check result and udsMessagePtr - if ((ret_val.first == uds_transport::UdsTransportProtocolMgr::IndicationResult::kIndicationOk) && + if ((ret_val.first == + uds_transport::UdsTransportProtocolMgr::IndicationResult::kIndicationOk) && (ret_val.second != nullptr)) { // copy to application buffer (void) std::copy(doip_payload.GetPayload().begin(), doip_payload.GetPayload().end(), @@ -459,8 +474,9 @@ auto DiagnosticMessageHandler::ProcessDoIPDiagnosticMessageResponse(DoipMessage handler_impl_->GetDoipChannel().HandleMessage(std::move(ret_val.second)); } else { logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogVerbose( - __FILE__, __LINE__, __func__, - [](std::stringstream &msg) { msg << "Diagnostic message response ignored due to unknown error"; }); + __FILE__, __LINE__, __func__, [](std::stringstream &msg) { + msg << "Diagnostic message response ignored due to unknown error"; + }); } handler_impl_->GetStateContext().TransitionTo(DiagnosticMessageState::kIdle); } @@ -474,17 +490,20 @@ auto DiagnosticMessageHandler::ProcessDoIPDiagnosticMessageResponse(DoipMessage } } -auto DiagnosticMessageHandler::HandleDiagnosticRequest(uds_transport::UdsMessageConstPtr diagnostic_request) noexcept +auto DiagnosticMessageHandler::HandleDiagnosticRequest( + uds_transport::UdsMessageConstPtr diagnostic_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult { uds_transport::UdsTransportProtocolMgr::TransmissionResult result{ uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitFailed}; - if (handler_impl_->GetStateContext().GetActiveState().GetState() == DiagnosticMessageState::kIdle) { + if (handler_impl_->GetStateContext().GetActiveState().GetState() == + DiagnosticMessageState::kIdle) { if (SendDiagnosticRequest(std::move(diagnostic_request)) == uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitOk) { handler_impl_->GetStateContext().TransitionTo(DiagnosticMessageState::kWaitForDiagnosticAck); handler_impl_->GetSyncTimer().WaitForTimeout( [this, &result]() { - result = uds_transport::UdsTransportProtocolMgr::TransmissionResult::kNoTransmitAckReceived; + result = + uds_transport::UdsTransportProtocolMgr::TransmissionResult::kNoTransmitAckReceived; handler_impl_->GetStateContext().TransitionTo(DiagnosticMessageState::kIdle); logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogError( __FILE__, __LINE__, "", [](std::stringstream &msg) { @@ -496,15 +515,18 @@ auto DiagnosticMessageHandler::HandleDiagnosticRequest(uds_transport::UdsMessage [this, &result]() { if (handler_impl_->GetStateContext().GetActiveState().GetState() == DiagnosticMessageState::kDiagnosticPositiveAckRecvd) { - handler_impl_->GetStateContext().TransitionTo(DiagnosticMessageState::kWaitForDiagnosticResponse); + handler_impl_->GetStateContext().TransitionTo( + DiagnosticMessageState::kWaitForDiagnosticResponse); // success result = uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitOk; logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogInfo( - __FILE__, __LINE__, "", - [](std::stringstream &msg) { msg << "Diagnostic Message Positive Ack received"; }); + __FILE__, __LINE__, "", [](std::stringstream &msg) { + msg << "Diagnostic Message Positive Ack received"; + }); } else { // failed with neg acknowledgement from server - result = uds_transport::UdsTransportProtocolMgr::TransmissionResult::kNegTransmitAckReceived; + result = uds_transport::UdsTransportProtocolMgr::TransmissionResult:: + kNegTransmitAckReceived; handler_impl_->GetStateContext().TransitionTo(DiagnosticMessageState::kIdle); logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogInfo( __FILE__, __LINE__, "", [](std::stringstream &msg) { @@ -525,34 +547,41 @@ auto DiagnosticMessageHandler::HandleDiagnosticRequest(uds_transport::UdsMessage // channel not in idle state result = uds_transport::UdsTransportProtocolMgr::TransmissionResult::kBusyProcessing; logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogVerbose( - __FILE__, __LINE__, "", - [](std::stringstream &msg) { msg << "Diagnostic Message Transmission already in progress"; }); + __FILE__, __LINE__, "", [](std::stringstream &msg) { + msg << "Diagnostic Message Transmission already in progress"; + }); } return result; } -auto DiagnosticMessageHandler::SendDiagnosticRequest(uds_transport::UdsMessageConstPtr diagnostic_request) noexcept +auto DiagnosticMessageHandler::SendDiagnosticRequest( + uds_transport::UdsMessageConstPtr diagnostic_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult { uds_transport::UdsTransportProtocolMgr::TransmissionResult ret_val{ uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitFailed}; constexpr std::uint8_t kSourceAddressSize{4u}; // Create header - std::uint32_t const total_diagnostic_response_length{ - static_cast(kDoipDiagMessageReqResMinLen + diagnostic_request->GetPayload().size())}; - TcpMessage::BufferType compose_diag_req{CreateDoipGenericHeader(kDoipDiagMessage, total_diagnostic_response_length)}; + std::uint32_t const total_diagnostic_response_length{static_cast( + kDoipDiagMessageReqResMinLen + diagnostic_request->GetPayload().size())}; + TcpMessage::BufferType compose_diag_req{ + CreateDoipGenericHeader(kDoipDiagMessage, total_diagnostic_response_length)}; compose_diag_req.reserve(kDoipheadrSize + total_diagnostic_response_length); // Add source address - compose_diag_req.emplace_back(static_cast((diagnostic_request->GetSa() & 0xFF00) >> 8u)); + compose_diag_req.emplace_back( + static_cast((diagnostic_request->GetSa() & 0xFF00) >> 8u)); compose_diag_req.emplace_back(static_cast(diagnostic_request->GetSa() & 0x00FF)); // Add target address - compose_diag_req.emplace_back(static_cast((diagnostic_request->GetTa() & 0xFF00) >> 8u)); + compose_diag_req.emplace_back( + static_cast((diagnostic_request->GetTa() & 0xFF00) >> 8u)); compose_diag_req.emplace_back(static_cast(diagnostic_request->GetTa() & 0x00FF)); // Copy data bytes compose_diag_req.insert(compose_diag_req.begin() + kDoipheadrSize + kSourceAddressSize, - diagnostic_request->GetPayload().begin(), diagnostic_request->GetPayload().end()); - TcpMessagePtr doip_diag_req{std::make_unique( - diagnostic_request->GetHostIpAddress(), diagnostic_request->GetHostPortNumber(), std::move(compose_diag_req))}; + diagnostic_request->GetPayload().begin(), + diagnostic_request->GetPayload().end()); + TcpMessagePtr doip_diag_req{std::make_unique(diagnostic_request->GetHostIpAddress(), + diagnostic_request->GetHostPortNumber(), + std::move(compose_diag_req))}; // Initiate transmission if (handler_impl_->GetSocketHandler().Transmit(std::move(doip_diag_req))) { ret_val = uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitOk; diff --git a/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_routing_activation_handler.cpp b/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_routing_activation_handler.cpp index 210194a1..8301a306 100644 --- a/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_routing_activation_handler.cpp +++ b/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_routing_activation_handler.cpp @@ -104,7 +104,8 @@ class kWaitForRoutingActivationRes final : public utility::state::State(state) {} + explicit kWaitForRoutingActivationRes(RoutingActivationState state) + : State(state) {} /** * @brief Function to start the current state @@ -127,7 +128,8 @@ class kRoutingActivationSuccessful final : public utility::state::State(state) {} + explicit kRoutingActivationSuccessful(RoutingActivationState state) + : State(state) {} /** * @brief Function to start the current state @@ -150,7 +152,8 @@ class kRoutingActivationFailed final : public utility::state::State(state) {} + explicit kRoutingActivationFailed(RoutingActivationState state) + : State(state) {} /** * @brief Function to start the current state @@ -255,19 +258,20 @@ class RoutingActivationHandler::RoutingActivationHandlerImpl final { sync_timer_{} { // create and add state for routing activation // kIdle - state_context_.AddState(RoutingActivationState::kIdle, std::make_unique(RoutingActivationState::kIdle)); + state_context_.AddState(RoutingActivationState::kIdle, + std::make_unique(RoutingActivationState::kIdle)); // kWaitForRoutingActivationRes - state_context_.AddState( - RoutingActivationState::kWaitForRoutingActivationRes, - std::make_unique(RoutingActivationState::kWaitForRoutingActivationRes)); + state_context_.AddState(RoutingActivationState::kWaitForRoutingActivationRes, + std::make_unique( + RoutingActivationState::kWaitForRoutingActivationRes)); // kRoutingActivationSuccessful - state_context_.AddState( - RoutingActivationState::kRoutingActivationSuccessful, - std::make_unique(RoutingActivationState::kRoutingActivationSuccessful)); + state_context_.AddState(RoutingActivationState::kRoutingActivationSuccessful, + std::make_unique( + RoutingActivationState::kRoutingActivationSuccessful)); // kRoutingActivationFailed - state_context_.AddState( - RoutingActivationState::kRoutingActivationFailed, - std::make_unique(RoutingActivationState::kRoutingActivationFailed)); + state_context_.AddState(RoutingActivationState::kRoutingActivationFailed, + std::make_unique( + RoutingActivationState::kRoutingActivationFailed)); // Transit to idle state state_context_.TransitionTo(RoutingActivationState::kIdle); } @@ -338,7 +342,8 @@ void RoutingActivationHandler::Stop() { handler_impl_->Stop(); } void RoutingActivationHandler::Reset() { handler_impl_->Reset(); } -auto RoutingActivationHandler::ProcessDoIPRoutingActivationResponse(DoipMessage &doip_payload) noexcept -> void { +auto RoutingActivationHandler::ProcessDoIPRoutingActivationResponse( + DoipMessage &doip_payload) noexcept -> void { RoutingActivationState final_state{RoutingActivationState::kRoutingActivationFailed}; if (handler_impl_->GetStateContext().GetActiveState().GetState() == RoutingActivationState::kWaitForRoutingActivationRes) { @@ -367,8 +372,9 @@ auto RoutingActivationHandler::ProcessDoIPRoutingActivationResponse(DoipMessage default: // failure, do nothing logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogWarn( - __FILE__, __LINE__, __func__, - [&rout_act_type](std::stringstream &msg) { msg << "Routing activation denied due to " << rout_act_type; }); + __FILE__, __LINE__, __func__, [&rout_act_type](std::stringstream &msg) { + msg << "Routing activation denied due to " << rout_act_type; + }); break; } handler_impl_->GetStateContext().TransitionTo(final_state); @@ -383,11 +389,13 @@ auto RoutingActivationHandler::HandleRoutingActivationRequest( -> uds_transport::UdsTransportProtocolMgr::ConnectionResult { uds_transport::UdsTransportProtocolMgr::ConnectionResult result{ uds_transport::UdsTransportProtocolMgr::ConnectionResult::kConnectionFailed}; - if (handler_impl_->GetStateContext().GetActiveState().GetState() == RoutingActivationState::kIdle) { + if (handler_impl_->GetStateContext().GetActiveState().GetState() == + RoutingActivationState::kIdle) { if (SendRoutingActivationRequest(std::move(routing_activation_request)) == uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitOk) { // Wait for routing activation response - handler_impl_->GetStateContext().TransitionTo(RoutingActivationState::kWaitForRoutingActivationRes); + handler_impl_->GetStateContext().TransitionTo( + RoutingActivationState::kWaitForRoutingActivationRes); handler_impl_->GetSyncTimer().WaitForTimeout( [this, &result]() { result = uds_transport::UdsTransportProtocolMgr::ConnectionResult::kConnectionTimeout; @@ -405,13 +413,15 @@ auto RoutingActivationHandler::HandleRoutingActivationRequest( // success result = uds_transport::UdsTransportProtocolMgr::ConnectionResult::kConnectionOk; logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogInfo( - __FILE__, __LINE__, "", - [](std::stringstream &msg) { msg << "RoutingActivation successful with remote server"; }); + __FILE__, __LINE__, "", [](std::stringstream &msg) { + msg << "RoutingActivation successful with remote server"; + }); } else { // failed handler_impl_->GetStateContext().TransitionTo(RoutingActivationState::kIdle); logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogError( - __FILE__, __LINE__, "", - [](std::stringstream &msg) { msg << "RoutingActivation failed with remote server"; }); + __FILE__, __LINE__, "", [](std::stringstream &msg) { + msg << "RoutingActivation failed with remote server"; + }); } }, std::chrono::milliseconds{kDoIPRoutingActivationTimeout}); @@ -419,13 +429,15 @@ auto RoutingActivationHandler::HandleRoutingActivationRequest( // failed, do nothing handler_impl_->GetStateContext().TransitionTo(RoutingActivationState::kIdle); logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogError( - __FILE__, __LINE__, "", - [](std::stringstream &msg) { msg << "RoutingActivation Request send failed with remote server"; }); + __FILE__, __LINE__, "", [](std::stringstream &msg) { + msg << "RoutingActivation Request send failed with remote server"; + }); } } else { // channel not free logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogVerbose( - __FILE__, __LINE__, "", [](std::stringstream &msg) { msg << "RoutingActivation channel not free"; }); + __FILE__, __LINE__, "", + [](std::stringstream &msg) { msg << "RoutingActivation channel not free"; }); } return result; } @@ -435,7 +447,8 @@ auto RoutingActivationHandler::IsRoutingActivated() noexcept -> bool { RoutingActivationState::kRoutingActivationSuccessful); } -auto RoutingActivationHandler::SendRoutingActivationRequest(uds_transport::UdsMessageConstPtr message) noexcept +auto RoutingActivationHandler::SendRoutingActivationRequest( + uds_transport::UdsMessageConstPtr message) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult { uds_transport::UdsTransportProtocolMgr::TransmissionResult ret_val{ uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitFailed}; @@ -446,7 +459,8 @@ auto RoutingActivationHandler::SendRoutingActivationRequest(uds_transport::UdsMe compose_routing_activation_req.reserve(kDoipheadrSize + kDoipRoutingActivationReqMinLen); // Add source address - compose_routing_activation_req.emplace_back(static_cast((message->GetSa() & 0xFF00) >> 8u)); + compose_routing_activation_req.emplace_back( + static_cast((message->GetSa() & 0xFF00) >> 8u)); compose_routing_activation_req.emplace_back(static_cast(message->GetSa() & 0x00FF)); // Add activation type compose_routing_activation_req.emplace_back(kDoip_RoutingActivation_ReqActType_Default); @@ -456,8 +470,9 @@ auto RoutingActivationHandler::SendRoutingActivationRequest(uds_transport::UdsMe compose_routing_activation_req.emplace_back(0x00); compose_routing_activation_req.emplace_back(0x00); - TcpMessagePtr doip_routing_act_req{std::make_unique( - message->GetHostIpAddress(), message->GetHostPortNumber(), std::move(compose_routing_activation_req))}; + TcpMessagePtr doip_routing_act_req{ + std::make_unique(message->GetHostIpAddress(), message->GetHostPortNumber(), + std::move(compose_routing_activation_req))}; // Initiate transmission if (handler_impl_->GetSocketHandler().Transmit(std::move(doip_routing_act_req))) { ret_val = uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitOk; diff --git a/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_routing_activation_handler.h b/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_routing_activation_handler.h index 83c4437b..c4e6c0b9 100644 --- a/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_routing_activation_handler.h +++ b/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_routing_activation_handler.h @@ -81,7 +81,8 @@ class RoutingActivationHandler final { * The routing activation request * @return Transmission result */ - auto HandleRoutingActivationRequest(uds_transport::UdsMessageConstPtr routing_activation_request) noexcept + auto HandleRoutingActivationRequest( + uds_transport::UdsMessageConstPtr routing_activation_request) noexcept -> uds_transport::UdsTransportProtocolMgr::ConnectionResult; /** @@ -97,7 +98,8 @@ class RoutingActivationHandler final { * The routing activation request * @return Transmission result */ - auto SendRoutingActivationRequest(uds_transport::UdsMessageConstPtr routing_activation_request) noexcept + auto SendRoutingActivationRequest( + uds_transport::UdsMessageConstPtr routing_activation_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult; private: diff --git a/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_tcp_channel.cpp b/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_tcp_channel.cpp index c1331515..75a0d111 100644 --- a/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_tcp_channel.cpp +++ b/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_tcp_channel.cpp @@ -16,7 +16,8 @@ namespace doip_client { namespace channel { namespace tcp_channel { -DoipTcpChannel::DoipTcpChannel(TcpSocketHandler tcp_socket_handler, uds_transport::Connection &connection) +DoipTcpChannel::DoipTcpChannel(TcpSocketHandler tcp_socket_handler, + uds_transport::Connection &connection) : tcp_socket_handler_{std::move(tcp_socket_handler)}, tcp_channel_handler_{tcp_socket_handler_, *this}, connection_{connection} {} @@ -84,8 +85,9 @@ uds_transport::UdsTransportProtocolMgr::TransmissionResult DoipTcpChannel::Trans ret_val = tcp_channel_handler_.SendDiagnosticRequest(std::move(message)); } else { logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogError( - __FILE__, __LINE__, __func__, - [](std::stringstream &msg) { msg << "Routing Activation required, please connect to server first"; }); + __FILE__, __LINE__, __func__, [](std::stringstream &msg) { + msg << "Routing Activation required, please connect to server first"; + }); } return ret_val; } @@ -93,12 +95,13 @@ uds_transport::UdsTransportProtocolMgr::TransmissionResult DoipTcpChannel::Trans std::pair DoipTcpChannel::IndicateMessage(uds_transport::UdsMessage::Address source_addr, uds_transport::UdsMessage::Address target_addr, - uds_transport::UdsMessage::TargetAddressType type, uds_transport::ChannelID channel_id, - std::size_t size, uds_transport::Priority priority, + uds_transport::UdsMessage::TargetAddressType type, + uds_transport::ChannelID channel_id, std::size_t size, + uds_transport::Priority priority, uds_transport::ProtocolKind protocol_kind, core_type::Span payload_info) { - return connection_.IndicateMessage(source_addr, target_addr, type, channel_id, size, priority, protocol_kind, - payload_info); + return connection_.IndicateMessage(source_addr, target_addr, type, channel_id, size, priority, + protocol_kind, payload_info); } void DoipTcpChannel::HandleMessage(uds_transport::UdsMessagePtr message) { diff --git a/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_tcp_channel.h b/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_tcp_channel.h index 5608a2b5..27cb1a49 100644 --- a/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_tcp_channel.h +++ b/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_tcp_channel.h @@ -71,7 +71,8 @@ class DoipTcpChannel final { * The connection message * @return Connection result */ - uds_transport::UdsTransportProtocolMgr::ConnectionResult ConnectToHost(uds_transport::UdsMessageConstPtr message); + uds_transport::UdsTransportProtocolMgr::ConnectionResult ConnectToHost( + uds_transport::UdsMessageConstPtr message); /** * @brief Function to disconnect from remote host server @@ -104,18 +105,21 @@ class DoipTcpChannel final { * The pair of IndicationResult and a pointer to UdsMessage owned/created by DM core and returned * to the handler to get filled */ - std::pair IndicateMessage( - uds_transport::UdsMessage::Address source_addr, uds_transport::UdsMessage::Address target_addr, - uds_transport::UdsMessage::TargetAddressType type, uds_transport::ChannelID channel_id, std::size_t size, - uds_transport::Priority priority, uds_transport::ProtocolKind protocol_kind, - core_type::Span payload_info); + std::pair + IndicateMessage(uds_transport::UdsMessage::Address source_addr, + uds_transport::UdsMessage::Address target_addr, + uds_transport::UdsMessage::TargetAddressType type, + uds_transport::ChannelID channel_id, std::size_t size, + uds_transport::Priority priority, uds_transport::ProtocolKind protocol_kind, + core_type::Span payload_info); /** * @brief Function to transmit a valid Uds message * @param[in] message * The Uds message ptr (unique_ptr semantics) with the request. */ - uds_transport::UdsTransportProtocolMgr::TransmissionResult Transmit(uds_transport::UdsMessageConstPtr message); + uds_transport::UdsTransportProtocolMgr::TransmissionResult Transmit( + uds_transport::UdsMessageConstPtr message); /** * @brief Function to Hands over a valid received Uds message to upper layer diff --git a/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_tcp_channel_handler.cpp b/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_tcp_channel_handler.cpp index fad537a0..bc2d97e4 100644 --- a/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_tcp_channel_handler.cpp +++ b/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_tcp_channel_handler.cpp @@ -63,7 +63,8 @@ constexpr std::uint32_t kDoipRoutingActivationResMaxLen{13u}; //with OEM specif } // namespace -DoipTcpChannelHandler::DoipTcpChannelHandler(sockets::TcpSocketHandler &tcp_socket_handler, DoipTcpChannel &channel) +DoipTcpChannelHandler::DoipTcpChannelHandler(sockets::TcpSocketHandler &tcp_socket_handler, + DoipTcpChannel &channel) : routing_activation_handler_{tcp_socket_handler}, diagnostic_message_handler_{tcp_socket_handler, channel} {} @@ -85,10 +86,12 @@ void DoipTcpChannelHandler::Reset() { auto DoipTcpChannelHandler::SendRoutingActivationRequest( uds_transport::UdsMessageConstPtr routing_activation_request) noexcept -> uds_transport::UdsTransportProtocolMgr::ConnectionResult { - return routing_activation_handler_.HandleRoutingActivationRequest(std::move(routing_activation_request)); + return routing_activation_handler_.HandleRoutingActivationRequest( + std::move(routing_activation_request)); } -auto DoipTcpChannelHandler::SendDiagnosticRequest(uds_transport::UdsMessageConstPtr diagnostic_request) noexcept +auto DoipTcpChannelHandler::SendDiagnosticRequest( + uds_transport::UdsMessageConstPtr diagnostic_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult { return diagnostic_message_handler_.HandleDiagnosticRequest(std::move(diagnostic_request)); } @@ -110,13 +113,16 @@ auto DoipTcpChannelHandler::IsRoutingActivated() noexcept -> bool { return routing_activation_handler_.IsRoutingActivated(); } -auto DoipTcpChannelHandler::ProcessDoIPHeader(DoipMessage &doip_rx_message, std::uint8_t &nack_code) noexcept -> bool { +auto DoipTcpChannelHandler::ProcessDoIPHeader(DoipMessage &doip_rx_message, + std::uint8_t &nack_code) noexcept -> bool { bool ret_val = false; /* Check the header synchronisation pattern */ if (((doip_rx_message.GetProtocolVersion() == kDoip_ProtocolVersion) && - (doip_rx_message.GetInverseProtocolVersion() == static_cast(~kDoip_ProtocolVersion))) || + (doip_rx_message.GetInverseProtocolVersion() == + static_cast(~kDoip_ProtocolVersion))) || ((doip_rx_message.GetProtocolVersion() == kDoip_ProtocolVersion_Def) && - (doip_rx_message.GetInverseProtocolVersion() == static_cast(~kDoip_ProtocolVersion_Def)))) { + (doip_rx_message.GetInverseProtocolVersion() == + static_cast(~kDoip_ProtocolVersion_Def)))) { /* Check the supported payload type */ if ((doip_rx_message.GetPayloadType() == kDoip_RoutingActivation_ResType) || (doip_rx_message.GetPayloadType() == kDoipDiagMessagePosAck) || @@ -128,7 +134,8 @@ auto DoipTcpChannelHandler::ProcessDoIPHeader(DoipMessage &doip_rx_message, std: /* Req-[AUTOSAR_SWS_DiagnosticOverIP][SWS_DoIP_00018] */ if (doip_rx_message.GetPayloadLength() <= kTcpChannelLength) { /* Req-[AUTOSAR_SWS_DiagnosticOverIP][SWS_DoIP_00019] */ - if (ProcessDoIPPayloadLength(doip_rx_message.GetPayloadLength(), doip_rx_message.GetPayloadType())) { + if (ProcessDoIPPayloadLength(doip_rx_message.GetPayloadLength(), + doip_rx_message.GetPayloadType())) { ret_val = true; } else { // Send NACK code 0x04, close the socket @@ -153,8 +160,8 @@ auto DoipTcpChannelHandler::ProcessDoIPHeader(DoipMessage &doip_rx_message, std: return ret_val; } -auto DoipTcpChannelHandler::ProcessDoIPPayloadLength(std::uint32_t payload_length, std::uint16_t payload_type) noexcept - -> bool { +auto DoipTcpChannelHandler::ProcessDoIPPayloadLength(std::uint32_t payload_length, + std::uint16_t payload_type) noexcept -> bool { bool ret_val{false}; switch (payload_type) { case kDoip_RoutingActivation_ResType: { diff --git a/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_tcp_channel_handler.h b/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_tcp_channel_handler.h index ec6ce69c..ac5b3b5e 100644 --- a/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_tcp_channel_handler.h +++ b/diag-client-lib/lib/doip-client/channel/tcp_channel/doip_tcp_channel_handler.h @@ -67,7 +67,8 @@ class DoipTcpChannelHandler final { * @return ConnectionResult * The connection result */ - auto SendRoutingActivationRequest(uds_transport::UdsMessageConstPtr routing_activation_request) noexcept + auto SendRoutingActivationRequest( + uds_transport::UdsMessageConstPtr routing_activation_request) noexcept -> uds_transport::UdsTransportProtocolMgr::ConnectionResult; /** @@ -110,7 +111,8 @@ class DoipTcpChannelHandler final { * @param[in] payload_type * The type of payload */ - auto ProcessDoIPPayloadLength(std::uint32_t payload_len, std::uint16_t payload_type) noexcept -> bool; + auto ProcessDoIPPayloadLength(std::uint32_t payload_len, std::uint16_t payload_type) noexcept + -> bool; /** * @brief Function to process the doip payload diff --git a/diag-client-lib/lib/doip-client/channel/udp_channel/doip_udp_channel.cpp b/diag-client-lib/lib/doip-client/channel/udp_channel/doip_udp_channel.cpp index 2bb480a6..02eff5be 100644 --- a/diag-client-lib/lib/doip-client/channel/udp_channel/doip_udp_channel.cpp +++ b/diag-client-lib/lib/doip-client/channel/udp_channel/doip_udp_channel.cpp @@ -21,10 +21,12 @@ udp_channel::DoipUdpChannel::DoipUdpChannel(UdpSocketHandler udp_socket_handler_ connection_{connection} {} void DoipUdpChannel::Start() { - udp_socket_handler_broadcast_.SetReadHandler( - [this](UdpMessagePtr udp_message) noexcept { ProcessReceivedUdpBroadcast(std::move(udp_message)); }); - udp_socket_handler_unicast_.SetReadHandler( - [this](UdpMessagePtr udp_message) noexcept { ProcessReceivedUdpUnicast(std::move(udp_message)); }); + udp_socket_handler_broadcast_.SetReadHandler([this](UdpMessagePtr udp_message) noexcept { + ProcessReceivedUdpBroadcast(std::move(udp_message)); + }); + udp_socket_handler_unicast_.SetReadHandler([this](UdpMessagePtr udp_message) noexcept { + ProcessReceivedUdpUnicast(std::move(udp_message)); + }); udp_socket_handler_broadcast_.Initialize(); udp_socket_handler_unicast_.Initialize(); } @@ -50,12 +52,13 @@ uds_transport::UdsTransportProtocolMgr::TransmissionResult DoipUdpChannel::Trans std::pair DoipUdpChannel::IndicateMessage(uds_transport::UdsMessage::Address source_addr, uds_transport::UdsMessage::Address target_addr, - uds_transport::UdsMessage::TargetAddressType type, uds_transport::ChannelID channel_id, - std::size_t size, uds_transport::Priority priority, + uds_transport::UdsMessage::TargetAddressType type, + uds_transport::ChannelID channel_id, std::size_t size, + uds_transport::Priority priority, uds_transport::ProtocolKind protocol_kind, core_type::Span payload_info) { - return connection_.IndicateMessage(source_addr, target_addr, type, channel_id, size, priority, protocol_kind, - payload_info); + return connection_.IndicateMessage(source_addr, target_addr, type, channel_id, size, priority, + protocol_kind, payload_info); } void DoipUdpChannel::HandleMessage(uds_transport::UdsMessagePtr message) { diff --git a/diag-client-lib/lib/doip-client/channel/udp_channel/doip_udp_channel.h b/diag-client-lib/lib/doip-client/channel/udp_channel/doip_udp_channel.h index e8fbf12c..30396ec8 100644 --- a/diag-client-lib/lib/doip-client/channel/udp_channel/doip_udp_channel.h +++ b/diag-client-lib/lib/doip-client/channel/udp_channel/doip_udp_channel.h @@ -44,7 +44,8 @@ class DoipUdpChannel final { * @param[in] connection * The reference to tcp transport handler */ - DoipUdpChannel(UdpSocketHandler udp_socket_handler_broadcast, UdpSocketHandler udp_socket_handler_unicast, + DoipUdpChannel(UdpSocketHandler udp_socket_handler_broadcast, + UdpSocketHandler udp_socket_handler_unicast, uds_transport::Connection &connection); /** @@ -87,11 +88,13 @@ class DoipUdpChannel final { * The pair of IndicationResult and a pointer to UdsMessage owned/created by DM core and returned * to the handler to get filled */ - std::pair IndicateMessage( - uds_transport::UdsMessage::Address source_addr, uds_transport::UdsMessage::Address target_addr, - uds_transport::UdsMessage::TargetAddressType type, uds_transport::ChannelID channel_id, std::size_t size, - uds_transport::Priority priority, uds_transport::ProtocolKind protocol_kind, - core_type::Span payload_info); + std::pair + IndicateMessage(uds_transport::UdsMessage::Address source_addr, + uds_transport::UdsMessage::Address target_addr, + uds_transport::UdsMessage::TargetAddressType type, + uds_transport::ChannelID channel_id, std::size_t size, + uds_transport::Priority priority, uds_transport::ProtocolKind protocol_kind, + core_type::Span payload_info); /** * @brief Function to Hands over a valid received Uds message to upper layer @@ -122,7 +125,8 @@ class DoipUdpChannel final { * @param[in] message * The vehicle identification message */ - uds_transport::UdsTransportProtocolMgr::TransmissionResult Transmit(uds_transport::UdsMessageConstPtr message); + uds_transport::UdsTransportProtocolMgr::TransmissionResult Transmit( + uds_transport::UdsMessageConstPtr message); private: /** diff --git a/diag-client-lib/lib/doip-client/channel/udp_channel/doip_udp_channel_handler.cpp b/diag-client-lib/lib/doip-client/channel/udp_channel/doip_udp_channel_handler.cpp index 2b6939dc..be3bd667 100644 --- a/diag-client-lib/lib/doip-client/channel/udp_channel/doip_udp_channel_handler.cpp +++ b/diag-client-lib/lib/doip-client/channel/udp_channel/doip_udp_channel_handler.cpp @@ -27,9 +27,9 @@ constexpr std::uint8_t kDoip_GenericHeader_MessageTooLarge{0x02}; constexpr std::uint8_t kDoip_GenericHeader_OutOfMemory{0x03}; constexpr std::uint8_t kDoip_GenericHeader_InvalidPayloadLen{0x04}; -DoipUdpChannelHandler::DoipUdpChannelHandler(sockets::UdpSocketHandler &udp_socket_handler_broadcast, - sockets::UdpSocketHandler &udp_socket_handler_unicast, - DoipUdpChannel &channel) +DoipUdpChannelHandler::DoipUdpChannelHandler( + sockets::UdpSocketHandler &udp_socket_handler_broadcast, + sockets::UdpSocketHandler &udp_socket_handler_unicast, DoipUdpChannel &channel) : vehicle_discovery_handler_{udp_socket_handler_broadcast, channel}, vehicle_identification_handler_{udp_socket_handler_unicast, channel} {} @@ -44,8 +44,8 @@ auto DoipUdpChannelHandler::SendVehicleIdentificationRequest( switch (handler_type) { case 0U: // 0U -> Vehicle Identification Req - ret_val = - vehicle_identification_handler_.HandleVehicleIdentificationRequest(std::move(vehicle_identification_request)); + ret_val = vehicle_identification_handler_.HandleVehicleIdentificationRequest( + std::move(vehicle_identification_request)); break; case 1U: // 1U -> Power Mode Req @@ -80,13 +80,16 @@ auto DoipUdpChannelHandler::HandleMessageBroadcast(UdpMessagePtr udp_rx_message) } } -auto DoipUdpChannelHandler::ProcessDoIPHeader(DoipMessage &doip_rx_message, std::uint8_t &nack_code) noexcept -> bool { +auto DoipUdpChannelHandler::ProcessDoIPHeader(DoipMessage &doip_rx_message, + std::uint8_t &nack_code) noexcept -> bool { bool ret_val{false}; /* Check the header synchronisation pattern */ if (((doip_rx_message.GetProtocolVersion() == kDoip_ProtocolVersion) && - (doip_rx_message.GetInverseProtocolVersion() == static_cast(~kDoip_ProtocolVersion))) || + (doip_rx_message.GetInverseProtocolVersion() == + static_cast(~kDoip_ProtocolVersion))) || ((doip_rx_message.GetProtocolVersion() == kDoip_ProtocolVersion_Def) && - (doip_rx_message.GetInverseProtocolVersion() == static_cast(~kDoip_ProtocolVersion_Def)))) { + (doip_rx_message.GetInverseProtocolVersion() == + static_cast(~kDoip_ProtocolVersion_Def)))) { /* Check the supported payload type */ if (doip_rx_message.GetPayloadType() == kDoip_VehicleAnnouncement_ResType) { /* Req-[AUTOSAR_SWS_DiagnosticOverIP][SWS_DoIP_00017] */ @@ -94,7 +97,8 @@ auto DoipUdpChannelHandler::ProcessDoIPHeader(DoipMessage &doip_rx_message, std: /* Req-[AUTOSAR_SWS_DiagnosticOverIP][SWS_DoIP_00018] */ if (doip_rx_message.GetPayloadLength() <= kUdpChannelLength) { /* Req-[AUTOSAR_SWS_DiagnosticOverIP][SWS_DoIP_00019] */ - if (ProcessDoIPPayloadLength(doip_rx_message.GetPayloadLength(), doip_rx_message.GetPayloadType())) { + if (ProcessDoIPPayloadLength(doip_rx_message.GetPayloadLength(), + doip_rx_message.GetPayloadType())) { ret_val = true; } else { // Send NACK code 0x04, close the socket @@ -119,8 +123,8 @@ auto DoipUdpChannelHandler::ProcessDoIPHeader(DoipMessage &doip_rx_message, std: return ret_val; } -auto DoipUdpChannelHandler::ProcessDoIPPayloadLength(std::uint32_t payload_len, std::uint16_t payload_type) noexcept - -> bool { +auto DoipUdpChannelHandler::ProcessDoIPPayloadLength(std::uint32_t payload_len, + std::uint16_t payload_type) noexcept -> bool { bool ret_val{false}; switch (payload_type) { case kDoip_VehicleAnnouncement_ResType: { @@ -134,7 +138,8 @@ auto DoipUdpChannelHandler::ProcessDoIPPayloadLength(std::uint32_t payload_len, return ret_val; } -void DoipUdpChannelHandler::ProcessDoIPPayload(DoipMessage &doip_payload, DoipMessage::RxSocketType) { +void DoipUdpChannelHandler::ProcessDoIPPayload(DoipMessage &doip_payload, + DoipMessage::RxSocketType) { std::lock_guard const lck(channel_handler_lock); switch (doip_payload.GetPayloadType()) { case kDoip_VehicleAnnouncement_ResType: { diff --git a/diag-client-lib/lib/doip-client/channel/udp_channel/doip_udp_channel_handler.h b/diag-client-lib/lib/doip-client/channel/udp_channel/doip_udp_channel_handler.h index 55438594..1c9435eb 100644 --- a/diag-client-lib/lib/doip-client/channel/udp_channel/doip_udp_channel_handler.h +++ b/diag-client-lib/lib/doip-client/channel/udp_channel/doip_udp_channel_handler.h @@ -44,7 +44,8 @@ class DoipUdpChannelHandler final { * The reference to tcp transport handler */ DoipUdpChannelHandler(sockets::UdpSocketHandler &udp_socket_handler_broadcast, - sockets::UdpSocketHandler &udp_socket_handler_unicast, DoipUdpChannel &channel); + sockets::UdpSocketHandler &udp_socket_handler_unicast, + DoipUdpChannel &channel); /** * @brief Function to vehicle identification request to the connected network @@ -53,7 +54,8 @@ class DoipUdpChannelHandler final { * @return TransmissionResult * The transmission result */ - auto SendVehicleIdentificationRequest(uds_transport::UdsMessageConstPtr vehicle_identification_request) noexcept + auto SendVehicleIdentificationRequest( + uds_transport::UdsMessageConstPtr vehicle_identification_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult; /** @@ -87,15 +89,16 @@ class DoipUdpChannelHandler final { * @param[in] payload_type * The type of payload */ - static auto ProcessDoIPPayloadLength(std::uint32_t payload_len, std::uint16_t payload_type) noexcept -> bool; + static auto ProcessDoIPPayloadLength(std::uint32_t payload_len, + std::uint16_t payload_type) noexcept -> bool; /** * @brief Function to process the doip payload * @param[in] doip_payload * The reference to received payload */ - void ProcessDoIPPayload(DoipMessage &doip_payload, - DoipMessage::RxSocketType socket_type = DoipMessage::RxSocketType::kUnicast); + void ProcessDoIPPayload(DoipMessage &doip_payload, DoipMessage::RxSocketType socket_type = + DoipMessage::RxSocketType::kUnicast); /** * @brief Handler to process vehicle discovery messages diff --git a/diag-client-lib/lib/doip-client/channel/udp_channel/doip_vehicle_discovery_handler.cpp b/diag-client-lib/lib/doip-client/channel/udp_channel/doip_vehicle_discovery_handler.cpp index 74deec2c..c294dc4f 100644 --- a/diag-client-lib/lib/doip-client/channel/udp_channel/doip_vehicle_discovery_handler.cpp +++ b/diag-client-lib/lib/doip-client/channel/udp_channel/doip_vehicle_discovery_handler.cpp @@ -18,7 +18,11 @@ namespace { /** * @brief Different vehicle discovery state */ -enum class VehicleDiscoveryState : std::uint8_t { kIdle = 0U, kWaitForVehicleAnnouncement, kDoIPCtrlTimeout }; +enum class VehicleDiscoveryState : std::uint8_t { + kIdle = 0U, + kWaitForVehicleAnnouncement, + kDoIPCtrlTimeout +}; /** * @brief Class implements idle state @@ -53,7 +57,8 @@ class kWaitForVehicleAnnouncement final : public utility::state::State(state) {} + explicit kWaitForVehicleAnnouncement(VehicleDiscoveryState state) + : State(state) {} /** * @brief Function to start the current state @@ -111,14 +116,16 @@ class VehicleDiscoveryHandler::VehicleDiscoveryHandlerImpl final { state_context_{} { // create and add state for vehicle discovery // kIdle - state_context_.AddState(VehicleDiscoveryState::kIdle, std::make_unique(VehicleDiscoveryState::kIdle)); + state_context_.AddState(VehicleDiscoveryState::kIdle, + std::make_unique(VehicleDiscoveryState::kIdle)); // kWaitForVehicleAnnouncement - state_context_.AddState( - VehicleDiscoveryState::kWaitForVehicleAnnouncement, - std::make_unique(VehicleDiscoveryState::kWaitForVehicleAnnouncement)); + state_context_.AddState(VehicleDiscoveryState::kWaitForVehicleAnnouncement, + std::make_unique( + VehicleDiscoveryState::kWaitForVehicleAnnouncement)); // kDoIPCtrlTimeout - state_context_.AddState(VehicleDiscoveryState::kDoIPCtrlTimeout, - std::make_unique(VehicleDiscoveryState::kDoIPCtrlTimeout)); + state_context_.AddState( + VehicleDiscoveryState::kDoIPCtrlTimeout, + std::make_unique(VehicleDiscoveryState::kDoIPCtrlTimeout)); // Transit to wait for vehicle announcement state_context_.TransitionTo(VehicleDiscoveryState::kWaitForVehicleAnnouncement); } @@ -147,8 +154,8 @@ class VehicleDiscoveryHandler::VehicleDiscoveryHandlerImpl final { VehicleDiscoveryStateContext state_context_; }; -udp_channel::VehicleDiscoveryHandler::VehicleDiscoveryHandler(sockets::UdpSocketHandler &udp_socket_handler, - DoipUdpChannel &) +udp_channel::VehicleDiscoveryHandler::VehicleDiscoveryHandler( + sockets::UdpSocketHandler &udp_socket_handler, DoipUdpChannel &) : handler_impl_{std::make_unique(udp_socket_handler)} {} VehicleDiscoveryHandler::~VehicleDiscoveryHandler() = default; @@ -158,8 +165,9 @@ void VehicleDiscoveryHandler::ProcessVehicleAnnouncementResponse(DoipMessage &) VehicleDiscoveryState::kWaitForVehicleAnnouncement) { // Deserialize and Add to task executor logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogWarn( - __FILE__, __LINE__, __func__, - [](std::stringstream &msg) { msg << "Processing of vehicle announcement is not implemented"; }); + __FILE__, __LINE__, __func__, [](std::stringstream &msg) { + msg << "Processing of vehicle announcement is not implemented"; + }); } else { // ignore } diff --git a/diag-client-lib/lib/doip-client/channel/udp_channel/doip_vehicle_identification_handler.cpp b/diag-client-lib/lib/doip-client/channel/udp_channel/doip_vehicle_identification_handler.cpp index ce60364c..ba7042e5 100644 --- a/diag-client-lib/lib/doip-client/channel/udp_channel/doip_vehicle_identification_handler.cpp +++ b/diag-client-lib/lib/doip-client/channel/udp_channel/doip_vehicle_identification_handler.cpp @@ -60,14 +60,16 @@ class kIdle final : public utility::state::State { /** * @brief Class implements sending of vehicle identification request state */ -class kSendVehicleIdentificationReq final : public utility::state::State { +class kSendVehicleIdentificationReq final + : public utility::state::State { public: /** * @brief Constructs an instance of kSendVehicleIdentificationReq * @param[in] state * The kSendVehicleIdentificationReq state */ - explicit kSendVehicleIdentificationReq(VehicleIdentificationState state) : State(state) {} + explicit kSendVehicleIdentificationReq(VehicleIdentificationState state) + : State(state) {} /** * @brief Function to start the current state @@ -83,7 +85,8 @@ class kSendVehicleIdentificationReq final : public utility::state::State { +class kWaitForVehicleIdentificationRes final + : public utility::state::State { public: /** * @brief Constructs an instance of kWaitForVehicleIdentificationRes @@ -114,7 +117,8 @@ class kDoIPCtrlTimeout final : public utility::state::State(state) {} + explicit kDoIPCtrlTimeout(VehicleIdentificationState state) + : State(state) {} /** * @brief Function to start the current state @@ -154,7 +158,8 @@ auto CreateDoipGenericHeader(std::uint16_t payload_type, std::uint32_t payload_l * The preselection mode * @return The payload type with request type and request length */ -auto GetVehicleIdentificationPayloadType(std::uint8_t preselection_mode) noexcept -> VehiclePayloadType { +auto GetVehicleIdentificationPayloadType(std::uint8_t preselection_mode) noexcept + -> VehiclePayloadType { std::uint16_t vehicle_identification_type{0u}; std::uint8_t vehicle_identification_length{0u}; switch (preselection_mode) { @@ -186,7 +191,8 @@ class VehicleIdentificationHandler::VehicleIdentificationHandlerImpl final { /** * @brief Type alias for state context */ - using VehicleIdentificationStateContext = utility::state::StateContext; + using VehicleIdentificationStateContext = + utility::state::StateContext; /** * @brief Type alias for Sync timer @@ -198,7 +204,8 @@ class VehicleIdentificationHandler::VehicleIdentificationHandlerImpl final { * @param[in] udp_socket_handler * The reference to socket handler */ - explicit VehicleIdentificationHandlerImpl(sockets::UdpSocketHandler &udp_socket_handler, DoipUdpChannel &channel) + explicit VehicleIdentificationHandlerImpl(sockets::UdpSocketHandler &udp_socket_handler, + DoipUdpChannel &channel) : udp_socket_handler_{udp_socket_handler}, channel_{channel}, state_context_{} { @@ -207,16 +214,17 @@ class VehicleIdentificationHandler::VehicleIdentificationHandlerImpl final { state_context_.AddState(VehicleIdentificationState::kIdle, std::make_unique(VehicleIdentificationState::kIdle)); // kSendVehicleIdentificationReq - state_context_.AddState( - VehicleIdentificationState::kSendVehicleIdentificationReq, - std::make_unique(VehicleIdentificationState::kSendVehicleIdentificationReq)); + state_context_.AddState(VehicleIdentificationState::kSendVehicleIdentificationReq, + std::make_unique( + VehicleIdentificationState::kSendVehicleIdentificationReq)); // kWaitForVehicleIdentificationRes state_context_.AddState(VehicleIdentificationState::kWaitForVehicleIdentificationRes, std::make_unique( VehicleIdentificationState::kWaitForVehicleIdentificationRes)); // kDoIPCtrlTimeout - state_context_.AddState(VehicleIdentificationState::kDoIPCtrlTimeout, - std::make_unique(VehicleIdentificationState::kDoIPCtrlTimeout)); + state_context_.AddState( + VehicleIdentificationState::kDoIPCtrlTimeout, + std::make_unique(VehicleIdentificationState::kDoIPCtrlTimeout)); // Transit to idle state state_context_.TransitionTo(VehicleIdentificationState::kIdle); } @@ -267,9 +275,10 @@ class VehicleIdentificationHandler::VehicleIdentificationHandlerImpl final { SyncTimer sync_timer_; }; -VehicleIdentificationHandler::VehicleIdentificationHandler(sockets::UdpSocketHandler &udp_socket_handler, - DoipUdpChannel &channel) - : handler_impl_{std::make_unique(udp_socket_handler, channel)} {} +VehicleIdentificationHandler::VehicleIdentificationHandler( + sockets::UdpSocketHandler &udp_socket_handler, DoipUdpChannel &channel) + : handler_impl_{ + std::make_unique(udp_socket_handler, channel)} {} VehicleIdentificationHandler::~VehicleIdentificationHandler() = default; @@ -278,17 +287,20 @@ auto VehicleIdentificationHandler::HandleVehicleIdentificationRequest( -> uds_transport::UdsTransportProtocolMgr::TransmissionResult { uds_transport::UdsTransportProtocolMgr::TransmissionResult ret_val{ uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitFailed}; - if (handler_impl_->GetStateContext().GetActiveState().GetState() == VehicleIdentificationState::kIdle) { + if (handler_impl_->GetStateContext().GetActiveState().GetState() == + VehicleIdentificationState::kIdle) { // change state before sending if SendVehicleIdentificationRequest call takes more time to return and in the // same time async reception starts - handler_impl_->GetStateContext().TransitionTo(VehicleIdentificationState::kWaitForVehicleIdentificationRes); + handler_impl_->GetStateContext().TransitionTo( + VehicleIdentificationState::kWaitForVehicleIdentificationRes); if (SendVehicleIdentificationRequest(std::move(vehicle_identification_request)) == uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitOk) { ret_val = uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitOk; // Wait for 2 sec to collect all the vehicle identification response handler_impl_->GetSyncTimer().WaitForTimeout( [&]() { - handler_impl_->GetStateContext().TransitionTo(VehicleIdentificationState::kDoIPCtrlTimeout); + handler_impl_->GetStateContext().TransitionTo( + VehicleIdentificationState::kDoIPCtrlTimeout); // Todo: Send data to upper layer here }, [&]() { @@ -300,8 +312,9 @@ auto VehicleIdentificationHandler::HandleVehicleIdentificationRequest( // failed, do nothing handler_impl_->GetStateContext().TransitionTo(VehicleIdentificationState::kIdle); logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogError( - __FILE__, __LINE__, "", - [](std::stringstream &msg) { msg << "Vehicle Identification request transmission Failed"; }); + __FILE__, __LINE__, "", [](std::stringstream &msg) { + msg << "Vehicle Identification request transmission Failed"; + }); } } else { // not free, state already in idle state @@ -309,21 +322,26 @@ auto VehicleIdentificationHandler::HandleVehicleIdentificationRequest( return ret_val; } -void VehicleIdentificationHandler::ProcessVehicleIdentificationResponse(DoipMessage &doip_payload) noexcept { +void VehicleIdentificationHandler::ProcessVehicleIdentificationResponse( + DoipMessage &doip_payload) noexcept { if (handler_impl_->GetStateContext().GetActiveState().GetState() == VehicleIdentificationState::kWaitForVehicleIdentificationRes) { // Deserialize data to indicate to upper layer - std::pair ret_val{ - handler_impl_->GetDoipChannel().IndicateMessage( - static_cast(0U), static_cast(0U), - uds_transport::UdsMessage::TargetAddressType::kPhysical, 0U, doip_payload.GetPayload().size(), 0U, - "DoIPUdp", doip_payload.GetPayload())}; - if ((ret_val.first == uds_transport::UdsTransportProtocolMgr::IndicationResult::kIndicationOk) && + std::pair + ret_val{handler_impl_->GetDoipChannel().IndicateMessage( + static_cast(0U), + static_cast(0U), + uds_transport::UdsMessage::TargetAddressType::kPhysical, 0U, + doip_payload.GetPayload().size(), 0U, "DoIPUdp", doip_payload.GetPayload())}; + if ((ret_val.first == + uds_transport::UdsTransportProtocolMgr::IndicationResult::kIndicationOk) && (ret_val.second != nullptr)) { // Add meta info about ip address uds_transport::UdsMessage::MetaInfoMap meta_info_map{ {"kRemoteIpAddress", std::string{doip_payload.GetHostIpAddress()}}}; - ret_val.second->AddMetaInfo(std::make_shared(meta_info_map)); + ret_val.second->AddMetaInfo( + std::make_shared(meta_info_map)); // copy to application buffer (void) std::copy(doip_payload.GetPayload().begin(), doip_payload.GetPayload().end(), ret_val.second->GetPayload().begin()); @@ -342,21 +360,24 @@ auto VehicleIdentificationHandler::SendVehicleIdentificationRequest( // Get preselection mode std::uint8_t const preselection_mode{vehicle_identification_request->GetPayload()[1u]}; // Get the payload type & length from preselection mode - VehiclePayloadType const doip_vehicle_payload_type{GetVehicleIdentificationPayloadType(preselection_mode)}; + VehiclePayloadType const doip_vehicle_payload_type{ + GetVehicleIdentificationPayloadType(preselection_mode)}; // create header UdpMessage::BufferType compose_vehicle_identification_req{ CreateDoipGenericHeader(doip_vehicle_payload_type.first, doip_vehicle_payload_type.second)}; // Copy only if containing VIN / EID if (doip_vehicle_payload_type.first != kDoip_VehicleIdentification_ReqType) { - compose_vehicle_identification_req.insert(compose_vehicle_identification_req.begin() + kDoipheadrSize, - vehicle_identification_request->GetPayload().begin() + 2U, - vehicle_identification_request->GetPayload().end()); + compose_vehicle_identification_req.insert( + compose_vehicle_identification_req.begin() + kDoipheadrSize, + vehicle_identification_request->GetPayload().begin() + 2U, + vehicle_identification_request->GetPayload().end()); } - UdpMessagePtr doip_vehicle_identification_req{std::make_unique( - vehicle_identification_request->GetHostIpAddress(), vehicle_identification_request->GetHostPortNumber(), - std::move(compose_vehicle_identification_req))}; + UdpMessagePtr doip_vehicle_identification_req{ + std::make_unique(vehicle_identification_request->GetHostIpAddress(), + vehicle_identification_request->GetHostPortNumber(), + std::move(compose_vehicle_identification_req))}; if (handler_impl_->GetSocketHandler().Transmit(std::move(doip_vehicle_identification_req))) { ret_val = uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitOk; } diff --git a/diag-client-lib/lib/doip-client/channel/udp_channel/doip_vehicle_identification_handler.h b/diag-client-lib/lib/doip-client/channel/udp_channel/doip_vehicle_identification_handler.h index 959c9778..c4cfe878 100644 --- a/diag-client-lib/lib/doip-client/channel/udp_channel/doip_vehicle_identification_handler.h +++ b/diag-client-lib/lib/doip-client/channel/udp_channel/doip_vehicle_identification_handler.h @@ -43,7 +43,8 @@ class VehicleIdentificationHandler final { * @param[in] channel * The reference to doip udp channel */ - VehicleIdentificationHandler(sockets::UdpSocketHandler &udp_socket_handler, DoipUdpChannel &channel); + VehicleIdentificationHandler(sockets::UdpSocketHandler &udp_socket_handler, + DoipUdpChannel &channel); /** * @brief Destruct an instance of VehicleIdentificationHandler @@ -56,7 +57,8 @@ class VehicleIdentificationHandler final { * The vehicle identification request * @return Transmission result */ - auto HandleVehicleIdentificationRequest(uds_transport::UdsMessageConstPtr vehicle_identification_request) noexcept + auto HandleVehicleIdentificationRequest( + uds_transport::UdsMessageConstPtr vehicle_identification_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult; /** @@ -73,7 +75,8 @@ class VehicleIdentificationHandler final { * The vehicle identification request * @return Transmission result */ - auto SendVehicleIdentificationRequest(uds_transport::UdsMessageConstPtr vehicle_identification_request) noexcept + auto SendVehicleIdentificationRequest( + uds_transport::UdsMessageConstPtr vehicle_identification_request) noexcept -> uds_transport::UdsTransportProtocolMgr::TransmissionResult; private: diff --git a/diag-client-lib/lib/doip-client/common/doip_message.cpp b/diag-client-lib/lib/doip-client/common/doip_message.cpp index 145adee7..86e66359 100644 --- a/diag-client-lib/lib/doip-client/common/doip_message.cpp +++ b/diag-client-lib/lib/doip-client/common/doip_message.cpp @@ -28,7 +28,8 @@ auto ConvertToAddr(core_type::Span payload) noexcept -> std: } // namespace DoipMessage::DoipMessage(MessageType message_type, DoipMessage::IpAddressType host_ip_address, - std::uint16_t host_port_number, core_type::Span payload) + std::uint16_t host_port_number, + core_type::Span payload) : host_ip_address_{host_ip_address}, host_port_number_{host_port_number}, protocol_version_{payload[0u]}, @@ -40,15 +41,19 @@ DoipMessage::DoipMessage(MessageType message_type, DoipMessage::IpAddressType ho constexpr std::uint8_t kDoipHeaderSize{8u}; constexpr std::uint8_t kSourceAddressSize{4u}; if (message_type == MessageType::kTcp) { - payload_ = core_type::Span{&payload[kDoipHeaderSize + kSourceAddressSize], - payload.size() - (kDoipHeaderSize + kSourceAddressSize)}; + payload_ = core_type::Span{ + &payload[kDoipHeaderSize + kSourceAddressSize], + payload.size() - (kDoipHeaderSize + kSourceAddressSize)}; } else { - payload_ = core_type::Span{&payload[kDoipHeaderSize], payload.size() - kDoipHeaderSize}; + payload_ = core_type::Span{&payload[kDoipHeaderSize], + payload.size() - kDoipHeaderSize}; } if (message_type == MessageType::kTcp) { - client_address_ = ConvertToAddr(core_type::Span{&payload[kDoipHeaderSize], 2u}); - server_address_ = ConvertToAddr(core_type::Span{&payload[kDoipHeaderSize + 2u], 2u}); + client_address_ = + ConvertToAddr(core_type::Span{&payload[kDoipHeaderSize], 2u}); + server_address_ = + ConvertToAddr(core_type::Span{&payload[kDoipHeaderSize + 2u], 2u}); } // no client } diff --git a/diag-client-lib/lib/doip-client/common/doip_message.h b/diag-client-lib/lib/doip-client/common/doip_message.h index 538115e7..a91eb7b7 100644 --- a/diag-client-lib/lib/doip-client/common/doip_message.h +++ b/diag-client-lib/lib/doip-client/common/doip_message.h @@ -47,8 +47,8 @@ class DoipMessage final { * @param[in] payload * The received data payload */ - DoipMessage(MessageType message_type, IpAddressType host_ip_address, std::uint16_t host_port_number, - core_type::Span payload); + DoipMessage(MessageType message_type, IpAddressType host_ip_address, + std::uint16_t host_port_number, core_type::Span payload); /** * @brief Default copy assignment, copy constructor, move assignment and move constructor diff --git a/diag-client-lib/lib/doip-client/connection/connection_manager.cpp b/diag-client-lib/lib/doip-client/connection/connection_manager.cpp index 15595ec8..4aa2ee30 100644 --- a/diag-client-lib/lib/doip-client/connection/connection_manager.cpp +++ b/diag-client-lib/lib/doip-client/connection/connection_manager.cpp @@ -42,8 +42,8 @@ class DoipTcpConnection final : public uds_transport::Connection { * @param[in] io_context * The reference to io context */ - DoipTcpConnection(uds_transport::ConversionHandler const &conversation_handler, std::string_view tcp_ip_address, - std::uint16_t port_num) + DoipTcpConnection(uds_transport::ConversionHandler const &conversation_handler, + std::string_view tcp_ip_address, std::uint16_t port_num) : uds_transport::Connection{1u, conversation_handler}, doip_tcp_channel_{sockets::TcpSocketHandler{TcpClient{tcp_ip_address, port_num}}, *this} {} @@ -118,13 +118,15 @@ class DoipTcpConnection final : public uds_transport::Connection { * The pair of IndicationResult and a pointer to UdsMessage owned/created by DM core and returned * to the handler to get filled */ - std::pair IndicateMessage( - uds_transport::UdsMessage::Address source_addr, uds_transport::UdsMessage::Address target_addr, - uds_transport::UdsMessage::TargetAddressType type, uds_transport::ChannelID channel_id, std::size_t size, - uds_transport::Priority priority, uds_transport::ProtocolKind protocol_kind, - core_type::Span payload_info) override { - return (conversation_handler_.IndicateMessage(source_addr, target_addr, type, channel_id, size, priority, - protocol_kind, payload_info)); + std::pair + IndicateMessage(uds_transport::UdsMessage::Address source_addr, + uds_transport::UdsMessage::Address target_addr, + uds_transport::UdsMessage::TargetAddressType type, + uds_transport::ChannelID channel_id, std::size_t size, + uds_transport::Priority priority, uds_transport::ProtocolKind protocol_kind, + core_type::Span payload_info) override { + return (conversation_handler_.IndicateMessage(source_addr, target_addr, type, channel_id, size, + priority, protocol_kind, payload_info)); } /** @@ -178,8 +180,8 @@ class DoipUdpConnection final : public uds_transport::Connection { * @param[in] port_num * The local port number */ - DoipUdpConnection(uds_transport::ConversionHandler const &conversation_handler, std::string_view udp_ip_address, - std::uint16_t port_num) + DoipUdpConnection(uds_transport::ConversionHandler const &conversation_handler, + std::string_view udp_ip_address, std::uint16_t port_num) : uds_transport::Connection(1, conversation_handler), doip_udp_channel_{sockets::UdpSocketHandler{UdpClient{udp_ip_address, port_num}}, sockets::UdpSocketHandler{UdpClient{udp_ip_address, port_num}}, *this} {} @@ -217,7 +219,8 @@ class DoipUdpConnection final : public uds_transport::Connection { * The connection message * @return Connection result */ - uds_transport::UdsTransportProtocolMgr::ConnectionResult ConnectToHost(uds_transport::UdsMessageConstPtr) override { + uds_transport::UdsTransportProtocolMgr::ConnectionResult ConnectToHost( + uds_transport::UdsMessageConstPtr) override { return (uds_transport::UdsTransportProtocolMgr::ConnectionResult::kConnectionFailed); } @@ -254,14 +257,16 @@ class DoipUdpConnection final : public uds_transport::Connection { * The pair of IndicationResult and a pointer to UdsMessage owned/created by DM core and returned * to the handler to get filled */ - std::pair IndicateMessage( - uds_transport::UdsMessage::Address source_addr, uds_transport::UdsMessage::Address target_addr, - uds_transport::UdsMessage::TargetAddressType type, uds_transport::ChannelID channel_id, std::size_t size, - uds_transport::Priority priority, uds_transport::ProtocolKind protocol_kind, - core_type::Span payload_info) override { + std::pair + IndicateMessage(uds_transport::UdsMessage::Address source_addr, + uds_transport::UdsMessage::Address target_addr, + uds_transport::UdsMessage::TargetAddressType type, + uds_transport::ChannelID channel_id, std::size_t size, + uds_transport::Priority priority, uds_transport::ProtocolKind protocol_kind, + core_type::Span payload_info) override { // Send Indication to conversion - return (conversation_handler_.IndicateMessage(source_addr, target_addr, type, channel_id, size, priority, - protocol_kind, payload_info)); + return (conversation_handler_.IndicateMessage(source_addr, target_addr, type, channel_id, size, + priority, protocol_kind, payload_info)); } /** @@ -295,12 +300,14 @@ class DoipUdpConnection final : public uds_transport::Connection { ConnectionManager::ConnectionManager() noexcept : io_context_{} {} std::unique_ptr ConnectionManager::CreateTcpConnection( - uds_transport::ConversionHandler const &conversation, std::string_view tcp_ip_address, std::uint16_t port_num) { + uds_transport::ConversionHandler const &conversation, std::string_view tcp_ip_address, + std::uint16_t port_num) { return std::make_unique(conversation, tcp_ip_address, port_num); } std::unique_ptr ConnectionManager::CreateUdpConnection( - uds_transport::ConversionHandler const &conversation, std::string_view udp_ip_address, std::uint16_t port_num) { + uds_transport::ConversionHandler const &conversation, std::string_view udp_ip_address, + std::uint16_t port_num) { return std::make_unique(conversation, udp_ip_address, port_num); } diff --git a/diag-client-lib/lib/doip-client/connection/connection_manager.h b/diag-client-lib/lib/doip-client/connection/connection_manager.h index 40238ea6..ec2825b3 100644 --- a/diag-client-lib/lib/doip-client/connection/connection_manager.h +++ b/diag-client-lib/lib/doip-client/connection/connection_manager.h @@ -48,9 +48,9 @@ class ConnectionManager final { * The local port number * @return The unique pointer to tcp connection created */ - std::unique_ptr CreateTcpConnection(uds_transport::ConversionHandler const &conversation, - std::string_view tcp_ip_address, - std::uint16_t port_num); + std::unique_ptr CreateTcpConnection( + uds_transport::ConversionHandler const &conversation, std::string_view tcp_ip_address, + std::uint16_t port_num); /** * @brief Function to find or create a new Udp connection @@ -62,9 +62,9 @@ class ConnectionManager final { * The local port number * @return The unique pointer to udp connection created */ - std::unique_ptr CreateUdpConnection(uds_transport::ConversionHandler const &conversation, - std::string_view udp_ip_address, - std::uint16_t port_num); + std::unique_ptr CreateUdpConnection( + uds_transport::ConversionHandler const &conversation, std::string_view udp_ip_address, + std::uint16_t port_num); private: /** diff --git a/diag-client-lib/lib/doip-client/doip_transport_protocol_handler.cpp b/diag-client-lib/lib/doip-client/doip_transport_protocol_handler.cpp index 82ce134d..7335679f 100644 --- a/diag-client-lib/lib/doip-client/doip_transport_protocol_handler.cpp +++ b/diag-client-lib/lib/doip-client/doip_transport_protocol_handler.cpp @@ -29,7 +29,8 @@ void DoipTransportProtocolHandler::Start() {} void DoipTransportProtocolHandler::Stop() {} std::unique_ptr DoipTransportProtocolHandler::CreateTcpConnection( - uds_transport::ConversionHandler &conversation, std::string_view tcp_ip_address, std::uint16_t port_num) { + uds_transport::ConversionHandler &conversation, std::string_view tcp_ip_address, + std::uint16_t port_num) { logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogInfo( __FILE__, __LINE__, __func__, [tcp_ip_address](std::stringstream &msg) { msg << "DoIP Tcp protocol requested with local endpoint : " @@ -39,7 +40,8 @@ std::unique_ptr DoipTransportProtocolHandler::CreateT } std::unique_ptr DoipTransportProtocolHandler::CreateUdpConnection( - uds_transport::ConversionHandler &conversation, std::string_view udp_ip_address, std::uint16_t port_num) { + uds_transport::ConversionHandler &conversation, std::string_view udp_ip_address, + std::uint16_t port_num) { logger::DoipClientLogger::GetDiagClientLogger().GetLogger().LogInfo( __FILE__, __LINE__, __func__, [udp_ip_address](std::stringstream &msg) { msg << "DoIP Udp protocol requested with local endpoint : " diff --git a/diag-client-lib/lib/doip-client/doip_transport_protocol_handler.h b/diag-client-lib/lib/doip-client/doip_transport_protocol_handler.h index c7885f33..39a2d0b4 100644 --- a/diag-client-lib/lib/doip-client/doip_transport_protocol_handler.h +++ b/diag-client-lib/lib/doip-client/doip_transport_protocol_handler.h @@ -27,7 +27,8 @@ class DoipTransportProtocolHandler final : public uds_transport::UdsTransportPro /** * @brief Type alias for handler id */ - using UdsTransportProtocolHandlerId = uds_transport::UdsTransportProtocolHandler::UdsTransportProtocolHandlerId; + using UdsTransportProtocolHandlerId = + uds_transport::UdsTransportProtocolHandler::UdsTransportProtocolHandlerId; /** * @brief Type alias for Initialization result @@ -41,8 +42,9 @@ class DoipTransportProtocolHandler final : public uds_transport::UdsTransportPro * @param[in] transport_protocol_mgr * The reference to transport protocol manager */ - DoipTransportProtocolHandler(UdsTransportProtocolHandlerId handler_id, - uds_transport::UdsTransportProtocolMgr const &transport_protocol_mgr); + DoipTransportProtocolHandler( + UdsTransportProtocolHandlerId handler_id, + uds_transport::UdsTransportProtocolMgr const &transport_protocol_mgr); /** * @brief Destruct an instance of DoipTransportProtocolHandler @@ -75,9 +77,9 @@ class DoipTransportProtocolHandler final : public uds_transport::UdsTransportPro * The local port number * @return The unique pointer to the connection created */ - std::unique_ptr CreateTcpConnection(uds_transport::ConversionHandler &conversation, - std::string_view tcp_ip_address, - std::uint16_t port_num) override; + std::unique_ptr CreateTcpConnection( + uds_transport::ConversionHandler &conversation, std::string_view tcp_ip_address, + std::uint16_t port_num) override; /** * @brief Function to create a new Udp connection @@ -89,9 +91,9 @@ class DoipTransportProtocolHandler final : public uds_transport::UdsTransportPro * The local port number * @return The unique pointer to the connection created */ - std::unique_ptr CreateUdpConnection(uds_transport::ConversionHandler &conversation, - std::string_view udp_ip_address, - std::uint16_t port_num) override; + std::unique_ptr CreateUdpConnection( + uds_transport::ConversionHandler &conversation, std::string_view udp_ip_address, + std::uint16_t port_num) override; private: /** diff --git a/diag-client-lib/lib/doip-client/error_domain/doip_error_domain.cpp b/diag-client-lib/lib/doip-client/error_domain/doip_error_domain.cpp index e75b7f14..ee551677 100644 --- a/diag-client-lib/lib/doip-client/error_domain/doip_error_domain.cpp +++ b/diag-client-lib/lib/doip-client/error_domain/doip_error_domain.cpp @@ -58,7 +58,8 @@ const char* DoipErrorDomain::Message(core_type::ErrorDomain::CodeType error_code return message_.c_str(); } -core_type::ErrorCode MakeErrorCode(DoipErrorErrc, core_type::ErrorDomain::SupportDataType data) noexcept { +core_type::ErrorCode MakeErrorCode(DoipErrorErrc, + core_type::ErrorDomain::SupportDataType data) noexcept { return core_type::ErrorCode{data, doip_error_domain}; } diff --git a/diag-client-lib/lib/doip-client/error_domain/doip_error_domain.h b/diag-client-lib/lib/doip-client/error_domain/doip_error_domain.h index 321d70a4..2e4b7707 100644 --- a/diag-client-lib/lib/doip-client/error_domain/doip_error_domain.h +++ b/diag-client-lib/lib/doip-client/error_domain/doip_error_domain.h @@ -83,8 +83,9 @@ class DoipErrorDomain final : public core_type::ErrorDomain { * @return ErrorCode * A new ErrorCode instance */ -core_type::ErrorCode MakeErrorCode(DoipErrorErrc code, core_type::ErrorDomain::SupportDataType data = - core_type::ErrorDomain::SupportDataType{}) noexcept; +core_type::ErrorCode MakeErrorCode(DoipErrorErrc code, + core_type::ErrorDomain::SupportDataType data = + core_type::ErrorDomain::SupportDataType{}) noexcept; } // namespace error_domain } // namespace doip_client diff --git a/diag-client-lib/lib/doip-client/sockets/socket_handler.h b/diag-client-lib/lib/doip-client/sockets/socket_handler.h index 3af48a29..f8dfdf74 100644 --- a/diag-client-lib/lib/doip-client/sockets/socket_handler.h +++ b/diag-client-lib/lib/doip-client/sockets/socket_handler.h @@ -98,7 +98,8 @@ class SocketHandler final { * The host port number * @return Empty void on success, otherwise error is returned */ - core_type::Result ConnectToHost(std::string_view host_ip_address, std::uint16_t host_port_num) { + core_type::Result ConnectToHost(std::string_view host_ip_address, + std::uint16_t host_port_num) { return client_.ConnectToHost(host_ip_address, host_port_num); } @@ -120,7 +121,9 @@ class SocketHandler final { * The message to be sent * @return Empty void on success, otherwise error is returned */ - core_type::Result Transmit(MessageConstPtr message) { return client_.Transmit(std::move(message)); } + core_type::Result Transmit(MessageConstPtr message) { + return client_.Transmit(std::move(message)); + } private: /** diff --git a/diag-client-lib/lib/platform-core/core/include/error_code.h b/diag-client-lib/lib/platform-core/core/include/error_code.h index 0610c0d3..6f203fc2 100644 --- a/diag-client-lib/lib/platform-core/core/include/error_code.h +++ b/diag-client-lib/lib/platform-core/core/include/error_code.h @@ -32,7 +32,8 @@ class ErrorCode final { * Optional vendor-specific supplementary error context data */ template - explicit ErrorCode(EnumT e, ErrorDomain::SupportDataType data = ErrorDomain::SupportDataType{}) noexcept; + explicit ErrorCode(EnumT e, + ErrorDomain::SupportDataType data = ErrorDomain::SupportDataType{}) noexcept; /** * @brief Construct a new ErrorCode instance with parameters diff --git a/diag-client-lib/lib/platform-core/core/include/result.h b/diag-client-lib/lib/platform-core/core/include/result.h index 0246803f..6378dbb7 100644 --- a/diag-client-lib/lib/platform-core/core/include/result.h +++ b/diag-client-lib/lib/platform-core/core/include/result.h @@ -157,8 +157,8 @@ class Result final { * @param[in] other * The other instance */ - Result(Result &&other) noexcept( - std::is_nothrow_move_constructible::value &&std::is_nothrow_move_constructible::value) = default; + Result(Result &&other) noexcept(std::is_nothrow_move_constructible::value + &&std::is_nothrow_move_constructible::value) = default; /** * @brief Move-assign another Result to this instance @@ -169,7 +169,8 @@ class Result final { */ Result &operator=(Result &&other) noexcept( std::is_nothrow_move_constructible::value &&std::is_nothrow_move_assignable::value - &&std::is_nothrow_move_constructible::value &&std::is_nothrow_move_assignable::value) = default; + &&std::is_nothrow_move_constructible::value + &&std::is_nothrow_move_assignable::value) = default; /** * @brief Destruct an instance of Result @@ -326,7 +327,8 @@ class Result final { */ template> auto AndThen(F &&fn) &&noexcept -> R2 { - return HasValue() ? std::forward(fn)(std::move(*this).Value()) : R2{std::move(*this).Error()}; + return HasValue() ? std::forward(fn)(std::move(*this).Value()) + : R2{std::move(*this).Error()}; } /** @@ -341,7 +343,8 @@ class Result final { */ template> Result MapError(F &&fn) { - return HasValue() ? Result{std::move(*this).Value()} : Result{fn(std::move(*this).Error())}; + return HasValue() ? Result{std::move(*this).Value()} + : Result{fn(std::move(*this).Error())}; } /** @@ -554,7 +557,8 @@ class Result final { * *this, containing the contents of other */ Result &operator=(Result &&other) noexcept( - std::is_nothrow_move_constructible::value &&std::is_nothrow_move_assignable::value) = default; + std::is_nothrow_move_constructible::value &&std::is_nothrow_move_assignable::value) = + default; /** * @brief Destruct an instance of Result diff --git a/diag-client-lib/lib/platform-core/core/include/span.h b/diag-client-lib/lib/platform-core/core/include/span.h index 70f70f0e..5a353284 100644 --- a/diag-client-lib/lib/platform-core/core/include/span.h +++ b/diag-client-lib/lib/platform-core/core/include/span.h @@ -43,7 +43,8 @@ namespace details { * @param[in] message * The message to output when violated */ -inline void CheckIfExpectedOrAbort(bool cond, const char *message, const std::string_view file_name, int line_no) { +inline void CheckIfExpectedOrAbort(bool cond, const char *message, const std::string_view file_name, + int line_no) { if (!cond) { std::cerr << message << " [" << file_name << ":" << line_no << "]" << std::endl; std::abort(); @@ -102,8 +103,8 @@ struct is_data_size_valid : std::false_type {}; * The element type */ template -struct is_data_size_valid())), decltype(std::size(std::declval()))>> +struct is_data_size_valid< + T, std::void_t())), decltype(std::size(std::declval()))>> : std::true_type {}; /** @@ -139,8 +140,8 @@ struct is_container_element_type_convertible : std::false_type {}; template struct is_container_element_type_convertible< F, T, - typename std::enable_if< - std::is_convertible()))> (*)[], T (*)[]>::value>::type> + typename std::enable_if()))> (*)[], T (*)[]>::value>::type> : std::true_type {}; /** @@ -188,7 +189,8 @@ struct span_storage { */ template class Span final { - static_assert(!std::is_abstract::value, "A span's element type cannot be an abstract class type"); + static_assert(!std::is_abstract::value, + "A span's element type cannot be an abstract class type"); public: /** @@ -262,7 +264,8 @@ class Span final { * @brief Default constructor * @details This constructor shall not participate in overload resolution unless (Extent == dynamic_extent || Extent == 0) is true */ - template::type = true> + template::type = true> constexpr Span() noexcept {} /** @@ -275,7 +278,8 @@ class Span final { * The number of elements to take from ptr */ constexpr Span(pointer ptr, size_type count) : storage_{ptr, count} { - details::CheckIfExpectedOrAbort(Extent == dynamic_extent || count == Extent, "Invalid range", __FILE__, __LINE__); + details::CheckIfExpectedOrAbort(Extent == dynamic_extent || count == Extent, "Invalid range", + __FILE__, __LINE__); } /** @@ -287,9 +291,10 @@ class Span final { * @param[in] last_elem * The pointer to past the last element */ - constexpr Span(pointer first_elem, pointer last_elem) : storage_{first_elem, last_elem - first_elem} { - details::CheckIfExpectedOrAbort(Extent == dynamic_extent || (last_elem - first_elem) == Extent, "Invalid range", - __FILE__, __LINE__); + constexpr Span(pointer first_elem, pointer last_elem) + : storage_{first_elem, last_elem - first_elem} { + details::CheckIfExpectedOrAbort(Extent == dynamic_extent || (last_elem - first_elem) == Extent, + "Invalid range", __FILE__, __LINE__); } /** @@ -302,9 +307,10 @@ class Span final { * The raw array */ template::value, - bool>::type = true> + typename std::enable_if< + (E == dynamic_extent || N == extent) && + details::is_container_element_type_convertible::value, + bool>::type = true> constexpr explicit Span(element_type (&arr)[N]) noexcept : storage_{arr, N} {} /** @@ -319,9 +325,10 @@ class Span final { * The std::array */ template &, T>::value, - bool>::type = true> + typename std::enable_if< + (E == dynamic_extent || N == extent) && + details::is_container_element_type_convertible &, T>::value, + bool>::type = true> constexpr explicit Span(std::array &arr) noexcept : storage_{arr.data(), N} {} /** @@ -335,11 +342,11 @@ class Span final { * @param[in] arr * The std::array */ - template< - typename U, std::size_t N, std::size_t E = Extent, - typename std::enable_if<(E == dynamic_extent || N == extent) && - details::is_container_element_type_convertible &, T>::value, - bool>::type = true> + template &, T>::value, + bool>::type = true> constexpr explicit Span(const std::array &arr) noexcept : storage_{arr.data(), N} {} /** @@ -355,9 +362,10 @@ class Span final { * The container */ template::value && - details::is_container_element_type_convertible::value, - bool>::type = true> + typename std::enable_if< + (E == dynamic_extent) && details::is_container_type::value && + details::is_container_element_type_convertible::value, + bool>::type = true> constexpr explicit Span(Container &cont) noexcept : storage_{std::data(cont), std::size(cont)} {} /** @@ -373,10 +381,12 @@ class Span final { * The container */ template::value && - details::is_container_element_type_convertible::value, - bool>::type = true> - constexpr explicit Span(const Container &cont) noexcept : storage_{std::data(cont), std::size(cont)} {} + typename std::enable_if< + (E == dynamic_extent) && details::is_container_type::value && + details::is_container_element_type_convertible::value, + bool>::type = true> + constexpr explicit Span(const Container &cont) noexcept + : storage_{std::data(cont), std::size(cont)} {} /** * @brief Copy construct a new Span from another instance @@ -397,9 +407,11 @@ class Span final { */ template< typename U, std::size_t N, - typename std::enable_if<(Extent == dynamic_extent || N == dynamic_extent || Extent == N) && - details::is_container_element_type_convertible::value>::type = true> - constexpr explicit Span(const Span &other_span) noexcept : storage_{other_span.data(), other_span.size()} {} + typename std::enable_if< + (Extent == dynamic_extent || N == dynamic_extent || Extent == N) && + details::is_container_element_type_convertible::value>::type = true> + constexpr explicit Span(const Span &other_span) noexcept + : storage_{other_span.data(), other_span.size()} {} /** * @brief Destructor @@ -477,12 +489,14 @@ class Span final { */ template constexpr auto subspan() const noexcept - -> Span { - details::CheckIfExpectedOrAbort((Offset <= size() && (Count == dynamic_extent || Count <= size() - Offset)), - "(Offset <= size() && (Count == dynamic_extent || Count <= size() - " - "Offset))", - __FILE__, __LINE__); + -> Span { + details::CheckIfExpectedOrAbort( + (Offset <= size() && (Count == dynamic_extent || Count <= size() - Offset)), + "(Offset <= size() && (Count == dynamic_extent || Count <= size() - " + "Offset))", + __FILE__, __LINE__); return Span{data() + Offset, Count != dynamic_extent ? Count : size() - Offset}; } @@ -495,11 +509,13 @@ class Span final { * The number of elements to take over * @return The subspan */ - constexpr Span subspan(size_type offset, size_type count = dynamic_extent) const { - details::CheckIfExpectedOrAbort((offset <= size() && (count == dynamic_extent || count <= size() - offset)), - "(offset <= size() && (count == dynamic_extent || count <= size() - " - "offset))", - __FILE__, __LINE__); + constexpr Span subspan(size_type offset, + size_type count = dynamic_extent) const { + details::CheckIfExpectedOrAbort( + (offset <= size() && (count == dynamic_extent || count <= size() - offset)), + "(offset <= size() && (count == dynamic_extent || count <= size() - " + "offset))", + __FILE__, __LINE__); return {data() + offset, count == dynamic_extent ? size() - offset : count}; } @@ -598,13 +614,17 @@ class Span final { * @brief Return a const_reverse_iterator pointing to the last element of this Span * @return The const_reverse_iterator */ - constexpr const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + constexpr const_reverse_iterator crbegin() const noexcept { + return const_reverse_iterator(end()); + } /** * @brief Return a const_reverse_iterator pointing past the first element of this Span * @return The const_reverse_iterator */ - constexpr const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } + constexpr const_reverse_iterator crend() const noexcept { + return const_reverse_iterator(begin()); + } private: /** @@ -623,7 +643,8 @@ template Span(const std::array &) -> Span; template -Span(Container &) -> Span()))>::type>; +Span(Container &) -> Span< + typename std::remove_reference()))>::type>; template Span(const Container &) -> Span; diff --git a/diag-client-lib/lib/platform-core/core/src/error_code.cpp b/diag-client-lib/lib/platform-core/core/src/error_code.cpp index 0c77b715..28958f09 100644 --- a/diag-client-lib/lib/platform-core/core/src/error_code.cpp +++ b/diag-client-lib/lib/platform-core/core/src/error_code.cpp @@ -11,10 +11,12 @@ namespace core_type { template -ErrorCode::ErrorCode(EnumT e, ErrorDomain::SupportDataType data) noexcept : code_value_{e}, - support_data_{data} {} +ErrorCode::ErrorCode(EnumT e, ErrorDomain::SupportDataType data) noexcept + : code_value_{e}, + support_data_{data} {} -ErrorCode::ErrorCode(ErrorDomain::CodeType value, ErrorDomain &domain, ErrorDomain::SupportDataType data) noexcept +ErrorCode::ErrorCode(ErrorDomain::CodeType value, ErrorDomain &domain, + ErrorDomain::SupportDataType data) noexcept : code_value_{value}, domain_{domain}, support_data_{data} {} @@ -23,8 +25,12 @@ constexpr ErrorDomain::CodeType ErrorCode::Value() const noexcept { return code_ constexpr const ErrorDomain &ErrorCode::Domain() const noexcept { return domain_; } -constexpr ErrorDomain::SupportDataType ErrorCode::SupportData() const noexcept { return support_data_; } +constexpr ErrorDomain::SupportDataType ErrorCode::SupportData() const noexcept { + return support_data_; +} -std::string_view ErrorCode::Message() noexcept { return std::string_view{domain_.Message(code_value_)}; } +std::string_view ErrorCode::Message() noexcept { + return std::string_view{domain_.Message(code_value_)}; +} } // namespace core_type \ No newline at end of file diff --git a/diag-client-lib/lib/uds-transport-layer-api/uds_transport/connection.h b/diag-client-lib/lib/uds-transport-layer-api/uds_transport/connection.h index 8bd8297d..ed4bcf05 100644 --- a/diag-client-lib/lib/uds-transport-layer-api/uds_transport/connection.h +++ b/diag-client-lib/lib/uds-transport-layer-api/uds_transport/connection.h @@ -39,7 +39,8 @@ class Connection { * @param[in] conversation_handler * The reference to conversation handler */ - Connection(ConnectionId connection_id, uds_transport::ConversionHandler const &conversation_handler) noexcept + Connection(ConnectionId connection_id, + uds_transport::ConversionHandler const &conversation_handler) noexcept : conversation_handler_{conversation_handler}, connection_id_{connection_id} {} @@ -116,9 +117,9 @@ class Connection { * to the handler to get filled */ virtual std::pair IndicateMessage( - UdsMessage::Address source_addr, UdsMessage::Address target_addr, UdsMessage::TargetAddressType type, - ChannelID channel_id, std::size_t size, Priority priority, ProtocolKind protocol_kind, - core_type::Span payload_info) = 0; + UdsMessage::Address source_addr, UdsMessage::Address target_addr, + UdsMessage::TargetAddressType type, ChannelID channel_id, std::size_t size, Priority priority, + ProtocolKind protocol_kind, core_type::Span payload_info) = 0; /** * @brief Function to transmit a valid Uds message diff --git a/diag-client-lib/lib/uds-transport-layer-api/uds_transport/conversation_handler.h b/diag-client-lib/lib/uds-transport-layer-api/uds_transport/conversation_handler.h index 76cc1324..e7620352 100644 --- a/diag-client-lib/lib/uds-transport-layer-api/uds_transport/conversation_handler.h +++ b/diag-client-lib/lib/uds-transport-layer-api/uds_transport/conversation_handler.h @@ -23,7 +23,8 @@ class ConversionHandler { * @param[in] handler_id * The handle id of conversation */ - explicit ConversionHandler(conversion_manager::ConversionHandlerID handler_id) : handler_id_{handler_id} {} + explicit ConversionHandler(conversion_manager::ConversionHandlerID handler_id) + : handler_id_{handler_id} {} /** * @brief Default copy assignment and copy constructor @@ -68,8 +69,9 @@ class ConversionHandler { * to the handler to get filled */ virtual std::pair IndicateMessage( - UdsMessage::Address source_addr, UdsMessage::Address target_addr, UdsMessage::TargetAddressType type, - ChannelID channel_id, std::size_t size, Priority priority, ProtocolKind protocol_kind, + UdsMessage::Address source_addr, UdsMessage::Address target_addr, + UdsMessage::TargetAddressType type, ChannelID channel_id, std::size_t size, Priority priority, + ProtocolKind protocol_kind, core_type::Span payload_info) const noexcept = 0; /** diff --git a/diag-client-lib/lib/uds-transport-layer-api/uds_transport/protocol_handler.h b/diag-client-lib/lib/uds-transport-layer-api/uds_transport/protocol_handler.h index 2cd45a0b..bd160310 100644 --- a/diag-client-lib/lib/uds-transport-layer-api/uds_transport/protocol_handler.h +++ b/diag-client-lib/lib/uds-transport-layer-api/uds_transport/protocol_handler.h @@ -38,7 +38,8 @@ class UdsTransportProtocolHandler { * @param[in] transport_protocol_mgr * The reference to transport protocol manager */ - UdsTransportProtocolHandler(UdsTransportProtocolHandlerId const handler_id, UdsTransportProtocolMgr const&) + UdsTransportProtocolHandler(UdsTransportProtocolHandlerId const handler_id, + UdsTransportProtocolMgr const&) : handler_id_{handler_id} {} /** @@ -79,7 +80,8 @@ class UdsTransportProtocolHandler { * @return The unique pointer to Connection created */ virtual std::unique_ptr CreateTcpConnection(ConversionHandler& conversion_handler, - std::string_view tcpIpaddress, uint16_t portNum) = 0; + std::string_view tcpIpaddress, + uint16_t portNum) = 0; /** * @brief Function to create a new Udp connection @@ -92,7 +94,8 @@ class UdsTransportProtocolHandler { * @return The unique pointer to Connection created */ virtual std::unique_ptr CreateUdpConnection(ConversionHandler& conversion_handler, - std::string_view udpIpaddress, uint16_t portNum) = 0; + std::string_view udpIpaddress, + uint16_t portNum) = 0; protected: /** diff --git a/diag-client-lib/lib/uds-transport-layer-api/uds_transport/protocol_mgr.h b/diag-client-lib/lib/uds-transport-layer-api/uds_transport/protocol_mgr.h index 9844f30f..514e48b4 100644 --- a/diag-client-lib/lib/uds-transport-layer-api/uds_transport/protocol_mgr.h +++ b/diag-client-lib/lib/uds-transport-layer-api/uds_transport/protocol_mgr.h @@ -34,7 +34,11 @@ class UdsTransportProtocolMgr { kBusyProcessing }; // Result for connection to remote endpoint - enum class ConnectionResult : std::uint8_t { kConnectionOk = 0U, kConnectionFailed, kConnectionTimeout }; + enum class ConnectionResult : std::uint8_t { + kConnectionOk = 0U, + kConnectionFailed, + kConnectionTimeout + }; // Result for disconnection to remote endpoint enum class DisconnectionResult : std::uint8_t { kDisconnectionOk = 0U, kDisconnectionFailed }; diff --git a/diag-client-lib/lib/utility-support/utility/logger.h b/diag-client-lib/lib/utility-support/utility/logger.h index 7f579a89..17e0b744 100644 --- a/diag-client-lib/lib/utility-support/utility/logger.h +++ b/diag-client-lib/lib/utility-support/utility/logger.h @@ -45,8 +45,8 @@ class Logger final { * The functor which gets invoked on log level set to fatal */ template - auto LogFatal(const std::string_view file_name, int line_no, const std::string_view func_name, Func &&func) noexcept - -> void { + auto LogFatal(const std::string_view file_name, int line_no, const std::string_view func_name, + Func &&func) noexcept -> void { #ifdef ENABLE_DLT_LOGGER LogDltMessage(DLT_LOG_FATAL, file_name, func_name, line_no, std::forward(func)); #else @@ -72,8 +72,8 @@ class Logger final { * The functor which gets invoked on log level set to error */ template - auto LogError(const std::string_view file_name, int line_no, const std::string_view func_name, Func &&func) noexcept - -> void { + auto LogError(const std::string_view file_name, int line_no, const std::string_view func_name, + Func &&func) noexcept -> void { #ifdef ENABLE_DLT_LOGGER LogDltMessage(DLT_LOG_ERROR, file_name, func_name, line_no, std::forward(func)); #else @@ -98,8 +98,8 @@ class Logger final { * The functor which gets invoked on log level set to warning */ template - auto LogWarn(const std::string_view file_name, int line_no, const std::string_view func_name, Func &&func) noexcept - -> void { + auto LogWarn(const std::string_view file_name, int line_no, const std::string_view func_name, + Func &&func) noexcept -> void { #ifdef ENABLE_DLT_LOGGER LogDltMessage(DLT_LOG_WARN, file_name, func_name, line_no, std::forward(func)); #else @@ -124,8 +124,8 @@ class Logger final { * The functor which gets invoked on log level set to info */ template - auto LogInfo(const std::string_view file_name, int line_no, const std::string_view func_name, Func &&func) noexcept - -> void { + auto LogInfo(const std::string_view file_name, int line_no, const std::string_view func_name, + Func &&func) noexcept -> void { #ifdef ENABLE_DLT_LOGGER LogDltMessage(DLT_LOG_INFO, file_name, func_name, line_no, std::forward(func)); #else @@ -150,8 +150,8 @@ class Logger final { * The functor which gets invoked on log level set to debug */ template - auto LogDebug(const std::string_view file_name, int line_no, const std::string_view func_name, Func &&func) noexcept - -> void { + auto LogDebug(const std::string_view file_name, int line_no, const std::string_view func_name, + Func &&func) noexcept -> void { #ifdef ENABLE_DLT_LOGGER LogDltMessage(DLT_LOG_DEBUG, file_name, func_name, line_no, std::forward(func)); #else @@ -176,8 +176,8 @@ class Logger final { * The functor which gets invoked on log level set to verbose */ template - auto LogVerbose(const std::string_view file_name, int line_no, const std::string_view func_name, Func &&func) noexcept - -> void { + auto LogVerbose(const std::string_view file_name, int line_no, const std::string_view func_name, + Func &&func) noexcept -> void { #ifdef ENABLE_DLT_LOGGER LogDltMessage(DLT_LOG_VERBOSE, file_name, func_name, line_no, std::forward(func)); #else @@ -225,7 +225,8 @@ class Logger final { * The functor which gets invoked */ template - auto CreateLoggingMessage(const std::string_view file_name, const std::string_view /* func_name */, int line_no, + auto CreateLoggingMessage(const std::string_view file_name, + const std::string_view /* func_name */, int line_no, Func &&func) noexcept -> std::stringstream { std::stringstream msg{}; func(msg); @@ -248,11 +249,14 @@ class Logger final { */ #ifdef ENABLE_DLT_LOGGER template - void LogDltMessage(DltLogLevelType log_level, const std::string_view file_name, const std::string_view func_name, - int line_no, Func &&func) { + void LogDltMessage(DltLogLevelType log_level, const std::string_view file_name, + const std::string_view func_name, int line_no, Func &&func) { - DLT_LOG(contxt_, log_level, - DLT_CSTRING(CreateLoggingMessage(file_name, func_name, line_no, std::forward(func)).str().c_str())); + DLT_LOG( + contxt_, log_level, + DLT_CSTRING(CreateLoggingMessage(file_name, func_name, line_no, std::forward(func)) + .str() + .c_str())); } #endif diff --git a/diag-client-lib/lib/utility-support/utility/state.h b/diag-client-lib/lib/utility-support/utility/state.h index 8092143d..b4bae789 100644 --- a/diag-client-lib/lib/utility-support/utility/state.h +++ b/diag-client-lib/lib/utility-support/utility/state.h @@ -56,7 +56,8 @@ class StateContext { // Add the needed state void AddState(EnumState state, std::unique_ptr> state_ptr) { - state_map_.insert(std::pair>>(state, std::move(state_ptr))); + state_map_.insert( + std::pair>>(state, std::move(state_ptr))); } // Get the current state diff --git a/examples/example_1/src/main.cpp b/examples/example_1/src/main.cpp index c41fc1d7..ce7a381f 100644 --- a/examples/example_1/src/main.cpp +++ b/examples/example_1/src/main.cpp @@ -32,14 +32,16 @@ int main() { // Get conversation for tester one by providing the conversation name configured // in diag_client_config file passed while creating the diag client - DiagClientConversation diag_client_conversation1{diag_client->GetDiagnosticClientConversation("DiagTesterOne")}; + DiagClientConversation diag_client_conversation1{ + diag_client->GetDiagnosticClientConversation("DiagTesterOne")}; // Start the conversation for tester one diag_client_conversation1.Startup(); // Get conversation for tester two by providing the conversation name configured // in diag_client_config file passed while creating the diag client - DiagClientConversation diag_client_conversation2{diag_client->GetDiagnosticClientConversation("DiagTesterTwo")}; + DiagClientConversation diag_client_conversation2{ + diag_client->GetDiagnosticClientConversation("DiagTesterTwo")}; // Start the conversation for tester two diag_client_conversation2.Startup(); @@ -66,31 +68,37 @@ int main() { diag_client_conversation2.ConnectToDiagServer(0x1235, uds_message_1->GetHostIpAddress()); // Use Tester One to send the diagnostic message to ECU1 - diag::client::Result const - ret_val_1{diag_client_conversation1.SendDiagnosticRequest(std::move(uds_message_1))}; + diag::client::Result const ret_val_1{ + diag_client_conversation1.SendDiagnosticRequest(std::move(uds_message_1))}; if (ret_val_1.HasValue()) { // Use Value() to get the pointer to UdsMessage and then use different method to get payload or host ip address etc. - std::cout << "diag_client_conversation1 Total size: " << ret_val_1.Value()->GetPayload().size() << std::endl; + std::cout << "diag_client_conversation1 Total size: " + << ret_val_1.Value()->GetPayload().size() << std::endl; // Print the payload for (auto const byte: ret_val_1.Value()->GetPayload()) { - std::cout << "diag_client_conversation1 byte: " << std::hex << static_cast(byte) << std::endl; + std::cout << "diag_client_conversation1 byte: " << std::hex << static_cast(byte) + << std::endl; } } else { // Use Error() to get the error type that occured when sending the request - std::cout << "diag_client_conversation1 error code: " << static_cast(ret_val_1.Error()) - << std::endl; + std::cout << "diag_client_conversation1 error code: " + << static_cast(ret_val_1.Error()) << std::endl; } // Use Tester Two to send the diagnostic message to ECU2 - diag::client::Result const - ret_val_2{diag_client_conversation2.SendDiagnosticRequest(std::move(uds_message_2))}; + diag::client::Result const ret_val_2{ + diag_client_conversation2.SendDiagnosticRequest(std::move(uds_message_2))}; if (ret_val_2.HasValue()) { - std::cout << "diag_client_conversation2 Total size: " << ret_val_2.Value()->GetPayload().size() << std::endl; + std::cout << "diag_client_conversation2 Total size: " + << ret_val_2.Value()->GetPayload().size() << std::endl; // Print the payload for (auto const byte: ret_val_2.Value()->GetPayload()) { - std::cout << "diag_client_conversation2 byte: " << std::hex << static_cast(byte) << std::endl; + std::cout << "diag_client_conversation2 byte: " << std::hex << static_cast(byte) + << std::endl; } } diff --git a/examples/example_1/src/uds_message.h b/examples/example_1/src/uds_message.h index 59649ff5..e827c3d7 100644 --- a/examples/example_1/src/uds_message.h +++ b/examples/example_1/src/uds_message.h @@ -17,7 +17,8 @@ class UdsMessage : public diag::client::uds_message::UdsMessage { public: // ctor - UdsMessage(std::string_view host_ip_address, diag::client::uds_message::UdsMessage::ByteVector &payload) + UdsMessage(std::string_view host_ip_address, + diag::client::uds_message::UdsMessage::ByteVector &payload) : host_ip_address_{host_ip_address}, uds_payload_{payload} {} @@ -31,7 +32,9 @@ class UdsMessage : public diag::client::uds_message::UdsMessage { // store only UDS payload to be sent diag::client::uds_message::UdsMessage::ByteVector &uds_payload_; - const diag::client::uds_message::UdsMessage::ByteVector &GetPayload() const override { return uds_payload_; } + const diag::client::uds_message::UdsMessage::ByteVector &GetPayload() const override { + return uds_payload_; + } // return the underlying buffer for write access diag::client::uds_message::UdsMessage::ByteVector &GetPayload() override { return uds_payload_; } diff --git a/examples/example_2/src/uds_message.h b/examples/example_2/src/uds_message.h index 2429d0ea..2cb76391 100644 --- a/examples/example_2/src/uds_message.h +++ b/examples/example_2/src/uds_message.h @@ -16,7 +16,8 @@ class UdsMessage final : public diag::client::uds_message::UdsMessage { public: // ctor - UdsMessage(std::string_view host_ip_address, diag::client::uds_message::UdsMessage::ByteVector payload) + UdsMessage(std::string_view host_ip_address, + diag::client::uds_message::UdsMessage::ByteVector payload) : host_ip_address_{host_ip_address}, uds_payload_{std::move(payload)} {} @@ -30,7 +31,9 @@ class UdsMessage final : public diag::client::uds_message::UdsMessage { // store only UDS payload to be sent diag::client::uds_message::UdsMessage::ByteVector uds_payload_; - const diag::client::uds_message::UdsMessage::ByteVector &GetPayload() const override { return uds_payload_; } + const diag::client::uds_message::UdsMessage::ByteVector &GetPayload() const override { + return uds_payload_; + } // return the underlying buffer for write access diag::client::uds_message::UdsMessage::ByteVector &GetPayload() override { return uds_payload_; } diff --git a/test/component/common/handler/doip_tcp_handler.cpp b/test/component/common/handler/doip_tcp_handler.cpp index c73bf5ef..77b0ac8a 100644 --- a/test/component/common/handler/doip_tcp_handler.cpp +++ b/test/component/common/handler/doip_tcp_handler.cpp @@ -61,23 +61,27 @@ auto GetVmSpecific(core_type::Span payload) noexcept -> std: } // namespace -DoipTcpHandler::DoipTcpHandler(boost_support::server::tcp::TcpServer tcp_server) : tcp_server_{std::move(tcp_server)} {} +DoipTcpHandler::DoipTcpHandler(boost_support::server::tcp::TcpServer tcp_server) + : tcp_server_{std::move(tcp_server)} {} void DoipTcpHandler::Initialize() { - tcp_server_.SetReadHandler( - [this](TcpServer::MessagePtr tcp_message) { ProcessReceivedTcpMessage(std::move(tcp_message)); }); + tcp_server_.SetReadHandler([this](TcpServer::MessagePtr tcp_message) { + ProcessReceivedTcpMessage(std::move(tcp_message)); + }); tcp_server_.Initialize(); } void DoipTcpHandler::DeInitialize() { tcp_server_.DeInitialize(); } -void DoipTcpHandler::SendTcpMessage(boost_support::server::tcp::TcpServer::MessageConstPtr tcp_message) noexcept { +void DoipTcpHandler::SendTcpMessage( + boost_support::server::tcp::TcpServer::MessageConstPtr tcp_message) noexcept { EXPECT_TRUE(tcp_server_.Transmit(std::move(tcp_message)).HasValue()); } -void DoipTcpHandler::ProcessReceivedTcpMessage(boost_support::server::tcp::TcpServer::MessagePtr tcp_message) { - message::DoipMessage doip_message{tcp_message->GetHostIpAddress(), tcp_message->GetHostPortNumber(), - tcp_message->GetPayload()}; +void DoipTcpHandler::ProcessReceivedTcpMessage( + boost_support::server::tcp::TcpServer::MessagePtr tcp_message) { + message::DoipMessage doip_message{tcp_message->GetHostIpAddress(), + tcp_message->GetHostPortNumber(), tcp_message->GetPayload()}; switch (doip_message.GetPayloadType()) { case kDoipRoutingActivationReqType: { std::uint16_t const client_source_address{ConvertToAddr(doip_message.GetPayload())}; @@ -99,15 +103,18 @@ void DoipTcpHandler::ProcessReceivedTcpMessage(boost_support::server::tcp::TcpSe case kDoipDiagMessage: { constexpr std::uint8_t kSourceAddressSize{4u}; std::uint16_t const client_source_address{ConvertToAddr(doip_message.GetPayload())}; - std::uint16_t const server_target_address{ConvertToAddr({&doip_message.GetPayload()[2u], 2u})}; + std::uint16_t const server_target_address{ + ConvertToAddr({&doip_message.GetPayload()[2u], 2u})}; core_type::Span diag_request{core_type::Span{ - &doip_message.GetPayload()[kSourceAddressSize], doip_message.GetPayload().size() - kSourceAddressSize}}; + &doip_message.GetPayload()[kSourceAddressSize], + doip_message.GetPayload().size() - kSourceAddressSize}}; ProcessDiagnosticRequestMessage(client_source_address, server_target_address, diag_request); } break; } } -auto ComposeRoutingActivationResponse(std::uint16_t client_logical_address, std::uint16_t server_logical_address, +auto ComposeRoutingActivationResponse(std::uint16_t client_logical_address, + std::uint16_t server_logical_address, std::uint8_t activation_response_code, std::optional vm_specific) noexcept -> DoipTcpHandler::TcpServer::MessagePtr { @@ -133,7 +140,8 @@ auto ComposeRoutingActivationResponse(std::uint16_t client_logical_address, std: return response; } -auto ComposeDiagnosticPositiveAcknowledgementMessage(std::uint16_t source_address, std::uint16_t target_address, +auto ComposeDiagnosticPositiveAcknowledgementMessage(std::uint16_t source_address, + std::uint16_t target_address, std::uint8_t ack_code) noexcept -> DoipTcpHandler::TcpServer::MessagePtr { // Create header @@ -153,7 +161,8 @@ auto ComposeDiagnosticPositiveAcknowledgementMessage(std::uint16_t source_addres return response; } -auto ComposeDiagnosticNegativeAcknowledgementMessage(std::uint16_t source_address, std::uint16_t target_address, +auto ComposeDiagnosticNegativeAcknowledgementMessage(std::uint16_t source_address, + std::uint16_t target_address, std::uint8_t ack_code) noexcept -> DoipTcpHandler::TcpServer::MessagePtr { // Create header @@ -180,8 +189,8 @@ auto ComposeDiagnosticResponseMessage(std::uint16_t source_address, std::uint16_ constexpr std::uint8_t kDoipHeaderSize{8u}; constexpr std::uint8_t kSourceAddressSize{4u}; // Create header - DoipTcpHandler::TcpServer::Message::BufferType response_buffer{ - CreateDoipGenericHeader(kDoipDiagMessage, kDoipDiagMessageReqResMinLen + diag_response.size())}; + DoipTcpHandler::TcpServer::Message::BufferType response_buffer{CreateDoipGenericHeader( + kDoipDiagMessage, kDoipDiagMessageReqResMinLen + diag_response.size())}; // Add SA response_buffer.emplace_back(source_address >> 8U); response_buffer.emplace_back(source_address & 0xFFU); @@ -189,8 +198,8 @@ auto ComposeDiagnosticResponseMessage(std::uint16_t source_address, std::uint16_ response_buffer.emplace_back(target_address >> 8U); response_buffer.emplace_back(target_address & 0xFFU); // Copy data bytes - response_buffer.insert(response_buffer.begin() + kDoipHeaderSize + kSourceAddressSize, diag_response.cbegin(), - diag_response.cend()); + response_buffer.insert(response_buffer.begin() + kDoipHeaderSize + kSourceAddressSize, + diag_response.cbegin(), diag_response.cend()); DoipTcpHandler::TcpServer::MessagePtr response{ std::make_unique("", 0u, std::move(response_buffer))}; diff --git a/test/component/common/handler/doip_tcp_handler.h b/test/component/common/handler/doip_tcp_handler.h index f635ebc4..b38e4781 100644 --- a/test/component/common/handler/doip_tcp_handler.h +++ b/test/component/common/handler/doip_tcp_handler.h @@ -58,16 +58,19 @@ class DoipTcpHandler { TcpServer tcp_server_; }; -auto ComposeRoutingActivationResponse(std::uint16_t client_logical_address, std::uint16_t server_logical_address, +auto ComposeRoutingActivationResponse(std::uint16_t client_logical_address, + std::uint16_t server_logical_address, std::uint8_t activation_response_code, std::optional vm_specific) noexcept -> DoipTcpHandler::TcpServer::MessagePtr; -auto ComposeDiagnosticPositiveAcknowledgementMessage(std::uint16_t source_address, std::uint16_t target_address, +auto ComposeDiagnosticPositiveAcknowledgementMessage(std::uint16_t source_address, + std::uint16_t target_address, std::uint8_t ack_code) noexcept -> DoipTcpHandler::TcpServer::MessagePtr; -auto ComposeDiagnosticNegativeAcknowledgementMessage(std::uint16_t source_address, std::uint16_t target_address, +auto ComposeDiagnosticNegativeAcknowledgementMessage(std::uint16_t source_address, + std::uint16_t target_address, std::uint8_t ack_code) noexcept -> DoipTcpHandler::TcpServer::MessagePtr; diff --git a/test/component/common/handler/doip_udp_handler.cpp b/test/component/common/handler/doip_udp_handler.cpp index f9fd4e4c..4f526562 100644 --- a/test/component/common/handler/doip_udp_handler.cpp +++ b/test/component/common/handler/doip_udp_handler.cpp @@ -82,7 +82,8 @@ auto RemoveCharFromString(std::string_view input_string, T removal_type) noexcep } template -auto AddCharToString(std::string_view input_string, T character, std::uint8_t substring_range) noexcept -> std::string { +auto AddCharToString(std::string_view input_string, T character, + std::uint8_t substring_range) noexcept -> std::string { std::string result{}; std::uint8_t const string_length{static_cast(input_string.length())}; for (std::uint8_t char_count{0u}; char_count < string_length; char_count += substring_range) { @@ -118,16 +119,18 @@ auto ConvertToHexString(Container container) noexcept -> std::string { } } // namespace -DoipUdpHandler::DoipUdpHandler(std::string_view broadcast_ip_address, std::string_view unicast_ip_address, - std::uint16_t local_port_number) +DoipUdpHandler::DoipUdpHandler(std::string_view broadcast_ip_address, + std::string_view unicast_ip_address, std::uint16_t local_port_number) : udp_broadcast_server_{broadcast_ip_address, local_port_number}, udp_unicast_server_{unicast_ip_address, local_port_number} {} void DoipUdpHandler::Initialize() { - udp_broadcast_server_.SetReadHandler( - [this](UdpServer::MessagePtr udp_message) { ProcessReceivedUdpMessage(std::move(udp_message)); }); - udp_unicast_server_.SetReadHandler( - [this](UdpServer::MessagePtr udp_message) { ProcessReceivedUdpMessage(std::move(udp_message)); }); + udp_broadcast_server_.SetReadHandler([this](UdpServer::MessagePtr udp_message) { + ProcessReceivedUdpMessage(std::move(udp_message)); + }); + udp_unicast_server_.SetReadHandler([this](UdpServer::MessagePtr udp_message) { + ProcessReceivedUdpMessage(std::move(udp_message)); + }); udp_broadcast_server_.Initialize(); udp_unicast_server_.Initialize(); } @@ -138,60 +141,67 @@ void DoipUdpHandler::DeInitialize() { } void DoipUdpHandler::ProcessReceivedUdpMessage(DoipUdpHandler::UdpServer::MessagePtr udp_message) { - message::DoipMessage doip_message{udp_message->GetHostIpAddress(), udp_message->GetHostPortNumber(), - udp_message->GetPayload()}; + message::DoipMessage doip_message{udp_message->GetHostIpAddress(), + udp_message->GetHostPortNumber(), udp_message->GetPayload()}; switch (doip_message.GetPayloadType()) { case kDoip_VehicleIdentification_ReqType: - ProcessVehicleIdentificationRequestMessage(doip_message.GetHostIpAddress(), doip_message.GetHostPortNumber(), {}, - {}); + ProcessVehicleIdentificationRequestMessage(doip_message.GetHostIpAddress(), + doip_message.GetHostPortNumber(), {}, {}); break; case kDoip_VehicleIdentificationEID_ReqType: { - std::string const eid{AddCharToString(ConvertToHexString(doip_message.GetPayload()), ':', 2u)}; - ProcessVehicleIdentificationRequestMessage(doip_message.GetHostIpAddress(), doip_message.GetHostPortNumber(), eid, - {}); + std::string const eid{ + AddCharToString(ConvertToHexString(doip_message.GetPayload()), ':', 2u)}; + ProcessVehicleIdentificationRequestMessage(doip_message.GetHostIpAddress(), + doip_message.GetHostPortNumber(), eid, {}); } break; case kDoip_VehicleIdentificationVIN_ReqType: { std::string const vin{ConvertToAsciiString(doip_message.GetPayload())}; - ProcessVehicleIdentificationRequestMessage(doip_message.GetHostIpAddress(), doip_message.GetHostPortNumber(), {}, - vin); + ProcessVehicleIdentificationRequestMessage(doip_message.GetHostIpAddress(), + doip_message.GetHostPortNumber(), {}, vin); } break; } } -void DoipUdpHandler::SendUdpMessage(DoipUdpHandler::UdpServer::MessageConstPtr udp_message) noexcept { +void DoipUdpHandler::SendUdpMessage( + DoipUdpHandler::UdpServer::MessageConstPtr udp_message) noexcept { EXPECT_TRUE(udp_unicast_server_.Transmit(std::move(udp_message)).HasValue()); } -auto DoipUdpHandler::ComposeVehicleIdentificationResponse(std::string_view remote_ip_address, - std::uint16_t remote_port_number, std::string_view vin, - std::uint16_t logical_address, std::string_view eid, - std::string_view gid, std::uint8_t action_byte, - std::optional sync_status) noexcept +auto DoipUdpHandler::ComposeVehicleIdentificationResponse( + std::string_view remote_ip_address, std::uint16_t remote_port_number, std::string_view vin, + std::uint16_t logical_address, std::string_view eid, std::string_view gid, + std::uint8_t action_byte, std::optional sync_status) noexcept -> UdpServer::MessagePtr { // Create header constexpr std::uint8_t kHeaderSize{8u}; - UdpServer::Message::BufferType response_buffer{CreateDoipGenericHeader(kDoip_VehicleAnnouncement_ResType, 32)}; + UdpServer::Message::BufferType response_buffer{ + CreateDoipGenericHeader(kDoip_VehicleAnnouncement_ResType, 32)}; // Add VIN UdpServer::Message::BufferType const vin_in_bytes{SerializeToByteVectorFromString(vin, 1u)}; - response_buffer.insert(std::next(response_buffer.begin(), kHeaderSize), vin_in_bytes.cbegin(), vin_in_bytes.cend()); + response_buffer.insert(std::next(response_buffer.begin(), kHeaderSize), vin_in_bytes.cbegin(), + vin_in_bytes.cend()); // Add LA response_buffer.emplace_back(logical_address >> 8U); response_buffer.emplace_back(logical_address & 0xFFU); // Add EID - UdpServer::Message::BufferType const eid_in_bytes{SerializeToHexVectorFromString(RemoveCharFromString(eid, ':'), 2u)}; + UdpServer::Message::BufferType const eid_in_bytes{ + SerializeToHexVectorFromString(RemoveCharFromString(eid, ':'), 2u)}; constexpr std::uint8_t kEidOffset{kHeaderSize + 19u}; - response_buffer.insert(std::next(response_buffer.begin(), kEidOffset), eid_in_bytes.cbegin(), eid_in_bytes.cend()); + response_buffer.insert(std::next(response_buffer.begin(), kEidOffset), eid_in_bytes.cbegin(), + eid_in_bytes.cend()); // Add GID - UdpServer::Message::BufferType const gid_in_bytes{SerializeToHexVectorFromString(RemoveCharFromString(gid, ':'), 2u)}; + UdpServer::Message::BufferType const gid_in_bytes{ + SerializeToHexVectorFromString(RemoveCharFromString(gid, ':'), 2u)}; constexpr std::uint8_t kGidOffset{kHeaderSize + 25u}; - response_buffer.insert(std::next(response_buffer.begin(), kGidOffset), gid_in_bytes.cbegin(), gid_in_bytes.cend()); + response_buffer.insert(std::next(response_buffer.begin(), kGidOffset), gid_in_bytes.cbegin(), + gid_in_bytes.cend()); // Set Further action byte response_buffer.emplace_back(action_byte); // Set sync status if (sync_status.has_value()) { response_buffer.emplace_back(sync_status.value()); } - UdpServer::MessagePtr response{ - std::make_unique(remote_ip_address, remote_port_number, std::move(response_buffer))}; + UdpServer::MessagePtr response{std::make_unique( + remote_ip_address, remote_port_number, std::move(response_buffer))}; return response; } diff --git a/test/component/common/handler/doip_udp_handler.h b/test/component/common/handler/doip_udp_handler.h index a7f066f9..37041000 100644 --- a/test/component/common/handler/doip_udp_handler.h +++ b/test/component/common/handler/doip_udp_handler.h @@ -36,14 +36,16 @@ class DoipUdpHandler { * @brief Function that gets invoked on reception of Vehicle identification request message */ MOCK_METHOD(void, ProcessVehicleIdentificationRequestMessage, - (std::string_view client_ip_address, std::uint16_t client_port_number, std::string_view eid, - std::string_view vin), + (std::string_view client_ip_address, std::uint16_t client_port_number, + std::string_view eid, std::string_view vin), (noexcept)); - auto ComposeVehicleIdentificationResponse(std::string_view remote_ip_address, std::uint16_t remote_port_number, - std::string_view vin, std::uint16_t logical_address, std::string_view eid, + auto ComposeVehicleIdentificationResponse(std::string_view remote_ip_address, + std::uint16_t remote_port_number, std::string_view vin, + std::uint16_t logical_address, std::string_view eid, std::string_view gid, std::uint8_t action_byte, - std::optional sync_status) noexcept -> UdpServer::MessagePtr; + std::optional sync_status) noexcept + -> UdpServer::MessagePtr; void SendUdpMessage(UdpServer::MessageConstPtr udp_message) noexcept; diff --git a/test/component/main.h b/test/component/main.h index ad88d0a1..a0a7b54c 100644 --- a/test/component/main.h +++ b/test/component/main.h @@ -56,7 +56,9 @@ class DoipClientFixture : public ::testing::Test { auto GetDiagClientRef() noexcept -> diag::client::DiagClient& { return *diag_client_; } // Function to get Doip Test Handler reference - auto GetDoipTestUdpHandlerRef() noexcept -> doip_handler::DoipUdpHandler& { return doip_udp_handler_; } + auto GetDoipTestUdpHandlerRef() noexcept -> doip_handler::DoipUdpHandler& { + return doip_udp_handler_; + } private: // diag client library diff --git a/test/component/test_cases/diagnostic_message_test.cpp b/test/component/test_cases/diagnostic_message_test.cpp index a51f66a6..66d842f4 100644 --- a/test/component/test_cases/diagnostic_message_test.cpp +++ b/test/component/test_cases/diagnostic_message_test.cpp @@ -79,7 +79,8 @@ class UdsMessage : public diag::client::uds_message::UdsMessage { // Helper class for auto connection and disconnection to server class DiagConnectedConversation final { public: - DiagConnectedConversation(diag::client::DiagClient& diag_client, std::string_view conversation_name) noexcept + DiagConnectedConversation(diag::client::DiagClient& diag_client, + std::string_view conversation_name) noexcept : conversation_{diag_client.GetDiagnosticClientConversation(conversation_name)} { conversation_.Startup(); // Start connecting to server @@ -87,11 +88,14 @@ class DiagConnectedConversation final { diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); } - auto GetConversation() noexcept -> diag::client::conversation::DiagClientConversation& { return conversation_; } + auto GetConversation() noexcept -> diag::client::conversation::DiagClientConversation& { + return conversation_; + } ~DiagConnectedConversation() noexcept { - EXPECT_EQ(conversation_.DisconnectFromDiagServer(), - diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); + EXPECT_EQ( + conversation_.DisconnectFromDiagServer(), + diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); conversation_.Shutdown(); } @@ -124,16 +128,17 @@ class DiagMessageFixture : public component::ComponentTest { template auto CreateServerWithExpectation(Functor expectation_functor) noexcept -> std::future { - return std::async(std::launch::async, [this, expectation_functor = std::move(expectation_functor)]() { - std::optional server{tcp_acceptor_.GetTcpServer()}; - if (server.has_value()) { - doip_tcp_handler_.emplace(std::move(server).value()); - doip_tcp_handler_->Initialize(); - // Set Expectation - expectation_functor(); - } - return doip_tcp_handler_.has_value(); - }); + return std::async(std::launch::async, + [this, expectation_functor = std::move(expectation_functor)]() { + std::optional server{tcp_acceptor_.GetTcpServer()}; + if (server.has_value()) { + doip_tcp_handler_.emplace(std::move(server).value()); + doip_tcp_handler_->Initialize(); + // Set Expectation + expectation_functor(); + } + return doip_tcp_handler_.has_value(); + }); } protected: @@ -150,12 +155,14 @@ class DiagMessageFixture : public component::ComponentTest { class DiagMessageFixtureValueParameter : public DiagMessageFixture, public ::testing::WithParamInterface {}; -INSTANTIATE_TEST_SUITE_P( - DiagMessage, DiagMessageFixtureValueParameter, - testing::Values(kDoipDiagnosticMessageNegAckCodeInvalidSa, kDoipDiagnosticMessageNegAckCodeUnknownTa, - kDoipDiagnosticMessageNegAckCodeMessageTooLarge, kDoipDiagnosticMessageNegAckCodeOutOfMemory, - kDoipDiagnosticMessageNegAckCodeTargetUnreachable, kDoipDiagnosticMessageNegAckCodeUnknownNetwork, - kDoipDiagnosticMessageNegAckCodeTpError)); +INSTANTIATE_TEST_SUITE_P(DiagMessage, DiagMessageFixtureValueParameter, + testing::Values(kDoipDiagnosticMessageNegAckCodeInvalidSa, + kDoipDiagnosticMessageNegAckCodeUnknownTa, + kDoipDiagnosticMessageNegAckCodeMessageTooLarge, + kDoipDiagnosticMessageNegAckCodeOutOfMemory, + kDoipDiagnosticMessageNegAckCodeTargetUnreachable, + kDoipDiagnosticMessageNegAckCodeUnknownNetwork, + kDoipDiagnosticMessageNegAckCodeTpError)); /** * @brief Verify that sending of diagnostic request works correctly and response is received. @@ -164,36 +171,43 @@ TEST_F(DiagMessageFixture, VerifyDiagPositiveResponse) { UdsMessage::ByteVector kDiagRequest{0x10, 0x01}; UdsMessage::ByteVector kDiagResponse{0x50, 0x01, 0x00, 0x32, 0x01, 0xF4}; - std::future is_server_created{CreateServerWithExpectation([this, &kDiagRequest, &kDiagResponse]() { - // Create an expectation of routing activation response - EXPECT_CALL(*doip_tcp_handler_, ProcessRoutingActivationRequestMessage(testing::_, testing::_, testing::_)) - .WillOnce(::testing::Invoke([this](std::uint16_t client_source_address, std::uint8_t activation_type, - std::optional vm_specific) { - EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); - EXPECT_EQ(activation_type, kDoipRoutingActivationReqActTypeDefault); - EXPECT_FALSE(vm_specific.has_value()); - // Send Routing activation response - doip_tcp_handler_->SendTcpMessage(common::handler::ComposeRoutingActivationResponse( - client_source_address, kDiagServerLogicalAddress, kDoipRoutingActivationResCodeRoutingSuccessful, - std::nullopt)); - })); + std::future is_server_created{ + CreateServerWithExpectation([this, &kDiagRequest, &kDiagResponse]() { + // Create an expectation of routing activation response + EXPECT_CALL(*doip_tcp_handler_, + ProcessRoutingActivationRequestMessage(testing::_, testing::_, testing::_)) + .WillOnce(::testing::Invoke([this](std::uint16_t client_source_address, + std::uint8_t activation_type, + std::optional vm_specific) { + EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); + EXPECT_EQ(activation_type, kDoipRoutingActivationReqActTypeDefault); + EXPECT_FALSE(vm_specific.has_value()); + // Send Routing activation response + doip_tcp_handler_->SendTcpMessage(common::handler::ComposeRoutingActivationResponse( + client_source_address, kDiagServerLogicalAddress, + kDoipRoutingActivationResCodeRoutingSuccessful, std::nullopt)); + })); - EXPECT_CALL(*doip_tcp_handler_, ProcessDiagnosticRequestMessage(testing::_, testing::_, testing::_)) - .WillOnce(::testing::Invoke([this, &kDiagRequest, &kDiagResponse]( - std::uint16_t client_source_address, std::uint16_t server_target_address, - core_type::Span diag_request) { - EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); - EXPECT_EQ(server_target_address, kDiagServerLogicalAddress); - EXPECT_THAT(diag_request, testing::ElementsAreArray(kDiagRequest)); - // Send Diagnostic Positive Acknowledgement message - doip_tcp_handler_->SendTcpMessage(common::handler::ComposeDiagnosticPositiveAcknowledgementMessage( - kDiagServerLogicalAddress, kDiagClientLogicalAddress, kDoipDiagnosticMessagePosAckCodeConfirm)); - // Send Diagnostic response message - doip_tcp_handler_->SendTcpMessage( - common::handler::ComposeDiagnosticResponseMessage(kDiagServerLogicalAddress, kDiagClientLogicalAddress, - core_type::Span{kDiagResponse})); - })); - })}; + EXPECT_CALL(*doip_tcp_handler_, + ProcessDiagnosticRequestMessage(testing::_, testing::_, testing::_)) + .WillOnce(::testing::Invoke([this, &kDiagRequest, &kDiagResponse]( + std::uint16_t client_source_address, + std::uint16_t server_target_address, + core_type::Span diag_request) { + EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); + EXPECT_EQ(server_target_address, kDiagServerLogicalAddress); + EXPECT_THAT(diag_request, testing::ElementsAreArray(kDiagRequest)); + // Send Diagnostic Positive Acknowledgement message + doip_tcp_handler_->SendTcpMessage( + common::handler::ComposeDiagnosticPositiveAcknowledgementMessage( + kDiagServerLogicalAddress, kDiagClientLogicalAddress, + kDoipDiagnosticMessagePosAckCodeConfirm)); + // Send Diagnostic response message + doip_tcp_handler_->SendTcpMessage(common::handler::ComposeDiagnosticResponseMessage( + kDiagServerLogicalAddress, kDiagClientLogicalAddress, + core_type::Span{kDiagResponse})); + })); + })}; DiagConnectedConversation diag_client_conversation{*diag_client_, "DiagTesterOne"}; @@ -205,7 +219,8 @@ TEST_F(DiagMessageFixture, VerifyDiagPositiveResponse) { diag::client::Result - diag_result{diag_client_conversation.GetConversation().SendDiagnosticRequest(std::move(uds_message))}; + diag_result{ + diag_client_conversation.GetConversation().SendDiagnosticRequest(std::move(uds_message))}; ASSERT_TRUE(diag_result.HasValue()); EXPECT_THAT(diag_result.Value()->GetPayload(), testing::ElementsAreArray(kDiagResponse)); @@ -218,36 +233,43 @@ TEST_F(DiagMessageFixture, VerifyDiagNegativeResponse) { UdsMessage::ByteVector kDiagRequest{0x10, 0x01}; UdsMessage::ByteVector kDiagResponse{0x7F, 0x10, 0x10}; - std::future is_server_created{CreateServerWithExpectation([this, &kDiagRequest, &kDiagResponse]() { - // Create an expectation of routing activation response - EXPECT_CALL(*doip_tcp_handler_, ProcessRoutingActivationRequestMessage(testing::_, testing::_, testing::_)) - .WillOnce(::testing::Invoke([this](std::uint16_t client_source_address, std::uint8_t activation_type, - std::optional vm_specific) { - EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); - EXPECT_EQ(activation_type, kDoipRoutingActivationReqActTypeDefault); - EXPECT_FALSE(vm_specific.has_value()); - // Send Routing activation response - doip_tcp_handler_->SendTcpMessage(common::handler::ComposeRoutingActivationResponse( - client_source_address, kDiagServerLogicalAddress, kDoipRoutingActivationResCodeRoutingSuccessful, - std::nullopt)); - })); + std::future is_server_created{ + CreateServerWithExpectation([this, &kDiagRequest, &kDiagResponse]() { + // Create an expectation of routing activation response + EXPECT_CALL(*doip_tcp_handler_, + ProcessRoutingActivationRequestMessage(testing::_, testing::_, testing::_)) + .WillOnce(::testing::Invoke([this](std::uint16_t client_source_address, + std::uint8_t activation_type, + std::optional vm_specific) { + EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); + EXPECT_EQ(activation_type, kDoipRoutingActivationReqActTypeDefault); + EXPECT_FALSE(vm_specific.has_value()); + // Send Routing activation response + doip_tcp_handler_->SendTcpMessage(common::handler::ComposeRoutingActivationResponse( + client_source_address, kDiagServerLogicalAddress, + kDoipRoutingActivationResCodeRoutingSuccessful, std::nullopt)); + })); - EXPECT_CALL(*doip_tcp_handler_, ProcessDiagnosticRequestMessage(testing::_, testing::_, testing::_)) - .WillOnce(::testing::Invoke([this, &kDiagRequest, &kDiagResponse]( - std::uint16_t client_source_address, std::uint16_t server_target_address, - core_type::Span diag_request) { - EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); - EXPECT_EQ(server_target_address, kDiagServerLogicalAddress); - EXPECT_THAT(diag_request, testing::ElementsAreArray(kDiagRequest)); - // Send Diagnostic Positive Acknowledgement message - doip_tcp_handler_->SendTcpMessage(common::handler::ComposeDiagnosticPositiveAcknowledgementMessage( - kDiagServerLogicalAddress, kDiagClientLogicalAddress, kDoipDiagnosticMessagePosAckCodeConfirm)); - // Send Diagnostic response message - doip_tcp_handler_->SendTcpMessage( - common::handler::ComposeDiagnosticResponseMessage(kDiagServerLogicalAddress, kDiagClientLogicalAddress, - core_type::Span{kDiagResponse})); - })); - })}; + EXPECT_CALL(*doip_tcp_handler_, + ProcessDiagnosticRequestMessage(testing::_, testing::_, testing::_)) + .WillOnce(::testing::Invoke([this, &kDiagRequest, &kDiagResponse]( + std::uint16_t client_source_address, + std::uint16_t server_target_address, + core_type::Span diag_request) { + EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); + EXPECT_EQ(server_target_address, kDiagServerLogicalAddress); + EXPECT_THAT(diag_request, testing::ElementsAreArray(kDiagRequest)); + // Send Diagnostic Positive Acknowledgement message + doip_tcp_handler_->SendTcpMessage( + common::handler::ComposeDiagnosticPositiveAcknowledgementMessage( + kDiagServerLogicalAddress, kDiagClientLogicalAddress, + kDoipDiagnosticMessagePosAckCodeConfirm)); + // Send Diagnostic response message + doip_tcp_handler_->SendTcpMessage(common::handler::ComposeDiagnosticResponseMessage( + kDiagServerLogicalAddress, kDiagClientLogicalAddress, + core_type::Span{kDiagResponse})); + })); + })}; DiagConnectedConversation diag_client_conversation{*diag_client_, "DiagTesterOne"}; @@ -259,7 +281,8 @@ TEST_F(DiagMessageFixture, VerifyDiagNegativeResponse) { diag::client::Result - diag_result{diag_client_conversation.GetConversation().SendDiagnosticRequest(std::move(uds_message))}; + diag_result{ + diag_client_conversation.GetConversation().SendDiagnosticRequest(std::move(uds_message))}; ASSERT_TRUE(diag_result.HasValue()); EXPECT_THAT(diag_result.Value()->GetPayload(), testing::ElementsAreArray(kDiagResponse)); @@ -274,31 +297,38 @@ TEST_F(DiagMessageFixture, VerifyDiagPendingResponse) { UdsMessage::ByteVector kDiagFinalResponse{0x50, 0x01, 0x00, 0x32, 0x01, 0xF4}; constexpr std::uint8_t kNumOfPending{10u}; - std::future is_server_created{ - CreateServerWithExpectation([this, &kDiagRequest, &kDiagPendingResponse, &kDiagFinalResponse]() { + std::future is_server_created{CreateServerWithExpectation( + [this, &kDiagRequest, &kDiagPendingResponse, &kDiagFinalResponse]() { // Create an expectation of routing activation response - EXPECT_CALL(*doip_tcp_handler_, ProcessRoutingActivationRequestMessage(testing::_, testing::_, testing::_)) - .WillOnce(::testing::Invoke([this](std::uint16_t client_source_address, std::uint8_t activation_type, + EXPECT_CALL(*doip_tcp_handler_, + ProcessRoutingActivationRequestMessage(testing::_, testing::_, testing::_)) + .WillOnce(::testing::Invoke([this](std::uint16_t client_source_address, + std::uint8_t activation_type, std::optional vm_specific) { EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); EXPECT_EQ(activation_type, kDoipRoutingActivationReqActTypeDefault); EXPECT_FALSE(vm_specific.has_value()); // Send Routing activation response doip_tcp_handler_->SendTcpMessage(common::handler::ComposeRoutingActivationResponse( - client_source_address, kDiagServerLogicalAddress, kDoipRoutingActivationResCodeRoutingSuccessful, - std::nullopt)); + client_source_address, kDiagServerLogicalAddress, + kDoipRoutingActivationResCodeRoutingSuccessful, std::nullopt)); })); - EXPECT_CALL(*doip_tcp_handler_, ProcessDiagnosticRequestMessage(testing::_, testing::_, testing::_)) - .WillOnce(::testing::Invoke([this, &kDiagRequest, &kDiagPendingResponse, &kDiagFinalResponse]( - std::uint16_t client_source_address, std::uint16_t server_target_address, + EXPECT_CALL(*doip_tcp_handler_, + ProcessDiagnosticRequestMessage(testing::_, testing::_, testing::_)) + .WillOnce(::testing::Invoke([this, &kDiagRequest, &kDiagPendingResponse, + &kDiagFinalResponse]( + std::uint16_t client_source_address, + std::uint16_t server_target_address, core_type::Span diag_request) { EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); EXPECT_EQ(server_target_address, kDiagServerLogicalAddress); EXPECT_THAT(diag_request, testing::ElementsAreArray(kDiagRequest)); // Send Diagnostic Positive Acknowledgement message - doip_tcp_handler_->SendTcpMessage(common::handler::ComposeDiagnosticPositiveAcknowledgementMessage( - kDiagServerLogicalAddress, kDiagClientLogicalAddress, kDoipDiagnosticMessagePosAckCodeConfirm)); + doip_tcp_handler_->SendTcpMessage( + common::handler::ComposeDiagnosticPositiveAcknowledgementMessage( + kDiagServerLogicalAddress, kDiagClientLogicalAddress, + kDoipDiagnosticMessagePosAckCodeConfirm)); // Send Diagnostic pending response message for (std::uint8_t pending_count{0}; pending_count < kNumOfPending; pending_count++) { doip_tcp_handler_->SendTcpMessage(common::handler::ComposeDiagnosticResponseMessage( @@ -323,7 +353,8 @@ TEST_F(DiagMessageFixture, VerifyDiagPendingResponse) { diag::client::Result - diag_result{diag_client_conversation.GetConversation().SendDiagnosticRequest(std::move(uds_message))}; + diag_result{ + diag_client_conversation.GetConversation().SendDiagnosticRequest(std::move(uds_message))}; ASSERT_TRUE(diag_result.HasValue()); EXPECT_THAT(diag_result.Value()->GetPayload(), testing::ElementsAreArray(kDiagFinalResponse)); @@ -337,29 +368,35 @@ TEST_F(DiagMessageFixture, VerifyDiagResponseTimeout) { std::future is_server_created{CreateServerWithExpectation([this, &kDiagRequest]() { // Create an expectation of routing activation response - EXPECT_CALL(*doip_tcp_handler_, ProcessRoutingActivationRequestMessage(testing::_, testing::_, testing::_)) - .WillOnce(::testing::Invoke([this](std::uint16_t client_source_address, std::uint8_t activation_type, + EXPECT_CALL(*doip_tcp_handler_, + ProcessRoutingActivationRequestMessage(testing::_, testing::_, testing::_)) + .WillOnce(::testing::Invoke([this](std::uint16_t client_source_address, + std::uint8_t activation_type, std::optional vm_specific) { EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); EXPECT_EQ(activation_type, kDoipRoutingActivationReqActTypeDefault); EXPECT_FALSE(vm_specific.has_value()); // Send Routing activation response doip_tcp_handler_->SendTcpMessage(common::handler::ComposeRoutingActivationResponse( - client_source_address, kDiagServerLogicalAddress, kDoipRoutingActivationResCodeRoutingSuccessful, - std::nullopt)); + client_source_address, kDiagServerLogicalAddress, + kDoipRoutingActivationResCodeRoutingSuccessful, std::nullopt)); })); - EXPECT_CALL(*doip_tcp_handler_, ProcessDiagnosticRequestMessage(testing::_, testing::_, testing::_)) - .WillOnce(::testing::Invoke([this, &kDiagRequest](std::uint16_t client_source_address, - std::uint16_t server_target_address, - core_type::Span diag_request) { - EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); - EXPECT_EQ(server_target_address, kDiagServerLogicalAddress); - EXPECT_THAT(diag_request, testing::ElementsAreArray(kDiagRequest)); - // Send Diagnostic Positive Acknowledgement message - doip_tcp_handler_->SendTcpMessage(common::handler::ComposeDiagnosticPositiveAcknowledgementMessage( - kDiagServerLogicalAddress, kDiagClientLogicalAddress, kDoipDiagnosticMessagePosAckCodeConfirm)); - })); + EXPECT_CALL(*doip_tcp_handler_, + ProcessDiagnosticRequestMessage(testing::_, testing::_, testing::_)) + .WillOnce(::testing::Invoke( + [this, &kDiagRequest](std::uint16_t client_source_address, + std::uint16_t server_target_address, + core_type::Span diag_request) { + EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); + EXPECT_EQ(server_target_address, kDiagServerLogicalAddress); + EXPECT_THAT(diag_request, testing::ElementsAreArray(kDiagRequest)); + // Send Diagnostic Positive Acknowledgement message + doip_tcp_handler_->SendTcpMessage( + common::handler::ComposeDiagnosticPositiveAcknowledgementMessage( + kDiagServerLogicalAddress, kDiagClientLogicalAddress, + kDoipDiagnosticMessagePosAckCodeConfirm)); + })); })}; DiagConnectedConversation diag_client_conversation{*diag_client_, "DiagTesterOne"}; @@ -372,10 +409,12 @@ TEST_F(DiagMessageFixture, VerifyDiagResponseTimeout) { diag::client::Result - diag_result{diag_client_conversation.GetConversation().SendDiagnosticRequest(std::move(uds_message))}; + diag_result{ + diag_client_conversation.GetConversation().SendDiagnosticRequest(std::move(uds_message))}; ASSERT_FALSE(diag_result.HasValue()); - EXPECT_THAT(diag_result.Error(), diag::client::conversation::DiagClientConversation::DiagError::kDiagResponseTimeout); + EXPECT_THAT(diag_result.Error(), + diag::client::conversation::DiagClientConversation::DiagError::kDiagResponseTimeout); } /** @@ -384,20 +423,24 @@ TEST_F(DiagMessageFixture, VerifyDiagResponseTimeout) { TEST_F(DiagMessageFixture, VerifyInvalidParameterInRequest) { std::future is_server_created{CreateServerWithExpectation([this]() { // Create an expectation of routing activation response - EXPECT_CALL(*doip_tcp_handler_, ProcessRoutingActivationRequestMessage(testing::_, testing::_, testing::_)) - .WillOnce(::testing::Invoke([this](std::uint16_t client_source_address, std::uint8_t activation_type, + EXPECT_CALL(*doip_tcp_handler_, + ProcessRoutingActivationRequestMessage(testing::_, testing::_, testing::_)) + .WillOnce(::testing::Invoke([this](std::uint16_t client_source_address, + std::uint8_t activation_type, std::optional vm_specific) { EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); EXPECT_EQ(activation_type, kDoipRoutingActivationReqActTypeDefault); EXPECT_FALSE(vm_specific.has_value()); // Send Routing activation response doip_tcp_handler_->SendTcpMessage(common::handler::ComposeRoutingActivationResponse( - client_source_address, kDiagServerLogicalAddress, kDoipRoutingActivationResCodeRoutingSuccessful, - std::nullopt)); + client_source_address, kDiagServerLogicalAddress, + kDoipRoutingActivationResCodeRoutingSuccessful, std::nullopt)); })); // Expect no diagnostic request received - EXPECT_CALL(*doip_tcp_handler_, ProcessDiagnosticRequestMessage(testing::_, testing::_, testing::_)).Times(0u); + EXPECT_CALL(*doip_tcp_handler_, + ProcessDiagnosticRequestMessage(testing::_, testing::_, testing::_)) + .Times(0u); })}; DiagConnectedConversation diag_client_conversation{*diag_client_, "DiagTesterOne"}; @@ -409,7 +452,8 @@ TEST_F(DiagMessageFixture, VerifyInvalidParameterInRequest) { diag::client::Result - diag_result{diag_client_conversation.GetConversation().SendDiagnosticRequest(std::move(uds_message))}; + diag_result{ + diag_client_conversation.GetConversation().SendDiagnosticRequest(std::move(uds_message))}; ASSERT_FALSE(diag_result.HasValue()); EXPECT_THAT(diag_result.Error(), @@ -424,29 +468,34 @@ TEST_P(DiagMessageFixtureValueParameter, VerifyDiagNegativeAcknowledgement) { std::future is_server_created{CreateServerWithExpectation([this, &kDiagRequest]() { // Create an expectation of routing activation response - EXPECT_CALL(*doip_tcp_handler_, ProcessRoutingActivationRequestMessage(testing::_, testing::_, testing::_)) - .WillOnce(::testing::Invoke([this](std::uint16_t client_source_address, std::uint8_t activation_type, + EXPECT_CALL(*doip_tcp_handler_, + ProcessRoutingActivationRequestMessage(testing::_, testing::_, testing::_)) + .WillOnce(::testing::Invoke([this](std::uint16_t client_source_address, + std::uint8_t activation_type, std::optional vm_specific) { EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); EXPECT_EQ(activation_type, kDoipRoutingActivationReqActTypeDefault); EXPECT_FALSE(vm_specific.has_value()); // Send Routing activation response doip_tcp_handler_->SendTcpMessage(common::handler::ComposeRoutingActivationResponse( - client_source_address, kDiagServerLogicalAddress, kDoipRoutingActivationResCodeRoutingSuccessful, - std::nullopt)); + client_source_address, kDiagServerLogicalAddress, + kDoipRoutingActivationResCodeRoutingSuccessful, std::nullopt)); })); - EXPECT_CALL(*doip_tcp_handler_, ProcessDiagnosticRequestMessage(testing::_, testing::_, testing::_)) - .WillOnce(::testing::Invoke([this, &kDiagRequest](std::uint16_t client_source_address, - std::uint16_t server_target_address, - core_type::Span diag_request) { - EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); - EXPECT_EQ(server_target_address, kDiagServerLogicalAddress); - EXPECT_THAT(diag_request, testing::ElementsAreArray(kDiagRequest)); - // Send Diagnostic negative Acknowledgement message - doip_tcp_handler_->SendTcpMessage(common::handler::ComposeDiagnosticNegativeAcknowledgementMessage( - kDiagServerLogicalAddress, kDiagClientLogicalAddress, GetParam())); - })); + EXPECT_CALL(*doip_tcp_handler_, + ProcessDiagnosticRequestMessage(testing::_, testing::_, testing::_)) + .WillOnce(::testing::Invoke( + [this, &kDiagRequest](std::uint16_t client_source_address, + std::uint16_t server_target_address, + core_type::Span diag_request) { + EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); + EXPECT_EQ(server_target_address, kDiagServerLogicalAddress); + EXPECT_THAT(diag_request, testing::ElementsAreArray(kDiagRequest)); + // Send Diagnostic negative Acknowledgement message + doip_tcp_handler_->SendTcpMessage( + common::handler::ComposeDiagnosticNegativeAcknowledgementMessage( + kDiagServerLogicalAddress, kDiagClientLogicalAddress, GetParam())); + })); })}; DiagConnectedConversation diag_client_conversation{*diag_client_, "DiagTesterOne"}; @@ -459,10 +508,12 @@ TEST_P(DiagMessageFixtureValueParameter, VerifyDiagNegativeAcknowledgement) { diag::client::Result - diag_result{diag_client_conversation.GetConversation().SendDiagnosticRequest(std::move(uds_message))}; + diag_result{ + diag_client_conversation.GetConversation().SendDiagnosticRequest(std::move(uds_message))}; ASSERT_FALSE(diag_result.HasValue()); - EXPECT_THAT(diag_result.Error(), diag::client::conversation::DiagClientConversation::DiagError::kDiagNegAckReceived); + EXPECT_THAT(diag_result.Error(), + diag::client::conversation::DiagClientConversation::DiagError::kDiagNegAckReceived); } /** @@ -473,21 +524,25 @@ TEST_F(DiagMessageFixture, VerifyDiagAcknowledgementTimeout) { std::future is_server_created{CreateServerWithExpectation([this, &kDiagRequest]() { // Create an expectation of routing activation response - EXPECT_CALL(*doip_tcp_handler_, ProcessRoutingActivationRequestMessage(testing::_, testing::_, testing::_)) - .WillOnce(::testing::Invoke([this](std::uint16_t client_source_address, std::uint8_t activation_type, + EXPECT_CALL(*doip_tcp_handler_, + ProcessRoutingActivationRequestMessage(testing::_, testing::_, testing::_)) + .WillOnce(::testing::Invoke([this](std::uint16_t client_source_address, + std::uint8_t activation_type, std::optional vm_specific) { EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); EXPECT_EQ(activation_type, kDoipRoutingActivationReqActTypeDefault); EXPECT_FALSE(vm_specific.has_value()); // Send Routing activation response doip_tcp_handler_->SendTcpMessage(common::handler::ComposeRoutingActivationResponse( - client_source_address, kDiagServerLogicalAddress, kDoipRoutingActivationResCodeRoutingSuccessful, - std::nullopt)); + client_source_address, kDiagServerLogicalAddress, + kDoipRoutingActivationResCodeRoutingSuccessful, std::nullopt)); })); - EXPECT_CALL(*doip_tcp_handler_, ProcessDiagnosticRequestMessage(testing::_, testing::_, testing::_)) + EXPECT_CALL(*doip_tcp_handler_, + ProcessDiagnosticRequestMessage(testing::_, testing::_, testing::_)) .WillOnce( - ::testing::Invoke([&kDiagRequest](std::uint16_t client_source_address, std::uint16_t server_target_address, + ::testing::Invoke([&kDiagRequest](std::uint16_t client_source_address, + std::uint16_t server_target_address, core_type::Span diag_request) { EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); EXPECT_EQ(server_target_address, kDiagServerLogicalAddress); @@ -505,10 +560,12 @@ TEST_F(DiagMessageFixture, VerifyDiagAcknowledgementTimeout) { diag::client::Result - diag_result{diag_client_conversation.GetConversation().SendDiagnosticRequest(std::move(uds_message))}; + diag_result{ + diag_client_conversation.GetConversation().SendDiagnosticRequest(std::move(uds_message))}; ASSERT_FALSE(diag_result.HasValue()); - EXPECT_THAT(diag_result.Error(), diag::client::conversation::DiagClientConversation::DiagError::kDiagAckTimeout); + EXPECT_THAT(diag_result.Error(), + diag::client::conversation::DiagClientConversation::DiagError::kDiagAckTimeout); } } // namespace test_cases diff --git a/test/component/test_cases/routing_activation_test.cpp b/test/component/test_cases/routing_activation_test.cpp index ab515548..0bc504c1 100644 --- a/test/component/test_cases/routing_activation_test.cpp +++ b/test/component/test_cases/routing_activation_test.cpp @@ -71,16 +71,17 @@ class RoutingActivationFixture : public component::ComponentTest { // Function to create a Tcp server with test expectation template auto CreateServerWithExpectation(Functor expectation_functor) noexcept -> std::future { - return std::async(std::launch::async, [this, expectation_functor = std::move(expectation_functor)]() { - std::optional server{tcp_acceptor_.GetTcpServer()}; - if (server.has_value()) { - doip_tcp_handler_.emplace(std::move(server).value()); - doip_tcp_handler_->Initialize(); - // Set Expectation - expectation_functor(); - } - return doip_tcp_handler_.has_value(); - }); + return std::async(std::launch::async, + [this, expectation_functor = std::move(expectation_functor)]() { + std::optional server{tcp_acceptor_.GetTcpServer()}; + if (server.has_value()) { + doip_tcp_handler_.emplace(std::move(server).value()); + doip_tcp_handler_->Initialize(); + // Set Expectation + expectation_functor(); + } + return doip_tcp_handler_.has_value(); + }); } protected: @@ -100,16 +101,18 @@ class RoutingActivationFixture : public component::ComponentTest { TEST_F(RoutingActivationFixture, VerifyRoutingActivationSuccessful) { std::future is_server_created{CreateServerWithExpectation([this]() { // Create an expectation of routing activation response - EXPECT_CALL(*doip_tcp_handler_, ProcessRoutingActivationRequestMessage(testing::_, testing::_, testing::_)) - .WillOnce(::testing::Invoke([this](std::uint16_t client_source_address, std::uint8_t activation_type, + EXPECT_CALL(*doip_tcp_handler_, + ProcessRoutingActivationRequestMessage(testing::_, testing::_, testing::_)) + .WillOnce(::testing::Invoke([this](std::uint16_t client_source_address, + std::uint8_t activation_type, std::optional vm_specific) { EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); EXPECT_EQ(activation_type, kDoipRoutingActivationReqActTypeDefault); EXPECT_FALSE(vm_specific.has_value()); // Send Routing activation response doip_tcp_handler_->SendTcpMessage(common::handler::ComposeRoutingActivationResponse( - client_source_address, kDiagServerLogicalAddress, kDoipRoutingActivationResCodeRoutingSuccessful, - std::nullopt)); + client_source_address, kDiagServerLogicalAddress, + kDoipRoutingActivationResCodeRoutingSuccessful, std::nullopt)); })); })}; @@ -123,27 +126,33 @@ TEST_F(RoutingActivationFixture, VerifyRoutingActivationSuccessful) { diag_client_conversation.ConnectToDiagServer(kDiagServerLogicalAddress, kDiagTcpIpAddress)}; ASSERT_TRUE(is_server_created.get()); - EXPECT_EQ(connect_result, diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); + EXPECT_EQ(connect_result, + diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); diag::client::conversation::DiagClientConversation::DisconnectResult disconnect_result{ diag_client_conversation.DisconnectFromDiagServer()}; - EXPECT_EQ(disconnect_result, - diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); + EXPECT_EQ( + disconnect_result, + diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); diag_client_conversation.Shutdown(); } class RoutingActivationFixtureValueParameter : public RoutingActivationFixture, - public ::testing::WithParamInterface {}; + public ::testing::WithParamInterface { +}; -INSTANTIATE_TEST_SUITE_P( - RoutingActivation, RoutingActivationFixtureValueParameter, - testing::Values(kDoipRoutingActivationResCodeUnknownSa, kDoipRoutingActivationResCodeAllSocketActive, - kDoipRoutingActivationResCodeDifferentSa, kDoipRoutingActivationResCodeActiveSa, - kDoipRoutingActivationResCodeAuthentnMissng, kDoipRoutingActivationResCodeConfirmtnRejectd, - kDoipRoutingActivationResCodeUnsupportdActType, kDoipRoutingActivationResCodeTlsRequired, - kDoipRoutingActivationResCodeConfirmtnRequired)); +INSTANTIATE_TEST_SUITE_P(RoutingActivation, RoutingActivationFixtureValueParameter, + testing::Values(kDoipRoutingActivationResCodeUnknownSa, + kDoipRoutingActivationResCodeAllSocketActive, + kDoipRoutingActivationResCodeDifferentSa, + kDoipRoutingActivationResCodeActiveSa, + kDoipRoutingActivationResCodeAuthentnMissng, + kDoipRoutingActivationResCodeConfirmtnRejectd, + kDoipRoutingActivationResCodeUnsupportdActType, + kDoipRoutingActivationResCodeTlsRequired, + kDoipRoutingActivationResCodeConfirmtnRequired)); /** * @brief Verify that sending of routing activation request fails on reception of negative activation code . @@ -151,8 +160,10 @@ INSTANTIATE_TEST_SUITE_P( TEST_P(RoutingActivationFixtureValueParameter, VerifyRoutingActivationFailure) { std::future is_server_created{CreateServerWithExpectation([this]() { // Create an expectation of routing activation response - EXPECT_CALL(*doip_tcp_handler_, ProcessRoutingActivationRequestMessage(testing::_, testing::_, testing::_)) - .WillOnce(::testing::Invoke([this](std::uint16_t client_source_address, std::uint8_t activation_type, + EXPECT_CALL(*doip_tcp_handler_, + ProcessRoutingActivationRequestMessage(testing::_, testing::_, testing::_)) + .WillOnce(::testing::Invoke([this](std::uint16_t client_source_address, + std::uint8_t activation_type, std::optional vm_specific) { EXPECT_EQ(client_source_address, kDiagClientLogicalAddress); EXPECT_EQ(activation_type, kDoipRoutingActivationReqActTypeDefault); @@ -173,13 +184,15 @@ TEST_P(RoutingActivationFixtureValueParameter, VerifyRoutingActivationFailure) { diag_client_conversation.ConnectToDiagServer(kDiagServerLogicalAddress, kDiagTcpIpAddress)}; ASSERT_TRUE(is_server_created.get()); - EXPECT_EQ(connect_result, diag::client::conversation::DiagClientConversation::ConnectResult::kConnectFailed); + EXPECT_EQ(connect_result, + diag::client::conversation::DiagClientConversation::ConnectResult::kConnectFailed); diag::client::conversation::DiagClientConversation::DisconnectResult disconnect_result{ diag_client_conversation.DisconnectFromDiagServer()}; - EXPECT_EQ(disconnect_result, - diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); + EXPECT_EQ( + disconnect_result, + diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); diag_client_conversation.Shutdown(); } diff --git a/test/component/test_cases/tls_test.cpp b/test/component/test_cases/tls_test.cpp index a77d4ba4..60442189 100644 --- a/test/component/test_cases/tls_test.cpp +++ b/test/component/test_cases/tls_test.cpp @@ -65,14 +65,16 @@ class Tls12Fixture : public component::ComponentTest { : tls_acceptor_{kTlsServerIpAddress, kTlsServerTcpPortNum, 1u, - TlsServerVersion{{TlsServerCipherSuite::TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, - TlsServerCipherSuite ::TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}}, + TlsServerVersion{ + {TlsServerCipherSuite::TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, + TlsServerCipherSuite ::TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}}, kCertificatePath, kPrivateKeyPath}, tls_server_{}, - tls_client_{kTlsClientIpAddress, kTlsClientTcpPortNum, kCACertificatePath, - TlsClientVersion{{TlsClientCipherSuite::TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, - TlsClientCipherSuite::TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256}}} {} + tls_client_{ + kTlsClientIpAddress, kTlsClientTcpPortNum, kCACertificatePath, + TlsClientVersion{{TlsClientCipherSuite::TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, + TlsClientCipherSuite::TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256}}} {} void SetUp() override { tls_client_.Initialize(); } @@ -83,16 +85,17 @@ class Tls12Fixture : public component::ComponentTest { template auto CreateServerWithExpectation(Functor expectation_functor) noexcept -> std::future { - return std::async(std::launch::async, [this, expectation_functor = std::move(expectation_functor)]() { - std::optional server{tls_acceptor_.GetTlsServer()}; - if (server.has_value()) { - tls_server_.emplace(std::move(server).value()); - tls_server_->Initialize(); - // Set Expectation - expectation_functor(); - } - return tls_server_.has_value(); - }); + return std::async(std::launch::async, + [this, expectation_functor = std::move(expectation_functor)]() { + std::optional server{tls_acceptor_.GetTlsServer()}; + if (server.has_value()) { + tls_server_.emplace(std::move(server).value()); + tls_server_->Initialize(); + // Set Expectation + expectation_functor(); + } + return tls_server_.has_value(); + }); } protected: @@ -122,9 +125,10 @@ TEST_F(Tls12Fixture, SendDataFromClientToServer) { EXPECT_TRUE(tls_client_.ConnectToHost(kTlsServerIpAddress, kTlsServerTcpPortNum).HasValue()); EXPECT_TRUE(tls_client_.IsConnectedToHost()); // Send test data to tls server - EXPECT_TRUE( - tls_client_.Transmit(std::make_unique(kTlsServerIpAddress, kTlsServerTcpPortNum, kTestData)) - .HasValue()); + EXPECT_TRUE(tls_client_ + .Transmit(std::make_unique(kTlsServerIpAddress, + kTlsServerTcpPortNum, kTestData)) + .HasValue()); } TEST_F(Tls12Fixture, SendDataFromServerToClient) {} diff --git a/test/component/test_cases/vehicle_discovery_test.cpp b/test/component/test_cases/vehicle_discovery_test.cpp index adf30262..6bbdaef2 100644 --- a/test/component/test_cases/vehicle_discovery_test.cpp +++ b/test/component/test_cases/vehicle_discovery_test.cpp @@ -67,17 +67,19 @@ TEST_F(VehicleDiscoveryFixture, VerifyPreselectionModeEmpty) { std::uint16_t const kLogicalAddress{0xFA25u}; // Create an expectation of vehicle identification response - EXPECT_CALL(doip_udp_handler_, - ProcessVehicleIdentificationRequestMessage(testing::_, testing::_, testing::_, testing::_)) - .WillOnce(::testing::Invoke([this, kVin, kEid, kGid](std::string_view client_ip_address, - std::uint16_t client_port_number, std::string_view eid, - std::string_view vin) { - EXPECT_TRUE(eid.empty()); - EXPECT_TRUE(vin.empty()); - // Send Vehicle Identification response - doip_udp_handler_.SendUdpMessage(doip_udp_handler_.ComposeVehicleIdentificationResponse( - client_ip_address, client_port_number, kVin, kLogicalAddress, kEid, kGid, 0, std::nullopt)); - })); + EXPECT_CALL(doip_udp_handler_, ProcessVehicleIdentificationRequestMessage(testing::_, testing::_, + testing::_, testing::_)) + .WillOnce( + ::testing::Invoke([this, kVin, kEid, kGid](std::string_view client_ip_address, + std::uint16_t client_port_number, + std::string_view eid, std::string_view vin) { + EXPECT_TRUE(eid.empty()); + EXPECT_TRUE(vin.empty()); + // Send Vehicle Identification response + doip_udp_handler_.SendUdpMessage(doip_udp_handler_.ComposeVehicleIdentificationResponse( + client_ip_address, client_port_number, kVin, kLogicalAddress, kEid, kGid, 0, + std::nullopt)); + })); // Send Vehicle Identification request and expect response diag::client::vehicle_info::VehicleInfoListRequestType vehicle_info_request{0u, ""}; @@ -88,8 +90,8 @@ TEST_F(VehicleDiscoveryFixture, VerifyPreselectionModeEmpty) { ASSERT_TRUE(response.HasValue()); // Get the list of all vehicle available - diag::client::vehicle_info::VehicleInfoMessage::VehicleInfoListResponseType const response_collection{ - response.Value()->GetVehicleList()}; + diag::client::vehicle_info::VehicleInfoMessage::VehicleInfoListResponseType const + response_collection{response.Value()->GetVehicleList()}; // Expect only one vehicle available EXPECT_EQ(response_collection.size(), 1U); @@ -110,20 +112,23 @@ TEST_F(VehicleDiscoveryFixture, VerifyPreselectionModeVin) { std::uint16_t const kLogicalAddress{0xFA25u}; // Create an expectation of vehicle identification response - EXPECT_CALL(doip_udp_handler_, - ProcessVehicleIdentificationRequestMessage(testing::_, testing::_, testing::_, testing::_)) - .WillOnce(::testing::Invoke([this, kVin, kEid, kGid](std::string_view client_ip_address, - std::uint16_t client_port_number, std::string_view eid, - std::string_view vin) { - EXPECT_TRUE(eid.empty()); - EXPECT_EQ(vin, kVin); - // Send Vehicle Identification response - doip_udp_handler_.SendUdpMessage(doip_udp_handler_.ComposeVehicleIdentificationResponse( - client_ip_address, client_port_number, kVin, kLogicalAddress, kEid, kGid, 0, std::nullopt)); - })); + EXPECT_CALL(doip_udp_handler_, ProcessVehicleIdentificationRequestMessage(testing::_, testing::_, + testing::_, testing::_)) + .WillOnce( + ::testing::Invoke([this, kVin, kEid, kGid](std::string_view client_ip_address, + std::uint16_t client_port_number, + std::string_view eid, std::string_view vin) { + EXPECT_TRUE(eid.empty()); + EXPECT_EQ(vin, kVin); + // Send Vehicle Identification response + doip_udp_handler_.SendUdpMessage(doip_udp_handler_.ComposeVehicleIdentificationResponse( + client_ip_address, client_port_number, kVin, kLogicalAddress, kEid, kGid, 0, + std::nullopt)); + })); // Send Vehicle Identification request and expect response - diag::client::vehicle_info::VehicleInfoListRequestType vehicle_info_request{1u, std::string{kVin}}; + diag::client::vehicle_info::VehicleInfoListRequestType vehicle_info_request{1u, + std::string{kVin}}; diag::client::Result response{diag_client_->SendVehicleIdentificationRequest(std::move(vehicle_info_request))}; @@ -131,8 +136,8 @@ TEST_F(VehicleDiscoveryFixture, VerifyPreselectionModeVin) { ASSERT_TRUE(response.HasValue()); // Get the list of all vehicle available - diag::client::vehicle_info::VehicleInfoMessage::VehicleInfoListResponseType const response_collection{ - response.Value()->GetVehicleList()}; + diag::client::vehicle_info::VehicleInfoMessage::VehicleInfoListResponseType const + response_collection{response.Value()->GetVehicleList()}; // Expect only one vehicle available EXPECT_EQ(response_collection.size(), 1U); @@ -153,20 +158,23 @@ TEST_F(VehicleDiscoveryFixture, VerifyPreselectionModeEid) { std::uint16_t const kLogicalAddress{0xFA25u}; // Create an expectation of vehicle identification response - EXPECT_CALL(doip_udp_handler_, - ProcessVehicleIdentificationRequestMessage(testing::_, testing::_, testing::_, testing::_)) - .WillOnce(::testing::Invoke([this, kVin, kEid, kGid](std::string_view client_ip_address, - std::uint16_t client_port_number, std::string_view eid, - std::string_view vin) { - EXPECT_TRUE(vin.empty()); - EXPECT_EQ(eid, kEid); - // Send Vehicle Identification response - doip_udp_handler_.SendUdpMessage(doip_udp_handler_.ComposeVehicleIdentificationResponse( - client_ip_address, client_port_number, kVin, kLogicalAddress, kEid, kGid, 0, std::nullopt)); - })); + EXPECT_CALL(doip_udp_handler_, ProcessVehicleIdentificationRequestMessage(testing::_, testing::_, + testing::_, testing::_)) + .WillOnce( + ::testing::Invoke([this, kVin, kEid, kGid](std::string_view client_ip_address, + std::uint16_t client_port_number, + std::string_view eid, std::string_view vin) { + EXPECT_TRUE(vin.empty()); + EXPECT_EQ(eid, kEid); + // Send Vehicle Identification response + doip_udp_handler_.SendUdpMessage(doip_udp_handler_.ComposeVehicleIdentificationResponse( + client_ip_address, client_port_number, kVin, kLogicalAddress, kEid, kGid, 0, + std::nullopt)); + })); // Send Vehicle Identification request and expect response - diag::client::vehicle_info::VehicleInfoListRequestType vehicle_info_request{2u, std::string{kEid}}; + diag::client::vehicle_info::VehicleInfoListRequestType vehicle_info_request{2u, + std::string{kEid}}; diag::client::Result response{diag_client_->SendVehicleIdentificationRequest(std::move(vehicle_info_request))}; @@ -174,8 +182,8 @@ TEST_F(VehicleDiscoveryFixture, VerifyPreselectionModeEid) { ASSERT_TRUE(response.HasValue()); // Get the list of all vehicle available - diag::client::vehicle_info::VehicleInfoMessage::VehicleInfoListResponseType const response_collection{ - response.Value()->GetVehicleList()}; + diag::client::vehicle_info::VehicleInfoMessage::VehicleInfoListResponseType const + response_collection{response.Value()->GetVehicleList()}; // Expect only one vehicle available EXPECT_EQ(response_collection.size(), 1U); @@ -190,8 +198,10 @@ TEST_F(VehicleDiscoveryFixture, VerifyPreselectionModeEid) { class MultipleVehicleDiscoveryFixture : public component::ComponentTest { protected: MultipleVehicleDiscoveryFixture() - : first_doip_udp_handler_{kDiagUdpBroadCastIpAddress, kDiagUdpUnicastIpAddress, kDiagUdpPortNum}, - second_doip_udp_handler_{kDiagUdpBroadCastIpAddress, kDiagUdpAnotherUnicastIpAddress, kDiagUdpPortNum}, + : first_doip_udp_handler_{kDiagUdpBroadCastIpAddress, kDiagUdpUnicastIpAddress, + kDiagUdpPortNum}, + second_doip_udp_handler_{kDiagUdpBroadCastIpAddress, kDiagUdpAnotherUnicastIpAddress, + kDiagUdpPortNum}, diag_client_{diag::client::CreateDiagnosticClient(kDiagClientConfigPath)} {} void SetUp() override { @@ -231,33 +241,38 @@ TEST_F(MultipleVehicleDiscoveryFixture, VerifyPreselectionModeVin) { }; std::vector const kExpectedResponse{ - {"ABCDEFGH123456789", "00:02:36:31:00:1c", "0a:0b:0c:0d:0e:0f", kDiagUdpUnicastIpAddress, 0xFA25u}, - {"IJKLMNOP123456789", "00:02:36:32:00:1d", "0a:0b:0c:0d:0e:0f", kDiagUdpAnotherUnicastIpAddress, 0xFA26u}}; + {"ABCDEFGH123456789", "00:02:36:31:00:1c", "0a:0b:0c:0d:0e:0f", kDiagUdpUnicastIpAddress, + 0xFA25u}, + {"IJKLMNOP123456789", "00:02:36:32:00:1d", "0a:0b:0c:0d:0e:0f", + kDiagUdpAnotherUnicastIpAddress, 0xFA26u}}; // This is needed so that first doip handler always sends the response first std::promise is_response_sent_promise{}; std::future is_response_sent_future{is_response_sent_promise.get_future()}; // Create an expectation of vehicle identification response - EXPECT_CALL(first_doip_udp_handler_, - ProcessVehicleIdentificationRequestMessage(testing::_, testing::_, testing::_, testing::_)) + EXPECT_CALL(first_doip_udp_handler_, ProcessVehicleIdentificationRequestMessage( + testing::_, testing::_, testing::_, testing::_)) .WillOnce(::testing::Invoke([this, &kExpectedResponse, &is_response_sent_promise]( - std::string_view client_ip_address, std::uint16_t client_port_number, - std::string_view eid, std::string_view vin) { + std::string_view client_ip_address, + std::uint16_t client_port_number, std::string_view eid, + std::string_view vin) { EXPECT_TRUE(eid.empty()); EXPECT_TRUE(vin.empty()); // Send Vehicle Identification response - first_doip_udp_handler_.SendUdpMessage(first_doip_udp_handler_.ComposeVehicleIdentificationResponse( - client_ip_address, client_port_number, kExpectedResponse.at(0u).vin, - kExpectedResponse.at(0u).logical_address, kExpectedResponse.at(0u).eid, kExpectedResponse.at(0u).gid, 0, - std::nullopt)); + first_doip_udp_handler_.SendUdpMessage( + first_doip_udp_handler_.ComposeVehicleIdentificationResponse( + client_ip_address, client_port_number, kExpectedResponse.at(0u).vin, + kExpectedResponse.at(0u).logical_address, kExpectedResponse.at(0u).eid, + kExpectedResponse.at(0u).gid, 0, std::nullopt)); is_response_sent_promise.set_value(true); })); - EXPECT_CALL(second_doip_udp_handler_, - ProcessVehicleIdentificationRequestMessage(testing::_, testing::_, testing::_, testing::_)) + EXPECT_CALL(second_doip_udp_handler_, ProcessVehicleIdentificationRequestMessage( + testing::_, testing::_, testing::_, testing::_)) .WillOnce(::testing::Invoke([this, &kExpectedResponse, &is_response_sent_future]( - std::string_view client_ip_address, std::uint16_t client_port_number, - std::string_view eid, std::string_view vin) { + std::string_view client_ip_address, + std::uint16_t client_port_number, std::string_view eid, + std::string_view vin) { EXPECT_TRUE(eid.empty()); EXPECT_TRUE(vin.empty()); if (is_response_sent_future.get()) { @@ -265,10 +280,11 @@ TEST_F(MultipleVehicleDiscoveryFixture, VerifyPreselectionModeVin) { // sending the response std::this_thread::sleep_for(std::chrono::seconds(1)); // Send Vehicle Identification response - second_doip_udp_handler_.SendUdpMessage(second_doip_udp_handler_.ComposeVehicleIdentificationResponse( - client_ip_address, client_port_number, kExpectedResponse.at(1u).vin, - kExpectedResponse.at(1u).logical_address, kExpectedResponse.at(1u).eid, kExpectedResponse.at(1u).gid, 0, - std::nullopt)); + second_doip_udp_handler_.SendUdpMessage( + second_doip_udp_handler_.ComposeVehicleIdentificationResponse( + client_ip_address, client_port_number, kExpectedResponse.at(1u).vin, + kExpectedResponse.at(1u).logical_address, kExpectedResponse.at(1u).eid, + kExpectedResponse.at(1u).gid, 0, std::nullopt)); } })); @@ -281,8 +297,8 @@ TEST_F(MultipleVehicleDiscoveryFixture, VerifyPreselectionModeVin) { ASSERT_TRUE(response.HasValue()); // Get the list of all vehicle available - diag::client::vehicle_info::VehicleInfoMessage::VehicleInfoListResponseType const response_collection{ - response.Value()->GetVehicleList()}; + diag::client::vehicle_info::VehicleInfoMessage::VehicleInfoListResponseType const + response_collection{response.Value()->GetVehicleList()}; // Expect two vehicle available EXPECT_EQ(response_collection.size(), kExpectedResponse.size()); @@ -291,7 +307,8 @@ TEST_F(MultipleVehicleDiscoveryFixture, VerifyPreselectionModeVin) { for (VehicleIdentificationResponse const &expected_response: kExpectedResponse) { EXPECT_EQ(response_collection[vehicle_number].ip_address, expected_response.ip_address); - EXPECT_EQ(response_collection[vehicle_number].logical_address, expected_response.logical_address); + EXPECT_EQ(response_collection[vehicle_number].logical_address, + expected_response.logical_address); EXPECT_EQ(response_collection[vehicle_number].vin, expected_response.vin); EXPECT_EQ(response_collection[vehicle_number].eid, expected_response.eid); EXPECT_EQ(response_collection[vehicle_number].gid, expected_response.gid); diff --git a/test/test_case/diag_request_response_test.cpp b/test/test_case/diag_request_response_test.cpp index 446c760b..68367c96 100644 --- a/test/test_case/diag_request_response_test.cpp +++ b/test/test_case/diag_request_response_test.cpp @@ -125,7 +125,8 @@ class DiagReqResFixture : public ::testing::Test { TEST_F(DiagReqResFixture, VerifyRoutingActivationSuccessful) { // Get the doip channel and Initialize it - DoipTcpHandler::DoipChannel& doip_channel{GetDoipTestTcpHandlerRef().CreateDoipChannel(DiagServerLogicalAddress)}; + DoipTcpHandler::DoipChannel& doip_channel{ + GetDoipTestTcpHandlerRef().CreateDoipChannel(DiagServerLogicalAddress)}; doip_channel.Initialize(); // Get conversation for tester one and start up the conversation @@ -137,13 +138,15 @@ TEST_F(DiagReqResFixture, VerifyRoutingActivationSuccessful) { diag::client::conversation::DiagClientConversation::ConnectResult connect_result{ diag_client_conversation.ConnectToDiagServer(DiagServerLogicalAddress, DiagTcpIpAddress)}; - EXPECT_EQ(connect_result, diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); + EXPECT_EQ(connect_result, + diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); diag::client::conversation::DiagClientConversation::DisconnectResult disconnect_result{ diag_client_conversation.DisconnectFromDiagServer()}; - EXPECT_EQ(disconnect_result, - diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); + EXPECT_EQ( + disconnect_result, + diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); diag_client_conversation.Shutdown(); doip_channel.DeInitialize(); @@ -160,19 +163,22 @@ TEST_F(DiagReqResFixture, VerifyRoutingActivationFailure) { diag_client_conversation.Startup(); // Set expectation code - RoutingSuccess - doip_channel.SetExpectedRoutingActivationResponseToBeSent(kDoip_RoutingActivation_ResCode_UnknownSA); + doip_channel.SetExpectedRoutingActivationResponseToBeSent( + kDoip_RoutingActivation_ResCode_UnknownSA); // Connect Tester One to remote ip address 172.16.25.128 diag::client::conversation::DiagClientConversation::ConnectResult connect_result{ diag_client_conversation.ConnectToDiagServer(DiagServerLogicalAddress, DiagTcpIpAddress)}; - EXPECT_EQ(connect_result, diag::client::conversation::DiagClientConversation::ConnectResult::kConnectFailed); + EXPECT_EQ(connect_result, + diag::client::conversation::DiagClientConversation::ConnectResult::kConnectFailed); diag::client::conversation::DiagClientConversation::DisconnectResult disconnect_result{ diag_client_conversation.DisconnectFromDiagServer()}; - EXPECT_EQ(disconnect_result, - diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); + EXPECT_EQ( + disconnect_result, + diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); diag_client_conversation.Shutdown(); doip_channel.DeInitialize(); @@ -196,9 +202,11 @@ TEST_F(DiagReqResFixture, VerifyDiagPositiveResponseDiagSession) { // Connect Tester One to remote ip address 172.16.25.128 diag::client::conversation::DiagClientConversation::ConnectResult connect_result{ - diag_client_conversation.ConnectToDiagServer(DiagServerLogicalAddress, uds_message->GetHostIpAddress())}; + diag_client_conversation.ConnectToDiagServer(DiagServerLogicalAddress, + uds_message->GetHostIpAddress())}; - EXPECT_EQ(connect_result, diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); + EXPECT_EQ(connect_result, + diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); // Send Diagnostic message auto diag_result{diag_client_conversation.SendDiagnosticRequest(std::move(uds_message))}; @@ -211,8 +219,9 @@ TEST_F(DiagReqResFixture, VerifyDiagPositiveResponseDiagSession) { diag::client::conversation::DiagClientConversation::DisconnectResult disconnect_result{ diag_client_conversation.DisconnectFromDiagServer()}; - EXPECT_EQ(disconnect_result, - diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); + EXPECT_EQ( + disconnect_result, + diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); diag_client_conversation.Shutdown(); doip_channel.DeInitialize(); @@ -236,22 +245,26 @@ TEST_F(DiagReqResFixture, VerifyDiagNegativeResponseDiagSession) { diag::client::uds_message::UdsRequestMessagePtr uds_message{ std::make_unique(DiagTcpIpAddress, UdsMessage::ByteVector{0x10, 0x01})}; diag::client::conversation::DiagClientConversation::ConnectResult connect_result{ - diag_client_conversation.ConnectToDiagServer(DiagServerLogicalAddress, uds_message->GetHostIpAddress())}; + diag_client_conversation.ConnectToDiagServer(DiagServerLogicalAddress, + uds_message->GetHostIpAddress())}; - EXPECT_EQ(connect_result, diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); + EXPECT_EQ(connect_result, + diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); // Send Diagnostic message auto diag_result{diag_client_conversation.SendDiagnosticRequest(std::move(uds_message))}; // Verify positive response EXPECT_TRUE(diag_result.HasValue()); - EXPECT_THAT(diag_result.Value()->GetPayload(), ::testing::ElementsAreArray(diag_expected_response)); + EXPECT_THAT(diag_result.Value()->GetPayload(), + ::testing::ElementsAreArray(diag_expected_response)); diag::client::conversation::DiagClientConversation::DisconnectResult disconnect_result{ diag_client_conversation.DisconnectFromDiagServer()}; - EXPECT_EQ(disconnect_result, - diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); + EXPECT_EQ( + disconnect_result, + diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); diag_client_conversation.Shutdown(); doip_channel.DeInitialize(); @@ -263,7 +276,8 @@ TEST_F(DiagReqResFixture, VerifyDiagPositiveResponseReadDID) { doip_channel.Initialize(); // Create expected uds response - UdsMessage::ByteVector diag_expected_response{0x62, 0xF1, 0x90, 0x57, 0x3C, 0x50, 0x30, 0x30, 0x30}; + UdsMessage::ByteVector diag_expected_response{0x62, 0xF1, 0x90, 0x57, 0x3C, + 0x50, 0x30, 0x30, 0x30}; doip_channel.SetExpectedDiagnosticMessageUdsMessageToBeSend(diag_expected_response); // Get conversation for tester one and start up the conversation @@ -275,22 +289,26 @@ TEST_F(DiagReqResFixture, VerifyDiagPositiveResponseReadDID) { diag::client::uds_message::UdsRequestMessagePtr uds_message{ std::make_unique(DiagTcpIpAddress, UdsMessage::ByteVector{0x22, 0xF1, 0x90})}; diag::client::conversation::DiagClientConversation::ConnectResult connect_result{ - diag_client_conversation.ConnectToDiagServer(DiagServerLogicalAddress, uds_message->GetHostIpAddress())}; + diag_client_conversation.ConnectToDiagServer(DiagServerLogicalAddress, + uds_message->GetHostIpAddress())}; - EXPECT_EQ(connect_result, diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); + EXPECT_EQ(connect_result, + diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); // Send Diagnostic message auto diag_result{diag_client_conversation.SendDiagnosticRequest(std::move(uds_message))}; // Verify positive response EXPECT_TRUE(diag_result.HasValue()); - EXPECT_THAT(diag_result.Value()->GetPayload(), ::testing::ElementsAreArray(diag_expected_response)); + EXPECT_THAT(diag_result.Value()->GetPayload(), + ::testing::ElementsAreArray(diag_expected_response)); diag::client::conversation::DiagClientConversation::DisconnectResult disconnect_result{ diag_client_conversation.DisconnectFromDiagServer()}; - EXPECT_EQ(disconnect_result, - diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); + EXPECT_EQ( + disconnect_result, + diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); diag_client_conversation.Shutdown(); doip_channel.DeInitialize(); @@ -302,7 +320,8 @@ TEST_F(DiagReqResFixture, VerifyDiagPendingResponse) { doip_channel.Initialize(); // Create expected uds pending response - doip_channel.SetExpectedDiagnosticMessageWithPendingUdsMessageToBeSend(UdsMessage::ByteVector{0x7F, 0x10, 0x78}, 10u); + doip_channel.SetExpectedDiagnosticMessageWithPendingUdsMessageToBeSend( + UdsMessage::ByteVector{0x7F, 0x10, 0x78}, 10u); // Create expected uds positive response doip_channel.SetExpectedDiagnosticMessageUdsMessageToBeSend(UdsMessage::ByteVector{0x50, 0x01}); @@ -318,9 +337,11 @@ TEST_F(DiagReqResFixture, VerifyDiagPendingResponse) { // Connect Tester One to remote ip address 172.16.25.128 diag::client::conversation::DiagClientConversation::ConnectResult connect_result{ - diag_client_conversation.ConnectToDiagServer(DiagServerLogicalAddress, uds_message->GetHostIpAddress())}; + diag_client_conversation.ConnectToDiagServer(DiagServerLogicalAddress, + uds_message->GetHostIpAddress())}; - EXPECT_EQ(connect_result, diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); + EXPECT_EQ(connect_result, + diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); // Send Diagnostic message auto diag_result{diag_client_conversation.SendDiagnosticRequest(std::move(uds_message))}; @@ -333,8 +354,9 @@ TEST_F(DiagReqResFixture, VerifyDiagPendingResponse) { diag::client::conversation::DiagClientConversation::DisconnectResult disconnect_result{ diag_client_conversation.DisconnectFromDiagServer()}; - EXPECT_EQ(disconnect_result, - diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); + EXPECT_EQ( + disconnect_result, + diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); diag_client_conversation.Shutdown(); doip_channel.DeInitialize(); @@ -349,7 +371,8 @@ TEST_F(DiagReqResFixture, VerifyDiagNegAcknowledgement) { diag::client::uds_message::UdsRequestMessagePtr uds_message{ std::make_unique(DiagTcpIpAddress, UdsMessage::ByteVector{0x10, 0x01})}; // Create expected Diag NACK - doip_channel.SetExpectedDiagnosticMessageAckResponseToBeSend(kDoip_DiagnosticMessage_NegAckCode_InvalidSA); + doip_channel.SetExpectedDiagnosticMessageAckResponseToBeSend( + kDoip_DiagnosticMessage_NegAckCode_InvalidSA); // Get conversation for tester one and start up the conversation diag::client::conversation::DiagClientConversation diag_client_conversation{ @@ -358,22 +381,26 @@ TEST_F(DiagReqResFixture, VerifyDiagNegAcknowledgement) { // Connect Tester One to remote ip address 172.16.25.128 diag::client::conversation::DiagClientConversation::ConnectResult connect_result{ - diag_client_conversation.ConnectToDiagServer(DiagServerLogicalAddress, uds_message->GetHostIpAddress())}; + diag_client_conversation.ConnectToDiagServer(DiagServerLogicalAddress, + uds_message->GetHostIpAddress())}; - EXPECT_EQ(connect_result, diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); + EXPECT_EQ(connect_result, + diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); // Send Diagnostic message auto diag_result{diag_client_conversation.SendDiagnosticRequest(std::move(uds_message))}; // Verify Negative Acknowledgement EXPECT_FALSE(diag_result.HasValue()); - EXPECT_EQ(diag_result.Error(), diag::client::conversation::DiagClientConversation::DiagError::kDiagNegAckReceived); + EXPECT_EQ(diag_result.Error(), + diag::client::conversation::DiagClientConversation::DiagError::kDiagNegAckReceived); diag::client::conversation::DiagClientConversation::DisconnectResult disconnect_result{ diag_client_conversation.DisconnectFromDiagServer()}; - EXPECT_EQ(disconnect_result, - diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); + EXPECT_EQ( + disconnect_result, + diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); diag_client_conversation.Shutdown(); doip_channel.DeInitialize(); @@ -382,21 +409,24 @@ TEST_F(DiagReqResFixture, VerifyDiagNegAcknowledgement) { TEST_F(DiagReqResFixture, VerifyDiagReqResponseWithVehicleDiscovery) { // Test preparation // ======================================================== - doip_handler::DoipUdpHandler::VehicleAddrInfo vehicle_addr_response{DiagServerLogicalAddress, "ABCDEFGH123456789", - "00:02:36:31:00:1c", "0a:0b:0c:0d:0e:0f"}; + doip_handler::DoipUdpHandler::VehicleAddrInfo vehicle_addr_response{ + DiagServerLogicalAddress, "ABCDEFGH123456789", "00:02:36:31:00:1c", "0a:0b:0c:0d:0e:0f"}; // Get the doip channel and Initialize it - DoipTcpHandler::DoipChannel& doip_channel{GetDoipTestTcpHandlerRef().CreateDoipChannel(DiagServerLogicalAddress)}; + DoipTcpHandler::DoipChannel& doip_channel{ + GetDoipTestTcpHandlerRef().CreateDoipChannel(DiagServerLogicalAddress)}; doip_channel.Initialize(); // Create an expected vehicle identification response - GetDoipTestUdpHandlerRef().SetExpectedVehicleIdentificationResponseToBeSent(vehicle_addr_response); + GetDoipTestUdpHandlerRef().SetExpectedVehicleIdentificationResponseToBeSent( + vehicle_addr_response); // Create expected uds response doip_channel.SetExpectedDiagnosticMessageUdsMessageToBeSend(UdsMessage::ByteVector{0x50, 0x01}); // Test execution // ======================================================== // Send Vehicle Identification request with VIN and expect response - diag::client::vehicle_info::VehicleInfoListRequestType vehicle_info_request{1U, "ABCDEFGH123456789"}; + diag::client::vehicle_info::VehicleInfoListRequestType vehicle_info_request{1U, + "ABCDEFGH123456789"}; diag::client::Result response_result{GetDiagClientRef().SendVehicleIdentificationRequest(vehicle_info_request)}; @@ -410,8 +440,8 @@ TEST_F(DiagReqResFixture, VerifyDiagReqResponseWithVehicleDiscovery) { response_result.Value()->GetVehicleList()}; // Create uds message using response collection - diag::client::uds_message::UdsRequestMessagePtr uds_message{ - std::make_unique(response_collection[0].ip_address, UdsMessage::ByteVector{0x10, 0x01})}; + diag::client::uds_message::UdsRequestMessagePtr uds_message{std::make_unique( + response_collection[0].ip_address, UdsMessage::ByteVector{0x10, 0x01})}; // Get conversation for tester one and start up the conversation diag::client::conversation::DiagClientConversation diag_client_conversation{ @@ -423,21 +453,24 @@ TEST_F(DiagReqResFixture, VerifyDiagReqResponseWithVehicleDiscovery) { diag_client_conversation.ConnectToDiagServer(response_collection[0].logical_address, uds_message->GetHostIpAddress())}; - ASSERT_EQ(connect_result, diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); + ASSERT_EQ(connect_result, + diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); // Send Diagnostic message auto diag_result{diag_client_conversation.SendDiagnosticRequest(std::move(uds_message))}; // Verify positive response - EXPECT_TRUE(diag_result.HasValue()) << " Error received, code: " << static_cast(diag_result.Error()); + EXPECT_TRUE(diag_result.HasValue()) + << " Error received, code: " << static_cast(diag_result.Error()); EXPECT_EQ(diag_result.Value()->GetPayload()[0], 0x50); EXPECT_EQ(diag_result.Value()->GetPayload()[1], 0x01); diag::client::conversation::DiagClientConversation::DisconnectResult disconnect_result{ diag_client_conversation.DisconnectFromDiagServer()}; - EXPECT_EQ(disconnect_result, - diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); + EXPECT_EQ( + disconnect_result, + diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); diag_client_conversation.Shutdown(); doip_channel.DeInitialize(); @@ -445,7 +478,8 @@ TEST_F(DiagReqResFixture, VerifyDiagReqResponseWithVehicleDiscovery) { TEST_F(DiagReqResFixture, VerifyTwoDiagClientConnection) { // Get the doip channels and Initialize it - DoipTcpHandler::DoipChannel& doip_channel_1{GetDoipTestTcpHandlerRef().CreateDoipChannel(DiagServerLogicalAddress)}; + DoipTcpHandler::DoipChannel& doip_channel_1{ + GetDoipTestTcpHandlerRef().CreateDoipChannel(DiagServerLogicalAddress)}; DoipTcpHandler::DoipChannel& doip_channel_2{ GetDoipTestTcpHandlerRef().CreateDoipChannel(DiagSecondServerLogicalAddress)}; doip_channel_1.Initialize(); @@ -465,11 +499,14 @@ TEST_F(DiagReqResFixture, VerifyTwoDiagClientConnection) { diag_client_conversation_1.ConnectToDiagServer(DiagServerLogicalAddress, DiagTcpIpAddress)}; diag::client::conversation::DiagClientConversation::ConnectResult connect_result_2{ - diag_client_conversation_2.ConnectToDiagServer(DiagSecondServerLogicalAddress, DiagTcpIpAddress)}; + diag_client_conversation_2.ConnectToDiagServer(DiagSecondServerLogicalAddress, + DiagTcpIpAddress)}; - EXPECT_EQ(connect_result_1, diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); + EXPECT_EQ(connect_result_1, + diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); - EXPECT_EQ(connect_result_2, diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); + EXPECT_EQ(connect_result_2, + diag::client::conversation::DiagClientConversation::ConnectResult::kConnectSuccess); diag::client::conversation::DiagClientConversation::DisconnectResult disconnect_result_1{ diag_client_conversation_1.DisconnectFromDiagServer()}; @@ -477,11 +514,13 @@ TEST_F(DiagReqResFixture, VerifyTwoDiagClientConnection) { diag::client::conversation::DiagClientConversation::DisconnectResult disconnect_result_2{ diag_client_conversation_2.DisconnectFromDiagServer()}; - EXPECT_EQ(disconnect_result_1, - diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); + EXPECT_EQ( + disconnect_result_1, + diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); - EXPECT_EQ(disconnect_result_2, - diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); + EXPECT_EQ( + disconnect_result_2, + diag::client::conversation::DiagClientConversation::DisconnectResult::kDisconnectSuccess); diag_client_conversation_1.Shutdown(); diag_client_conversation_2.Shutdown(); diff --git a/test/test_case/tls_test.cpp b/test/test_case/tls_test.cpp index da8aec59..7484d557 100644 --- a/test/test_case/tls_test.cpp +++ b/test/test_case/tls_test.cpp @@ -30,10 +30,11 @@ constexpr std::string_view RootCACertificatePath{"../../../openssl/rootCA.pem"}; class TlsClient final { public: TlsClient(std::string_view local_ip_address, std::uint16_t local_port_num) - : tls_client_socket_{ - local_ip_address, local_port_num, - [this](boost_support::socket::tcp::TcpMessagePtr message) { OnMessageReceived(std::move(message)); }, - RootCACertificatePath} { + : tls_client_socket_{local_ip_address, local_port_num, + [this](boost_support::socket::tcp::TcpMessagePtr message) { + OnMessageReceived(std::move(message)); + }, + RootCACertificatePath} { // Open the socket tls_client_socket_.Open(); } @@ -201,7 +202,8 @@ TEST_F(TLSFixture, SendAndReceiveMessage) { tls_server_->StartAcceptingNewConnection(); tls_client_->Connect(TlsServerIpAddress, TlsPort); - boost_support::socket::tcp::TcpMessagePtr tcp_message{std::make_unique()}; + boost_support::socket::tcp::TcpMessagePtr tcp_message{ + std::make_unique()}; tcp_message->GetTxBuffer().reserve(2u); tcp_message->GetTxBuffer().emplace_back(1u);