knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::StorageManager Class Reference

#include <StorageManager.h>

Inheritance diagram for knowrob::StorageManager:
Collaboration diagram for knowrob::StorageManager:

Public Member Functions

 StorageManager (const std::shared_ptr< Vocabulary > &vocabulary)
 
 ~StorageManager () override=default
 
auto & vocabulary () const
 
const auto & persistent () const
 
const auto & queryable () const
 
void addPlugin (const std::shared_ptr< NamedBackend > &backend)
 
std::shared_ptr< NamedBackendloadPlugin (const boost::property_tree::ptree &config) override
 
std::shared_ptr< NamedBackendaddPlugin (std::string_view reasonerID, PluginLanguage language, const StoragePtr &backend) override
 
 StorageManager (const std::shared_ptr< Vocabulary > &vocabulary)
 
 ~StorageManager () override=default
 
auto & vocabulary () const
 
const auto & persistent () const
 
const auto & queryable () const
 
void addPlugin (const std::shared_ptr< NamedBackend > &backend)
 
std::shared_ptr< NamedBackendloadPlugin (const boost::property_tree::ptree &config) override
 
std::shared_ptr< NamedBackendaddPlugin (std::string_view reasonerID, PluginLanguage language, const StoragePtr &backend) override
 
- Public Member Functions inherited from knowrob::PluginManager< Storage >
 PluginManager ()
 
 PluginManager ()
 
virtual ~PluginManager ()
 
virtual ~PluginManager ()
 
auto managerID () const
 
auto managerID () const
 
const auto & plugins () const
 
const auto & plugins () const
 
std::shared_ptr< NamedPlugin< Storage > > getPluginWithID (std::string_view pluginID)
 
std::shared_ptr< NamedPlugin< Storage > > getPluginWithID (std::string_view pluginID)
 
virtual std::shared_ptr< NamedPlugin< Storage > > addPlugin (std::string_view reasonerID, PluginLanguage language, const std::shared_ptr< Storage > &reasoner)=0
 
virtual std::shared_ptr< NamedPlugin< Storage > > addPlugin (std::string_view reasonerID, PluginLanguage language, const std::shared_ptr< Storage > &reasoner)=0
 
void removePlugin (const std::shared_ptr< NamedPlugin< Storage >> &namedPlugin)
 
void removePlugin (std::string_view pluginID)
 
void removePlugin (const std::shared_ptr< NamedPlugin< Storage >> &namedPlugin)
 
void removePlugin (std::string_view pluginID)
 

Additional Inherited Members

- Static Public Member Functions inherited from knowrob::PluginManager< Storage >
static PluginManager< Storage > * getManager (uint32_t managerID)
 
static PluginManager< Storage > * getManager (uint32_t managerID)
 
static bool addFactory (std::string_view typeName, const std::shared_ptr< PluginFactory< Storage >> &factory)
 
static bool addFactory (std::string_view typeName)
 
static bool addFactory (std::string_view typeName, const std::shared_ptr< PluginFactory< Storage >> &factory)
 
static bool addFactory (std::string_view typeName)
 
- Protected Member Functions inherited from knowrob::PluginManager< Storage >
std::shared_ptr< PluginLibrary< Storage > > loadSharedLibrary (std::string_view path)
 
std::shared_ptr< PluginLibrary< Storage > > loadSharedLibrary (std::string_view path)
 
std::shared_ptr< PluginModule< Storage > > loadPythonModule (std::string_view path, std::string_view type)
 
std::shared_ptr< PluginModule< Storage > > loadPythonModule (std::string_view path, std::string_view type)
 
std::shared_ptr< PluginFactory< Storage > > findFactory (const boost::property_tree::ptree &config)
 
std::shared_ptr< PluginFactory< Storage > > findFactory (const boost::property_tree::ptree &config)
 
std::string getPluginID (const std::shared_ptr< PluginFactory< Storage >> &factory, const boost::property_tree::ptree &config)
 
std::string getPluginID (const std::shared_ptr< PluginFactory< Storage >> &factory, const boost::property_tree::ptree &config)
 
- Static Protected Member Functions inherited from knowrob::PluginManager< Storage >
static uint32_t & managerIDCounter ()
 
static uint32_t & managerIDCounter ()
 
static auto & pluginFactories ()
 
static auto & pluginFactories ()
 
static auto & pluginManagers ()
 
static auto & pluginManagers ()
 
- Protected Attributes inherited from knowrob::PluginManager< Storage >
std::shared_ptr< std::map< uint32_t, PluginManager * > > pluginManagers_
 
std::mutex staticMutex_
 
uint32_t managerID_
 
uint32_t pluginIndex_
 
std::map< std::string_view, std::shared_ptr< NamedPlugin< Storage > >, std::less<> > pluginPool_
 
std::map< std::string, std::shared_ptr< PluginLibrary< Storage > >, std::less<> > loadedPlugins_
 
std::map< std::string, std::shared_ptr< PluginModule< Storage > >, std::less<> > loadedModules_
 

Detailed Description

Manages a set of available storage subsystems.

Definition at line 18 of file StorageManager.h.

Constructor & Destructor Documentation

◆ StorageManager() [1/2]

StorageManager::StorageManager ( const std::shared_ptr< Vocabulary > &  vocabulary)
explicit
Parameters
vocabularythe vocabulary associated with this manager.

Definition at line 15 of file StorageManager.cpp.

16  : PluginManager(),
17  vocabulary_(vocabulary) {
18 }
auto & vocabulary() const

◆ ~StorageManager() [1/2]

knowrob::StorageManager::~StorageManager ( )
overridedefault

◆ StorageManager() [2/2]

knowrob::StorageManager::StorageManager ( const std::shared_ptr< Vocabulary > &  vocabulary)
explicit
Parameters
vocabularythe vocabulary associated with this manager.

◆ ~StorageManager() [2/2]

knowrob::StorageManager::~StorageManager ( )
overridedefault

Member Function Documentation

◆ addPlugin() [1/4]

void StorageManager::addPlugin ( const std::shared_ptr< NamedBackend > &  backend)

Add a backend to this manager.

Parameters
backenda defined backend.

Definition at line 62 of file StorageManager.cpp.

62  {
63  if (pluginPool_.find(definedKG->name()) != pluginPool_.end()) {
64  KB_WARN("Overwriting backend with name '{}'", definedKG->name());
65  }
66  pluginPool_[definedKG->name()] = definedKG;
67  initBackend(definedKG);
68 }
#define KB_WARN
Definition: Logger.h:27
std::map< std::string_view, std::shared_ptr< NamedPlugin< Storage > >, std::less<> > pluginPool_

◆ addPlugin() [2/4]

void knowrob::StorageManager::addPlugin ( const std::shared_ptr< NamedBackend > &  backend)

Add a backend to this manager.

Parameters
backenda defined backend.

◆ addPlugin() [3/4]

std::shared_ptr< NamedBackend > StorageManager::addPlugin ( std::string_view  reasonerID,
PluginLanguage  language,
const StoragePtr backend 
)
override

Definition at line 52 of file StorageManager.cpp.

52  {
53  if (pluginPool_.find(backendID) != pluginPool_.end()) {
54  KB_WARN("Overwriting backend with name '{}'", backendID);
55  }
56  auto managedBackend = std::make_shared<NamedBackend>(backendID, language, backend);
57  pluginPool_.emplace(managedBackend->name(), managedBackend);
58  initBackend(managedBackend);
59  return managedBackend;
60 }

◆ addPlugin() [4/4]

std::shared_ptr<NamedBackend> knowrob::StorageManager::addPlugin ( std::string_view  reasonerID,
PluginLanguage  language,
const StoragePtr backend 
)
override

◆ loadPlugin() [1/2]

std::shared_ptr< NamedBackend > StorageManager::loadPlugin ( const boost::property_tree::ptree &  config)
overridevirtual

Load a new plugin instance into the plugin manager. The type of the plugin is determined based on either the value of "type", "lib" or "module" in the property tree root. The tree is further used to generate a plugin configuration. Plugin factories for libraries are created on the fly, the ones for built-in plugin types need to be added to the plugin manager before.

Parameters
configa property tree holding a plugin configuration

Implements knowrob::PluginManager< Storage >.

Definition at line 20 of file StorageManager.cpp.

20  {
21  // get a backend factory
22  std::shared_ptr<BackendFactory> factory = findFactory(config);
23  // make sure factory was found above
24  if (!factory) throw StorageError("failed to load a backend.");
25  // create a reasoner id, or use name property
26  std::string backendID = getPluginID(factory, config);
27  KB_INFO("Using backend `{}` with type `{}`.", backendID, factory->name());
28 
29  // create a new DataBackend instance
30  auto definedBackend = factory->create(backendID);
31  definedBackend->value()->setVocabulary(vocabulary());
32 
33  PropertyTree pluginConfig(std::make_shared<boost::property_tree::ptree>(config));
34  bool success;
35  {
36  if (definedBackend->language() == PluginLanguage::PYTHON) {
37  py::gil_lock lock;
38  success = definedBackend->value()->initializeBackend(pluginConfig);
39  } else {
40  success = definedBackend->value()->initializeBackend(pluginConfig);
41  }
42  }
43  if (!success) {
44  KB_WARN("Backend `{}` failed to loadConfig.", backendID);
45  } else {
46  addPlugin(definedBackend);
47  }
48 
49  return definedBackend;
50 }
#define KB_INFO
Definition: Logger.h:26
std::shared_ptr< PluginFactory< Storage > > findFactory(const boost::property_tree::ptree &config)
std::string getPluginID(const std::shared_ptr< PluginFactory< Storage >> &factory, const boost::property_tree::ptree &config)
void addPlugin(const std::shared_ptr< NamedBackend > &backend)
TermRule & string()
Definition: terms.cpp:63

◆ loadPlugin() [2/2]

std::shared_ptr<NamedBackend> knowrob::StorageManager::loadPlugin ( const boost::property_tree::ptree &  config)
overridevirtual

Load a new plugin instance into the plugin manager. The type of the plugin is determined based on either the value of "type", "lib" or "module" in the property tree root. The tree is further used to generate a plugin configuration. Plugin factories for libraries are created on the fly, the ones for built-in plugin types need to be added to the plugin manager before.

Parameters
configa property tree holding a plugin configuration

Implements knowrob::PluginManager< Storage >.

◆ persistent() [1/2]

const auto& knowrob::StorageManager::persistent ( ) const
inline
Returns
map of all persistent storages defined by this manager.

Definition at line 35 of file StorageManager.h.

35 { return persistent_; }

◆ persistent() [2/2]

const auto& knowrob::StorageManager::persistent ( ) const
inline
Returns
map of all persistent storages defined by this manager.

Definition at line 35 of file StorageManager.h.

35 { return persistent_; }

◆ queryable() [1/2]

const auto& knowrob::StorageManager::queryable ( ) const
inline
Returns
map of all queryable storages defined by this manager.

Definition at line 40 of file StorageManager.h.

40 { return queryable_; }

◆ queryable() [2/2]

const auto& knowrob::StorageManager::queryable ( ) const
inline
Returns
map of all queryable storages defined by this manager.

Definition at line 40 of file StorageManager.h.

40 { return queryable_; }

◆ vocabulary() [1/2]

auto& knowrob::StorageManager::vocabulary ( ) const
inline
Returns
the vocabulary associated with this manager.

Definition at line 30 of file StorageManager.h.

30 { return vocabulary_; }

◆ vocabulary() [2/2]

auto& knowrob::StorageManager::vocabulary ( ) const
inline
Returns
the vocabulary associated with this manager.

Definition at line 30 of file StorageManager.h.

30 { return vocabulary_; }

The documentation for this class was generated from the following files: