6 #ifndef KNOWROB_PLUGIN_MANAGER_H_ 
    7 #define KNOWROB_PLUGIN_MANAGER_H_ 
   13 #include <boost/property_tree/ptree.hpp> 
   14 #include "knowrob/plugins/TypedPluginFactory.h" 
   15 #include "knowrob/plugins/PluginLibrary.h" 
   16 #include "knowrob/plugins/PluginModule.h" 
   17 #include "knowrob/Logger.h" 
   18 #include "knowrob/URI.h" 
   42                 entry.second->unloadModule();
 
   94             if (factories.find(typeName) != factories.end()) {
 
   95                 KB_WARN(
"overwriting factory for plugin type '{}'", typeName);
 
   97             factories.emplace(typeName, factory);
 
  119         virtual std::shared_ptr<NamedPlugin<T>> 
loadPlugin(
const boost::property_tree::ptree &config) = 0;
 
  127         virtual std::shared_ptr<NamedPlugin<T>>
 
  153         std::map<std::string_view, std::shared_ptr<NamedPlugin<T>>, std::less<>> 
pluginPool_;
 
  155         std::map<std::string, std::shared_ptr<PluginLibrary<T>>, std::less<>> 
loadedPlugins_;
 
  156         std::map<std::string, std::shared_ptr<PluginModule<T>>, std::less<>> 
loadedModules_;
 
  160             static uint32_t val = 0;
 
  166             static std::map<std::string, std::shared_ptr<PluginFactory<T>>, std::less<>> factories;
 
  172             static auto val = std::make_shared<std::map<uint32_t, PluginManager *>>();
 
  177             auto absPath = std::filesystem::absolute(path);
 
  180                 auto p = std::make_shared<PluginLibrary<T>>(absPath.c_str());
 
  183                 if (jt.first->second->loadDLL()) {
 
  184                     return jt.first->second;
 
  186             } 
else if (it->second->isLoaded()) {
 
  189             KB_WARN(
"Failed to open plugin library at path '{}'.", path);
 
  196                 auto p = std::make_shared<PluginModule<T>>(path, 
type);
 
  199                 if (jt.first->second->loadModule()) {
 
  200                     return jt.first->second;
 
  202             } 
else if (it->second->isLoaded()) {
 
  205             KB_WARN(
"Failed to open plugin module at path '{}'.", path);
 
  209         std::shared_ptr<PluginFactory<T>> 
findFactory(
const boost::property_tree::ptree &config) {
 
  210             auto lib = config.get_optional<
std::string>(
"lib");
 
  211             auto module = config.get_optional<
std::string>(
"module");
 
  214             if (lib.has_value()) {
 
  216             } 
else if (module.has_value()) {
 
  217                 if (
type.has_value()) {
 
  220                     KB_WARN(
"modules require type key in settings, but it's missing for module '{}'.", module.value());
 
  222             } 
else if (
type.has_value()) {
 
  226                     KB_WARN(
"no factory registered for plugin type '{}'.", 
type.value());
 
  231                 KB_WARN(
"missing 'type', 'lib' and 'module' key in plugin config.");
 
  238             auto name = config.get_optional<
std::string>(
"name");
 
  239             if (name.has_value()) {
 
std::shared_ptr< PluginFactory< T > > findFactory(const boost::property_tree::ptree &config)
static bool addFactory(std::string_view typeName, const std::shared_ptr< PluginFactory< T >> &factory)
std::shared_ptr< std::map< uint32_t, PluginManager * > > pluginManagers_
std::shared_ptr< PluginModule< T > > loadPythonModule(std::string_view path, std::string_view type)
virtual std::shared_ptr< NamedPlugin< T > > loadPlugin(const boost::property_tree::ptree &config)=0
static PluginManager< T > * getManager(uint32_t managerID)
static uint32_t & managerIDCounter()
static bool addFactory(std::string_view typeName)
std::map< std::string, std::shared_ptr< PluginLibrary< T > >, std::less<> > loadedPlugins_
std::shared_ptr< PluginLibrary< T > > loadSharedLibrary(std::string_view path)
static auto & pluginManagers()
std::string getPluginID(const std::shared_ptr< PluginFactory< T >> &factory, const boost::property_tree::ptree &config)
std::shared_ptr< NamedPlugin< T > > getPluginWithID(std::string_view pluginID)
std::map< std::string, std::shared_ptr< PluginModule< T > >, std::less<> > loadedModules_
void removePlugin(const std::shared_ptr< NamedPlugin< T >> &namedPlugin)
std::map< std::string_view, std::shared_ptr< NamedPlugin< T > >, std::less<> > pluginPool_
static auto & pluginFactories()
virtual std::shared_ptr< NamedPlugin< T > > addPlugin(std::string_view reasonerID, PluginLanguage language, const std::shared_ptr< T > &reasoner)=0
void removePlugin(std::string_view pluginID)
const auto & plugins() const
static std::string resolve(const std::string_view &uriString)