diff --git a/.github/workflows/upload-apex-release-on-tag.yml b/.github/workflows/upload-apex-release-on-tag.yml index 5adc1d0eb..aaa3dcec3 100644 --- a/.github/workflows/upload-apex-release-on-tag.yml +++ b/.github/workflows/upload-apex-release-on-tag.yml @@ -45,7 +45,7 @@ jobs: with: tag_name: ${{ github.ref_name }} files: /tmp/${{ github.ref_name }}.tar.gz - draft: true + draft: false prerelease: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/BUILD b/BUILD index 95bc9f1ed..e72ac7b8d 100644 --- a/BUILD +++ b/BUILD @@ -1,18 +1,21 @@ -cc_shared_library( - name = "vsomeip3_shared", - shared_lib_name = "libvsomeip3.so", - tags = ["same-ros-pkg-as: vsomeip3"], - # Disabled due to linking problem when used as an external repository with sanitizers enabled. - #user_link_flags = [ - # "-Wl,--no-undefined", - #], - deps = ["//implementation"], -) +load("@apex//common/bazel/rules_cc:defs.bzl", "apex_cc_library") + +# apex_cc_library( +# name = "vsomeip3_shared", +# shared_lib_name = "libvsomeip3.so", +# tags = ["same-ros-pkg-as: vsomeip3"], +# # Disabled due to linking problem when used as an external repository with sanitizers enabled. +# #user_link_flags = [ +# # "-Wl,--no-undefined", +# #], +# deps = [ +# "//implementation:configuration", +# "//implementation:service_discovery", +# ], +# ) -cc_shared_library( +apex_cc_library( name = "vsomeip3_config_plugin", - dynamic_deps = [":vsomeip3_shared"], - shared_lib_name = "libvsomeip3-cfg.so.3", tags = ["same-ros-pkg-as: vsomeip3"], # Disabled due to linking problem when used as an external repository with sanitizers enabled. #user_link_flags = [ @@ -21,10 +24,8 @@ cc_shared_library( deps = ["//implementation:configuration"], ) -cc_shared_library( +apex_cc_library( name = "vsomeip3_sd_plugin", - dynamic_deps = [":vsomeip3_shared"], - shared_lib_name = "libvsomeip3-sd.so.3", tags = ["same-ros-pkg-as: vsomeip3"], # Disabled due to linking problem when used as an external repository with sanitizers enabled. #user_link_flags = [ @@ -33,32 +34,19 @@ cc_shared_library( deps = ["//implementation:service_discovery"], ) -cc_import( - name = "vsomeip3_import", - shared_library = ":vsomeip3_shared", - tags = ["same-ros-pkg-as: vsomeip3"], - deps = ["//interface"], -) +# apex_cc_library( +# name = "vsomeip3_import", +# shared_library = ":vsomeip3_shared", +# tags = ["same-ros-pkg-as: vsomeip3"], +# deps = ["//interface"], +# ) -cc_import( - name = "vsomeip3_configuration_plugin_import", - shared_library = ":vsomeip3_config_plugin", - tags = ["same-ros-pkg-as: vsomeip3"], -) - -cc_import( - name = "vsomeip3_sd_plugin_import", - shared_library = ":vsomeip3_sd_plugin", - tags = ["same-ros-pkg-as: vsomeip3"], -) # interface library, use this target to depend on vsomeip -cc_library( +apex_cc_library( name = "vsomeip3", - data = [ - ":vsomeip3_config_plugin", - ":vsomeip3_sd_plugin", - ], + srcs = ["src/plugin_init.cpp"], + alwayslink = True, linkopts = select({ "@platforms//os:linux": ["-lpthread"], "//conditions:default": [], @@ -66,9 +54,9 @@ cc_library( linkstatic = True, # no object files visibility = ["//visibility:public"], deps = [ - ":vsomeip3_configuration_plugin_import", - ":vsomeip3_import", - ":vsomeip3_sd_plugin_import", + ":vsomeip3_config_plugin", + # ":vsomeip3_import", + ":vsomeip3_sd_plugin", "//interface", ], ) diff --git a/implementation/BUILD b/implementation/BUILD index 8ce98e2c8..9d1df7ded 100644 --- a/implementation/BUILD +++ b/implementation/BUILD @@ -1,7 +1,8 @@ load("//bazel:expand_template.bzl", "expand_template") +load("@apex//common/bazel/rules_cc:defs.bzl", "apex_cc_library") load("@vsomeip//bazel:version.bzl", "version_dict_from_string") -APEX_VSOMEIP_VERSION_TAG = "3.6.1-apex8" # Must match the git tag version. +APEX_VSOMEIP_VERSION_TAG = "3.6.1-apex8-fix-qnx-gateway-com-02" # Must match the git tag version. expand_template( name = "config", @@ -24,13 +25,13 @@ expand_template( template = "configuration/include/internal.hpp.in", ) -cc_library( +apex_cc_library( name = "generated_config", hdrs = [":config"], strip_include_prefix = "configuration/include", ) -cc_library( +apex_cc_library( name = "helper", hdrs = glob( [ @@ -49,7 +50,7 @@ cc_library( ], ) -cc_library( +apex_cc_library( name = "configuration", srcs = glob( [ @@ -63,7 +64,7 @@ cc_library( ], ) -cc_library( +apex_cc_library( name = "service_discovery", srcs = glob( [ @@ -76,7 +77,7 @@ cc_library( ], ) -cc_library( +apex_cc_library( name = "implementation", srcs = glob( [ diff --git a/implementation/configuration/src/configuration_plugin_impl.cpp b/implementation/configuration/src/configuration_plugin_impl.cpp index a96553c87..b3d0fd5df 100644 --- a/implementation/configuration/src/configuration_plugin_impl.cpp +++ b/implementation/configuration/src/configuration_plugin_impl.cpp @@ -3,6 +3,8 @@ // 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 @@ -22,11 +24,17 @@ std::shared_ptr configuration_plugin_impl::get_configuration(cons std::scoped_lock its_lock(mutex_); auto its_iterator = configurations_.find(_name); if (its_iterator != configurations_.end()) { + std::cerr << "[vsomeip][configuration-debug] Reusing cached configuration for application \"" << _name << "\"." + << std::endl; its_configuration = its_iterator->second; } else { + std::cerr << "[vsomeip][configuration-debug] Creating new configuration_impl for application \"" << _name + << "\" with path \"" << _path << "\"." << std::endl; its_configuration = std::make_shared(_path); its_configuration->load(_name); configurations_[_name] = its_configuration; + std::cerr << "[vsomeip][configuration-debug] Configuration loaded and cached for application \"" << _name << "\"." + << std::endl; } return its_configuration; @@ -39,14 +47,17 @@ bool configuration_plugin_impl::remove_configuration(const std::string& _name) { namespace { -struct configuration_plugin_static_registrar { - configuration_plugin_static_registrar() { +struct configuration_plugin_static_registration { + configuration_plugin_static_registration() { + std::cerr << "[vsomeip][configuration-debug] Static configuration plugin registration is running. Registering " + "CONFIGURATION_PLUGIN factory with plugin_manager." + << std::endl; plugin_manager::register_static_plugin(plugin_type_e::CONFIGURATION_PLUGIN, configuration_plugin_impl::get_plugin); } }; -const configuration_plugin_static_registrar configuration_plugin_static_registrar_{}; +const configuration_plugin_static_registration configuration_plugin_static_registration_{}; } // namespace } // namespace vsomeip_v3 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 10c80365a..a370a586d 100644 --- a/implementation/endpoints/include/local_server_endpoint_impl_receive_op.hpp +++ b/implementation/endpoints/include/local_server_endpoint_impl_receive_op.hpp @@ -8,7 +8,13 @@ #if defined(__linux__) || defined(__QNX__) +#include +#include +#include +#include + #include +#include #include namespace vsomeip_v3 { @@ -36,7 +42,7 @@ inline std::function receive_cb(std::sha if (!_error) { if (!_data->socket_.native_non_blocking()) _data->socket_.native_non_blocking(true, _error); -#if defined(__linux__) +#if defined(__linux__) || defined(__QNX__) for (;;) { ssize_t its_result; int its_flags(0); diff --git a/implementation/endpoints/include/local_tcp_client_endpoint_impl.hpp b/implementation/endpoints/include/local_tcp_client_endpoint_impl.hpp index 382ace37d..476926b47 100644 --- a/implementation/endpoints/include/local_tcp_client_endpoint_impl.hpp +++ b/implementation/endpoints/include/local_tcp_client_endpoint_impl.hpp @@ -6,6 +6,8 @@ #ifndef VSOMEIP_V3_LOCAL_TCP_CLIENT_ENDPOINT_IMPL_HPP_ #define VSOMEIP_V3_LOCAL_TCP_CLIENT_ENDPOINT_IMPL_HPP_ +#include + #include #include @@ -56,6 +58,7 @@ class local_tcp_client_endpoint_impl : public local_tcp_client_endpoint_base_imp void max_allowed_reconnects_reached(); message_buffer_t recv_buffer_; + std::size_t recv_buffer_size_; // send data message_buffer_ptr_t send_data_buffer_; diff --git a/implementation/endpoints/include/local_uds_client_endpoint_impl.hpp b/implementation/endpoints/include/local_uds_client_endpoint_impl.hpp index 6129d54b9..cf111723d 100644 --- a/implementation/endpoints/include/local_uds_client_endpoint_impl.hpp +++ b/implementation/endpoints/include/local_uds_client_endpoint_impl.hpp @@ -6,6 +6,8 @@ #ifndef VSOMEIP_V3_LOCAL_UDS_CLIENT_ENDPOINT_IMPL_HPP_ #define VSOMEIP_V3_LOCAL_UDS_CLIENT_ENDPOINT_IMPL_HPP_ +#include + #include #include @@ -55,6 +57,7 @@ class local_uds_client_endpoint_impl : public local_uds_client_endpoint_base_imp void max_allowed_reconnects_reached(); message_buffer_t recv_buffer_; + std::size_t recv_buffer_size_; // send data message_buffer_ptr_t send_data_buffer_; diff --git a/implementation/endpoints/src/local_tcp_client_endpoint_impl.cpp b/implementation/endpoints/src/local_tcp_client_endpoint_impl.cpp index 08e9263ef..05ebdb3eb 100644 --- a/implementation/endpoints/src/local_tcp_client_endpoint_impl.cpp +++ b/implementation/endpoints/src/local_tcp_client_endpoint_impl.cpp @@ -33,7 +33,7 @@ local_tcp_client_endpoint_impl::local_tcp_client_endpoint_impl(const std::shared boost::asio::io_context& _io, const std::shared_ptr& _configuration) : local_tcp_client_endpoint_base_impl(_endpoint_host, _routing_host, _local, _remote, _io, _configuration), - recv_buffer_(VSOMEIP_LOCAL_CLIENT_ENDPOINT_RECV_BUFFER_SIZE, 0) { + recv_buffer_(VSOMEIP_LOCAL_CLIENT_ENDPOINT_RECV_BUFFER_SIZE, 0), recv_buffer_size_(0) { this->max_message_size_ = _configuration->get_max_message_size_local(); this->queue_limit_ = _configuration->get_endpoint_queue_limit_local(); @@ -60,6 +60,7 @@ void local_tcp_client_endpoint_impl::restart(bool _force) { queue_.clear(); queue_size_ = 0; is_sending_ = false; + recv_buffer_size_ = 0; } { std::lock_guard its_lock(socket_mutex_); @@ -230,7 +231,11 @@ void local_tcp_client_endpoint_impl::connect() { void local_tcp_client_endpoint_impl::receive() { std::lock_guard its_lock(socket_mutex_); if (socket_->is_open()) { - socket_->async_receive(boost::asio::buffer(recv_buffer_), + if (recv_buffer_size_ == recv_buffer_.size()) { + VSOMEIP_WARNING << "ltcei::" << __func__ << ": receive buffer full before receive endpoint > " << this; + recv_buffer_size_ = 0; + } + socket_->async_receive(boost::asio::buffer(&recv_buffer_[recv_buffer_size_], recv_buffer_.size() - recv_buffer_size_), strand_.wrap(std::bind(&local_tcp_client_endpoint_impl::receive_cbk, std::dynamic_pointer_cast(shared_from_this()), std::placeholders::_1, std::placeholders::_2))); @@ -317,6 +322,7 @@ void local_tcp_client_endpoint_impl::receive_cbk(boost::system::error_code const sending_blocked_ = false; queue_.clear(); queue_size_ = 0; + recv_buffer_size_ = 0; if (is_stopping_) { queue_cv_.notify_all(); @@ -334,16 +340,22 @@ void local_tcp_client_endpoint_impl::receive_cbk(boost::system::error_code const VSOMEIP_INFO << msg.str(); #endif + recv_buffer_size_ += _bytes; + // We only handle a single message here. Check whether the message // format matches what we do expect. // TODO: Replace the magic numbers. - if (_bytes == VSOMEIP_LOCAL_CLIENT_ENDPOINT_RECV_BUFFER_SIZE && recv_buffer_[0] == 0x67 && recv_buffer_[1] == 0x37 + if (recv_buffer_size_ == VSOMEIP_LOCAL_CLIENT_ENDPOINT_RECV_BUFFER_SIZE && recv_buffer_[0] == 0x67 && recv_buffer_[1] == 0x37 && recv_buffer_[2] == 0x6d && recv_buffer_[3] == 0x07 && recv_buffer_[4] == byte_t(protocol::id_e::ASSIGN_CLIENT_ACK_ID) && recv_buffer_[15] == 0x07 && recv_buffer_[16] == 0x6d && recv_buffer_[17] == 0x37 && recv_buffer_[18] == 0x67) { auto its_routing_host = routing_host_.lock(); if (its_routing_host) its_routing_host->on_message(&recv_buffer_[4], static_cast(recv_buffer_.size() - 8), this); + recv_buffer_size_ = 0; + } else if (recv_buffer_size_ == VSOMEIP_LOCAL_CLIENT_ENDPOINT_RECV_BUFFER_SIZE) { + VSOMEIP_WARNING << "ltcei::" << __func__ << ": received malformed assign client ack endpoint > " << this; + recv_buffer_size_ = 0; } receive(); diff --git a/implementation/endpoints/src/local_uds_client_endpoint_impl.cpp b/implementation/endpoints/src/local_uds_client_endpoint_impl.cpp index 8762ab729..f3b06322f 100644 --- a/implementation/endpoints/src/local_uds_client_endpoint_impl.cpp +++ b/implementation/endpoints/src/local_uds_client_endpoint_impl.cpp @@ -30,7 +30,7 @@ local_uds_client_endpoint_impl::local_uds_client_endpoint_impl(const std::shared local_uds_client_endpoint_base_impl(_endpoint_host, _routing_host, _remote, _remote, _io, _configuration), // Using _remote for the local(!) endpoint is ok, // because we have no bind for local endpoints! - recv_buffer_(VSOMEIP_LOCAL_CLIENT_ENDPOINT_RECV_BUFFER_SIZE, 0) { + recv_buffer_(VSOMEIP_LOCAL_CLIENT_ENDPOINT_RECV_BUFFER_SIZE, 0), recv_buffer_size_(0) { this->max_message_size_ = _configuration->get_max_message_size_local(); this->queue_limit_ = _configuration->get_endpoint_queue_limit_local(); @@ -50,6 +50,7 @@ void local_uds_client_endpoint_impl::restart(bool _force) { queue_.clear(); queue_size_ = 0; is_sending_ = false; + recv_buffer_size_ = 0; } { std::lock_guard its_lock(socket_mutex_); @@ -175,7 +176,11 @@ void local_uds_client_endpoint_impl::connect() { void local_uds_client_endpoint_impl::receive() { std::lock_guard its_lock(socket_mutex_); if (socket_->is_open()) { - socket_->async_receive(boost::asio::buffer(recv_buffer_), + if (recv_buffer_size_ == recv_buffer_.size()) { + VSOMEIP_WARNING << "lucei::" << __func__ << ": receive buffer full before receive | endpoint > " << this; + recv_buffer_size_ = 0; + } + socket_->async_receive(boost::asio::buffer(&recv_buffer_[recv_buffer_size_], recv_buffer_.size() - recv_buffer_size_), strand_.wrap(std::bind(&local_uds_client_endpoint_impl::receive_cbk, std::dynamic_pointer_cast(shared_from_this()), std::placeholders::_1, std::placeholders::_2))); @@ -263,6 +268,7 @@ void local_uds_client_endpoint_impl::receive_cbk(boost::system::error_code const sending_blocked_ = false; queue_.clear(); queue_size_ = 0; + recv_buffer_size_ = 0; } else if (_error == boost::asio::error::bad_descriptor) { restart(true); return; @@ -279,16 +285,22 @@ void local_uds_client_endpoint_impl::receive_cbk(boost::system::error_code const VSOMEIP_INFO << msg.str(); #endif + recv_buffer_size_ += _bytes; + // We only handle a single message here. Check whether the message // format matches what we do expect. // TODO: Replace the magic numbers. - if (_bytes == VSOMEIP_LOCAL_CLIENT_ENDPOINT_RECV_BUFFER_SIZE && recv_buffer_[0] == 0x67 && recv_buffer_[1] == 0x37 + if (recv_buffer_size_ == VSOMEIP_LOCAL_CLIENT_ENDPOINT_RECV_BUFFER_SIZE && recv_buffer_[0] == 0x67 && recv_buffer_[1] == 0x37 && recv_buffer_[2] == 0x6d && recv_buffer_[3] == 0x07 && recv_buffer_[4] == byte_t(protocol::id_e::ASSIGN_CLIENT_ACK_ID) && recv_buffer_[15] == 0x07 && recv_buffer_[16] == 0x6d && recv_buffer_[17] == 0x37 && recv_buffer_[18] == 0x67) { auto its_routing_host = routing_host_.lock(); if (its_routing_host) its_routing_host->on_message(&recv_buffer_[4], static_cast(recv_buffer_.size() - 8), this); + recv_buffer_size_ = 0; + } else if (recv_buffer_size_ == VSOMEIP_LOCAL_CLIENT_ENDPOINT_RECV_BUFFER_SIZE) { + VSOMEIP_WARNING << "lucei::" << __func__ << ": received malformed assign client ack | endpoint > " << this; + recv_buffer_size_ = 0; } receive(); diff --git a/implementation/plugin/src/plugin_manager_impl.cpp b/implementation/plugin/src/plugin_manager_impl.cpp index 9c33c94f4..6613334f8 100644 --- a/implementation/plugin/src/plugin_manager_impl.cpp +++ b/implementation/plugin/src/plugin_manager_impl.cpp @@ -35,6 +35,25 @@ namespace vsomeip_v3 { std::shared_ptr plugin_manager_impl::the_plugin_manager__ = nullptr; +namespace { + +const char* plugin_type_to_string(plugin_type_e _type) { + switch (_type) { + case plugin_type_e::APPLICATION_PLUGIN: + return "APPLICATION_PLUGIN"; + case plugin_type_e::CONFIGURATION_PLUGIN: + return "CONFIGURATION_PLUGIN"; + case plugin_type_e::PRE_CONFIGURATION_PLUGIN: + return "PRE_CONFIGURATION_PLUGIN"; + case plugin_type_e::SD_RUNTIME_PLUGIN: + return "SD_RUNTIME_PLUGIN"; + default: + return "UNKNOWN_PLUGIN"; + } +} + +} // namespace + std::shared_ptr plugin_manager_impl::get() { static std::once_flag initialization_flag; std::call_once(initialization_flag, []() { @@ -52,58 +71,81 @@ plugin_manager_impl::~plugin_manager_impl() { std::shared_ptr plugin_manager_impl::get_plugin(plugin_type_e _type, const std::string& _name) { std::lock_guard its_lock_start_stop(plugins_mutex_); + std::cerr << "[vsomeip][plugin-debug] get_plugin requested type=" << plugin_type_to_string(_type) << " (" + << static_cast(_type) << "), name=\"" << _name << "\"." << std::endl; auto its_type = plugins_.find(_type); if (its_type != plugins_.end()) { auto its_name = its_type->second.find(_name); if (its_name != its_type->second.end()) { + std::cerr << "[vsomeip][plugin-debug] Returning cached plugin for type=" << plugin_type_to_string(_type) + << ", name=\"" << _name << "\"." << std::endl; return its_name->second; } + std::cerr << "[vsomeip][plugin-debug] Plugin cache contains type=" << plugin_type_to_string(_type) + << " but no entry named \"" << _name << "\". Loading it now." << std::endl; + } else { + std::cerr << "[vsomeip][plugin-debug] Plugin cache has no entries for type=" << plugin_type_to_string(_type) + << ". Loading requested plugin now." << std::endl; } return load_plugin(_name, _type, 1); } std::shared_ptr plugin_manager_impl::load_plugin(const std::string& _library, plugin_type_e _type, uint32_t _version) { + std::cerr << "[vsomeip][plugin-debug] load_plugin started for library=\"" << _library << "\", expected type=" + << plugin_type_to_string(_type) << " (" << static_cast(_type) << "), expected version=" << _version << "." + << std::endl; if (auto its_plugin = load_static_plugin(_type, _version)) { + std::cerr << "[vsomeip][plugin-debug] Static plugin lookup succeeded for type=" << plugin_type_to_string(_type) + << ". Caching it under name=\"" << _library << "\"." << std::endl; handles_[_type][_library] = nullptr; add_plugin(its_plugin, _library); return its_plugin; } - void* handle = load_library(_library); - plugin_init_func its_init_func = reinterpret_cast(load_symbol(handle, VSOMEIP_PLUGIN_INIT_SYMBOL)); - if (its_init_func) { - create_plugin_func its_create_func = (*its_init_func)(); - if (its_create_func) { - handles_[_type][_library] = handle; - auto its_plugin = (*its_create_func)(); - if (its_plugin) { - if (its_plugin->get_plugin_type() == _type && its_plugin->get_plugin_version() == _version) { - add_plugin(its_plugin, _library); - return its_plugin; - } else { - VSOMEIP_ERROR << "Plugin version mismatch. Ignoring plugin " << its_plugin->get_plugin_name(); - } - } - } - } + std::cerr << "[vsomeip][plugin-debug] Static plugin lookup failed for type=" << plugin_type_to_string(_type) + << ". Shared-library plugin loading is disabled, so \"" << _library << "\" will not be dlopen'ed." << std::endl; + std::cerr << "[vsomeip][plugin-debug] load_plugin failed for library=\"" << _library << "\", expected type=" + << plugin_type_to_string(_type) << " (" << static_cast(_type) << "), expected version=" << _version + << ". Returning nullptr." << std::endl; return nullptr; } std::shared_ptr plugin_manager_impl::load_static_plugin(plugin_type_e _type, uint32_t _version) { std::lock_guard its_lock_start_stop(plugins_mutex_); + std::cerr << "[vsomeip][plugin-debug] Looking for registered static plugin factory for type=" << plugin_type_to_string(_type) + << " (" << static_cast(_type) << "), expected version=" << _version << "." << std::endl; auto its_factory = static_factories_.find(_type); if (its_factory == static_factories_.end()) { + std::cerr << "[vsomeip][plugin-debug] No static plugin factory registered for type=" << plugin_type_to_string(_type) + << ". For the configuration plugin, this usually means the object containing register_static_plugin was not linked " + "or its static registration did not run." + << std::endl; return nullptr; } auto its_create_func = its_factory->second; if (!its_create_func) { + std::cerr << "[vsomeip][plugin-debug] Static plugin factory entry exists for type=" << plugin_type_to_string(_type) + << " but the factory function pointer is nullptr." << std::endl; return nullptr; } auto its_plugin = (*its_create_func)(); if (its_plugin && its_plugin->get_plugin_type() == _type && its_plugin->get_plugin_version() == _version) { + std::cerr << "[vsomeip][plugin-debug] Static plugin factory created matching plugin: name=\"" + << its_plugin->get_plugin_name() << "\", type=" << plugin_type_to_string(its_plugin->get_plugin_type()) << " (" + << static_cast(its_plugin->get_plugin_type()) << "), version=" << its_plugin->get_plugin_version() << "." + << std::endl; return its_plugin; } if (its_plugin) { + std::cerr << "[vsomeip][plugin-debug] Static plugin factory created a plugin with wrong type/version: name=\"" + << its_plugin->get_plugin_name() << "\", expected type=" << plugin_type_to_string(_type) << " (" + << static_cast(_type) << "), expected version=" << _version << "; got type=" + << plugin_type_to_string(its_plugin->get_plugin_type()) << " (" + << static_cast(its_plugin->get_plugin_type()) << "), got version=" << its_plugin->get_plugin_version() << "." + << std::endl; VSOMEIP_ERROR << "Plugin version mismatch. Ignoring static plugin " << its_plugin->get_plugin_name(); + } else { + std::cerr << "[vsomeip][plugin-debug] Static plugin factory returned nullptr for type=" << plugin_type_to_string(_type) + << "." << std::endl; } return nullptr; } @@ -113,6 +155,9 @@ bool plugin_manager_impl::unload_plugin(plugin_type_e _type) { const auto found_handle = handles_.find(_type); if (found_handle != handles_.end()) { for (const auto& its_name : found_handle->second) { + if (!its_name.second) { + continue; + } #ifdef _WIN32 FreeLibrary((HMODULE)its_name.second); #else @@ -130,70 +175,36 @@ bool plugin_manager_impl::unload_plugin(plugin_type_e _type) { } void plugin_manager_impl::add_plugin(const std::shared_ptr& _plugin, const std::string& _name) { + std::cerr << "[vsomeip][plugin-debug] add_plugin storing plugin name=\"" << _name << "\", plugin_name=\"" + << _plugin->get_plugin_name() << "\", type=" << plugin_type_to_string(_plugin->get_plugin_type()) << " (" + << static_cast(_plugin->get_plugin_type()) << "), version=" << _plugin->get_plugin_version() << "." + << std::endl; plugins_[_plugin->get_plugin_type()][_name] = _plugin; } void plugin_manager_impl::register_static_plugin(plugin_type_e _type, create_plugin_func _factory) { std::lock_guard its_lock_start_stop(plugins_mutex_); + std::cerr << "[vsomeip][plugin-debug] register_static_plugin called for type=" << plugin_type_to_string(_type) << " (" + << static_cast(_type) << "), factory=" << (_factory ? "set" : "nullptr") << "." << std::endl; static_factories_[_type] = _factory; } void* plugin_manager_impl::load_library(const std::string& _path) { -#ifdef _WIN32 - return LoadLibrary(_path.c_str()); -#else - void* handle = dlopen(_path.c_str(), RTLD_LAZY | RTLD_LOCAL); - if (handle == nullptr) { - VSOMEIP_ERROR << "Could not dlopen \"" << _path << "\" due to err: " << dlerror(); - } - - return handle; -#endif + std::cerr << "[vsomeip][plugin-debug] Shared-library loading is disabled. Refusing to load \"" << _path << "\"." + << std::endl; + return nullptr; } void* plugin_manager_impl::load_symbol(void* _handle, const std::string& _symbol_name) { - void* symbol = nullptr; - if (_handle) { -#ifdef _WIN32 - symbol = GetProcAddress(reinterpret_cast(_handle), _symbol_name.c_str()); -#else - symbol = dlsym(_handle, _symbol_name.c_str()); -#endif - - if (!symbol) { - char* error_message = nullptr; - -#ifdef _WIN32 - DWORD error_code = GetLastError(); - FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, error_code, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast(&error_message), 0, nullptr); -#else - error_message = dlerror(); -#endif - -#ifdef __QNX__ - VSOMEIP_ERROR << "Cannot load symbol " << std::quoted(_symbol_name.c_str()) << " because: " << error_message; -#else - VSOMEIP_ERROR << "Cannot load symbol " << std::quoted(_symbol_name) << " because: " << error_message; -#endif - -#ifdef _WIN32 - // Required to release memory allocated by FormatMessageA() - LocalFree(error_message); -#endif - } - } - return symbol; + (void)_handle; + std::cerr << "[vsomeip][plugin-debug] Shared-library loading is disabled. Refusing to load symbol \"" << _symbol_name + << "\"." << std::endl; + return nullptr; } void plugin_manager_impl::unload_library(void* _handle) { - if (_handle) { -#ifdef _WIN32 - FreeLibrary(reinterpret_cast(_handle)); -#else - dlclose(_handle); -#endif - } + (void)_handle; + std::cerr << "[vsomeip][plugin-debug] Shared-library loading is disabled. Ignoring unload_library request." << std::endl; } } // namespace vsomeip_v3 diff --git a/implementation/runtime/src/application_impl.cpp b/implementation/runtime/src/application_impl.cpp index f48ade4ea..4e70730a4 100644 --- a/implementation/runtime/src/application_impl.cpp +++ b/implementation/runtime/src/application_impl.cpp @@ -165,24 +165,45 @@ bool application_impl::init() { std::string config_module = ""; const char* its_config_module = getenv(VSOMEIP_ENV_CONFIGURATION_MODULE); if (nullptr != its_config_module) { + std::cerr << "[vsomeip][configuration-debug] Environment variable " << VSOMEIP_ENV_CONFIGURATION_MODULE << " is set to \"" + << its_config_module << "\". Custom configuration module loading is currently not implemented in this path." + << std::endl; // TODO: Add loading of custom configuration module } else { // load default module + std::cerr << "[vsomeip][configuration-debug] Environment variable " << VSOMEIP_ENV_CONFIGURATION_MODULE + << " is not set. Trying to load the default configuration plugin \"" << VSOMEIP_CFG_LIBRARY << "\"." + << std::endl; #ifndef VSOMEIP_ENABLE_MULTIPLE_ROUTING_MANAGERS auto its_plugin = plugin_manager::get()->get_plugin(plugin_type_e::CONFIGURATION_PLUGIN, VSOMEIP_CFG_LIBRARY); if (its_plugin) { + std::cerr << "[vsomeip][configuration-debug] Plugin manager returned a plugin for \"" << VSOMEIP_CFG_LIBRARY + << "\". Verifying that it implements configuration_plugin." << std::endl; auto its_configuration_plugin = std::dynamic_pointer_cast(its_plugin); if (its_configuration_plugin) { + std::cerr << "[vsomeip][configuration-debug] Configuration plugin cast succeeded. Loading configuration for application \"" + << name_ << "\" with configuration path \"" << path_ << "\"." << std::endl; configuration_ = its_configuration_plugin->get_configuration(name_, path_); VSOMEIP_INFO << "Configuration module loaded."; } else { + std::cerr << "[vsomeip][configuration-debug] Plugin manager returned a plugin, but dynamic_pointer_cast " + "failed. The plugin has an unexpected concrete type." + << std::endl; std::cerr << "Invalid configuration module!" << std::endl; std::exit(EXIT_FAILURE); } } else { + std::cerr << "[vsomeip][configuration-debug] Plugin manager returned nullptr for the default configuration plugin \"" + << VSOMEIP_CFG_LIBRARY + << "\". This means no valid static configuration plugin was registered/created and no valid dynamic plugin " + "could be loaded from that library name." + << std::endl; std::cerr << "1 Configuration module could not be loaded!" << std::endl; std::exit(EXIT_FAILURE); } #else + std::cerr << "[vsomeip][configuration-debug] VSOMEIP_ENABLE_MULTIPLE_ROUTING_MANAGERS is enabled. Bypassing the configuration " + "plugin manager and constructing cfg::configuration_impl directly." + << std::endl; configuration_ = std::dynamic_pointer_cast(std::make_shared(configuration_path)); if (configuration_path.length()) { diff --git a/implementation/service_discovery/src/runtime_impl.cpp b/implementation/service_discovery/src/runtime_impl.cpp index c1e9e438b..2898c3b33 100644 --- a/implementation/service_discovery/src/runtime_impl.cpp +++ b/implementation/service_discovery/src/runtime_impl.cpp @@ -30,13 +30,13 @@ std::shared_ptr runtime_impl::create_service_discovery(servic namespace { -struct sd_plugin_registrar { - sd_plugin_registrar() { +struct sd_plugin_registration { + sd_plugin_registration() { plugin_manager::register_static_plugin(plugin_type_e::SD_RUNTIME_PLUGIN, sd::runtime_impl::get_plugin); } }; -const sd_plugin_registrar sd_plugin_registrar_{}; +const sd_plugin_registration sd_plugin_registration_{}; } // namespace diff --git a/src/plugin_init.cpp b/src/plugin_init.cpp new file mode 100644 index 000000000..bd11ad2a0 --- /dev/null +++ b/src/plugin_init.cpp @@ -0,0 +1,34 @@ +// Copyright (C) 2024 Apex.AI, Inc. + +#include +#include + +#include + +#include "../implementation/configuration/include/configuration_plugin_impl.hpp" +#include "../implementation/service_discovery/include/runtime_impl.hpp" + +namespace vsomeip_v3 { +namespace { + +void initialize_builtin_plugins() { + static std::once_flag registration_flag; + std::call_once(registration_flag, []() { + std::cerr << "[vsomeip][plugin-debug] Explicit builtin plugin initialization is running." << std::endl; + plugin_manager::register_static_plugin(plugin_type_e::CONFIGURATION_PLUGIN, + configuration_plugin_impl::get_plugin); + plugin_manager::register_static_plugin(plugin_type_e::SD_RUNTIME_PLUGIN, + sd::runtime_impl::get_plugin); + }); +} + +struct builtin_plugin_initializer { + builtin_plugin_initializer() { + initialize_builtin_plugins(); + } +}; + +const builtin_plugin_initializer builtin_plugin_initializer_{}; + +} // namespace +} // namespace vsomeip_v3