ContRap-Core
|
Class PluginManager implements a singleton plugin library management interface. More...
#include <pluginmanager.h>
Data Structures | |
class | CastCache |
Cache structure for static casts. More... | |
Public Member Functions | |
~PluginManager () | |
Cleans up memory. | |
void | update () |
Updates the contents of the loaded libraries. | |
void | search () |
Searches for new libraries. | |
void | clear () |
Cleans up. | |
void | clear_caches () |
Cleans up the plugin and the cast caches. | |
void | load_plugin_cache () |
Reloads the plugin cache. | |
void | save_plugin_cache () |
Saves the cache to a file. | |
XMLDataPool & | get_library_cache () |
Gets the contents of the cache file without changing the plugin manager. | |
XMLDataPool & | get_plugin_cache () |
Gets the contents of the cache file without changing the plugin manager. | |
void | update_plugin_cache () |
Updates the plugin cache. | |
void | load_library_cache () |
Reloads the library cache. | |
void | save_library_cache () |
Saves the cache to a file. | |
Library * | get_library (const std::string &library) |
Returns the library for a given library name if the library exists. | |
void | unload_library (const std::string &library) |
Unloads a library. | |
void | unload_libraries () |
Unloads all libraries. | |
std::vector< std::string > | get_libraries () |
Returns all the library names. | |
std::vector< std::string > | get_library_paths () |
Returns all the library names. | |
std::vector< std::string > | get_loaded_libraries () |
Returns all the loaded library names. | |
SPtr< AtomicFunction > | find_function (const std::string &name) |
Returns a pointer to a function from a function name. | |
ModuleInfo * | find_function_info (const std::string &name) |
Returns a pointer to a function info from a function name. | |
std::vector< ModuleInfo * > | find_function_infos (const std::string &name) |
Returns a pointer to a function info from a function name. | |
std::vector< std::string > | get_objects () |
Returns the list of paths to installed objects. | |
XMLDataPool * | find_object_info (const std::string &name) |
Returns the objects info. | |
std::string | can_cast (const std::string &source, const std::string &target) |
Returns a non empty string if the two types can be statically casted. | |
std::string | get_cast_library (const std::string &source, const std::string &target) |
Returns the library of the cast function needed to cast from source to target or an empty string if no function exists. | |
std::map< std::string, std::vector< ModuleInfo * > > | get_module_base () |
Creates a data base with associations of functions to base classes. | |
Static Public Member Functions | |
static PluginManager * | get_instance () |
Returns the instance of the plugin manager. | |
Protected Member Functions | |
void | search_path (const std::string &path) |
Searches for libraries at the given path. | |
Protected Attributes | |
std::map< std::string, Library > | libraries |
Associates library names without prefixes to libraries. | |
XMLDataPool | library_cache |
Library cache. | |
XMLDataPool | plugin_cache |
Plugin cache. | |
std::map< std::string, XMLDataPool * > | objects |
List of objects. | |
std::map< std::string, CastCache > | cast_cache |
Cast cache. | |
Options * | options |
Options instance. | |
Logger * | logger |
Logger. | |
Static Protected Attributes | |
static PluginManager * | plugin_manager |
Singleton instance. |
Class PluginManager implements a singleton plugin library management interface.
The most important goal of the PluginManager is to ensure that each plugin library is loaded at most once in the system. This implies that unloading this library causes the operating system to release its contents and the contents of other loaded libraries which do not depend on the current plugin library. This is the basis for changing the library implementation at runtime.
On Windows you will have to call to unload() to first unload all the plugin libraries from the memory. Then it is guaranteed that the file of your library is not locked for removal.
Plugin manager has two plugin caches: the library cache and the plugin cache. The library cache only contains the the library information and is small compared to the plugin cache. The plugin cache contains the full plugin information. The library cache is used on start up to load libraries efficiently. The plugin cache is not essential for the core to work. It is used by the user interfaces to support fast access to plugin information.
crp::PluginManager::~PluginManager | ( | ) |
Cleans up memory.
In particular this unloads all libraries loaded by the plugin manager instance.
std::string crp::PluginManager::can_cast | ( | const std::string & | source, |
const std::string & | target | ||
) |
Returns a non empty string if the two types can be statically casted.
If the string is not empty it contains a description of the converter function.
Notice that the set of statically convertable types is a subset of convertable types at runtime, since new converters can be added dynamically.
source | Source type |
target | Target type |
void crp::PluginManager::clear | ( | ) |
Cleans up.
This method unloads all libraries and clears the caches besides the plugin cache. Use clear_cache() to clean up the plugin cache.
void crp::PluginManager::clear_caches | ( | ) |
Cleans up the plugin and the cast caches.
Notice that this method removes all the plugin information from the system. Use it only if you are going to reload or search the cache subsequently.
This method does not clear the library cache.
SPtr<AtomicFunction> crp::PluginManager::find_function | ( | const std::string & | name | ) |
Returns a pointer to a function from a function name.
function | Name of the function |
ModuleInfo* crp::PluginManager::find_function_info | ( | const std::string & | name | ) |
Returns a pointer to a function info from a function name.
This method takes the first available function.
function | Name of the function |
std::vector<ModuleInfo*> crp::PluginManager::find_function_infos | ( | const std::string & | name | ) |
Returns a pointer to a function info from a function name.
This method returns all available functions.
function | Name of the function |
XMLDataPool* crp::PluginManager::find_object_info | ( | const std::string & | name | ) |
Returns the objects info.
The name of an object is assumed to be a unique identifier for the object.
object | Objects name |
std::string crp::PluginManager::get_cast_library | ( | const std::string & | source, |
const std::string & | target | ||
) |
Returns the library of the cast function needed to cast from source to target or an empty string if no function exists.
source | Source type |
target | Target type |
static PluginManager* crp::PluginManager::get_instance | ( | ) | [static] |
Returns the instance of the plugin manager.
std::vector<std::string> crp::PluginManager::get_libraries | ( | ) |
Returns all the library names.
Library* crp::PluginManager::get_library | ( | const std::string & | library | ) |
Returns the library for a given library name if the library exists.
This method neither updates the library nor the plugin manager. Use the PluginManager::search() method to update the library data base. Use Library::update() on the returned object to update the library contents.
library | Name of the library |
XMLDataPool& crp::PluginManager::get_library_cache | ( | ) |
Gets the contents of the cache file without changing the plugin manager.
You should not call this method unless you know what you are doing.
std::vector<std::string> crp::PluginManager::get_library_paths | ( | ) |
Returns all the library names.
std::vector<std::string> crp::PluginManager::get_loaded_libraries | ( | ) |
Returns all the loaded library names.
std::map<std::string, std::vector<ModuleInfo*> > crp::PluginManager::get_module_base | ( | ) |
Creates a data base with associations of functions to base classes.
std::vector<std::string> crp::PluginManager::get_objects | ( | ) |
Returns the list of paths to installed objects.
XMLDataPool& crp::PluginManager::get_plugin_cache | ( | ) |
Gets the contents of the cache file without changing the plugin manager.
You should not call this method unless you know what you are doing.
void crp::PluginManager::load_library_cache | ( | ) |
Reloads the library cache.
This method discards the cache and loads it again from the cache file on disk.
This method is light weighted and is called each time the plugin manager starts.
void crp::PluginManager::load_plugin_cache | ( | ) |
Reloads the plugin cache.
This method descards the plugin cache and loads it again from the cache file on disk.
This method is heavy weighted, since the complete plugin information table is loaded.
void crp::PluginManager::save_library_cache | ( | ) |
Saves the cache to a file.
The cache is saved to a cache file in your home directory.
This method is light weighted and is called each time the plugin manager searches for libraries.
void crp::PluginManager::save_plugin_cache | ( | ) |
Saves the cache to a file.
The cache is saved to a cache file in your home directory.
void crp::PluginManager::search | ( | ) |
Searches for new libraries.
This method makes a full search for ContRap libraries inside the paths marked as plugin library paths.
void crp::PluginManager::search_path | ( | const std::string & | path | ) | [protected] |
Searches for libraries at the given path.
path | Path to a directory |
void crp::PluginManager::unload_libraries | ( | ) |
Unloads all libraries.
This causes the system to reload all dependent libraries (even in global mode).
void crp::PluginManager::unload_library | ( | const std::string & | library | ) |
Unloads a library.
This is equivalent to get_library(library)->unload(), provided that the library exists.
library | Name of the library |
void crp::PluginManager::update | ( | ) |
Updates the contents of the loaded libraries.
This operation does not search for new libraries on the system. It walks through the existent libraries and calls an update to each of them.
The update is faster than search() because it touches only library paths, which are already registered in the cache.
void crp::PluginManager::update_plugin_cache | ( | ) |
Updates the plugin cache.
This method is computationally intensive, since every library has to be loaded and unloaded.
std::map<std::string, CastCache> crp::PluginManager::cast_cache [protected] |
Cast cache.
std::map<std::string, Library> crp::PluginManager::libraries [protected] |
Associates library names without prefixes to libraries.
XMLDataPool crp::PluginManager::library_cache [protected] |
Library cache.
The library cache is a small cache only containing the library names paths and the function paths. This cache is used inside the command line interpreter.
Logger* crp::PluginManager::logger [protected] |
std::map<std::string, XMLDataPool*> crp::PluginManager::objects [protected] |
List of objects.
Options* crp::PluginManager::options [protected] |
Options instance.
XMLDataPool crp::PluginManager::plugin_cache [protected] |
Plugin cache.
PluginManager* crp::PluginManager::plugin_manager [static, protected] |
Singleton instance.