VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
vlink::Plugin Class Referencefinal

Type-safe dynamic plugin loader with version verification and lifecycle management. More...

#include <plugin.h>

Collaboration diagram for vlink::Plugin:

Public Types

using Handle = void*
 Opaque handle to a loaded shared library object (used internally).

Public Member Functions

 Plugin ()
 Constructs a Plugin manager with an empty library registry.
 ~Plugin ()
 Destructor. Calls clear() to unload all still-loaded libraries.
void set_log_level (Logger::Level level)
 Sets the log level used for plugin load/unload diagnostics.
Logger::Level get_log_level () const
 Returns the current log level for plugin diagnostics.
template<class T>
std::shared_ptr< T > load (const std::string &lib_name, uint16_t version_major, uint16_t version_minor, const std::string &dir_name="", const std::deque< std::string > &search_paths=default_search_path(), const std::string &function_name=VLINK_MACRO_STRING_GET(VLINK_PLUGIN_CREATE_FUNC_NAME))
 Loads a plugin implementing interface T from a shared library.
template<class T>
bool unload (const std::string &lib_name)
 Unloads the plugin library for interface T.
template<class T>
bool has_loaded (const std::string &lib_name)
 Returns true if the plugin for interface T is currently loaded.
template<class T>
std::string get_plugin_complex_id (const std::string &lib_name)
 Returns the composite key used internally to identify a (library, interface) pair.
void clear ()
 Unloads all loaded plugin libraries.

Static Public Member Functions

static std::deque< std::string > default_search_path ()
 Returns the default search path list for finding plugin shared libraries.
static bool process_plugin_internal (const std::string &lib_name, const std::string &local_plugin_id, uint16_t local_version_major, uint16_t local_version_minor, const std::string &target_plugin_id, uint16_t target_version_major, uint16_t target_version_minor, uint8_t log_level)
 Internal entry-point handler called from VLINK_PLUGIN_DECLARE.

Detailed Description

Type-safe dynamic plugin loader with version verification and lifecycle management.

Loads one or more shared library plugins by interface type T. Multiple distinct interface types may be loaded by a single Plugin instance.

Member Typedef Documentation

◆ Handle

using vlink::Plugin::Handle = void*

Opaque handle to a loaded shared library object (used internally).

Constructor & Destructor Documentation

◆ Plugin()

vlink::Plugin::Plugin ( )

Constructs a Plugin manager with an empty library registry.

Here is the caller graph for this function:

◆ ~Plugin()

vlink::Plugin::~Plugin ( )

Destructor. Calls clear() to unload all still-loaded libraries.

Member Function Documentation

◆ clear()

void vlink::Plugin::clear ( )

Unloads all loaded plugin libraries.

Equivalent to calling unload<T>(lib_name) for every previously loaded plugin.

◆ default_search_path()

std::deque< std::string > vlink::Plugin::default_search_path ( )
staticnodiscard

Returns the default search path list for finding plugin shared libraries.

Includes the executable directory, the system library directories, and the current working directory.

Returns
Deque of directory path strings to search in order.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_log_level()

Logger::Level vlink::Plugin::get_log_level ( ) const
nodiscard

Returns the current log level for plugin diagnostics.

Returns
Current log level.

◆ get_plugin_complex_id()

template<class T>
std::string vlink::Plugin::get_plugin_complex_id ( const std::string & lib_name)
inlinenodiscard

Returns the composite key used internally to identify a (library, interface) pair.

The key is lib_name + "@" + T::get_plugin_id().

Template Parameters
TInterface type.
Parameters
lib_nameLibrary file name.
Returns
Composite ID string.
Here is the caller graph for this function:

◆ has_loaded()

template<class T>
bool vlink::Plugin::has_loaded ( const std::string & lib_name)
inlinenodiscard

Returns true if the plugin for interface T is currently loaded.

Template Parameters
TInterface type.
Parameters
lib_nameLibrary file name used during load().
Returns
true if loaded.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load()

template<class T>
std::shared_ptr< T > vlink::Plugin::load ( const std::string & lib_name,
uint16_t version_major,
uint16_t version_minor,
const std::string & dir_name = "",
const std::deque< std::string > & search_paths = default_search_path(),
const std::string & function_name = VLINK_MACRO_STRING_GET(VLINK_PLUGIN_CREATE_FUNC_NAME) )
inlinenodiscard

Loads a plugin implementing interface T from a shared library.

Details.

  1. Resolves the library file by searching search_paths for a file whose name matches lib_name (with platform-appropriate prefix/suffix).
  2. Opens the library with dlopen (or LoadLibrary on Windows).
  3. Calls the vlink_plugin_create entry point with version and ID information.
  4. Returns a shared_ptr<T> whose custom deleter calls vlink_plugin_destroy.
Template Parameters
TInterface type. Must have a get_plugin_id() static method (inserted by VLINK_PLUGIN_REGISTER or VLINK_PLUGIN_REGISTER_BY_ID).
Parameters
lib_nameFile name of the shared library (without prefix/suffix).
version_majorRequired major version.
version_minorRequired minor version.
dir_nameOptional explicit directory to search first. Default: empty.
search_pathsOrdered list of directories to search. Default: default_search_path().
function_nameName of the creation entry point. Default: vlink_plugin_create.
Returns
shared_ptr<T> on success, or nullptr on failure.
Here is the caller graph for this function:

◆ process_plugin_internal()

bool vlink::Plugin::process_plugin_internal ( const std::string & lib_name,
const std::string & local_plugin_id,
uint16_t local_version_major,
uint16_t local_version_minor,
const std::string & target_plugin_id,
uint16_t target_version_major,
uint16_t target_version_minor,
uint8_t log_level )
static

Internal entry-point handler called from VLINK_PLUGIN_DECLARE.

Validates the plugin ID and version, then configures the logger level inside the plugin. Should not be called directly by user code.

Parameters
lib_nameLibrary name (for logging).
local_plugin_idID exported by the plugin implementation.
local_version_majorMajor version exported by the plugin.
local_version_minorMinor version exported by the plugin.
target_plugin_idID expected by the caller (from T::get_plugin_id()).
target_version_majorMajor version required by the caller.
target_version_minorMinor version required by the caller.
log_levelLogger level to propagate into the plugin.
Returns
true if the ID and version match.
Here is the call graph for this function:

◆ set_log_level()

void vlink::Plugin::set_log_level ( Logger::Level level)

Sets the log level used for plugin load/unload diagnostics.

Parameters
levelLogger level.

◆ unload()

template<class T>
bool vlink::Plugin::unload ( const std::string & lib_name)
inline

Unloads the plugin library for interface T.

Removes the library from the internal registry and decrements the reference count. The library is actually closed when all shared_ptr instances to the plugin object are destroyed.

Template Parameters
TInterface type.
Parameters
lib_nameLibrary file name used during load().
Returns
true if the library was found and unloaded.
Here is the call graph for this function:
Here is the caller graph for this function:

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