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
79 lines
1.5 KiB
C++
79 lines
1.5 KiB
C++
#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);
|
|
}
|
|
}
|