mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 10:33:20 +00:00
tree and document plug-ins
This commit is contained in:
@@ -19,6 +19,12 @@
|
||||
|
||||
#include "plugin.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <dlfcn.h>
|
||||
#else
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/dll/shared_library.hpp>
|
||||
|
||||
@@ -195,3 +201,30 @@ void ifcopenshell::plugin::validate_abi(const abi_info& abi) {
|
||||
stream << " (plugin debug " << abi.debug_build << ", host debug " << host.debug_build << ")";
|
||||
throw std::runtime_error(stream.str());
|
||||
}
|
||||
|
||||
std::filesystem::path ifcopenshell::plugin::module_directory(const void* symbol) {
|
||||
#ifdef _WIN32
|
||||
HMODULE module_handle = nullptr;
|
||||
if (!GetModuleHandleExW(
|
||||
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||
reinterpret_cast<LPCWSTR>(symbol),
|
||||
&module_handle)) {
|
||||
throw std::runtime_error("Unable to resolve module path");
|
||||
}
|
||||
|
||||
wchar_t buffer[MAX_PATH];
|
||||
const DWORD length = GetModuleFileNameW(module_handle, buffer, MAX_PATH);
|
||||
if (length == 0) {
|
||||
throw std::runtime_error("Unable to read module filename");
|
||||
}
|
||||
|
||||
return std::filesystem::path(std::wstring(buffer, length)).parent_path();
|
||||
#else
|
||||
Dl_info info;
|
||||
if (dladdr(symbol, &info) == 0 || !info.dli_fname) {
|
||||
throw std::runtime_error("Unable to resolve module path");
|
||||
}
|
||||
|
||||
return std::filesystem::path(info.dli_fname).parent_path();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ enum class kind {
|
||||
parse_schema,
|
||||
mapping,
|
||||
kernel,
|
||||
tree,
|
||||
document_serializer,
|
||||
geometry_serializer,
|
||||
opencascade_geometry_ifc_writer
|
||||
@@ -101,6 +102,7 @@ private:
|
||||
|
||||
PLUGIN_API abi_info host_abi();
|
||||
PLUGIN_API void validate_abi(const abi_info& abi);
|
||||
PLUGIN_API std::filesystem::path module_directory(const void* symbol);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@
|
||||
#ifndef PLUGIN_API_H
|
||||
#define PLUGIN_API_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef SWIG
|
||||
#define PLUGIN_API
|
||||
#elif defined(_WIN32)
|
||||
#ifdef PLUGIN_EXPORTS
|
||||
#define PLUGIN_API __declspec(dllexport)
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user