Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Public Member Functions | Private Member Functions | Private Attributes | List of all members
DobbyRdkPluginManager Class Reference

Class that manages all the RDK plugin hook libraries. More...

#include <DobbyRdkPluginManager.h>

Public Member Functions

 DobbyRdkPluginManager (std::shared_ptr< rt_dobby_schema > containerConfig, const std::string &rootfsPath, const std::string &pluginPath, const std::shared_ptr< DobbyRdkPluginUtils > &utils)
 Create instance of DobbyRdkPlugin Manager and load all plugins that can be found in pluginPath. More...
 
 ~DobbyRdkPluginManager ()
 
const std::vector< std::string > listLoadedPlugins () const
 Just return a list of all loaded plugin names.
 
const std::vector< std::string > listLoadedLoggers () const
 Just return a list of all loaded logging plugin names.
 
bool runPlugins (const IDobbyRdkPlugin::HintFlags &hookPoint, const uint timeoutMs=0) const
 Run the plugins specified in the container config at the given hook point. Returns true if all required plugins execute successfully. If non-required plugins fail or are not loaded, then it logs an error but continues running other plugins. More...
 
std::shared_ptr< IDobbyRdkLoggingPlugingetContainerLogger () const
 Get the logging plugin specified in the container config. Each container can only have a single plugin for logging, otherwise there is a chance of conflicts whilst reading the container stdout/err. More...
 
void setExitStatus (int status) const
 Set the exit status of the container. More...
 

Private Member Functions

bool loadPlugins ()
 Scans the given path for any shared objects that implement the plugin entry points. More...
 
bool preprocessPlugins ()
 Prepares the dependency solver and required plugins data structures. More...
 
bool executeHook (const std::string &pluginName, const IDobbyRdkPlugin::HintFlags hook) const
 
bool executeHookTimeout (const std::string &pluginName, const IDobbyRdkPlugin::HintFlags hook, const uint timeoutMs) const
 
std::string HookPointToString (const IDobbyRdkPlugin::HintFlags &hookPoint) const
 
bool implementsHook (const std::string &pluginName, const IDobbyRdkPlugin::HintFlags hook) const
 Check if a plugin implements the specified hook. More...
 
bool isLoaded (const std::string &pluginName) const
 Check if a plugin is loaded. More...
 
bool isRequired (const std::string &pluginName) const
 Check if a plugin is required. More...
 
std::shared_ptr< IDobbyRdkPlugingetPlugin (const std::string &name) const
 Get the plugin with the name, or nullptr if no plugin. More...
 
std::shared_ptr< IDobbyRdkLoggingPlugingetLogger (const std::string &name) const
 Get the logger with the name, or nullptr if no plugin. More...
 

Private Attributes

bool mValid
 
std::map< std::string, std::pair< void *, std::shared_ptr< IDobbyRdkLoggingPlugin > > > mLoggers
 
std::map< std::string, std::pair< void *, std::shared_ptr< IDobbyRdkPlugin > > > mPlugins
 
std::set< std::string > mRequiredPlugins
 
std::shared_ptr< rt_dobby_schema > mContainerConfig
 
const std::string mRootfsPath
 
const std::string mPluginPath
 
const std::shared_ptr< DobbyRdkPluginUtilsmUtils
 
std::unique_ptr< DobbyRdkPluginDependencySolvermDependencySolver
 

Detailed Description

Class that manages all the RDK plugin hook libraries.

At creation time it loads all the plugin libraries.

Constructor & Destructor Documentation

◆ DobbyRdkPluginManager()

DobbyRdkPluginManager::DobbyRdkPluginManager ( std::shared_ptr< rt_dobby_schema >  containerConfig,
const std::string &  rootfsPath,
const std::string &  pluginPath,
const std::shared_ptr< DobbyRdkPluginUtils > &  utils 
)

Create instance of DobbyRdkPlugin Manager and load all plugins that can be found in pluginPath.

Parameters
[in]containerConfigPointer to the libocispec struct for the container config
[in]pluginPathWhere to search for plugins

◆ ~DobbyRdkPluginManager()

DobbyRdkPluginManager::~DobbyRdkPluginManager ( )

Unload all plugins on destruction

Member Function Documentation

◆ executeHook()

bool DobbyRdkPluginManager::executeHook ( const std::string &  pluginName,
const IDobbyRdkPlugin::HintFlags  hook 
) const
private

Runs the specified hook for a given plugin

Parameters
[in]pluginNameName of the plugin to run
[in]hookWhich hook to execute
Returns
True if the hook executed successfully

◆ executeHookTimeout()

bool DobbyRdkPluginManager::executeHookTimeout ( const std::string &  pluginName,
const IDobbyRdkPlugin::HintFlags  hook,
const uint  timeoutMs 
) const
private

Runs the specified hook for a given plugin, checks if execution takes less than timeoutMs value, and if so kills the process.

Parameters
[in]pluginNameName of the plugin to run
[in]hookWhich hook to execute
[in]timeoutMsTimeout value in miliseconds
Returns
True if the hook executed successfully

◆ getContainerLogger()

std::shared_ptr< IDobbyRdkLoggingPlugin > DobbyRdkPluginManager::getContainerLogger ( ) const

Get the logging plugin specified in the container config. Each container can only have a single plugin for logging, otherwise there is a chance of conflicts whilst reading the container stdout/err.

Parameters
[in]nameThe name of the plugin.
Returns
The logging plugin

◆ getLogger()

std::shared_ptr< IDobbyRdkLoggingPlugin > DobbyRdkPluginManager::getLogger ( const std::string &  name) const
inlineprivate

Get the logger with the name, or nullptr if no plugin.

Parameters
[in]nameThe name of the plugin.
Returns
The plugin interface shared pointer.

◆ getPlugin()

std::shared_ptr< IDobbyRdkPlugin > DobbyRdkPluginManager::getPlugin ( const std::string &  name) const
inlineprivate

Get the plugin with the name, or nullptr if no plugin.

Parameters
[in]nameThe name of the plugin.
Returns
The plugin interface shared pointer.

◆ HookPointToString()

std::string DobbyRdkPluginManager::HookPointToString ( const IDobbyRdkPlugin::HintFlags hookPoint) const
private

Converts hook point into human readable string

Parameters
[in]hookWhich hook to translate
Returns
std::string with representation, empty if not found.

◆ implementsHook()

bool DobbyRdkPluginManager::implementsHook ( const std::string &  pluginName,
const IDobbyRdkPlugin::HintFlags  hook 
) const
private

Check if a plugin implements the specified hook.

Parameters
[in]pluginNameThe name of the plugin to check
[in]hookThe hook to check if the plugin implements
Returns
True if plugin implements specified hook

◆ isLoaded()

bool DobbyRdkPluginManager::isLoaded ( const std::string &  pluginName) const
private

Check if a plugin is loaded.

Parameters
[in]pluginNameThe name of the plugin to check.
Returns
True if a plugin is loaded, false if not.

◆ isRequired()

bool DobbyRdkPluginManager::isRequired ( const std::string &  pluginName) const
private

Check if a plugin is required.

Parameters
[in]pluginNameThe name of the plugin to check.
Returns
True if a plugin is required, false if not.

◆ loadPlugins()

bool DobbyRdkPluginManager::loadPlugins ( )
private

Scans the given path for any shared objects that implement the plugin entry points.

This calls dlopen() on all the executable files in the given path (although it doesn't recurse into subdirs), if the file has symbols createIDobbyRdkPlugin and destroyIDobbyRdkPlugin then it's deemed to be a 'rdk' plugin.

If loaded successfully the plugins are stored in an internal map, keyed off the plugin name.

Returns
False if unable to open the given directory, true otherwise.

◆ preprocessPlugins()

bool DobbyRdkPluginManager::preprocessPlugins ( )
private

Prepares the dependency solver and required plugins data structures.

This method scans the container config and based on its contents:

  1. Adds all the plugins, along with their dependencies, to the plugin dependency solver,
  2. Creates a list of the required plugins,
  3. Checks if the required plugins are loaded.
Returns
False if a required plugin is not loaded or if one of the dependencies is not a known plugin. True otherwise.

◆ runPlugins()

bool DobbyRdkPluginManager::runPlugins ( const IDobbyRdkPlugin::HintFlags hookPoint,
const uint  timeoutMs = 0 
) const

Run the plugins specified in the container config at the given hook point. Returns true if all required plugins execute successfully. If non-required plugins fail or are not loaded, then it logs an error but continues running other plugins.

Parameters
[in]hookPointWhich hook point to execute
[in]timeoutMsTimeout in miliseconds, if 0 (default value) then there will be no timeout.
Returns
True if all required plugins ran successfully

◆ setExitStatus()

void DobbyRdkPluginManager::setExitStatus ( int  status) const

Set the exit status of the container.

Parameters
[in]statusThe exit status of the container.
Returns
void

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