VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
vlink::Plugin类 参考final

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

#include <plugin.h>

vlink::Plugin 的协作图:

Public 类型

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

Public 成员函数

 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.

静态 Public 成员函数

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.

详细描述

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.

成员类型定义说明

◆ Handle

using vlink::Plugin::Handle = void*

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

构造及析构函数说明

◆ Plugin()

vlink::Plugin::Plugin ( )

Constructs a Plugin manager with an empty library registry.

这是这个函数的调用关系图:

◆ ~Plugin()

vlink::Plugin::~Plugin ( )

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

成员函数说明

◆ 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.

返回
Deque of directory path strings to search in order.
函数调用图:
这是这个函数的调用关系图:

◆ get_log_level()

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

Returns the current log level for plugin diagnostics.

返回
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().

模板参数
TInterface type.
参数
lib_nameLibrary file name.
返回
Composite ID string.
这是这个函数的调用关系图:

◆ 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.

模板参数
TInterface type.
参数
lib_nameLibrary file name used during load().
返回
true if loaded.
函数调用图:
这是这个函数的调用关系图:

◆ 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.
模板参数
TInterface type. Must have a get_plugin_id() static method (inserted by VLINK_PLUGIN_REGISTER or VLINK_PLUGIN_REGISTER_BY_ID).
参数
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.
返回
shared_ptr<T> on success, or nullptr on failure.
这是这个函数的调用关系图:

◆ 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.

参数
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.
返回
true if the ID and version match.
函数调用图:

◆ set_log_level()

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

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

参数
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.

模板参数
TInterface type.
参数
lib_nameLibrary file name used during load().
返回
true if the library was found and unloaded.
函数调用图:
这是这个函数的调用关系图:

该类的文档由以下文件生成: