From 0f0e06c6b893c11631b9da7a837f30c55eaaa31f Mon Sep 17 00:00:00 2001 From: Mathis Logemann Date: Mon, 14 Feb 2022 10:14:59 +0100 Subject: [PATCH] [datasource] add plugin_registered function --- include/mapnik/datasource_cache.hpp | 5 +++-- src/datasource_cache.cpp | 26 ++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/include/mapnik/datasource_cache.hpp b/include/mapnik/datasource_cache.hpp index 8504b05c2..4e321c9ad 100644 --- a/include/mapnik/datasource_cache.hpp +++ b/include/mapnik/datasource_cache.hpp @@ -47,7 +47,8 @@ class MAPNIK_DECL datasource_cache : public singleton; public: - std::vector plugin_names(); + bool plugin_registered(const std::string& plugin_name) const; + std::vector plugin_names() const; std::string plugin_directories(); bool register_datasources(std::string const& path, bool recurse = false); bool register_datasource(std::string const& path); @@ -62,7 +63,7 @@ class MAPNIK_DECL datasource_cache : public singleton; diff --git a/src/datasource_cache.cpp b/src/datasource_cache.cpp index 28ae3a12d..bcb5d49da 100644 --- a/src/datasource_cache.cpp +++ b/src/datasource_cache.cpp @@ -113,7 +113,7 @@ datasource_ptr datasource_cache::create(parameters const& params) #ifdef __GNUC__ __extension__ #endif - datasource_plugin* create_datasource = reinterpret_cast(itr->second->get_symbol("plugin")); + datasource_plugin* create_datasource = reinterpret_cast(itr->second->get_symbol("plugin")); if (!create_datasource) { @@ -131,7 +131,29 @@ std::string datasource_cache::plugin_directories() return boost::algorithm::join(plugin_directories_, ", "); } -std::vector datasource_cache::plugin_names() +bool datasource_cache::plugin_registered(const std::string& plugin_name) const +{ +#ifdef MAPNIK_STATIC_PLUGINS + const auto static_names = get_static_datasource_names(); + const auto static_it = std::find(static_names.begin(), static_names.end(), plugin_name); + if (static_it != static_names.end()) + return true; +#endif + +#ifdef MAPNIK_THREADSAFE + std::lock_guard lock(instance_mutex_); +#endif + + std::map>::const_iterator itr; + for (itr = plugins_.begin(); itr != plugins_.end(); ++itr) + { + if (itr->second->name() == plugin_name) + return true; + } + return false; +} + +std::vector datasource_cache::plugin_names() const { std::vector names;