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:
faumarayandClaude Fable 5 committed 2026-07-11 23:39:10 +03:00
1 parent 7ca0e1b62e
commit ee4486e1d2
15 files changed
+750 -24

No files matched your search

+37
View File
@@ -114,6 +114,43 @@ Void::Testing::Test registry_replace_provider()
Void::Testing::expect_eq(reg.size(), std::size_t{1});
}
Void::Testing::Test registry_remove_withdraws_entry()
{
ServiceRegistry reg;
auto clock = std::make_shared<FixedClock>(7);
reg.provide<IClock>(clock);
// A consumer resolved before the removal keeps its instance.
auto held = reg.get<IClock>();
Void::Testing::expect(reg.remove<IClock>());
Void::Testing::expect(!reg.has<IClock>());
Void::Testing::expect(reg.get<IClock>() == nullptr);
Void::Testing::expect_eq(reg.size(), std::size_t{0});
Void::Testing::expect_eq(held->now(), 7);
// Removing again reports nothing to remove.
Void::Testing::expect(!reg.remove<IClock>());
// Re-providing after removal works (fresh lifecycle position).
reg.provide<IClock>(std::make_shared<FixedClock>(9));
Void::Testing::expect_eq(reg.require<IClock>().now(), 9);
}
Void::Testing::Test registry_remove_in_child_reexposes_parent()
{
ServiceRegistry parent;
parent.provide<IClock>(std::make_shared<FixedClock>(1));
ServiceRegistry child{&parent};
child.provide<IClock>(std::make_shared<FixedClock>(2));
Void::Testing::expect_eq(child.require<IClock>().now(), 2);
// Removing the child's shadow re-exposes the parent's entry.
Void::Testing::expect(child.remove<IClock>());
Void::Testing::expect_eq(child.require<IClock>().now(), 1);
}
Void::Testing::Test registry_lifecycle_order()
{
std::vector<std::string> log;