Plugin adapter: self-initialize so Void reload protocol works end-to-end
Void::Plugin::PluginLoader::reload() transfers state (deserialize_state) before on_load(), on a freshly-created instance — but Core's restoreAfterHotReload needs an initialized Core. Make the adapter self-initialize from the default config path in both on_load() (first load / post-swap) and deserialize_state (during transfer), guarded by isInitialized() so it is idempotent. This resolves the init-before-restore ordering and lets the host migrate to PluginManager as plain wiring. The legacy CreateCore path is unaffected (on_load is only reached through the void_plugin_* C ABI). Live hot-reload state-survival under TeamSpeak remains the runtime gate. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
aedd3e1692
commit
17f31ea3e0
1 file changed
+21
@@ -36,6 +36,17 @@ namespace Echoion::Core
|
|||||||
{
|
{
|
||||||
return "Echoion";
|
return "Echoion";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Void::Plugin::PluginLoader calls on_load() once after create
|
||||||
|
// (first load and after a reload swap). Self-initialize from the
|
||||||
|
// default config path so the plugin is ready without host-provided
|
||||||
|
// wiring; idempotent via isInitialized().
|
||||||
|
void on_load() override
|
||||||
|
{
|
||||||
|
if (!isInitialized()) {
|
||||||
|
(void)initialize(ConfigLoader::getDefaultConfigPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
} // namespace Echoion::Core
|
} // namespace Echoion::Core
|
||||||
|
|
||||||
@@ -103,6 +114,16 @@ extern "C"
|
|||||||
if (!core || !json) {
|
if (!core || !json) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
// reload() transfers state before on_load(), so the freshly-created
|
||||||
|
// instance is not yet initialized — bring it up first, then restore.
|
||||||
|
// Idempotent: a no-op once initialized.
|
||||||
|
if (!core->isInitialized()) {
|
||||||
|
auto initResult =
|
||||||
|
core->initialize(Echoion::Core::ConfigLoader::getDefaultConfigPath());
|
||||||
|
if (!initResult) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
auto result = core->restoreAfterHotReload(std::string(json));
|
auto result = core->restoreAfterHotReload(std::string(json));
|
||||||
return result ? 0 : -1;
|
return result ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user