3#include <ghc/fs_std.hpp>
11 std::shared_ptr<Plugin> plugin = std::make_shared<Plugin>();
15 plugin->mHnd = ::dlopen(file.c_str(), RTLD_LAZY);
17 plugin->mHnd = (
void*) ::LoadLibraryA(file.c_str());
19 if (plugin->mHnd ==
nullptr) {
23 plugin->mIsLoaded =
true;
31 if (dllEntryPoint ==
nullptr) {
35 plugin->mEntryPoint = dllEntryPoint();
43 mHnd = std::move(rhs.mHnd);
44 mFile = std::move(rhs.mFile);
60 if (
mHnd !=
nullptr) {
64 ::FreeLibrary((HMODULE)
mHnd);
74 std::swap(rhs.mHnd,
mHnd);
75 std::swap(rhs.mFile,
mFile);
92 std::lock_guard<std::mutex> tLock(
mMutex);
93 ins =
pInstance.load(std::memory_order_relaxed);
96 pInstance.store(ins, std::memory_order_release);
108#elif defined(__unix__) && !defined(__apple__)
110#elif defined(__apple__)
113#error "Not implemented for this platform"
121 if (plugin !=
nullptr)
123 std::cout <<
"\033[32m\033[1m" <<
"[Plugin]: loading " << pluginName <<
" in success " <<
"\033[0m" << std::endl;
130 std::cout <<
"\033[31m\033[1m" <<
"[Plugin]: loading " << pluginName <<
" in failure " <<
"\033[0m" << std::endl;
138 fs::path file_path(pathName);
140 std::error_code error;
141 auto file_status = fs::status(file_path, error);
142 if (!fs::exists(file_status)) {
143 std::cout <<
"Plugin path do not exist !" << std::endl;
147 for (
const auto& entry : fs::directory_iterator(pathName))
149 std::string name = entry.path().filename().string();
150 if (entry.path().extension() ==
getExtension() && name.find(
"plugin-") != std::string::npos)
159 auto it =
mPlugins.find(pluginName);
static std::shared_ptr< Plugin > load(std::string file)
std::string mFile
Shared library file name.
bool mIsLoaded
Flag to indicate whether plugin (shared library) is loaded into current process.
PluginEntry * mEntryPoint
Pointer to shared library factory class returned by the DLL entry-point function.
PluginEntry * getInfo() const
Plugin & operator=(const Plugin &)=delete
PluginEntry *(*)() PluginEntryFunc
Function pointer to DLL entry-point.
static constexpr const char * PluginEntryName
Name of DLL entry point that a Plugin should export.
void * mHnd
Shared library handle.
static PluginManager * instance()
bool loadPlugin(const std::string &pluginName)
void loadPluginByPath(const std::string &pathName)
std::shared_ptr< Plugin > getPlugin(const char *pluginName)
static std::atomic< PluginManager * > pInstance
std::string getExtension() const
This is an implementation of AdditiveCCD based on peridyno.