Kanzi 4.1.0
kanzi::LoadedPlugin Class Reference

RAII handle owning a dynamically loaded plugin shared library and the Module instance the library produced via its createModule() entry point. More...

#include <kanzi/core/module/plugin_metadata_extractor.hpp>

Public Member Functions

ModulegetModule () const noexcept
 Returns the loaded Module, or null if the handle is empty or moved-from.
 
 LoadedPlugin () noexcept=default
 Constructs an empty handle that owns nothing.
 
 LoadedPlugin (const LoadedPlugin &)=delete
 
 LoadedPlugin (LoadedPlugin &&other) noexcept
 Move-constructs from other, transferring ownership.
 
 operator bool () const noexcept
 Returns whether the handle owns a loaded plugin.
 
LoadedPluginoperator= (const LoadedPlugin &)=delete
 
LoadedPluginoperator= (LoadedPlugin &&other) noexcept
 Move-assigns from other, destroying any previously owned module and library handle before taking ownership of other's resources.
 
 ~LoadedPlugin ()
 Destroys the owned Module (if any) and then closes the owned library handle (if any).
 

Friends

LoadedPlugin loadPluginForMetadata (string_view)
 Opens a plugin shared library, invokes its createModule() entry point, and returns a handle owning the resulting Module together with the library handle.
 

Detailed Description

RAII handle owning a dynamically loaded plugin shared library and the Module instance the library produced via its createModule() entry point.

On destruction the Module is destroyed first and the library is closed afterwards. Move-only.

Since
Kanzi 4.1.0

Constructor & Destructor Documentation

◆ LoadedPlugin() [1/3]

kanzi::LoadedPlugin::LoadedPlugin ( )
defaultnoexcept

Constructs an empty handle that owns nothing.

◆ LoadedPlugin() [2/3]

kanzi::LoadedPlugin::LoadedPlugin ( LoadedPlugin && other)
noexcept

Move-constructs from other, transferring ownership.

◆ ~LoadedPlugin()

kanzi::LoadedPlugin::~LoadedPlugin ( )

Destroys the owned Module (if any) and then closes the owned library handle (if any).

◆ LoadedPlugin() [3/3]

kanzi::LoadedPlugin::LoadedPlugin ( const LoadedPlugin & )
delete

Member Function Documentation

◆ operator=() [1/2]

LoadedPlugin & kanzi::LoadedPlugin::operator= ( LoadedPlugin && other)
noexcept

Move-assigns from other, destroying any previously owned module and library handle before taking ownership of other's resources.

◆ operator=() [2/2]

LoadedPlugin & kanzi::LoadedPlugin::operator= ( const LoadedPlugin & )
delete

◆ operator bool()

kanzi::LoadedPlugin::operator bool ( ) const
explicitnoexcept

Returns whether the handle owns a loaded plugin.

◆ getModule()

Module * kanzi::LoadedPlugin::getModule ( ) const
noexcept

Returns the loaded Module, or null if the handle is empty or moved-from.

The pointer remains valid for the lifetime of this handle.

Friends And Related Symbol Documentation

◆ loadPluginForMetadata

LoadedPlugin loadPluginForMetadata ( string_view )
friend

Opens a plugin shared library, invokes its createModule() entry point, and returns a handle owning the resulting Module together with the library handle.

Does NOT register the module into any Domain and does NOT invoke Module::registerMetadataOverride().

Note
The plugin's Module subclass constructor fires at createModule() time. Subclasses that perform initialization in their constructor pay that cost here. Subclasses whose getMetaclassesOverride() output depends on setup that happens in registerMetadataOverride() will produce incomplete metadata, because the helper does not invoke that hook.
Configuration of the OS-level shared-library search path (SetDllDirectory on Windows, LD_LIBRARY_PATH on POSIX) is the caller's responsibility.
Parameters
pluginPathPath to the plugin shared library.
Returns
LoadedPlugin handle owning the module and library.
Exceptions
runtime_errorif the library fails to open, the createModule entry point is missing, or createModule() returns null.
Since
Kanzi 4.1.0

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