2026-04-15 18:07:28 +02:00
|
|
|
/********************************************************************************
|
|
|
|
|
* *
|
|
|
|
|
* This file is part of IfcOpenShell. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the Lesser GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation, either version 3.0 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* Lesser GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the Lesser GNU General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "kernel_plugin.h"
|
|
|
|
|
|
2026-05-06 21:17:25 +02:00
|
|
|
#include <boost/algorithm/string/case_conv.hpp>
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
2026-04-15 18:07:28 +02:00
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
constexpr const char* kernel_plugin_prefix = "geometry.kernel.";
|
2026-05-06 21:17:25 +02:00
|
|
|
|
|
|
|
|
std::string kernel_plugin_name(const std::string& backend_id) {
|
|
|
|
|
auto name = boost::to_lower_copy(backend_id);
|
|
|
|
|
name.erase(std::remove(name.begin(), name.end(), '-'), name.end());
|
|
|
|
|
return name;
|
|
|
|
|
}
|
2026-04-15 18:07:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* ifcopenshell::geometry::kernels::kernel_plugin_registration_symbol() {
|
|
|
|
|
return "ifcopenshell_register_kernel_plugin_v1";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ifcopenshell::plugin::metadata ifcopenshell::geometry::kernels::kernel_plugin_metadata(const std::string& plugin_name) {
|
|
|
|
|
plugin::metadata metadata;
|
|
|
|
|
metadata.kind_ = plugin::kind::kernel;
|
|
|
|
|
metadata.id = kernel_plugin_prefix + plugin_name;
|
|
|
|
|
return metadata;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::filesystem::path ifcopenshell::geometry::kernels::kernel_plugin_directory() {
|
2026-04-17 11:24:09 +02:00
|
|
|
return plugin::module_directory(reinterpret_cast<const void*>(&ifcopenshell::geometry::kernels::load_kernel_plugins));
|
2026-04-15 18:07:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ifcopenshell::geometry::kernels::load_kernel_plugins(kernel_registry& registry) {
|
|
|
|
|
plugin::manager manager;
|
|
|
|
|
manager.add_search_path(kernel_plugin_directory());
|
|
|
|
|
|
|
|
|
|
for (const auto& path : manager.discover(kernel_plugin_prefix)) {
|
|
|
|
|
auto module = manager.load(path);
|
|
|
|
|
if (module.meta().kind_ != plugin::kind::kernel) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto register_plugin = module.get_alias<register_kernel_plugin_fn>(kernel_plugin_registration_symbol());
|
|
|
|
|
register_plugin(registry, module);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-06 21:17:25 +02:00
|
|
|
|
|
|
|
|
bool ifcopenshell::geometry::kernels::load_kernel_plugin(kernel_registry& registry, const std::string& backend_id) {
|
|
|
|
|
plugin::manager manager;
|
|
|
|
|
manager.add_search_path(kernel_plugin_directory());
|
|
|
|
|
|
|
|
|
|
const auto plugin_name = kernel_plugin_name(backend_id);
|
|
|
|
|
const auto basename = std::string(kernel_plugin_prefix) + plugin_name;
|
|
|
|
|
|
|
|
|
|
for (const auto& path : manager.discover_exact(basename)) {
|
|
|
|
|
auto module = manager.load(path);
|
|
|
|
|
if (module.meta().kind_ != plugin::kind::kernel ||
|
|
|
|
|
module.meta().id != basename) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto register_plugin = module.get_alias<register_kernel_plugin_fn>(kernel_plugin_registration_symbol());
|
|
|
|
|
register_plugin(registry, module);
|
|
|
|
|
return registry.has(backend_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|