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
@@ -3,6 +3,7 @@
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
using namespace Void::EventBus;
|
||||
|
||||
@@ -113,3 +114,42 @@ Void::Testing::Test bus_event_data_forwarded()
|
||||
bus.publish(TextChanged{"hello"});
|
||||
Void::Testing::expect_eq(received, std::string{"hello"});
|
||||
}
|
||||
|
||||
// ── scoped (RAII) subscriptions ───────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test bus_scoped_subscription_unsubscribes_on_destruction()
|
||||
{
|
||||
EventBus bus;
|
||||
int count = 0;
|
||||
{
|
||||
auto sub =
|
||||
bus.subscribe_scoped<Clicked>([&](const Clicked&) { ++count; });
|
||||
Void::Testing::expect(static_cast<bool>(sub));
|
||||
bus.publish(Clicked{0, 0});
|
||||
Void::Testing::expect_eq(count, 1);
|
||||
}
|
||||
// Handler removed with the subscription.
|
||||
bus.publish(Clicked{0, 0});
|
||||
Void::Testing::expect_eq(count, 1);
|
||||
Void::Testing::expect_eq(bus.subscriber_count<Clicked>(), std::size_t{0});
|
||||
}
|
||||
|
||||
Void::Testing::Test bus_scoped_subscription_moves_ownership()
|
||||
{
|
||||
EventBus bus;
|
||||
int count = 0;
|
||||
auto outer = EventBus::Subscription{};
|
||||
{
|
||||
auto inner =
|
||||
bus.subscribe_scoped<Clicked>([&](const Clicked&) { ++count; });
|
||||
outer = std::move(inner);
|
||||
Void::Testing::expect(!static_cast<bool>(inner));
|
||||
}
|
||||
// The moved-from handle's death did not unsubscribe.
|
||||
bus.publish(Clicked{0, 0});
|
||||
Void::Testing::expect_eq(count, 1);
|
||||
|
||||
outer.reset();
|
||||
bus.publish(Clicked{0, 0});
|
||||
Void::Testing::expect_eq(count, 1);
|
||||
}
|
||||
Reference in new issue
Block a user