### P4-01 插件 ABI 1.4 mesher 扩展点 - VDE_PLUGIN_ABI_MINOR 3→4;VdePluginKind MESHER=8;VdeMesherStatus/Options/Result/Plugin; VdePluginRegistration 尾追加 mesher 指针(48→56B,旧 1.3 按 struct_size 安全); - PluginManager kind/meshers()/invoke_mesher()/失败隔离/unload 清理;ABI 语义 manifest.minor<=query.minor<=host.minor; - sample_mesher(mock tet4);ABI 矩阵 1.0–1.4 accepted=5 + 2.0 rejected;--abi/--check 适配; - test_plugin_mesher 7 用例 + VDE_PluginToolMesherAbi CTest;docs plugin-development §15/plugin-distribution §12; ### P4-02 Python ctypes 回归 - 可选 CTest VDE_PythonCtypesSmoke(Python3 可选/vde_capi_shared/smoke_test_ctypes.py;无 Python 跳过); - VDE_BUILD_PYTHON=ON MinGW 原生 pybind 明确跳过(ctypes 保留);README/testing 文档更新(C API 61/绑定 60); ### P4-03 模块包 CI 矩阵 - cmake/check_module_packages.cmake:configure/build/install → 10 模块包 find_package + 仓库内 consumer 编译运行; - tests/module_packages/consumers/(10 个最小工程);CI module-packages job;本地 MODULE_PACKAGES_PASS pass=10 fail=0; ### P4-04 宿主复测/平台 CI 交接 + 多团队分发体系 - docs/reference/76-宿主复测与平台CI交接包(1.0.78).md;VDE-1251/1252 反馈单追加复测指引; - docs/design/multi-team-development.md(T1–T8/ownership/契约/流程)、docs/planning/work-packages.md(39 WP)、 docs/guides/team-onboarding.md、docs/design/plugin-ecosystem-handoff.md、.github/ISSUE_TEMPLATE/work-package.yml; - roadmap P4-01..05 交付;WP 状态 27 Delivered/0 In-Progress/12 Candidate; ### 工程 - 版本 1.0.79;与远端 f6e0ac97(plugin template SDK consumption/ecosystem plan)rebase 集成; - 全量构建 0 error(405 targets);全量 ctest 7569 注册、7474/7474 PASS(0 failed,25 skipped,238.13s)。
149 lines
6.2 KiB
C++
149 lines
6.2 KiB
C++
// 示例 Mesher(网格生成)插件(VDE 微内核 P4 / 插件 ABI 1.4;纯 C ABI,不链接内核)。
|
||
//
|
||
// 这是 VdeMesherPlugin 扩展点的 mock/演示实现:不依赖任何内核符号,仅使用
|
||
// VdePluginHost 的 alloc/free/set_error;用于验证 ABI 1.4 注册、调用与错误隔离。
|
||
// 真实 mesher 插件可把 model_data 经 host->body_from_serialized 还原为实体后
|
||
// 用 host->body_volume/body_bbox/body_tessellate 查询几何,再调用自有网格算法。
|
||
//
|
||
// 本 mock 输出固定 8 节点 / 5 四面体的单位立方体网格(不读取模型几何),
|
||
// 并在 JSON 中回显 model_bytes/element_size/options_tolerance,便于测试断言。
|
||
#include <cstdint>
|
||
#include <cstdio>
|
||
#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;
|
||
}
|
||
|
||
bool valid_result(const VdeMesherResult* result) {
|
||
return result != nullptr && result->struct_size >= sizeof(VdeMesherResult);
|
||
}
|
||
|
||
void free_buffer(const VdePluginHost* host, VdeBuffer* buffer) {
|
||
if (buffer && buffer->data && host && host->free_buffer) host->free_buffer(buffer->data);
|
||
if (buffer) {
|
||
buffer->data = nullptr;
|
||
buffer->size = 0;
|
||
}
|
||
}
|
||
|
||
// 固定 tet4 单位立方体(8 节点 / 5 四面体;索引 0-based)
|
||
const double kVertices[8][3] = {
|
||
{0.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 1.0, 0.0}, {0.0, 1.0, 0.0},
|
||
{0.0, 0.0, 1.0}, {1.0, 0.0, 1.0}, {1.0, 1.0, 1.0}, {0.0, 1.0, 1.0}};
|
||
const unsigned kTets[5][4] = {{0, 1, 2, 6}, {0, 2, 3, 6}, {0, 3, 7, 6}, {0, 7, 4, 6}, {0, 4, 5, 6}};
|
||
|
||
int mesh(const VdePluginHost* host, const void* model_data, size_t model_size,
|
||
const VdeMesherOptions* options, VdeMesherResult* result) {
|
||
if (!host || !host->alloc || !host->set_error || !host->free_buffer)
|
||
return VDE_PLUGIN_ERR_INVALID_ARG;
|
||
if (!model_data || model_size == 0)
|
||
return fail(host, VDE_PLUGIN_ERR_INVALID_ARG, "mesher: model_data is empty");
|
||
if (!valid_result(result))
|
||
return fail(host, VDE_PLUGIN_ERR_INVALID_ARG, "mesher: result struct_size too small");
|
||
if (options && options->struct_size >= sizeof(VdeMesherOptions) && options->flags != 0)
|
||
return fail(host, VDE_PLUGIN_ERR_INVALID_ARG, "mesher: options.flags must be 0");
|
||
|
||
const double element_size =
|
||
(options && options->element_size > 0.0) ? options->element_size : 1.0;
|
||
const double tolerance = (options && options->tolerance > 0.0) ? options->tolerance : 1e-6;
|
||
const std::uint32_t requested_type = options ? options->element_type : 0;
|
||
if (requested_type > 2)
|
||
return fail(host, VDE_PLUGIN_ERR_INVALID_ARG, "mesher: unsupported element_type");
|
||
|
||
std::string json;
|
||
char buffer[512];
|
||
std::snprintf(buffer, sizeof(buffer),
|
||
"{\"mesher_id\":\"mesher.mock.tet4\",\"ok\":true,"
|
||
"\"element_type\":\"tet4\",\"nodes\":%zu,\"elements\":%zu,"
|
||
"\"model_bytes\":%zu,\"element_size\":%.12g,\"tolerance\":%.12g,",
|
||
sizeof(kVertices) / sizeof(kVertices[0]),
|
||
sizeof(kTets) / sizeof(kTets[0]), model_size, element_size, tolerance);
|
||
json += buffer;
|
||
json += "\"vertices\":[";
|
||
for (std::size_t i = 0; i < sizeof(kVertices) / sizeof(kVertices[0]); ++i) {
|
||
if (i != 0) json += ",";
|
||
std::snprintf(buffer, sizeof(buffer), "[%.12g,%.12g,%.12g]", kVertices[i][0],
|
||
kVertices[i][1], kVertices[i][2]);
|
||
json += buffer;
|
||
}
|
||
json += "],\"tets\":[";
|
||
for (std::size_t i = 0; i < sizeof(kTets) / sizeof(kTets[0]); ++i) {
|
||
if (i != 0) json += ",";
|
||
std::snprintf(buffer, sizeof(buffer), "[%u,%u,%u,%u]", kTets[i][0], kTets[i][1],
|
||
kTets[i][2], kTets[i][3]);
|
||
json += buffer;
|
||
}
|
||
json += "],\"diagnostics\":[\"mock tet4 mesher (unit cube template); not for production "
|
||
"use\"]}";
|
||
|
||
void* out = host->alloc(json.size() + 1);
|
||
if (!out) return fail(host, VDE_PLUGIN_ERR_BUFFER, "mesher: cannot allocate result buffer");
|
||
std::memcpy(out, json.c_str(), json.size() + 1);
|
||
result->status = VDE_MESHER_OK;
|
||
result->element_type = 1; // tet4
|
||
result->num_nodes = static_cast<std::uint32_t>(sizeof(kVertices) / sizeof(kVertices[0]));
|
||
result->num_elements = static_cast<std::uint32_t>(sizeof(kTets) / sizeof(kTets[0]));
|
||
result->mesh_json.data = out;
|
||
result->mesh_json.size = json.size();
|
||
return VDE_PLUGIN_OK;
|
||
}
|
||
|
||
const char* describe() {
|
||
return "VDE sample tet4 mesher (mock unit-cube template; ABI 1.4)";
|
||
}
|
||
|
||
const VdeMesherPlugin kMesher = [] {
|
||
VdeMesherPlugin plugin{};
|
||
plugin.struct_size = sizeof(VdeMesherPlugin);
|
||
plugin.mesher_id = "mesher.mock.tet4";
|
||
plugin.capabilities_json =
|
||
"{\"dimensions\":[3],\"element_types\":[\"tet4\"],\"mock\":true}";
|
||
plugin.mesh = &mesh;
|
||
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.mesher";
|
||
info->name = "VDE Sample Mesher (ABI 1.4)";
|
||
info->version = "0.1.0";
|
||
info->kind = VDE_PLUGIN_KIND_MESHER;
|
||
info->abi_major = VDE_PLUGIN_ABI_MAJOR;
|
||
info->abi_minor = VDE_PLUGIN_ABI_MINOR;
|
||
info->capabilities = "mesher:tet";
|
||
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;
|
||
if (reg->struct_size < sizeof(VdePluginRegistration)) return VDE_PLUGIN_ERR_ABI;
|
||
if (!host->alloc || !host->free_buffer || !host->set_error)
|
||
return fail(host, VDE_PLUGIN_ERR_INVALID_ARG, "mesher: host services incomplete");
|
||
reg->kind = VDE_PLUGIN_KIND_MESHER;
|
||
reg->format = nullptr;
|
||
reg->generic = nullptr;
|
||
reg->cae_solver = nullptr;
|
||
reg->cam_strategy = nullptr;
|
||
reg->gcs_solver = nullptr;
|
||
reg->mesher = &kMesher;
|
||
return VDE_PLUGIN_OK;
|
||
}
|
||
|
||
VDE_PLUGIN_EXPORT void vde_plugin_shutdown() {}
|
||
|
||
} // extern "C"
|