Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dynamic_pointer_cast error #661

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class configuration_plugin_impl
virtual ~configuration_plugin_impl();

std::shared_ptr<configuration> get_configuration(const std::string &_name,
const std::string &_path);
const std::string &_path) override;

void* get_plugin_impl_ptr() override;

private:
std::mutex mutex_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ configuration_plugin_impl::configuration_plugin_impl()
plugin_type_e::CONFIGURATION_PLUGIN) {
}

void *configuration_plugin_impl::get_plugin_impl_ptr() {
auto its_configuration_plugin = dynamic_cast<configuration_plugin *>(this);

printf("nullptr == configuration_plugin_p:%d\n", its_configuration_plugin == nullptr);

return its_configuration_plugin;
}

configuration_plugin_impl::~configuration_plugin_impl() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class e2e_provider_impl :
const e2e_buffer &_buffer, instance_t _instance,
profile_interface::check_status_t &_generic_check_status) override;

void* get_plugin_impl_ptr() override;

private:
std::map<e2exf::data_identifier_t, std::shared_ptr<profile_interface::protector>> custom_protectors_;
std::map<e2exf::data_identifier_t, std::shared_ptr<profile_interface::checker>> custom_checkers_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ e2e_provider_impl::~e2e_provider_impl()
{
}

void* e2e_provider_impl::get_plugin_impl_ptr()
{
auto e2e_provider_plugin = dynamic_cast<e2e_provider *>(this);
return e2e_provider_plugin;
}

bool e2e_provider_impl::add_configuration(std::shared_ptr<cfg::e2e> config)
{
if (config->profile == "CRC8" || config->profile == "P01") {
Expand Down
21 changes: 13 additions & 8 deletions implementation/routing/src/routing_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@

namespace vsomeip_v3 {

#ifdef ANDROID
namespace sd {
runtime::~runtime() {}
}
#endif

routing_manager_impl::routing_manager_impl(routing_manager_host *_host) :
routing_manager_base(_host),
version_log_timer_(_host->get_io()),
Expand Down Expand Up @@ -170,8 +164,19 @@ void routing_manager_impl::init() {
plugin_type_e::SD_RUNTIME_PLUGIN, VSOMEIP_SD_LIBRARY);
if (its_plugin) {
VSOMEIP_INFO << "Service Discovery module loaded.";
discovery_ = std::dynamic_pointer_cast<sd::runtime>(its_plugin)->create_service_discovery(this, configuration_);
discovery_->init();
auto runtime_plugin = std::dynamic_pointer_cast<sd::runtime>(its_plugin);
if (nullptr == runtime_plugin) {
runtime_plugin = its_plugin->get_ptr<sd::runtime>();
}

if (nullptr == runtime_plugin) {
VSOMEIP_ERROR << "Invalid Service Discovery module!" << std::endl;
std::exit(EXIT_FAILURE);
} else {
discovery_ = runtime_plugin->create_service_discovery(this, configuration_);
discovery_->init();
}

} else {
VSOMEIP_ERROR << "Service Discovery module could not be loaded!";
std::exit(EXIT_FAILURE);
Expand Down
35 changes: 29 additions & 6 deletions implementation/runtime/src/application_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ bool application_impl::init() {
if (its_plugin) {
auto its_configuration_plugin
= std::dynamic_pointer_cast<configuration_plugin>(its_plugin);

if (its_configuration_plugin == nullptr) {
its_configuration_plugin = its_plugin->get_ptr<configuration_plugin>();
}

if (its_configuration_plugin) {
configuration_ = its_configuration_plugin->get_configuration(name_, path_);
VSOMEIP_INFO << "Configuration module loaded.";
Expand Down Expand Up @@ -360,8 +365,15 @@ bool application_impl::init() {
if (its_application_plugin) {
VSOMEIP_INFO << "Client 0x" << std::hex << get_client()
<< " Loading plug-in library: " << its_library << " succeeded!";
std::dynamic_pointer_cast<application_plugin>(its_application_plugin)->
on_application_state_change(name_, application_plugin_state_e::STATE_INITIALIZED);

auto application_plugin_t = std::dynamic_pointer_cast<application_plugin>(its_application_plugin);
if (nullptr == application_plugin_t) {
application_plugin_t = its_application_plugin->get_ptr<application_plugin>();
}

if (nullptr != application_plugin_t) {
application_plugin_t->on_application_state_change(name_, application_plugin_state_e::STATE_INITIALIZED);
}
}
}
}
Expand Down Expand Up @@ -480,9 +492,15 @@ void application_impl::start() {
for (const auto& its_library : its_app_plugin_info->second) {
auto its_application_plugin = plugin_manager::get()->get_plugin(
plugin_type_e::APPLICATION_PLUGIN, its_library);

if (its_application_plugin) {
std::dynamic_pointer_cast<application_plugin>(its_application_plugin)->
on_application_state_change(name_, application_plugin_state_e::STATE_STARTED);
auto application_plugin_t = std::dynamic_pointer_cast<application_plugin>(its_application_plugin);
if (nullptr == application_plugin_t) {
application_plugin_t = its_application_plugin->get_ptr<application_plugin>();
}
if (nullptr != application_plugin_t) {
application_plugin_t->on_application_state_change(name_, application_plugin_state_e::STATE_STARTED);
}
}
}

Expand Down Expand Up @@ -569,8 +587,13 @@ void application_impl::stop() {
auto its_application_plugin = plugin_manager::get()->get_plugin(
plugin_type_e::APPLICATION_PLUGIN, its_library);
if (its_application_plugin) {
std::dynamic_pointer_cast<application_plugin>(its_application_plugin)->
on_application_state_change(name_, application_plugin_state_e::STATE_STOPPED);
auto application_plugin_t = std::dynamic_pointer_cast<application_plugin>(its_application_plugin);
if (nullptr == application_plugin_t) {
application_plugin_t = its_application_plugin->get_ptr<application_plugin>();
}
if (nullptr != application_plugin_t) {
application_plugin_t->on_application_state_change(name_, application_plugin_state_e::STATE_STOPPED);
}
}
}

Expand Down
9 changes: 2 additions & 7 deletions implementation/service_discovery/include/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@ class service_discovery_host;

class runtime {
public:
virtual ~runtime()
#ifndef ANDROID
{}
#else
;
#endif

virtual ~runtime() {}

virtual std::shared_ptr<service_discovery> create_service_discovery(
service_discovery_host *_host,
std::shared_ptr<configuration> _configuration) const = 0;
Expand Down
4 changes: 2 additions & 2 deletions implementation/service_discovery/include/runtime_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class runtime_impl
public:
runtime_impl();
virtual ~runtime_impl();

void * get_plugin_impl_ptr() override;
std::shared_ptr<service_discovery> create_service_discovery(
service_discovery_host *_host,
std::shared_ptr<configuration> _configuration) const;
std::shared_ptr<configuration> _configuration) const override;
};

} // namespace sd
Expand Down
6 changes: 6 additions & 0 deletions implementation/service_discovery/src/runtime_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ runtime_impl::runtime_impl()
runtime_impl::~runtime_impl() {
}

void *runtime_impl::get_plugin_impl_ptr() {
auto plugin = dynamic_cast<runtime *>(this);
return plugin;
}


std::shared_ptr<service_discovery>
runtime_impl::create_service_discovery(service_discovery_host *_host,
std::shared_ptr<configuration> _configuration) const {
Expand Down
6 changes: 3 additions & 3 deletions interface/compat/vsomeip/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ class plugin_impl : public plugin {
type_ = _type;
}

const std::string &get_plugin_name() const {
const std::string &get_plugin_name() const override {
return name_;
}

uint32_t get_plugin_version() const {
uint32_t get_plugin_version() const override {
return version_;
}

plugin_type_e get_plugin_type() const {
plugin_type_e get_plugin_type() const override {
return type_;
}

Expand Down
18 changes: 15 additions & 3 deletions interface/vsomeip/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ class VSOMEIP_IMPORT_EXPORT_PLUGIN plugin {
virtual uint32_t get_plugin_version() const = 0;
virtual const std::string &get_plugin_name() const = 0;
virtual plugin_type_e get_plugin_type() const = 0;

virtual void *get_plugin_impl_ptr() = 0;

template <typename T>
std::shared_ptr<T> get_ptr() {
T *configuration_plugin_ptr = reinterpret_cast<T *>(get_plugin_impl_ptr());

std::shared_ptr<T> plugin_sp(configuration_plugin_ptr, [](T *) {
});

return std::dynamic_pointer_cast<T>(plugin_sp);
}
};

template<class Plugin_>
Expand All @@ -60,15 +72,15 @@ class plugin_impl : public plugin {
type_ = _type;
}

const std::string &get_plugin_name() const {
const std::string &get_plugin_name() const override {
return name_;
}

uint32_t get_plugin_version() const {
uint32_t get_plugin_version() const override {
return version_;
}

plugin_type_e get_plugin_type() const {
plugin_type_e get_plugin_type() const override {
return type_;
}

Expand Down
Loading