shiva::dll
This class allows you to store plugin creation symbols through its template CreatorSignature parameter.
Through this class you are able to retrieve the number of plugins, apply a functor on each of the symbols (as creates the plugin for example).

Class Signature
Constructor
Functions
template <typename CreatorSignature>
class plugins_registry;
explicit plugins_registry(shiva::fs::path &&plugins_directory, const std::string library_pattern_matching) noexcept;
plugins_registry
Parameters
- plugins_directory represents the path to the directory containing the plugins
- library_pattern_matching represents a basic pattern to respect for libraries to load
For example if the pattern is [shiva-system] then only libraries that have [shiva-system] in their names will be loaded. [libshiva-system-plugin.so] will be loaded [libother-things.so] will not be loaded.
Functions Name | Description |
load all symbols for plugins creation from the plugins_directory | |
return the number of plugins | |
apply a functor on each symbols |
bool load_all_symbols() noexcept;
Return value
Possible name | Description |
success | boolean
|
Example
bool success = plugins_registry.load_all_symbols();
if (!success) {
/* The loading of symbols failed */
}
Notes
This function allows you to load symbols from the template to create the object.
The symbols are loaded recursively from the folder you specified in the object's constructor.
If one of the symbols could not be correctly loaded the function does not stop and proceeds to load the next plugin.
If when browsing folders a corrupted file is spotted the function switch to loading the next plugin.
size_t nb_plugins() const noexcept;
Return value
Possible name | Description |
nb_plugins | size_t
|
Example
size_t nb_plugins = plugins_registry.nb_plugins();
if (nb_plugins < 4) {
//! Oh no, i was exepcting at least 4 plugins
}
template <typename TFunctor>
void apply_on_each_symbols(TFunctor &&functor);
Template parameters
Name | Description |
functor | TFunctor
|
Example
auto functor = [this](auto &&symbol) {
auto res = symbol(/* parmeters for the creation of the object */);
// res -> object created by the symbol creator
// manipulate res or put it in a container for example.
this->container_object.push_back(std::move(res));
};
plugins_registry_.apply_on_each_symbols(functor);
Notes
- This function applies the functor as a parameter to each of the symbols that were previously loaded by the load_all_symbols function.
Functions Name | Description |
check if a specific path is a shared library |
static inline bool is_shared_library(const fs::path &path) noexcept;
Name | Description |
path | fs::path
|
Possible name | Description |
result | boolean
|
Example
// result is true
bool result = shiva::helpers::is_shared_library(shiva::fs::path("path/libfoo.so"));
// result is false
result = shiva::helpers::is_shared_library(shiva::fs::path("path/libbar"));
if (!result) {
/* The path given as parameter doesn't seem's to be a shared_library */
}
- check if the path passed in parameter is a shared library
Last modified 5yr ago