Expose Core as a Void::Plugin (C ABI + v2 state), additive
Add a CorePlugin adapter (IS-A Void::Plugin::IPlugin and IS-A Core, hence Api::ICoreInterface) and export the void_plugin_* C ABI from Export.cpp: create/destroy/info plus the v2 state protocol (serialize/deserialize routed through Core's already-Void::Json prepareForHotReload/restoreAfterHotReload). The host recovers the bot interface by dynamic_cast-ing the IPlugin* back to ICoreInterface*. Additive: the legacy CreateCore/DestroyCore exports stay, so the current dylib CoreLoader keeps working while the host migrates to Void::Plugin::PluginManager. Verified via a dlopen smoke test (symbols resolve; info/version correct; create/serialize/deserialize/destroy safe on an uninitialized Core). The live hot-reload + state-survival test under TeamSpeak is the remaining gate for the host-side loader swap. Link Void::Plugin. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
32fbffa171
commit
aedd3e1692
2 files changed
+91
No files matched your search
@@ -108,6 +108,7 @@ target_link_libraries(EchoionCore
|
||||
Void::Net
|
||||
Void::Sqlite
|
||||
Void::Service
|
||||
Void::Plugin
|
||||
PRIVATE
|
||||
Threads::Threads
|
||||
qjs
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#include <Export.hpp>
|
||||
#include "echoion/core/Core.hpp"
|
||||
#include <Void/Plugin/Plugin.hpp>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace Echoion::Api
|
||||
{
|
||||
@@ -17,3 +21,89 @@ namespace Echoion::Api
|
||||
}
|
||||
|
||||
} // namespace Echoion::Api
|
||||
|
||||
namespace Echoion::Core
|
||||
{
|
||||
// Adapter that makes Core loadable through Void::Plugin. It IS-A
|
||||
// Void::Plugin::IPlugin (the type the loader manages) and IS-A Core (hence
|
||||
// Api::ICoreInterface), so the host recovers the bot interface by
|
||||
// dynamic_cast-ing the IPlugin* back to Api::ICoreInterface*.
|
||||
class CorePlugin final : public Void::Plugin::IPlugin, public Core
|
||||
{
|
||||
public:
|
||||
|
||||
[[nodiscard]] std::string_view name() const noexcept override
|
||||
{
|
||||
return "Echoion";
|
||||
}
|
||||
};
|
||||
} // namespace Echoion::Core
|
||||
|
||||
// ── Void::Plugin C ABI ──────────────────────────────────────────────────────
|
||||
// Exposes Core as a Void plugin with the v2 state protocol (serialize/
|
||||
// deserialize via the already-Void::Json hot-reload path). The legacy
|
||||
// CreateCore/DestroyCore exports above remain for the current dylib CoreLoader;
|
||||
// these are additive and let the host migrate to Void::Plugin::PluginManager.
|
||||
//
|
||||
// NOTE: the live hot-reload + state-survival behaviour is only exercised
|
||||
// against a running TeamSpeak host — compile-verified here, runtime-gated there.
|
||||
extern "C"
|
||||
{
|
||||
void* void_plugin_create()
|
||||
{
|
||||
return static_cast<Void::Plugin::IPlugin*>(
|
||||
new Echoion::Core::CorePlugin());
|
||||
}
|
||||
|
||||
void void_plugin_destroy(void* instance)
|
||||
{
|
||||
delete static_cast<Void::Plugin::IPlugin*>(instance);
|
||||
}
|
||||
|
||||
Void::Plugin::PluginInfo void_plugin_info()
|
||||
{
|
||||
return Void::Plugin::PluginInfo{
|
||||
.abi_version = Void::Plugin::ABI_VERSION,
|
||||
.name = "Echoion",
|
||||
.plugin_version = Echoion::Api::VERSION_STRING,
|
||||
.description = "Echoion TeamSpeak music bot core"};
|
||||
}
|
||||
|
||||
// v2 state protocol — survives layout changes across plugin versions.
|
||||
std::uint32_t void_plugin_state_version()
|
||||
{
|
||||
return 1; // matches StateSerializer::CURRENT_VERSION
|
||||
}
|
||||
|
||||
const char* void_plugin_serialize_state(void* instance)
|
||||
{
|
||||
auto* core = dynamic_cast<Echoion::Api::ICoreInterface*>(
|
||||
static_cast<Void::Plugin::IPlugin*>(instance));
|
||||
if (!core) {
|
||||
return nullptr;
|
||||
}
|
||||
auto state = core->prepareForHotReload();
|
||||
if (!state) {
|
||||
return nullptr;
|
||||
}
|
||||
// Heap copy owned by this .so; released via void_plugin_free_string.
|
||||
return strdup(state->c_str());
|
||||
}
|
||||
|
||||
void void_plugin_free_string(const char* s)
|
||||
{
|
||||
std::free(const_cast<char*>(s));
|
||||
}
|
||||
|
||||
int void_plugin_deserialize_state(void* instance, const char* json,
|
||||
std::uint32_t /*from_version*/)
|
||||
{
|
||||
auto* core = dynamic_cast<Echoion::Api::ICoreInterface*>(
|
||||
static_cast<Void::Plugin::IPlugin*>(instance));
|
||||
if (!core || !json) {
|
||||
return -1;
|
||||
}
|
||||
auto result = core->restoreAfterHotReload(std::string(json));
|
||||
return result ? 0 : -1;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user