### ABI 1.5 - VDE_PLUGIN_ABI_MINOR 5;VdePluginKind OPTIMIZER=9/IO_BATCH=10; VdeOptimizer*/VdeIoBatch* 结构(JSON 输入输出回调);VdePluginRegistration 尾追加两指针 56→72B(offset 56/64), 旧 1.0–1.4 按 struct_size 安全加载、新 kind 结构不足拒绝; - PluginManager:OptimizerInfo/IoBatchInfo、optimizers()/invoke_optimizer、io_batches()/invoke_io_batch、 校验/失败隔离/卸载清理(IO_BATCH 支持 PARTIAL); - sample_optimizer/sample_io_batch(mock);ABI 矩阵 1.0–1.5 accepted=6+2.0 rejected;--abi/--check 适配; - test_plugin_abi15 6/6 + fixtures;既有 ABI 1.4 断言适配; - 文档 plugin-development §16/§17、plugin-distribution ABI 矩阵、plugin-ecosystem-handoff/ecosystem、plugin-ci-template; ### WP/claim - WP-P4-11 交付并移入 Delivered;claim Released 归档;统计 42=31 Delivered+11 Candidate; - claim check 修正:Released claim 可指向 Delivered WP(仅 Active 需要释放); ### 工程 - 版本 1.0.83;全量构建 0 error(421 targets);全量 ctest 7576 注册、7481/7481 PASS(0 failed,25 skipped,302.66s); - 收录 1.0.82 独立验证报告 80。
131 lines
4.7 KiB
C++
131 lines
4.7 KiB
C++
// 示例 IO_BATCH 插件(VDE 微内核 P4 / ABI 1.5;纯 C ABI,不链接内核)。
|
||
//
|
||
// mock 批量导入导出:不读写真实文件,按请求字节数返回 processed/failed JSON,
|
||
// 用于验证 ABI 1.5 VdeIoBatchPlugin 的注册/回调/JSON 输入输出/错误隔离。
|
||
#include <cstdint>
|
||
#include <cstdio>
|
||
#include <cstdlib>
|
||
#include <cstring>
|
||
#include <string>
|
||
|
||
#include "vde/plugin/vde_plugin_api.h"
|
||
|
||
namespace {
|
||
|
||
int fail(const VdePluginHost* host, int code, const char* message) {
|
||
if (host && host->set_error) host->set_error(message);
|
||
return code;
|
||
}
|
||
|
||
const char* find_string(const char* json, const char* key) {
|
||
if (!json) return nullptr;
|
||
const std::string pattern = "\"" + std::string(key) + "\"";
|
||
const char* pos = std::strstr(json, pattern.c_str());
|
||
return pos;
|
||
}
|
||
|
||
int run(const VdePluginHost* host, const char* options_json, const char* request_json,
|
||
size_t request_size, VdeBuffer* response_json, char* error_message,
|
||
size_t error_message_size) {
|
||
const auto set_error = [&](const char* text) {
|
||
if (host && host->set_error) host->set_error(text);
|
||
if (error_message && error_message_size > 0)
|
||
std::snprintf(error_message, error_message_size, "%s", text);
|
||
};
|
||
if (!host || !host->alloc || !host->free_buffer) {
|
||
set_error("io_batch: host services incomplete");
|
||
return VDE_PLUGIN_ERR_INVALID_ARG;
|
||
}
|
||
if (!request_json || request_size == 0) {
|
||
set_error("io_batch: request JSON is empty");
|
||
return VDE_PLUGIN_ERR_INVALID_ARG;
|
||
}
|
||
if (!response_json) {
|
||
set_error("io_batch: response buffer is null");
|
||
return VDE_PLUGIN_ERR_INVALID_ARG;
|
||
}
|
||
if (options_json && std::strstr(options_json, "\"flags\"")) {
|
||
const char* flags = std::strstr(options_json, "\"flags\"");
|
||
const char* colon = flags ? std::strchr(flags, ':') : nullptr;
|
||
if (colon && std::strtol(colon + 1, nullptr, 10) != 0) {
|
||
set_error("io_batch: options.flags must be 0");
|
||
return VDE_PLUGIN_ERR_INVALID_ARG;
|
||
}
|
||
}
|
||
const char* format = find_string(options_json, "format");
|
||
const std::uint32_t processed =
|
||
static_cast<std::uint32_t>(request_size / 16) + 1;
|
||
std::string json;
|
||
char buffer[384];
|
||
std::snprintf(buffer, sizeof(buffer),
|
||
"{\"batch_id\":\"io_batch.mock\",\"ok\":true,\"processed\":%u,"
|
||
"\"failed\":0,\"request_bytes\":%zu,\"format\":\"mock\"}",
|
||
processed, request_size);
|
||
json += buffer;
|
||
void* out = host->alloc(json.size() + 1);
|
||
if (!out) {
|
||
set_error("io_batch: cannot allocate response buffer");
|
||
return VDE_PLUGIN_ERR_BUFFER;
|
||
}
|
||
std::memcpy(out, json.c_str(), json.size() + 1);
|
||
response_json->data = out;
|
||
response_json->size = json.size();
|
||
(void)format;
|
||
return VDE_PLUGIN_OK;
|
||
}
|
||
|
||
const char* describe() {
|
||
return "VDE sample io_batch (mock copy; ABI 1.5)";
|
||
}
|
||
|
||
const VdeIoBatchPlugin kIoBatch = [] {
|
||
VdeIoBatchPlugin plugin{};
|
||
plugin.struct_size = sizeof(VdeIoBatchPlugin);
|
||
plugin.batch_id = "io_batch.mock";
|
||
plugin.capabilities_json = "{\"formats\":[\"mock\"],\"directions\":[\"import\",\"export\"]}";
|
||
plugin.run = &run;
|
||
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.sample.io_batch";
|
||
info->name = "VDE Sample IO Batch (ABI 1.5)";
|
||
info->version = "0.1.0";
|
||
info->kind = VDE_PLUGIN_KIND_IO_BATCH;
|
||
info->abi_major = VDE_PLUGIN_ABI_MAJOR;
|
||
info->abi_minor = VDE_PLUGIN_ABI_MINOR;
|
||
info->capabilities = "io_batch:mock";
|
||
info->license = "Apache-2.0";
|
||
return VDE_PLUGIN_OK;
|
||
}
|
||
|
||
VDE_PLUGIN_EXPORT int vde_plugin_init(const VdePluginHost* host, VdePluginRegistration* reg) {
|
||
if (!host || !reg) return VDE_PLUGIN_ERR_INVALID_ARG;
|
||
const std::size_t io_batch_field_end =
|
||
offsetof(VdePluginRegistration, io_batch) + sizeof(reg->io_batch);
|
||
if (reg->struct_size < io_batch_field_end) return VDE_PLUGIN_ERR_ABI;
|
||
if (!host->alloc || !host->free_buffer || !host->set_error)
|
||
return fail(host, VDE_PLUGIN_ERR_INVALID_ARG, "io_batch: host services incomplete");
|
||
reg->kind = VDE_PLUGIN_KIND_IO_BATCH;
|
||
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 = &kIoBatch;
|
||
return VDE_PLUGIN_OK;
|
||
}
|
||
|
||
VDE_PLUGIN_EXPORT void vde_plugin_shutdown() {}
|
||
|
||
} // extern "C"
|