diff --git a/Android.bp b/Android.bp index c6caa4de8..f314f22b1 100644 --- a/Android.bp +++ b/Android.bp @@ -30,9 +30,9 @@ libvsomeip_sd_srcs = [ cc_defaults { name: "vsomeip_defaults", + cpp_std: "c++17", cppflags: [ - "-std=c++14", "-fexceptions", "-Wno-non-virtual-dtor", "-Wno-unused-const-variable", diff --git a/CMakeLists.txt b/CMakeLists.txt index 75cb5428d..3501e02c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,8 @@ if(NOT CMAKE_BUILD_TYPE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") endif() +set(CMAKE_CXX_STANDARD 17) + # OS if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(DL_LIBRARY "dl") @@ -248,13 +250,13 @@ if (MSVC) # add_definitions(-DVSOMEIP_DLL_COMPILATION) now it is controlled per target SET(BOOST_WINDOWS_VERSION "0x600" CACHE STRING "Set the same Version as the Version with which Boost was built, otherwise there will be errors. (normaly 0x600 is for Windows 7 and 0x501 is for Windows XP)") # Disable warning C4250 since it warns that the compiler is correctly following the C++ Standard. It's a "We-Are-Doing-Things-By-The-Book" notice, not a real warning. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS -D_WIN32_WINNT=${BOOST_WINDOWS_VERSION} -DWIN32 -DBOOST_ASIO_DISABLE_IOCP /EHsc /std:c++14 /wd4250") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS -D_WIN32_WINNT=${BOOST_WINDOWS_VERSION} -DWIN32 -DBOOST_ASIO_DISABLE_IOCP /EHsc /wd4250") set(USE_RT "") link_directories(${Boost_LIBRARY_DIR_DEBUG}) elseif(${CMAKE_SYSTEM_NAME} MATCHES "QNX") set(USE_RT "") else() - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OS_CXX_FLAGS} -g ${OPTIMIZE} -std=c++14 ${NO_DEPRECATED} ${EXPORTSYMBOLS}") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OS_CXX_FLAGS} -g ${OPTIMIZE} ${NO_DEPRECATED} ${EXPORTSYMBOLS}") set(USE_RT "rt") endif() @@ -268,6 +270,7 @@ list(SORT ${VSOMEIP_NAME}-cfg_SRC) if (VSOMEIP_ENABLE_MULTIPLE_ROUTING_MANAGERS EQUAL 0) add_library(${VSOMEIP_NAME}-cfg SHARED ${${VSOMEIP_NAME}-cfg_SRC}) set_target_properties (${VSOMEIP_NAME}-cfg PROPERTIES VERSION ${VSOMEIP_VERSION} SOVERSION ${VSOMEIP_MAJOR_VERSION}) + target_compile_features(${VSOMEIP_NAME}-cfg PRIVATE cxx_std_17) if (MSVC) set_target_properties(${VSOMEIP_NAME}-cfg PROPERTIES COMPILE_DEFINITIONS "VSOMEIP_DLL_COMPILATION_PLUGIN") endif() @@ -302,6 +305,7 @@ list(SORT ${VSOMEIP_NAME}_SRC) add_library(${VSOMEIP_NAME} SHARED ${${VSOMEIP_NAME}_SRC}) set_target_properties (${VSOMEIP_NAME} PROPERTIES VERSION ${VSOMEIP_VERSION} SOVERSION ${VSOMEIP_MAJOR_VERSION}) +target_compile_features(${VSOMEIP_NAME} PRIVATE cxx_std_17) if (MSVC) set_target_properties(${VSOMEIP_NAME} PROPERTIES COMPILE_DEFINITIONS "VSOMEIP_DLL_COMPILATION") else () @@ -331,6 +335,7 @@ file(GLOB ${VSOMEIP_NAME}-sd_SRC list(SORT ${VSOMEIP_NAME}-sd_SRC) add_library(${VSOMEIP_NAME}-sd SHARED ${${VSOMEIP_NAME}-sd_SRC}) +target_compile_features(${VSOMEIP_NAME}-sd PRIVATE cxx_std_17) set_target_properties (${VSOMEIP_NAME}-sd PROPERTIES VERSION ${VSOMEIP_VERSION} SOVERSION ${VSOMEIP_MAJOR_VERSION}) if (MSVC) set_target_properties(${VSOMEIP_NAME}-sd PROPERTIES COMPILE_DEFINITIONS "VSOMEIP_DLL_COMPILATION_PLUGIN") @@ -348,6 +353,7 @@ file(GLOB_RECURSE ${VSOMEIP_NAME}-e2e_SRC list(SORT ${VSOMEIP_NAME}-e2e_SRC) add_library(${VSOMEIP_NAME}-e2e SHARED ${${VSOMEIP_NAME}-e2e_SRC}) +target_compile_features(${VSOMEIP_NAME}-e2e PRIVATE cxx_std_17) set_target_properties (${VSOMEIP_NAME}-e2e PROPERTIES VERSION ${VSOMEIP_VERSION} SOVERSION ${VSOMEIP_MAJOR_VERSION}) if (MSVC) set_target_properties(${VSOMEIP_NAME}-e2e PROPERTIES COMPILE_DEFINITIONS "VSOMEIP_DLL_COMPILATION_PLUGIN") @@ -375,6 +381,7 @@ file(GLOB_RECURSE ${VSOMEIP_COMPAT_NAME}_SRC list(SORT ${VSOMEIP_COMPAT_NAME}_SRC) add_library(${VSOMEIP_COMPAT_NAME} SHARED ${${VSOMEIP_COMPAT_NAME}_SRC}) +target_compile_features(${VSOMEIP_COMPAT_NAME} PRIVATE cxx_std_17) set_target_properties (${VSOMEIP_COMPAT_NAME} PROPERTIES VERSION ${VSOMEIP_COMPAT_VERSION} SOVERSION ${VSOMEIP_COMPAT_MAJOR_VERSION}) if (MSVC) set_target_properties(${VSOMEIP_COMPAT_NAME} PROPERTIES COMPILE_DEFINITIONS "VSOMEIP_DLL_COMPILATION_PLUGIN") diff --git a/examples/hello_world/hello_world_service.hpp b/examples/hello_world/hello_world_service.hpp index 7ac3b1e7c..b04cacea3 100644 --- a/examples/hello_world/hello_world_service.hpp +++ b/examples/hello_world/hello_world_service.hpp @@ -11,12 +11,12 @@ #if defined ANDROID || defined __ANDROID__ #include "android/log.h" #define LOG_TAG "hello_world_service" -#define LOG_INF(...) fprintf(stdout, __VA_ARGS__), fprintf(stdout, "\n"), (void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, ##__VA_ARGS__) -#define LOG_ERR(...) fprintf(stderr, __VA_ARGS__), fprintf(stderr, "\n"), (void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, ##__VA_ARGS__) +#define LOG_INF(...) std::fprintf(stdout, __VA_ARGS__), std::fprintf(stdout, "\n"), (void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, ##__VA_ARGS__) +#define LOG_ERR(...) std::fprintf(stderr, __VA_ARGS__), std::fprintf(stderr, "\n"), (void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, ##__VA_ARGS__) #else #include -#define LOG_INF(...) fprintf(stdout, __VA_ARGS__), fprintf(stdout, "\n") -#define LOG_ERR(...) fprintf(stderr, __VA_ARGS__), fprintf(stderr, "\n") +#define LOG_INF(...) std::fprintf(stdout, __VA_ARGS__), std::fprintf(stdout, "\n") +#define LOG_ERR(...) std::fprintf(stderr, __VA_ARGS__), std::fprintf(stderr, "\n") #endif static vsomeip::service_t service_id = 0x1111; @@ -32,9 +32,9 @@ class hello_world_service { hello_world_service() : rtm_(vsomeip::runtime::get()), app_(rtm_->create_application()), - stop_(false), - stop_thread_(std::bind(&hello_world_service::stop, this)) + stop_(false) { + stop_thread_ = std::thread{&hello_world_service::stop, this}; } ~hello_world_service() diff --git a/implementation/configuration/include/internal.hpp.in b/implementation/configuration/include/internal.hpp.in index 5a2799b28..1fcc6b41f 100644 --- a/implementation/configuration/include/internal.hpp.in +++ b/implementation/configuration/include/internal.hpp.in @@ -143,14 +143,14 @@ typedef enum { IS_SUBSCRIBING } subscription_state_e; -const std::uint32_t MESSAGE_SIZE_UNLIMITED = (std::numeric_limits::max)(); +inline constexpr std::uint32_t MESSAGE_SIZE_UNLIMITED = (std::numeric_limits::max)(); -const std::uint32_t QUEUE_SIZE_UNLIMITED = (std::numeric_limits::max)(); +inline constexpr std::uint32_t QUEUE_SIZE_UNLIMITED = (std::numeric_limits::max)(); #define VSOMEIP_DEFAULT_NPDU_DEBOUNCING_NANO 2 * 1000 * 1000 #define VSOMEIP_DEFAULT_NPDU_MAXIMUM_RETENTION_NANO 5 * 1000 * 1000 -const std::uint32_t MAX_RECONNECTS_UNLIMITED = (std::numeric_limits::max)(); +inline constexpr std::uint32_t MAX_RECONNECTS_UNLIMITED = (std::numeric_limits::max)(); const std::uint32_t ANY_UID = 0xFFFFFFFF; const std::uint32_t ANY_GID = 0xFFFFFFFF; diff --git a/implementation/configuration/include/internal_android.hpp b/implementation/configuration/include/internal_android.hpp index f26e89db6..c3e8993d3 100644 --- a/implementation/configuration/include/internal_android.hpp +++ b/implementation/configuration/include/internal_android.hpp @@ -130,17 +130,17 @@ typedef enum { IS_SUBSCRIBING } subscription_state_e; -const std::uint32_t MESSAGE_SIZE_UNLIMITED = std::numeric_limits::max(); +inline constexpr std::uint32_t MESSAGE_SIZE_UNLIMITED = std::numeric_limits::max(); -const std::uint32_t QUEUE_SIZE_UNLIMITED = std::numeric_limits::max(); +inline constexpr std::uint32_t QUEUE_SIZE_UNLIMITED = std::numeric_limits::max(); #define VSOMEIP_DEFAULT_NPDU_DEBOUNCING_NANO 2 * 1000 * 1000 #define VSOMEIP_DEFAULT_NPDU_MAXIMUM_RETENTION_NANO 5 * 1000 * 1000 -const std::uint32_t MAX_RECONNECTS_UNLIMITED = std::numeric_limits::max(); +inline constexpr std::uint32_t MAX_RECONNECTS_UNLIMITED = std::numeric_limits::max(); -const std::uint32_t ANY_UID = 0xFFFFFFFF; -const std::uint32_t ANY_GID = 0xFFFFFFFF; +inline constexpr std::uint32_t ANY_UID = 0xFFFFFFFF; +inline constexpr std::uint32_t ANY_GID = 0xFFFFFFFF; enum class port_type_e { PT_OPTIONAL, diff --git a/implementation/configuration/src/configuration_impl.cpp b/implementation/configuration/src/configuration_impl.cpp index ca1bd1dc7..380b29060 100644 --- a/implementation/configuration/src/configuration_impl.cpp +++ b/implementation/configuration/src/configuration_impl.cpp @@ -333,7 +333,7 @@ bool configuration_impl::load(const std::string &_name) { // Tell, if reading of configuration file(s) failed. // (This may file if the logger configuration is incomplete/missing). - for (auto f : its_failed) + for (const auto& f : its_failed) VSOMEIP_WARNING << "Reading of configuration file \"" << f << "\" failed. Configuration may be incomplete."; @@ -342,7 +342,7 @@ bool configuration_impl::load(const std::string &_name) { std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); - for (auto i : its_input) { + for (const auto& i : its_input) { if (utility::is_file(i)) VSOMEIP_INFO << "Using configuration file: \"" << i << "\"."; @@ -561,7 +561,7 @@ bool configuration_impl::load_data(const std::vector &_el if (is_logging_loaded_) { logger::logger_impl::init(shared_from_this()); - for (auto w : its_warnings) + for (const auto& w : its_warnings) VSOMEIP_WARNING << w; } } @@ -3255,7 +3255,7 @@ void configuration_impl::trim(std::string &_s) { std::find_if( _s.begin(), _s.end(), - [](unsigned char ch) { return !std::isspace(ch); } + [](const auto ch) { return !std::isspace(ch); } ) ); @@ -3263,8 +3263,9 @@ void configuration_impl::trim(std::string &_s) { std::find_if( _s.rbegin(), _s.rend(), - [](unsigned char ch) { return !std::isspace(ch); }).base(), - _s.end() + [](const auto ch) { return !std::isspace(ch); } + ).base(), + _s.end() ); } diff --git a/implementation/endpoints/include/endpoint_impl.hpp b/implementation/endpoints/include/endpoint_impl.hpp index 9d2b303c2..685eba4e0 100644 --- a/implementation/endpoints/include/endpoint_impl.hpp +++ b/implementation/endpoints/include/endpoint_impl.hpp @@ -34,6 +34,9 @@ class endpoint_impl: public virtual endpoint { std::uint32_t _max_message_size, configuration::endpoint_queue_limit_t _queue_limit, const std::shared_ptr& _configuration); + endpoint_impl(endpoint_impl const&) = delete; + endpoint_impl(endpoint_impl const&&) = delete; + virtual ~endpoint_impl(); void enable_magic_cookies(); diff --git a/implementation/endpoints/include/local_server_endpoint_impl_receive_op.hpp b/implementation/endpoints/include/local_server_endpoint_impl_receive_op.hpp index 53f4769a8..b1d8991da 100644 --- a/implementation/endpoints/include/local_server_endpoint_impl_receive_op.hpp +++ b/implementation/endpoints/include/local_server_endpoint_impl_receive_op.hpp @@ -25,8 +25,8 @@ struct storage : { socket_type_t &socket_; receive_handler_t handler_; - byte_t *buffer_; - std::size_t length_; + byte_t *buffer_ = nullptr; + size_t length_; uid_t uid_; gid_t gid_; size_t bytes_; diff --git a/implementation/endpoints/include/local_uds_client_endpoint_impl.hpp b/implementation/endpoints/include/local_uds_client_endpoint_impl.hpp index d7eede3f4..e1e1aaa23 100644 --- a/implementation/endpoints/include/local_uds_client_endpoint_impl.hpp +++ b/implementation/endpoints/include/local_uds_client_endpoint_impl.hpp @@ -25,7 +25,7 @@ class local_uds_client_endpoint_impl: public local_uds_client_endpoint_base_impl const endpoint_type& _remote, boost::asio::io_context &_io, const std::shared_ptr& _configuration); - virtual ~local_uds_client_endpoint_impl(); + virtual ~local_uds_client_endpoint_impl() = default; void start(); void stop(); diff --git a/implementation/endpoints/include/local_uds_server_endpoint_impl.hpp b/implementation/endpoints/include/local_uds_server_endpoint_impl.hpp index 1e78822d5..a4ed2eb57 100644 --- a/implementation/endpoints/include/local_uds_server_endpoint_impl.hpp +++ b/implementation/endpoints/include/local_uds_server_endpoint_impl.hpp @@ -50,7 +50,7 @@ class local_uds_server_endpoint_impl: public local_uds_server_endpoint_base_impl const std::shared_ptr& _configuration, bool _is_routing_endpoint); - virtual ~local_uds_server_endpoint_impl(); + virtual ~local_uds_server_endpoint_impl() = default; void start(); void stop(); diff --git a/implementation/endpoints/include/udp_server_endpoint_impl_receive_op.hpp b/implementation/endpoints/include/udp_server_endpoint_impl_receive_op.hpp index 1e4f0fe03..35638cd71 100644 --- a/implementation/endpoints/include/udp_server_endpoint_impl_receive_op.hpp +++ b/implementation/endpoints/include/udp_server_endpoint_impl_receive_op.hpp @@ -35,7 +35,7 @@ struct storage : socket_type_t &socket_; endpoint_type_t &sender_; receive_handler_t handler_; - byte_t *buffer_; + byte_t *buffer_ = nullptr; size_t length_; std::uint8_t multicast_id_; bool is_v4_; diff --git a/implementation/endpoints/src/endpoint_manager_base.cpp b/implementation/endpoints/src/endpoint_manager_base.cpp index 9dff9785a..4e484454a 100644 --- a/implementation/endpoints/src/endpoint_manager_base.cpp +++ b/implementation/endpoints/src/endpoint_manager_base.cpp @@ -38,7 +38,7 @@ std::shared_ptr endpoint_manager_base::create_local(client_t _client) return create_local_unlocked(_client); } -void endpoint_manager_base::remove_local(client_t _client) { +void endpoint_manager_base::remove_local(const client_t _client) { std::shared_ptr its_endpoint(find_local(_client)); if (its_endpoint) { its_endpoint->register_error_handler(nullptr); diff --git a/implementation/endpoints/src/local_uds_client_endpoint_impl.cpp b/implementation/endpoints/src/local_uds_client_endpoint_impl.cpp index 0b7e261c1..56c621dbc 100644 --- a/implementation/endpoints/src/local_uds_client_endpoint_impl.cpp +++ b/implementation/endpoints/src/local_uds_client_endpoint_impl.cpp @@ -40,12 +40,7 @@ local_uds_client_endpoint_impl::local_uds_client_endpoint_impl( is_supporting_magic_cookies_ = false; } -local_uds_client_endpoint_impl::~local_uds_client_endpoint_impl() { - -} - bool local_uds_client_endpoint_impl::is_local() const { - return true; } diff --git a/implementation/endpoints/src/local_uds_server_endpoint_impl.cpp b/implementation/endpoints/src/local_uds_server_endpoint_impl.cpp index 948fe9258..33876c56c 100644 --- a/implementation/endpoints/src/local_uds_server_endpoint_impl.cpp +++ b/implementation/endpoints/src/local_uds_server_endpoint_impl.cpp @@ -104,17 +104,11 @@ local_uds_server_endpoint_impl::local_uds_server_endpoint_impl( #endif } -local_uds_server_endpoint_impl::~local_uds_server_endpoint_impl() { - -} - bool local_uds_server_endpoint_impl::is_local() const { - return true; } void local_uds_server_endpoint_impl::start() { - std::lock_guard its_lock(acceptor_mutex_); if (acceptor_.is_open()) { connection::ptr new_connection = connection::create( diff --git a/implementation/endpoints/src/tcp_client_endpoint_impl.cpp b/implementation/endpoints/src/tcp_client_endpoint_impl.cpp index f42d93d41..e67551573 100644 --- a/implementation/endpoints/src/tcp_client_endpoint_impl.cpp +++ b/implementation/endpoints/src/tcp_client_endpoint_impl.cpp @@ -178,7 +178,7 @@ void tcp_client_endpoint_impl::connect() { std::string its_device(configuration_->get_device()); if (its_device != "") { if (setsockopt(socket_->native_handle(), - SOL_SOCKET, SO_BINDTODEVICE, its_device.c_str(), (socklen_t)its_device.size()) == -1) { + SOL_SOCKET, SO_BINDTODEVICE, its_device.c_str(), static_cast(its_device.size())) == -1) { VSOMEIP_WARNING << "TCP Client: Could not bind to device \"" << its_device << "\""; } } diff --git a/implementation/endpoints/src/tcp_server_endpoint_impl.cpp b/implementation/endpoints/src/tcp_server_endpoint_impl.cpp index f83252ae2..5aef72be9 100644 --- a/implementation/endpoints/src/tcp_server_endpoint_impl.cpp +++ b/implementation/endpoints/src/tcp_server_endpoint_impl.cpp @@ -55,7 +55,7 @@ tcp_server_endpoint_impl::tcp_server_endpoint_impl( std::string its_device(configuration_->get_device()); if (its_device != "") { if (setsockopt(acceptor_.native_handle(), - SOL_SOCKET, SO_BINDTODEVICE, its_device.c_str(), (socklen_t)its_device.size()) == -1) { + SOL_SOCKET, SO_BINDTODEVICE, its_device.c_str(), static_cast(its_device.size())) == -1) { VSOMEIP_WARNING << "TCP Server: Could not bind to device \"" << its_device << "\""; } } @@ -295,8 +295,8 @@ void tcp_server_endpoint_impl::accept_cbk(const connection::ptr& _connection, auto its_ep = std::dynamic_pointer_cast( shared_from_this()); its_timer->async_wait([its_timer, its_ep] - (const boost::system::error_code& _error) { - if (!_error) { + (const boost::system::error_code& _error_inner) { + if (!_error_inner) { its_ep->start(); } }); @@ -853,12 +853,12 @@ void tcp_server_endpoint_impl::connection::handle_recv_buffer_exception( << std::setfill('0') << std::hex; for (std::size_t i = 0; i < recv_buffer_size_ && i < 16; i++) { - its_message << std::setw(2) << (int) (recv_buffer_[i]) << " "; + its_message << std::setw(2) << static_cast(recv_buffer_[i]) << " "; } its_message << " Last 16 Bytes captured: "; for (int i = 15; recv_buffer_size_ > 15 && i >= 0; i--) { - its_message << std::setw(2) << (int) (recv_buffer_[static_cast(i)]) << " "; + its_message << std::setw(2) << static_cast(recv_buffer_[static_cast(i)]) << " "; } VSOMEIP_ERROR << its_message.str(); recv_buffer_.clear(); @@ -954,7 +954,7 @@ void tcp_server_endpoint_impl::print_status() { std::lock_guard its_lock(mutex_); connections_t its_connections; { - std::lock_guard its_lock(connections_mutex_); + std::lock_guard its_lock_inner(connections_mutex_); its_connections = connections_; } @@ -1027,7 +1027,7 @@ void tcp_server_endpoint_impl::connection::wait_until_sent(const boost::system:: } } { - std::lock_guard its_lock(its_server->connections_mutex_); + std::lock_guard its_lock_inner(its_server->connections_mutex_); stop(); } its_server->remove_connection(this); diff --git a/implementation/endpoints/src/udp_client_endpoint_impl.cpp b/implementation/endpoints/src/udp_client_endpoint_impl.cpp index d69522284..f52b23540 100644 --- a/implementation/endpoints/src/udp_client_endpoint_impl.cpp +++ b/implementation/endpoints/src/udp_client_endpoint_impl.cpp @@ -67,7 +67,7 @@ void udp_client_endpoint_impl::connect() { << get_address_port_remote(); } socket_->set_option(boost::asio::socket_base::receive_buffer_size( - udp_receive_buffer_size_), its_error); + static_cast(udp_receive_buffer_size_)), its_error); if (its_error) { VSOMEIP_WARNING << "udp_client_endpoint_impl::connect: couldn't set " << "SO_RCVBUF: " << its_error.message() diff --git a/implementation/endpoints/src/udp_server_endpoint_impl.cpp b/implementation/endpoints/src/udp_server_endpoint_impl.cpp index 48e35c5d3..587fb94c2 100644 --- a/implementation/endpoints/src/udp_server_endpoint_impl.cpp +++ b/implementation/endpoints/src/udp_server_endpoint_impl.cpp @@ -72,7 +72,7 @@ udp_server_endpoint_impl::udp_server_endpoint_impl( std::string its_device(configuration_->get_device()); if (its_device != "") { if (setsockopt(unicast_socket_.native_handle(), - SOL_SOCKET, SO_BINDTODEVICE, its_device.c_str(), (socklen_t)its_device.size()) == -1) { + SOL_SOCKET, SO_BINDTODEVICE, its_device.c_str(), static_cast(its_device.size())) == -1) { VSOMEIP_WARNING << "UDP Server: Could not bind to device \"" << its_device << "\""; } } @@ -108,7 +108,7 @@ udp_server_endpoint_impl::udp_server_endpoint_impl( const int its_udp_recv_buffer_size = configuration_->get_udp_receive_buffer_size(); unicast_socket_.set_option(boost::asio::socket_base::receive_buffer_size( - its_udp_recv_buffer_size), ec); + static_cast(its_udp_recv_buffer_size)), ec); if (ec) { VSOMEIP_WARNING << "udp_server_endpoint_impl: couldn't set " diff --git a/implementation/message/include/message_base_impl.hpp b/implementation/message/include/message_base_impl.hpp index acad2e899..2c953e985 100644 --- a/implementation/message/include/message_base_impl.hpp +++ b/implementation/message/include/message_base_impl.hpp @@ -6,8 +6,6 @@ #ifndef VSOMEIP_V3_MESSAGE_BASE_IMPL_HPP #define VSOMEIP_V3_MESSAGE_BASE_IMPL_HPP -#include - #include #include diff --git a/implementation/message/src/deserializer.cpp b/implementation/message/src/deserializer.cpp index 3c4eddfa2..bfa723d34 100644 --- a/implementation/message/src/deserializer.cpp +++ b/implementation/message/src/deserializer.cpp @@ -115,8 +115,8 @@ bool deserializer::deserialize(std::string &_target, std::size_t _length) { if (_length > remaining_ || _length > _target.capacity()) { return false; } - _target.assign(position_, position_ + long(_length)); - position_ += long(_length); + _target.assign(position_, position_ + static_cast::difference_type>(_length)); + position_ += static_cast::difference_type>(_length); remaining_ -= _length; return true; diff --git a/implementation/plugin/src/plugin_manager_impl.cpp b/implementation/plugin/src/plugin_manager_impl.cpp index bea96d019..23b7b892a 100644 --- a/implementation/plugin/src/plugin_manager_impl.cpp +++ b/implementation/plugin/src/plugin_manager_impl.cpp @@ -164,7 +164,7 @@ bool plugin_manager_impl::unload_plugin(plugin_type_e _type) { } } else { VSOMEIP_ERROR << "plugin_manager_impl::unload_plugin didn't find plugin" - << " type:" << (int)_type; + << " type:" << static_cast(_type); return false; } return plugins_.erase(_type); diff --git a/implementation/routing/src/routing_manager_base.cpp b/implementation/routing/src/routing_manager_base.cpp index dde6b260c..047e6566e 100644 --- a/implementation/routing/src/routing_manager_base.cpp +++ b/implementation/routing/src/routing_manager_base.cpp @@ -1184,8 +1184,8 @@ void routing_manager_base::remove_local(client_t _client, std::lock_guard its_lock(local_services_mutex_); // Finally remove all services that are implemented by the client. std::set> its_services; - for (auto& s : local_services_) { - for (auto& i : s.second) { + for (const auto& s : local_services_) { + for (const auto& i : s.second) { if (std::get<2>(i.second) == _client) { its_services.insert({ s.first, i.first }); host_->on_availability(s.first, i.first, availability_state_e::AS_UNAVAILABLE, @@ -1202,9 +1202,9 @@ void routing_manager_base::remove_local(client_t _client, // remove disconnected client from offer service history std::set> its_clients; - for (auto& s : local_services_history_) { - for (auto& i : s.second) { - for (auto& c : i.second) { + for (const auto& s : local_services_history_) { + for (const auto& i : s.second) { + for (const auto& c : i.second) { if (c == _client) { its_clients.insert(std::make_tuple(s.first, i.first, c)); } diff --git a/implementation/runtime/include/application_impl.hpp b/implementation/runtime/include/application_impl.hpp index 67187a87f..c647b5316 100644 --- a/implementation/runtime/include/application_impl.hpp +++ b/implementation/runtime/include/application_impl.hpp @@ -309,7 +309,7 @@ class application_impl: public application, std::shared_ptr get_next_handler(); void reschedule_availability_handler(const std::shared_ptr &_handler); bool has_active_dispatcher(); - bool is_active_dispatcher(const std::thread::id &_id); + bool is_active_dispatcher(const std::thread::id &_id) const; void remove_elapsed_dispatchers(); void shutdown(); @@ -436,7 +436,7 @@ class application_impl: public application, // Dispatcher threads that are running std::set running_dispatchers_; // Mutex to protect access to dispatchers_ & elapsed_dispatchers_ - std::mutex dispatcher_mutex_; + mutable std::mutex dispatcher_mutex_; // Condition to wakeup the dispatcher thread mutable std::condition_variable dispatcher_condition_; diff --git a/implementation/runtime/src/application_impl.cpp b/implementation/runtime/src/application_impl.cpp index aba906b7e..db880b42d 100644 --- a/implementation/runtime/src/application_impl.cpp +++ b/implementation/runtime/src/application_impl.cpp @@ -426,7 +426,8 @@ void application_impl::start() { std::lock_guard its_lock(dispatcher_mutex_); is_dispatching_ = true; auto its_main_dispatcher = std::make_shared( - std::bind(&application_impl::main_dispatch, shared_from_this())); + &application_impl::main_dispatch, shared_from_this() + ); dispatchers_[its_main_dispatcher->get_id()] = its_main_dispatcher; } @@ -1792,7 +1793,7 @@ void application_impl::main_dispatch() { } } else { std::shared_ptr its_handler; - while (is_dispatching_ && is_active_dispatcher(its_id) + while (is_dispatching_ && is_active_dispatcher(its_id) && (its_handler = get_next_handler())) { its_lock.unlock(); invoke_handler(its_handler); @@ -2048,7 +2049,7 @@ bool application_impl::has_active_dispatcher() { return false; } -bool application_impl::is_active_dispatcher(const std::thread::id &_id) { +bool application_impl::is_active_dispatcher(const std::thread::id &_id) const { while (is_dispatching_) { if (dispatcher_mutex_.try_lock()) { for (const auto &d : dispatchers_) { diff --git a/implementation/security/src/policy.cpp b/implementation/security/src/policy.cpp index 363412239..da0bbd869 100644 --- a/implementation/security/src/policy.cpp +++ b/implementation/security/src/policy.cpp @@ -175,7 +175,7 @@ policy::deserialize_ids(const byte_t * &_data, uint32_t &_size, if (its_result == false) return false; - for (const auto i : its_instances) + for (const auto& i : its_instances) its_ids += std::make_pair(i, its_methods); its_array_length -= (its_current_size - _size); @@ -379,7 +379,7 @@ policy::serialize_interval_set( uint32_t its_interval_set_size(0); serialize_u32(its_interval_set_size, _data); - for (const auto i : _intervals) + for (const auto& i : _intervals) serialize_interval(i, _data); its_interval_set_size = static_cast(_data.size() diff --git a/implementation/security/src/security.cpp b/implementation/security/src/security.cpp index a3b6ab3f9..19ff73dad 100644 --- a/implementation/security/src/security.cpp +++ b/implementation/security/src/security.cpp @@ -14,6 +14,7 @@ #include "../../plugin/include/plugin_manager.hpp" #include +#include #include #ifndef _WIN32 diff --git a/implementation/service_discovery/src/service_discovery_impl.cpp b/implementation/service_discovery/src/service_discovery_impl.cpp index de6e8467c..c38804575 100644 --- a/implementation/service_discovery/src/service_discovery_impl.cpp +++ b/implementation/service_discovery/src/service_discovery_impl.cpp @@ -5,8 +5,10 @@ #include -#include +#include +#include #include +#include #include #include @@ -869,7 +871,7 @@ service_discovery_impl::create_eventgroup_entry( << std::setw(4) << _service << "." << std::setw(4) << _instance << "." << std::setw(4) << _eventgroup << "] " - << (uint16_t) _reliability_type; + << static_cast(_reliability_type); return its_data; } std::shared_ptr its_entry, its_other; @@ -1074,7 +1076,7 @@ service_discovery_impl::insert_subscription_ack( // Selective if (_clients.size() > 1 || (*(_clients.begin())) != 0) { auto its_selective_option = std::make_shared(); - (void)its_selective_option->set_clients(_clients); + static_cast(its_selective_option->set_clients(_clients)); its_data.options_.push_back(its_selective_option); } @@ -1136,7 +1138,7 @@ service_discovery_impl::on_message( static bool must_start_last_msg_received_timer(true); boost::system::error_code ec; - std::lock_guard its_lock(last_msg_received_timer_mutex_); + std::lock_guard its_lock_inner(last_msg_received_timer_mutex_); if (0 < last_msg_received_timer_.cancel(ec) || must_start_last_msg_received_timer) { must_start_last_msg_received_timer = false; last_msg_received_timer_.expires_from_now( @@ -1272,7 +1274,7 @@ service_discovery_impl::on_message( } { - std::unique_lock its_lock(its_acknowledgement->get_lock()); + std::unique_lock its_lock_inner(its_acknowledgement->get_lock()); its_acknowledgement->complete(); // TODO: Check the following logic... if (its_acknowledgement->has_subscription()) { @@ -1543,7 +1545,7 @@ service_discovery_impl::process_offerservice_serviceentry( << std::setw(4) << _instance << "." << std::setw(4) << eg << "]" << " using reliability type: " - << std::setw(4) << (uint16_t) offer_type; + << std::setw(4) << static_cast(offer_type); its_info->set_reliability(offer_type); } } @@ -1947,7 +1949,7 @@ service_discovery_impl::process_eventgroupentry( << ": SOME/IP length field in SubscribeEventGroup message header: [" << std::dec << _entry->get_owning_message()->get_someip_length() << "] bytes, is shorter than length of deserialized message: [" - << (uint32_t) _entry->get_owning_message()->get_length() << "] bytes. " + << static_cast(_entry->get_owning_message()->get_length()) << "] bytes. " << its_sender.to_string(ec) << " session: " << std::hex << std::setw(4) << std::setfill('0') << its_session; return; @@ -2238,7 +2240,7 @@ service_discovery_impl::process_eventgroupentry( boost::system::error_code ec; VSOMEIP_WARNING << __func__ << ": Unsupported eventgroup option [" - << std::hex << (int)its_option->get_type() << "] " + << std::hex << static_cast(its_option->get_type()) << "] " << its_sender.to_string(ec) << " session: " << std::hex << std::setw(4) << std::setfill('0') << its_session; if (its_ttl > 0) { @@ -2332,7 +2334,7 @@ service_discovery_impl::handle_eventgroup_subscription( << std::setw(4) << _instance << "." << std::setw(4) << _eventgroup << "]" << " not valid: Event configuration (" - << (std::uint32_t)_info->get_reliability() + << static_cast(_info->get_reliability()) << ") does not match the provided endpoint options: " << _first_address.to_string(ec) << ":" << std::dec << _first_port << " " << _second_address.to_string(ec) << ":" << _second_port; @@ -2355,14 +2357,14 @@ service_discovery_impl::handle_eventgroup_subscription( boost::system::error_code ec; // TODO: Add session id VSOMEIP_ERROR << __func__ - << ": Requested major version:[" << (uint32_t) _major + << ": Requested major version:[" << static_cast(_major) << "] in subscription to service: [" << std::hex << std::setfill('0') << std::setw(4) << _service << "." << std::setw(4) << _instance << "." << std::setw(4) << _eventgroup << "]" << " does not match with services major version:[" - << (uint32_t) _info->get_major() << "] subscriber: " + << static_cast(_info->get_major()) << "] subscriber: " << _first_address.to_string(ec) << ":" << std::dec << _first_port; if (_ttl > 0) { insert_subscription_ack(_acknowledgement, its_info, 0, nullptr, _clients); @@ -3107,8 +3109,8 @@ service_discovery_impl::move_offers_into_main_phase( const auto its_timer = repetition_phase_timers_.find(_timer); if (its_timer != repetition_phase_timers_.end()) { for (const auto& its_service : its_timer->second) { - for (const auto& instance : its_service.second) { - instance.second->set_is_in_mainphase(true); + for (const auto& its_instance : its_service.second) { + its_instance.second->set_is_in_mainphase(true); } } repetition_phase_timers_.erase(_timer); @@ -3125,7 +3127,7 @@ service_discovery_impl::stop_offer_service( bool stop_offer_required(false); // Delete from initial phase offers { - std::lock_guard its_lock(collected_offers_mutex_); + std::lock_guard its_lock_inner(collected_offers_mutex_); if (collected_offers_.size()) { auto its_service_it = collected_offers_.find(its_service); if (its_service_it != collected_offers_.end()) { @@ -3147,7 +3149,7 @@ service_discovery_impl::stop_offer_service( // Delete from repetition phase offers { - std::lock_guard its_lock(repetition_phase_timers_mutex_); + std::lock_guard its_lock_inner(repetition_phase_timers_mutex_); for (auto rpt = repetition_phase_timers_.begin(); rpt != repetition_phase_timers_.end();) { auto its_service_it = rpt->second.find(its_service); @@ -3866,7 +3868,7 @@ reliability_type_e service_discovery_impl::get_eventgroup_reliability( << std::setw(4) << _instance << "." << std::setw(4) << _eventgroup << "]" << " using reliability type: " - << std::setw(4) << (uint16_t) its_reliability; + << std::setw(4) << static_cast(its_reliability); its_info->set_reliability(its_reliability); } } else { diff --git a/interface/vsomeip/constants.hpp b/interface/vsomeip/constants.hpp index 2b040c5ea..2519b57fe 100644 --- a/interface/vsomeip/constants.hpp +++ b/interface/vsomeip/constants.hpp @@ -13,54 +13,54 @@ namespace vsomeip_v3 { -const major_version_t DEFAULT_MAJOR = 0x00; -const minor_version_t DEFAULT_MINOR = 0x00000000; -const ttl_t DEFAULT_TTL = 0xFFFFFF; // "until next reboot" +inline constexpr major_version_t DEFAULT_MAJOR = 0x00; +inline constexpr minor_version_t DEFAULT_MINOR = 0x00000000; +inline constexpr ttl_t DEFAULT_TTL = 0xFFFFFF; // "until next reboot" const std::string DEFAULT_MULTICAST = "224.0.0.0"; -const uint16_t DEFAULT_PORT = 30500; -const uint16_t ILLEGAL_PORT = 0xFFFF; -const uint16_t ANY_PORT = 0; - -const uint16_t NO_TRACE_FILTER_EXPRESSION = 0x0000; - -const service_t ANY_SERVICE = 0xFFFF; -const instance_t ANY_INSTANCE = 0xFFFF; -const eventgroup_t ANY_EVENTGROUP = 0xFFFF; -const method_t ANY_METHOD = 0xFFFF; -const major_version_t ANY_MAJOR = 0xFF; -const minor_version_t ANY_MINOR = 0xFFFFFFFF; - -const eventgroup_t DEFAULT_EVENTGROUP = 0x0001; - -const client_t ILLEGAL_CLIENT = 0x0000; -const method_t INVALID_METHOD = 0x0000; - -const byte_t MAGIC_COOKIE_CLIENT_MESSAGE = 0x00; -const byte_t MAGIC_COOKIE_SERVICE_MESSAGE = 0x80; -const length_t MAGIC_COOKIE_SIZE = 0x00000008; -const request_t MAGIC_COOKIE_REQUEST = 0xDEADBEEF; -const client_t MAGIC_COOKIE_CLIENT = 0xDEAD; -const protocol_version_t MAGIC_COOKIE_PROTOCOL_VERSION = 0x01; -const interface_version_t MAGIC_COOKIE_INTERFACE_VERSION = 0x01; -const message_type_e MAGIC_COOKIE_CLIENT_MESSAGE_TYPE = +inline constexpr uint16_t DEFAULT_PORT = 30500; +inline constexpr uint16_t ILLEGAL_PORT = 0xFFFF; +inline constexpr uint16_t ANY_PORT = 0; + +inline constexpr uint16_t NO_TRACE_FILTER_EXPRESSION = 0x0000; + +inline constexpr service_t ANY_SERVICE = 0xFFFF; +inline constexpr instance_t ANY_INSTANCE = 0xFFFF; +inline constexpr eventgroup_t ANY_EVENTGROUP = 0xFFFF; +inline constexpr method_t ANY_METHOD = 0xFFFF; +inline constexpr major_version_t ANY_MAJOR = 0xFF; +inline constexpr minor_version_t ANY_MINOR = 0xFFFFFFFF; + +inline constexpr eventgroup_t DEFAULT_EVENTGROUP = 0x0001; + +inline constexpr client_t ILLEGAL_CLIENT = 0x0000; +inline constexpr method_t INVALID_METHOD = 0x0000; + +inline constexpr byte_t MAGIC_COOKIE_CLIENT_MESSAGE = 0x00; +inline constexpr byte_t MAGIC_COOKIE_SERVICE_MESSAGE = 0x80; +inline constexpr length_t MAGIC_COOKIE_SIZE = 0x00000008; +inline constexpr request_t MAGIC_COOKIE_REQUEST = 0xDEADBEEF; +inline constexpr client_t MAGIC_COOKIE_CLIENT = 0xDEAD; +inline constexpr protocol_version_t MAGIC_COOKIE_PROTOCOL_VERSION = 0x01; +inline constexpr interface_version_t MAGIC_COOKIE_INTERFACE_VERSION = 0x01; +inline constexpr message_type_e MAGIC_COOKIE_CLIENT_MESSAGE_TYPE = message_type_e::MT_REQUEST_NO_RETURN; -const message_type_e MAGIC_COOKIE_SERVICE_MESSAGE_TYPE = +inline constexpr message_type_e MAGIC_COOKIE_SERVICE_MESSAGE_TYPE = message_type_e::MT_NOTIFICATION; -const return_code_e MAGIC_COOKIE_RETURN_CODE = return_code_e::E_OK; +inline constexpr return_code_e MAGIC_COOKIE_RETURN_CODE = return_code_e::E_OK; -const byte_t CLIENT_COOKIE[] = { 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, +inline constexpr byte_t CLIENT_COOKIE[] = { 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xDE, 0xAD, 0xBE, 0xEF, 0x01, 0x01, 0x01, 0x00 }; -const byte_t SERVICE_COOKIE[] = { 0xFF, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, +inline constexpr byte_t SERVICE_COOKIE[] = { 0xFF, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xDE, 0xAD, 0xBE, 0xEF, 0x01, 0x01, 0x02, 0x00 }; -const event_t ANY_EVENT = 0xFFFF; -const client_t ANY_CLIENT = 0xFFFF; +inline constexpr event_t ANY_EVENT = 0xFFFF; +inline constexpr client_t ANY_CLIENT = 0xFFFF; -const int VSOMEIP_ALL = -1; +inline constexpr int VSOMEIP_ALL = -1; -const pending_security_update_id_t DEFAULT_SECURITY_UPDATE_ID = 0x0; +inline constexpr pending_security_update_id_t DEFAULT_SECURITY_UPDATE_ID = 0x0; } // namespace vsomeip_v3 diff --git a/test/network_tests/application_tests/application_test.cpp b/test/network_tests/application_tests/application_test.cpp index a4a1923d4..c70b6cd5c 100644 --- a/test/network_tests/application_tests/application_test.cpp +++ b/test/network_tests/application_tests/application_test.cpp @@ -3,6 +3,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. +#include #include #include #include diff --git a/tools/vsomeip_ctrl.cpp b/tools/vsomeip_ctrl.cpp index 745104274..3e74a8322 100644 --- a/tools/vsomeip_ctrl.cpp +++ b/tools/vsomeip_ctrl.cpp @@ -29,7 +29,6 @@ class vsomeip_sender { instance_(_instance), app_(vsomeip::runtime::get()->create_application("vsomeip_ctrl")), wait_service_available_(true), - send_thread_(std::bind(&vsomeip_sender::send, this)), service_id_(0x0), method_id_(0x0), length_(0), @@ -39,6 +38,8 @@ class vsomeip_sender { return_code_(vsomeip::return_code_e::E_UNKNOWN), wait_for_answer_(true) { + send_thread_ = std::thread{&vsomeip_sender::send, this}; + if (user_message_.size() < VSOMEIP_PAYLOAD_POS) { VSOMEIP_ERROR << "Provided message is to short, min. length " "is 16 Bytes, exiting."; @@ -117,11 +118,11 @@ class vsomeip_sender { << std::setw(4) << _response->get_instance() << "]:"; VSOMEIP_INFO << "########## begin message"; VSOMEIP_INFO << std::hex << std::setw(4) << std::setfill('0') - << _response->get_service() + << _response->get_service() << std::hex << std::setw(4) << std::setfill('0') << _response->get_method() << " # service id / instance id"; - VSOMEIP_INFO << std::hex << std::setw(8) << std::setfill('0') + VSOMEIP_INFO << std::hex << std::setw(8) << std::setfill('0') << _response->get_length() << " # length"; VSOMEIP_INFO << std::hex << std::setw(4) << std::setfill('0') << _response->get_client() @@ -243,7 +244,7 @@ class vsomeip_sender { } if (use_tcp_ && user_message_.size() > VSOMEIP_MAX_TCP_MESSAGE_SIZE) { - VSOMEIP_WARNING << "Max allowed message size for TCP is " + VSOMEIP_WARNING << "Max allowed message size for TCP is " << std::dec << VSOMEIP_MAX_TCP_MESSAGE_SIZE << ". Provided message size is: " << user_message_.size(); }