| 395 | Span<const Plugin> Plugin::plugins() noexcept { return PluginRegistry; } |
| 396 | |
| 397 | bool Plugin::loadFile(const std::filesystem::path &Path) noexcept { |
| 398 | std::unique_lock Lock(Mutex); |
| 399 | bool Result = false; |
| 400 | auto Lib = std::make_shared<Loader::SharedLibrary>(); |
| 401 | if (auto Res = Lib->load(Path); unlikely(!Res)) { |
| 402 | return false; |
| 403 | } |
| 404 | |
| 405 | if (auto GetDescriptor = |
| 406 | Lib->get<Plugin::PluginDescriptor const *()>("GetDescriptor")) { |
| 407 | Result = Plugin::registerPlugin(GetDescriptor()); |
| 408 | } |
| 409 | |
| 410 | if (!Result) { |
| 411 | // Check C interface |
| 412 | if (auto GetDescriptor = Lib->get<decltype(WasmEdge_Plugin_GetDescriptor)>( |
| 413 | "WasmEdge_Plugin_GetDescriptor"); |
| 414 | unlikely(!GetDescriptor)) { |
| 415 | return false; |
| 416 | } else if (const auto *Descriptor = GetDescriptor(); |
| 417 | unlikely(!Descriptor)) { |
| 418 | return false; |
| 419 | } else { |
| 420 | Result = |
| 421 | CAPIPluginRegisters |
| 422 | .emplace_back(std::make_unique<CAPIPluginRegister>(Descriptor)) |
| 423 | ->result(); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | if (!Result) { |
| 428 | return false; |
| 429 | } |
| 430 | |
| 431 | auto &Plugin = PluginRegistry.back(); |
| 432 | Plugin.Path = Path; |
| 433 | Plugin.Lib = std::move(Lib); |
| 434 | return true; |
| 435 | } |
| 436 | |
| 437 | void Plugin::registerBuiltInPlugins() noexcept { |
| 438 | std::unique_lock Lock(Mutex); |