|
VLink
2.0.0
A high-performance communication middleware
|
Manager that loads, tracks and unloads shared-library plugins by interface type. 更多...
#include <plugin.h>
Public 类型 | |
| using | Handle = void * |
| Opaque handle to a loaded shared library; treated as a token by the public API. 更多... | |
Public 成员函数 | |
| Plugin () | |
| Constructs an empty plugin manager with no libraries loaded. 更多... | |
| ~Plugin () | |
Destroys the plugin manager and unloads every still-resident library via clear(). 更多... | |
| void | set_log_level (Logger::Level level) |
| Sets the verbosity level used for plugin diagnostic messages. 更多... | |
| Logger::Level | get_log_level () const |
| Returns the verbosity level currently used 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 shared library that implements interface T and returns a tracked handle. 更多... | |
| template<class T > | |
| bool | unload (const std::string &lib_name) |
| Removes a previously loaded plugin from the registry. 更多... | |
| template<class T > | |
| bool | has_loaded (const std::string &lib_name) |
Reports whether a plugin for interface T is currently registered. 更多... | |
| template<class T > | |
| std::string | get_plugin_complex_id (const std::string &lib_name) |
| Builds the composite key used internally to identify a (library, interface) pair. 更多... | |
| void | clear () |
| Unloads every library currently tracked by this manager. 更多... | |
静态 Public 成员函数 | |
| static std::deque< std::string > | default_search_path () |
| Returns the default ordered search path used when locating plugin 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 version/ID gate invoked from the VLINK_PLUGIN_DECLARE entry point. 更多... | |
Manager that loads, tracks and unloads shared-library plugins by interface type.
A single Plugin instance can host multiple distinct interface types simultaneously and tracks each loaded library so repeated load() calls share the underlying dlopen handle. All operations are thread safe through the internal implementation.
| using vlink::Plugin::Handle = void* |
Opaque handle to a loaded shared library; treated as a token by the public API.
| vlink::Plugin::Plugin | ( | ) |
Constructs an empty plugin manager with no libraries loaded.
| vlink::Plugin::~Plugin | ( | ) |
Destroys the plugin manager and unloads every still-resident library via clear().
| void vlink::Plugin::clear | ( | ) |
Unloads every library currently tracked by this manager.
|
static |
Returns the default ordered search path used when locating plugin libraries.
The list contains, in priority order, directories from VLINK_PLUGIN_DIR (comma or whitespace separated), the current working directory, the executable directory, and the system library directories appropriate for the platform.
| Logger::Level vlink::Plugin::get_log_level | ( | ) | const |
Returns the verbosity level currently used for plugin diagnostics.
|
inline |
Builds the composite key used internally to identify a (library, interface) pair.
The key has the form lib_name + "@" + T::get_plugin_id() so the same shared library can be loaded twice when consumed via two different interfaces.
| T | Interface type. |
| lib_name | Library file name. |
|
inline |
|
inline |
Loads a shared library that implements interface T and returns a tracked handle.
Details
The loader appends the platform's library prefix/suffix to lib_name, scans search_paths, opens the first matching file, invokes the function_name entry point with the caller's ID and version, and finally wraps the returned object pointer in a shared_ptr<T> whose deleter invokes vlink_plugin_destroy.
| T | Interface type carrying get_plugin_id() (added by VLINK_PLUGIN_REGISTER or VLINK_PLUGIN_REGISTER_BY_ID). |
| lib_name | Library file name without prefix/suffix. |
| version_major | Required interface major version. |
| version_minor | Required interface minor version. |
| dir_name | Optional directory searched before search_paths. |
| search_paths | Ordered fallback search list. Default: default_search_path(). |
| function_name | Symbol name of the construction entry point. |
shared_ptr<T> owning the plugin instance, or nullptr on failure.
|
static |
Internal version/ID gate invoked from the VLINK_PLUGIN_DECLARE entry point.
Compares the plugin's exported ID and version against the host's expectations, emitting informational or error diagnostics gated by log_level. User code should never call this function directly. log_level only filters this function's own output and is not propagated into the plugin module's runtime logger.
| lib_name | Library file name (used as a tag in diagnostic output). |
| local_plugin_id | Plugin ID compiled into the plugin binary. |
| local_version_major | Major version compiled into the plugin binary. |
| local_version_minor | Minor version compiled into the plugin binary. |
| target_plugin_id | Plugin ID required by the host caller. |
| target_version_major | Major version required by the host caller. |
| target_version_minor | Minor version required by the host caller. |
| log_level | Threshold used to filter this function's own diagnostics. |
true when IDs match and local_major == target_major and local_minor >= target_minor. | void vlink::Plugin::set_log_level | ( | Logger::Level | level | ) |
Sets the verbosity level used for plugin diagnostic messages.
| level | Logger level to apply to plugin load/unload tracing. |
|
inline |
Removes a previously loaded plugin from the registry.
The shared library is finally unmapped once every shared_ptr returned by load() has been destroyed; this call only releases the tracker entry.
| T | Interface type used during the original load() call. |
| lib_name | Library file name passed to load(). |
true when the registry entry existed and was removed.