97 lines
3.1 KiB
C++
97 lines
3.1 KiB
C++
// P4-46 热重载回滚测试夹具(ABI 1.8 UI 插件)。
|
|
// 首次 init 成功;若环境变量 VDE_TEST_RELOAD_MARKER 指向的文件存在,
|
|
// init 删除该文件并返回失败 —— 用于让 reload 的新版本 init 失败,
|
|
// 随后宿主回滚重新加载旧版本时成功。
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
|
|
#include "vde/plugin/vde_plugin_api.h"
|
|
|
|
namespace {
|
|
|
|
bool marker_exists(const char* path) {
|
|
if (!path || !*path) return false;
|
|
std::FILE* file = std::fopen(path, "rb");
|
|
if (!file) return false;
|
|
std::fclose(file);
|
|
return true;
|
|
}
|
|
|
|
int get_theme_json(const VdePluginHost* host, const char* options_json,
|
|
VdeBuffer* result_json) {
|
|
(void)options_json;
|
|
if (result_json) {
|
|
result_json->data = nullptr;
|
|
result_json->size = 0;
|
|
}
|
|
if (!host || !host->alloc || !result_json) return VDE_PLUGIN_ERR_INVALID_ARG;
|
|
const char* json = "{\"ui_id\":\"test.reload.ui\",\"ok\":true}";
|
|
const std::size_t size = std::strlen(json);
|
|
void* data = host->alloc(size + 1);
|
|
if (!data) return VDE_PLUGIN_ERR_BUFFER;
|
|
std::memcpy(data, json, size + 1);
|
|
result_json->data = data;
|
|
result_json->size = size;
|
|
return VDE_PLUGIN_OK;
|
|
}
|
|
|
|
const char* describe() { return "P4-46 reload rollback fixture"; }
|
|
|
|
const VdeUiPlugin kUi = [] {
|
|
VdeUiPlugin plugin{};
|
|
plugin.struct_size = sizeof(VdeUiPlugin);
|
|
plugin.ui_id = "test.reload.ui";
|
|
plugin.capabilities_json = "{\"test\":true}";
|
|
plugin.get_theme_json = &get_theme_json;
|
|
plugin.describe = &describe;
|
|
return plugin;
|
|
}();
|
|
|
|
} // namespace
|
|
|
|
extern "C" {
|
|
|
|
VDE_PLUGIN_EXPORT int vde_plugin_query(std::uint32_t host_abi_major, VdePluginInfo* info) {
|
|
if (!info || info->struct_size < sizeof(VdePluginInfo)) return VDE_PLUGIN_ERR_INVALID_ARG;
|
|
if (host_abi_major != VDE_PLUGIN_ABI_MAJOR) return VDE_PLUGIN_ERR_ABI;
|
|
info->id = "com.vde.test.reload";
|
|
info->name = "VDE Reload Rollback Fixture";
|
|
info->version = "1.0.0";
|
|
info->kind = VDE_PLUGIN_KIND_UI;
|
|
info->abi_major = VDE_PLUGIN_ABI_MAJOR;
|
|
info->abi_minor = VDE_PLUGIN_ABI_MINOR;
|
|
info->capabilities = "ui:test_reload";
|
|
info->license = "Apache-2.0";
|
|
return VDE_PLUGIN_OK;
|
|
}
|
|
|
|
VDE_PLUGIN_EXPORT int vde_plugin_init(const VdePluginHost* host, VdePluginRegistration* reg) {
|
|
const char* marker = std::getenv("VDE_TEST_RELOAD_MARKER");
|
|
if (marker_exists(marker)) {
|
|
std::remove(marker);
|
|
if (host && host->set_error)
|
|
host->set_error("reload fixture: new version init failure (marker consumed)");
|
|
return VDE_PLUGIN_ERR_INTERNAL;
|
|
}
|
|
if (!reg || reg->struct_size < sizeof(VdePluginRegistration))
|
|
return VDE_PLUGIN_ERR_ABI;
|
|
reg->kind = VDE_PLUGIN_KIND_UI;
|
|
reg->format = nullptr;
|
|
reg->generic = nullptr;
|
|
reg->cae_solver = nullptr;
|
|
reg->cam_strategy = nullptr;
|
|
reg->gcs_solver = nullptr;
|
|
reg->mesher = nullptr;
|
|
reg->optimizer = nullptr;
|
|
reg->io_batch = nullptr;
|
|
reg->geom_op = nullptr;
|
|
reg->ui = &kUi;
|
|
return VDE_PLUGIN_OK;
|
|
}
|
|
|
|
VDE_PLUGIN_EXPORT void vde_plugin_shutdown() {}
|
|
|
|
} // extern "C"
|