Skip to content

Commit

Permalink
Resolve build error after enabling strict compiler flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Iandiehard committed Sep 29, 2023
1 parent bef32e7 commit bd97e15
Show file tree
Hide file tree
Showing 33 changed files with 224 additions and 158 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
# Others
.idea
cmake-build*
build*
build/*
15 changes: 15 additions & 0 deletions build_with_clang_14.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
BUILD_TYPE="Debug"
BUILD_DIR="clang14"

if [ ! -d build/$BUILD_DIR ]; then
echo "***************** Create build folder for clang 14 *************************"
mkdir -p build/$BUILD_DIR
fi


echo "********************** Configure CMake *************************************"
cmake -B build/$BUILD_DIR -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_WITH_DLT:BOOL=OFF -DBUILD_WITH_TEST:BOOL=ON -DBUILD_DOXYGEN:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_EXAMPLES:BOOL=ON -DCMAKE_INSTALL_PREFIX:PATH=build/install -DCMAKE_TOOLCHAIN_FILE=toolchains/linux_clang_14.cmake

echo "********************** Start Building **************************************"
cmake --build build/$BUILD_DIR --config $BUILD_TYPE
15 changes: 15 additions & 0 deletions build_with_gcc_9.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
BUILD_TYPE="Debug"
BUILD_DIR="gcc9"

if [ ! -d build/$BUILD_DIR ]; then
echo "***************** Create build folder for clang 14 *************************"
mkdir -p build/$BUILD_DIR
fi


echo "********************** Configure CMake *************************************"
cmake -B build/$BUILD_DIR -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_WITH_DLT:BOOL=OFF -DBUILD_WITH_TEST:BOOL=ON -DBUILD_DOXYGEN:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_EXAMPLES:BOOL=ON -DCMAKE_INSTALL_PREFIX:PATH=build/install -DCMAKE_TOOLCHAIN_FILE=toolchains/linux_gcc_9.cmake

echo "********************** Start Building **************************************"
cmake --build build/$BUILD_DIR --config $BUILD_TYPE
4 changes: 2 additions & 2 deletions diag-client-lib/appl/src/dcm/conversation/conversation.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Conversation {
* @return ConnectResult
* Connection result returned
*/
virtual ConnectResult ConnectToDiagServer(std::uint16_t target_address, IpAddress host_ip_addr) noexcept {
virtual ConnectResult ConnectToDiagServer(std::uint16_t, IpAddress) noexcept {
return ConnectResult::kConnectFailed;
}

Expand Down Expand Up @@ -158,7 +158,7 @@ class Conversation {
* Diagnostic Response message received, null_ptr in case of error
*/
virtual Result<uds_message::UdsResponseMessagePtr, DiagError> SendDiagnosticRequest(
uds_message::UdsRequestMessageConstPtr message) noexcept {
uds_message::UdsRequestMessageConstPtr) noexcept {
return Result<uds_message::UdsResponseMessagePtr, DiagError>::FromError(DiagError::kDiagRequestSendFailed);
}

Expand Down
27 changes: 15 additions & 12 deletions diag-client-lib/appl/src/dcm/conversation/dm_conversation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ 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<DmConversationHandler>(conversion_identifier.handler_id, *this)} {}
dm_conversion_handler_{std::make_unique<DmConversationHandler>(conversion_identifier.handler_id, *this)} {
(void)(active_session_);
(void)(active_security_level_);
}

DmConversation::~DmConversation() = default;

Expand Down Expand Up @@ -152,8 +155,8 @@ DiagClientConversation::ConnectResult DmConversation::ConnectToDiagServer(std::u
uds_transport::ByteVector payload{}; // empty payload
// Send Connect request to doip layer
DiagClientConversation::ConnectResult const connection_result{static_cast<DiagClientConversation::ConnectResult>(
connection_ptr_->ConnectToHost(std::move(std::make_unique<diag::client::uds_message::DmUdsMessage>(
source_address_, target_address, host_ip_addr, payload))))};
connection_ptr_->ConnectToHost(std::make_unique<diag::client::uds_message::DmUdsMessage>(
source_address_, target_address, host_ip_addr, payload)))};
remote_address_ = host_ip_addr;
target_address_ = target_address;
if (connection_result == DiagClientConversation::ConnectResult::kConnectSuccess) {
Expand Down Expand Up @@ -214,8 +217,8 @@ Result<uds_message::UdsResponseMessagePtr, DiagClientConversation::DiagError> Dm
uds_transport::ByteVector payload{message->GetPayload()};
// Initiate Sending of diagnostic request
uds_transport::UdsTransportProtocolMgr::TransmissionResult const transmission_result{
connection_ptr_->Transmit(std::move(std::make_unique<diag::client::uds_message::DmUdsMessage>(
source_address_, target_address_, message->GetHostIpAddress(), payload)))};
connection_ptr_->Transmit(std::make_unique<diag::client::uds_message::DmUdsMessage>(
source_address_, target_address_, message->GetHostIpAddress(), payload))};
if (transmission_result == uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitOk) {
// Diagnostic Request Sent successful
logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogInfo(
Expand Down Expand Up @@ -325,11 +328,11 @@ ::uds_transport::ConversionHandler &DmConversation::GetConversationHandler() noe
}

std::pair<uds_transport::UdsTransportProtocolMgr::IndicationResult, uds_transport::UdsMessagePtr>
DmConversation::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,
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<std::uint8_t> payload_info) noexcept {
std::pair<uds_transport::UdsTransportProtocolMgr::IndicationResult, uds_transport::UdsMessagePtr> ret_val{
uds_transport::UdsTransportProtocolMgr::IndicationResult::kIndicationNOk, nullptr};
Expand Down Expand Up @@ -359,8 +362,8 @@ DmConversation::IndicateMessage(uds_transport::UdsMessage::Address source_addr,
// resize the global rx buffer
payload_rx_buffer_.resize(size);
ret_val.first = uds_transport::UdsTransportProtocolMgr::IndicationResult::kIndicationOk;
ret_val.second = std::move(std::make_unique<diag::client::uds_message::DmUdsMessage>(
source_address_, target_address_, "", payload_rx_buffer_));
ret_val.second = std::make_unique<diag::client::uds_message::DmUdsMessage>(
source_address_, target_address_, "", payload_rx_buffer_);
conversation_state_.GetConversationStateContext().TransitionTo(ConversationState::kDiagRecvdFinalRes);
}
sync_timer_.CancelWait();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ ConversationStateImpl::ConversationStateImpl()
// create and add state
// kIdle
GetConversationStateContext().AddState(ConversationState::kIdle,
std::move(std::make_unique<kIdle>(ConversationState::kIdle)));
std::make_unique<kIdle>(ConversationState::kIdle));
// kDiagWaitForRes
GetConversationStateContext().AddState(
ConversationState::kDiagWaitForRes,
std::move(std::make_unique<kDiagWaitForRes>(ConversationState::kDiagWaitForRes)));
std::make_unique<kDiagWaitForRes>(ConversationState::kDiagWaitForRes));
// kDiagStartP2StarTimer
GetConversationStateContext().AddState(
ConversationState::kDiagStartP2StarTimer,
std::move(std::make_unique<kDiagStartP2StarTimer>(ConversationState::kDiagStartP2StarTimer)));
std::make_unique<kDiagStartP2StarTimer>(ConversationState::kDiagStartP2StarTimer));
// kDiagRecvdPendingRes
GetConversationStateContext().AddState(
ConversationState::kDiagRecvdPendingRes,
std::move(std::make_unique<kDiagRecvdPendingRes>(ConversationState::kDiagRecvdPendingRes)));
std::make_unique<kDiagRecvdPendingRes>(ConversationState::kDiagRecvdPendingRes));
// kDiagRecvdFinalRes
GetConversationStateContext().AddState(
ConversationState::kDiagRecvdFinalRes,
std::move(std::make_unique<kDiagRecvdFinalRes>(ConversationState::kDiagRecvdFinalRes)));
std::make_unique<kDiagRecvdFinalRes>(ConversationState::kDiagRecvdFinalRes));
// kDiagSuccess
GetConversationStateContext().AddState(ConversationState::kDiagSuccess,
std::move(std::make_unique<kDiagSuccess>(ConversationState::kDiagSuccess)));
std::make_unique<kDiagSuccess>(ConversationState::kDiagSuccess));
// transit to idle state
GetConversationStateContext().TransitionTo(ConversationState::kIdle);
}
Expand Down
20 changes: 10 additions & 10 deletions diag-client-lib/appl/src/dcm/conversation/vd_conversation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ std::string ConvertToHexString(std::uint8_t char_start, std::uint8_t char_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 <= 15U)) {
if ((payload_byte <= 15)) {
// "0" appended in case of value upto 15/0xF
vehicle_info_data_eid << "0";
}
Expand Down Expand Up @@ -226,16 +226,16 @@ VdConversation::SendVehicleIdentificationRequest(
DeserializeVehicleInfoRequest(vehicle_info_request)};

if (VerifyVehicleInfoRequest(vehicle_info_request_deserialized_value.first,
vehicle_info_request_deserialized_value.second.size())) {
if (connection_ptr_->Transmit(std::move(std::make_unique<diag::client::vd_message::VdMessage>(
static_cast<uint8_t>(vehicle_info_request_deserialized_value.second.size()))) {
if (connection_ptr_->Transmit(std::make_unique<diag::client::vd_message::VdMessage>(
vehicle_info_request_deserialized_value.first, vehicle_info_request_deserialized_value.second,
broadcast_address_))) != uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitFailed) {
broadcast_address_)) != uds_transport::UdsTransportProtocolMgr::TransmissionResult::kTransmitFailed) {
// Check if any response received
if (vehicle_info_collection_.empty()) {
// no response received
result.EmplaceError(DiagClient::VehicleInfoResponseError::kNoResponseReceived);
} else {
result.EmplaceValue(std::move(std::make_unique<VehicleInfoMessageImpl>(vehicle_info_collection_)));
result.EmplaceValue(std::make_unique<VehicleInfoMessageImpl>(vehicle_info_collection_));
// all the responses are copied, now clear the map
vehicle_info_collection_.clear();
}
Expand All @@ -252,15 +252,15 @@ std::pair<::uds_transport::UdsTransportProtocolMgr::IndicationResult, ::uds_tran
VdConversation::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,
uds_transport::ChannelID , std::size_t size, uds_transport::Priority ,
uds_transport::ProtocolKind ,
core_type::Span<std::uint8_t> payload_info) noexcept {
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::move(std::make_unique<diag::client::vd_message::VdMessage>());
ret_val.second = std::make_unique<diag::client::vd_message::VdMessage>();
ret_val.second->GetPayload().resize(size);
}
return ret_val;
Expand Down Expand Up @@ -338,14 +338,14 @@ 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,
vehicle_info_request.preselection_value.length(), 1U);
static_cast<uint8_t>(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(), ':'),
vehicle_info_request.preselection_value.end());
SerializeEIDGIDFromString(vehicle_info_request.preselection_value, ret_val.second,
vehicle_info_request.preselection_value.length(), 2U);
static_cast<uint8_t>(vehicle_info_request.preselection_value.length()), 2U);
} else {
// log failure
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const char* DmErrorDomain::Message(core_type::ErrorDomain::CodeType error_code)
return message_.c_str();
}

core_type::ErrorCode MakeErrorCode(DmErrorErrc code, 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};
}

Expand Down
2 changes: 1 addition & 1 deletion diag-client-lib/appl/src/dcm/service/dm_uds_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DmUdsMessage final : public uds_transport::UdsMessage {
uds_transport::ByteVector &uds_payload_;

// add new metaInfo to this message.
void AddMetaInfo(std::shared_ptr<const MetaInfoMap> meta_info) override {
void AddMetaInfo(std::shared_ptr<const MetaInfoMap>) override {
// Todo [Add meta info information]
}

Expand Down
2 changes: 1 addition & 1 deletion diag-client-lib/appl/src/diagnostic_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class DiagClient::DiagClientImpl final {
// read configuration
boost_support::parser::boost_tree config{};
return boost_support::parser::Read(diag_client_config_path_, config)
.MapError([](boost_support::parser::ParsingErrorCode) noexcept {
.MapError([](boost_support::parser::ParsingErrorCode const&) noexcept {
logger::DiagClientLogger::GetDiagClientLogger().GetLogger().LogError(
__FILE__, __LINE__, "", [](std::stringstream &msg) { msg << "DiagClient Initialization failed"; });
return error_domain::MakeErrorCode(error_domain::DmErrorErrc::kInitializationFailed);
Expand Down
8 changes: 5 additions & 3 deletions diag-client-lib/lib/boost-support/socket/tcp/tcp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ void CreateTcpClientSocket::HandleMessage() {
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 ((std::uint32_t)(
(std::uint32_t)((rx_buffer[4u] << 24u) & 0xFF000000) | (std::uint32_t)((rx_buffer[5u] << 16u) & 0x00FF0000) |
(std::uint32_t)((rx_buffer[6u] << 8u) & 0x0000FF00) | (std::uint32_t)((rx_buffer[7u] & 0x000000FF))));
return static_cast<std::uint32_t>(
(static_cast<std::uint32_t>(rx_buffer[4u] << 24u) & 0xFF000000) |
(static_cast<std::uint32_t>(rx_buffer[5u] << 16u) & 0x00FF0000) |
(static_cast<std::uint32_t>(rx_buffer[6u] << 8u) & 0x0000FF00) |
(static_cast<std::uint32_t>(rx_buffer[7u] & 0x000000FF)));
}();
// reserve the buffer
rx_buffer.resize(kDoipheadrSize + std::size_t(read_next_bytes));
Expand Down
16 changes: 3 additions & 13 deletions diag-client-lib/lib/boost-support/socket/tcp/tcp_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ class TcpMessage final {
* The received data payload
*/
TcpMessage(IpAddressType host_ip_address, std::uint16_t host_port_number, BufferType &&payload)
: host_ip_address_{host_ip_address},
host_port_number_{host_port_number},
rx_buffer_{std::move(payload)} {}
: rx_buffer_{std::move(payload)},
host_ip_address_{host_ip_address},
host_port_number_{host_port_number} {}

TcpMessage(TcpMessage &&other) noexcept = default;
TcpMessage &operator=(TcpMessage &&other) noexcept = default;
Expand Down Expand Up @@ -117,16 +117,6 @@ class TcpMessage final {
BufferType const &GetTxBuffer() const { return tx_buffer_; }

private:
/**
* @brief Store the socket state
*/
SocketState socket_state_{SocketState::kIdle};

/**
* @brief Store the socket error
*/
SocketError socket_error_{SocketError::kNone};

/**
* @brief The reception buffer
*/
Expand Down
12 changes: 7 additions & 5 deletions diag-client-lib/lib/boost-support/socket/tcp/tcp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CreateTcpServerSocket::TcpServerConnection CreateTcpServerSocket::GetTcpServerCo
CreateTcpServerSocket::TcpServerConnection tcp_connection{io_context_, std::move(tcp_handler_read)};

// blocking accept
auto socket = tcp_accepter_->accept(tcp_connection.GetSocket(), endpoint, ec);
static_cast<void>(tcp_accepter_->accept(tcp_connection.GetSocket(), endpoint, ec));
if (ec.value() == boost::system::errc::success) {
common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogDebug(
__FILE__, __LINE__, __func__, [endpoint](std::stringstream &msg) {
Expand Down Expand Up @@ -92,10 +92,12 @@ bool CreateTcpServerSocket::TcpServerConnection::ReceivedMessage() {
// Check for error
if (ec.value() == boost::system::errc::success) {
// read the next bytes to read
uint32_t read_next_bytes = [&rx_buffer]() noexcept -> std::uint32_t {
return ((uint32_t) ((uint32_t) ((rx_buffer[4u] << 24) & 0xFF000000) |
(uint32_t) ((rx_buffer[5u] << 16) & 0x00FF0000) |
(uint32_t) ((rx_buffer[6u] << 8) & 0x0000FF00) | (uint32_t) ((rx_buffer[7u] & 0x000000FF))));
std::uint32_t const read_next_bytes = [&rx_buffer]() noexcept -> std::uint32_t {
return static_cast<std::uint32_t>(
(static_cast<std::uint32_t>(rx_buffer[4u] << 24u) & 0xFF000000) |
(static_cast<std::uint32_t>(rx_buffer[5u] << 16u) & 0x00FF0000) |
(static_cast<std::uint32_t>(rx_buffer[6u] << 8u) & 0x0000FF00) |
(static_cast<std::uint32_t>(rx_buffer[7u] & 0x000000FF)));
}();
// reserve the buffer
rx_buffer.resize(kDoipheadrSize + std::size_t(read_next_bytes));
Expand Down
3 changes: 1 addition & 2 deletions diag-client-lib/lib/boost-support/socket/udp/udp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ void createUdpClientSocket::HandleMessage(const UdpErrorCodeType &error, std::si

// all message received, transfer to upper layer
UdpSocket::endpoint remote_endpoint{remote_endpoint_};
UdpSocket::endpoint local_endpoint{udp_socket_->local_endpoint()};
common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogInfo(
__FILE__, __LINE__, __func__, [this, remote_endpoint](std::stringstream &msg) {
msg << "Udp Message received: "
Expand All @@ -177,7 +176,7 @@ void createUdpClientSocket::HandleMessage(const UdpErrorCodeType &error, std::si
// start async receive
udp_socket_->async_receive_from(
boost::asio::buffer(rxbuffer_, kDoipUdpResSize), remote_endpoint_,
[this](const UdpErrorCodeType &error, std::size_t bytes_recvd) { HandleMessage(error, bytes_recvd); });
[this](const UdpErrorCodeType &error_received, std::size_t bytes_received) { HandleMessage(error_received, bytes_received); });
} else {
UdpSocket::endpoint endpoint_{remote_endpoint_};
common::logger::LibBoostLogger::GetLibBoostLogger().GetLogger().LogVerbose(
Expand Down
Loading

0 comments on commit bd97e15

Please sign in to comment.