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

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

#include <DobbyLegacyPluginManager.h>

Public Member Functions

 DobbyLegacyPluginManager (const std::shared_ptr< IDobbyEnv > &env, const std::shared_ptr< IDobbyUtils > &utils, const std::string &path=std::string(DEFAULT_PLUGIN_PATH))
 
void refreshPlugins (const std::string &path=std::string(DEFAULT_PLUGIN_PATH))
 (re)loads all the plugin libraries found at the given path More...
 
bool executePostConstructionHooks (const std::map< std::string, Json::Value > &plugins, const ContainerId &id, const std::shared_ptr< IDobbyStartState > &startupState, const std::string &rootfsPath) const
 Calls the postConstruction method for the given plugins. More...
 
bool executePreStartHooks (const std::map< std::string, Json::Value > &plugins, const ContainerId &id, pid_t pid, const std::string &rootfsPath) const
 Calls the preStart method for the given plugins. More...
 
bool executePostStartHooks (const std::map< std::string, Json::Value > &plugins, const ContainerId &id, pid_t pid, const std::string &rootfsPath) const
 Calls the postStart method for the given plugins. More...
 
bool executePostStopHooks (const std::map< std::string, Json::Value > &plugins, const ContainerId &id, const std::string &rootfsPath) const
 Calls the postStop method for the given plugins. More...
 
bool executePreDestructionHooks (const std::map< std::string, Json::Value > &plugins, const ContainerId &id, const std::string &rootfsPath) const
 Calls the preDestruction method for the given plugins. More...
 

Private Types

typedef std::function< bool(IDobbyPlugin *, const Json::Value &)> HookFn
 

Private Member Functions

bool executeHooks (const std::map< std::string, Json::Value > &plugins, const HookFn &hookFn, unsigned asyncFlag, unsigned syncFlag) const
 Calls the supplied hook function for the plugins in the list. More...
 
std::shared_ptr< IDobbyPlugingetPlugin (const std::string &name) const
 Get the plugin with the name, or nullptr if no plugin. More...
 
void loadPlugins (const std::string &path)
 Scans the given path for any shared objects that implement the plugin entry points. More...
 

Private Attributes

pthread_rwlock_t mRwLock
 
const std::shared_ptr< IDobbyEnvmEnvironment
 
const std::shared_ptr< IDobbyUtilsmUtilities
 
std::map< std::string, std::pair< void *, std::shared_ptr< IDobbyPlugin > > > mPlugins
 

Detailed Description

Class that manages all the plugin hook libraries.

This class doesn't manage the system hooks, they are setup in the DobbyManager class (we should probably change this ... TBD)

At creation time it loads all the plugin libraries from /opt/libexec.

Member Function Documentation

◆ executeHooks()

bool DobbyLegacyPluginManager::executeHooks ( const std::map< std::string, Json::Value > &  plugins,
const HookFn &  hookFn,
unsigned  asyncFlag,
unsigned  syncFlag 
) const
private

Calls the supplied hook function for the plugins in the list.

Because the process of executing plugin hooks is the same for all hooks, we use this function to do the work, supplying it with (effectively) a function pointer of the hook we want to execute.

This function will iterate over the plugins and call the function pointer on each plugin object.

The plugins themselves provide a bit-field indicating which hooks need to be executed, and if they should be executed whether they run in a separate thread or in the calling thread. These hints are queried before executing the supplied hook function.

Parameters
[in]pluginsA map of plugin names and their data to execute
[in]hookFnThe hook method to call on the plugin
[in]asyncFlagThe bit flag that if the plugin has set indicates the hook method should be called asynchronously
[in]syncFlagThe bit flag that if the plugin has set indicates the hook method should be called synchronously
Returns
true if all plugins executed the hook method without failure, otherwise false.

◆ executePostConstructionHooks()

bool DobbyLegacyPluginManager::executePostConstructionHooks ( const std::map< std::string, Json::Value > &  plugins,
const ContainerId id,
const std::shared_ptr< IDobbyStartState > &  startupState,
const std::string &  rootfsPath 
) const

Calls the postConstruction method for the given plugins.

The function iterates over the list of plugins and their data and calls the plugin's postConstruction method. Each plugin provides hints as to whether the hook method should be executed at all or synchronously or asynchronously.

Parameters
[in]pluginsA map of plugin names and their data to execute.
[in]idThe id of the container.
[in]startupStateThe start-up state of the container.
[in]rootfsPathThe path of the rootfs of the container.
Returns
true if all plugins executed the hook method without failure, otherwise false.

◆ executePostStartHooks()

bool DobbyLegacyPluginManager::executePostStartHooks ( const std::map< std::string, Json::Value > &  plugins,
const ContainerId id,
pid_t  pid,
const std::string &  rootfsPath 
) const

Calls the postStart method for the given plugins.

The function iterates over the list of plugins and their data and calls the plugin's postStart method. Each plugin provides hints as to whether the hook method should be executed; at all or synchronously or asynchronously.

Parameters
[in]pluginsA map of plugin names and their data to execute.
[in]idThe id of the container.
[in]pidThe pid of the init process inside the container.
[in]rootfsPathThe path of the rootfs of the container.
Returns
true if all plugins executed the hook method without failure, otherwise false.

◆ executePostStopHooks()

bool DobbyLegacyPluginManager::executePostStopHooks ( const std::map< std::string, Json::Value > &  plugins,
const ContainerId id,
const std::string &  rootfsPath 
) const

Calls the postStop method for the given plugins.

The function iterates over the list of plugins and their data and calls the plugin's postStop method. Each plugin provides hints as to whether the hook method should be executed; at all or synchronously or asynchronously.

Parameters
[in]pluginsA map of plugin names and their data to execute.
[in]idThe id of the container.
[in]rootfsPathThe path of the rootfs of the container.
Returns
true if all plugins executed the hook method without failure, otherwise false.

◆ executePreDestructionHooks()

bool DobbyLegacyPluginManager::executePreDestructionHooks ( const std::map< std::string, Json::Value > &  plugins,
const ContainerId id,
const std::string &  rootfsPath 
) const

Calls the preDestruction method for the given plugins.

The function iterates over the list of plugins and their data and calls the plugin's preDestruction method. Each plugin provides hints as to whether the hook method should be executed; at all or synchronously or asynchronously.

Parameters
[in]pluginsA map of plugin names and their data to execute.
[in]idThe id of the container.
[in]rootfsPathThe path of the rootfs of the container.
Returns
true if all plugins executed the hook method without failure, otherwise false.

◆ executePreStartHooks()

bool DobbyLegacyPluginManager::executePreStartHooks ( const std::map< std::string, Json::Value > &  plugins,
const ContainerId id,
pid_t  pid,
const std::string &  rootfsPath 
) const

Calls the preStart method for the given plugins.

The function iterates over the list of plugins and their data and calls the plugin's preStart method. Each plugin provides hints as to whether the hook method should be executed; at all or synchronously or asynchronously.

Parameters
[in]pluginsA map of plugin names and their data to execute.
[in]idThe id of the container.
[in]pidThe pid of the init process inside the container.
[in]rootfsPathThe path of the rootfs of the container.
Returns
true if all plugins executed the hook method without failure, otherwise false.

◆ getPlugin()

std::shared_ptr< IDobbyPlugin > DobbyLegacyPluginManager::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.

◆ loadPlugins()

void DobbyLegacyPluginManager::loadPlugins ( const std::string &  path)
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 createIDobbyPlugin and destroyIDobbyPlugin then it's deemed to be a 'dobby' plugin.

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

Parameters
[in]pathThe path to scan for hook libraries.

◆ refreshPlugins()

void DobbyLegacyPluginManager::refreshPlugins ( const std::string &  path = std::string(DEFAULT_PLUGIN_PATH))

(re)loads all the plugin libraries found at the given path

Intended for debugging / developing plugins as it allows for reloading libraries.

Parameters
[in]pathThe path to scan for plugins libraries.

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