Plugin: discovery, unload, config entry, multi-observer reloads, state API
Host-side additions for applications embedding a plugin system: - PluginManager::load_directory(dir) loads every shared-library file in a directory (filename order) with per-file expected results. - PluginManager::unload(name) drops the registry entry; the instance dies with its last pinned handle (RCU semantics, as on reload). - Optional C entry void_plugin_configure(inst, config): fed from PluginManagerOptions::config_provider after create and after each reload swap, before on_load(). - on_reloaded() is now multi-observer: returns a ReloadCallbackId, remove_on_reloaded() unregisters. Manual reload() now notifies observers too (previously only watched reloads did, contradicting the documented contract). PluginServiceBinding deregisters its callback on destruction (was a dangling-callback hazard). - PluginManager::serialize_state/deserialize_state expose the plugin's v2 state exports so an embedder can carry plugin state through its own hot reload. - ServiceRegistry::remove<I>() withdraws a provided service (child removal re-exposes a parent's entry). - EventBus::subscribe_scoped<E>() returns a move-only RAII Subscription that unsubscribes on destruction. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018yj92cCihyaYtf4gKCT3nv
This commit is contained in:
1 parent
7ca0e1b62e
commit
ee4486e1d2
15 files changed
+750
-24
No files matched your search
@@ -0,0 +1,78 @@
|
||||
#include "Configurable.hpp"
|
||||
|
||||
#include <Void/Plugin/Plugin.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
// A plugin that records what the host passes through the optional
|
||||
// void_plugin_configure entry point, and when (relative to on_load).
|
||||
|
||||
namespace
|
||||
{
|
||||
class ConfigurablePlugin final : public VoidTest::IConfigurable
|
||||
{
|
||||
public:
|
||||
|
||||
[[nodiscard]] std::string_view name() const noexcept override
|
||||
{
|
||||
return "ConfigurablePlugin";
|
||||
}
|
||||
|
||||
void on_load() override { loaded_ = true; }
|
||||
|
||||
[[nodiscard]] std::string_view last_config() const override
|
||||
{
|
||||
return config_;
|
||||
}
|
||||
|
||||
[[nodiscard]] int configure_calls() const override
|
||||
{
|
||||
return calls_;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool configured_before_on_load() const override
|
||||
{
|
||||
return before_on_load_;
|
||||
}
|
||||
|
||||
void apply_config(const char* config)
|
||||
{
|
||||
config_ = config != nullptr ? config : "";
|
||||
++calls_;
|
||||
if (!loaded_) {
|
||||
before_on_load_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::string config_;
|
||||
int calls_{0};
|
||||
bool loaded_{false};
|
||||
bool before_on_load_{false};
|
||||
};
|
||||
} // namespace
|
||||
|
||||
extern "C" {
|
||||
void* void_plugin_create() { return new ConfigurablePlugin; }
|
||||
|
||||
void void_plugin_destroy(void* p)
|
||||
{
|
||||
delete static_cast<ConfigurablePlugin*>(p);
|
||||
}
|
||||
|
||||
Void::Plugin::PluginInfo void_plugin_info()
|
||||
{
|
||||
return {
|
||||
.abi_version = Void::Plugin::ABI_VERSION,
|
||||
.name = "ConfigurablePlugin",
|
||||
.plugin_version = "1.0.0",
|
||||
.description = "Configure entry-point test plugin",
|
||||
};
|
||||
}
|
||||
|
||||
void void_plugin_configure(void* instance, const char* config)
|
||||
{
|
||||
static_cast<ConfigurablePlugin*>(instance)->apply_config(config);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user