|
VLink
2.0.0
A high-performance communication middleware
|
Strongly-typed shared-library plugin loader with ID and version verification. 更多...
#include <cstdint>#include <deque>#include <memory>#include <string>#include <string_view>#include "./logger.h"#include "./macros.h"#include "./name_detector.h"类 | |
| class | vlink::Plugin |
| Manager that loads, tracks and unloads shared-library plugins by interface type. 更多... | |
命名空间 | |
| vlink | |
宏定义 | |
| #define | VLINK_PLUGIN_CREATE_FUNC_NAME vlink_plugin_create |
Symbol name of the plugin construction entry point exported by VLINK_PLUGIN_DECLARE. 更多... | |
| #define | VLINK_PLUGIN_DESTROY_FUNC_NAME vlink_plugin_destroy |
Symbol name of the plugin destruction entry point exported by VLINK_PLUGIN_DECLARE. 更多... | |
| #define | VLINK_PLUGIN_EXPORT __attribute__((visibility("default"))) |
| Macro Definitions 更多... | |
| #define | VLINK_PLUGIN_REGISTER(InterfaceType) |
| Declares a plugin's identity from the demangled name of its abstract interface. 更多... | |
| #define | VLINK_PLUGIN_REGISTER_BY_ID(InterfaceType, PluginID) |
| Declares a plugin's identity from an explicit literal string. 更多... | |
| #define | VLINK_PLUGIN_DECLARE(ImplementType, VersionMajor, VersionMinor) |
Emits the extern "C" construction and destruction entry points exported by a plugin module. 更多... | |
Strongly-typed shared-library plugin loader with ID and version verification.
vlink::Plugin wraps the host platform's dynamic-library API (dlopen / LoadLibrary) and resolves the vlink_plugin_create / vlink_plugin_destroy entry points exported by every plugin built with VLINK_PLUGIN_DECLARE. Plugin implementations are bound to an abstract interface type so the loader can verify the ABI contract before any virtual call crosses the library boundary.
Plugin lifecycle observed by the loader:
* load() ---> open() ---> create() ---> in use ---+ * ^ | * | v * clear() <--- close() <--- destroy() <--- unload() *
Interface / implementation contract:
| Side | Required macro | Result |
|---|---|---|
| Abstract interface | VLINK_PLUGIN_REGISTER | Plugin ID = demangled name |
| Abstract interface | VLINK_PLUGIN_REGISTER_BY_ID(_, "id") | Plugin ID = literal string |
| Concrete impl .cc | VLINK_PLUGIN_DECLARE(Impl, major, minor) | Exports create/destroy ABI |
process_plugin_internal() runs inside the plugin entry point and verifies that the plugin ID matches and that the plugin's major version equals the host's required major and the plugin's minor is no lower than the host's required minor. Mismatches return nullptr from vlink_plugin_create() so an incompatible binary never crosses the vtable boundary.| #define VLINK_PLUGIN_CREATE_FUNC_NAME vlink_plugin_create |
Symbol name of the plugin construction entry point exported by VLINK_PLUGIN_DECLARE.
| #define VLINK_PLUGIN_DECLARE | ( | ImplementType, | |
| VersionMajor, | |||
| VersionMinor | |||
| ) |
Emits the extern "C" construction and destruction entry points exported by a plugin module.
The construction entry point validates the plugin ID and major/minor version against the caller's expectations via Plugin::process_plugin_internal() and returns a new instance of ImplementType only when the contract holds. The destruction entry point deletes the implementation pointer.
| ImplementType | Concrete class implementing the abstract interface. |
| VersionMajor | Major version exposed by this plugin binary. |
| VersionMinor | Minor version exposed by this plugin binary. |
| #define VLINK_PLUGIN_DESTROY_FUNC_NAME vlink_plugin_destroy |
Symbol name of the plugin destruction entry point exported by VLINK_PLUGIN_DECLARE.
| #define VLINK_PLUGIN_EXPORT __attribute__((visibility("default"))) |
Macro Definitions
| #define VLINK_PLUGIN_REGISTER | ( | InterfaceType | ) |
Declares a plugin's identity from the demangled name of its abstract interface.
Injects a static constexpr get_plugin_id() member that returns the demangled name of InterfaceType. Static assertions enforce that the interface is abstract and exposes a virtual destructor so polymorphic delete across the library boundary is well defined.
| InterfaceType | Abstract interface class the plugin implements. |
| #define VLINK_PLUGIN_REGISTER_BY_ID | ( | InterfaceType, | |
| PluginID | |||
| ) |
Declares a plugin's identity from an explicit literal string.
Same contract as VLINK_PLUGIN_REGISTER but get_plugin_id() returns PluginID instead of the demangled type name, which is useful when the plugin ID must remain stable across refactors that rename the interface class.
| InterfaceType | Abstract interface class the plugin implements. |
| PluginID | Literal string used as the plugin identity. |