| 54 | } |
| 55 | |
| 56 | bool PluginManager::loadPlugin(const std::filesystem::path& path) |
| 57 | { |
| 58 | // Early exit if plugin is already loaded. |
| 59 | { |
| 60 | std::lock_guard<std::mutex> lock(mLibrariesMutex); |
| 61 | if (mLibraries.find(path) != mLibraries.end()) |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | if (!std::filesystem::exists(path)) |
| 66 | FALCOR_THROW("Failed to load plugin library from {}. File not found.", path); |
| 67 | |
| 68 | SharedLibraryHandle library = loadSharedLibrary(path); |
| 69 | if (library == nullptr) |
| 70 | FALCOR_THROW("Failed to load plugin library from {}. Cannot load shared library.", path); |
| 71 | |
| 72 | using RegisterPluginProc = void (*)(PluginRegistry&); |
| 73 | |
| 74 | auto registerPluginProc = (RegisterPluginProc)getProcAddress(library, "registerPlugin"); |
| 75 | if (registerPluginProc == nullptr) |
| 76 | FALCOR_THROW("Failed to load plugin library from {}. Symbol 'registerPlugin' not found.", path); |
| 77 | |
| 78 | // Register plugin library. |
| 79 | { |
| 80 | std::lock_guard<std::mutex> lock(mLibrariesMutex); |
| 81 | mLibraries[path] = library; |
| 82 | } |
| 83 | |
| 84 | // Call plugin library to register plugin classes. |
| 85 | { |
| 86 | PluginRegistry registry(*this, library); |
| 87 | registerPluginProc(registry); |
| 88 | } |
| 89 | |
| 90 | return true; |
| 91 | } |
| 92 | |
| 93 | bool PluginManager::releasePlugin(const std::filesystem::path& path) |
| 94 | { |
nothing calls this directly
no test coverage detected