MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/xstudio / load_plugins

Method load_plugins

src/plugin_manager/src/plugin_manager.cpp:46–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44 : plugin_paths_(std::move(plugin_paths)) {}
45
46size_t PluginManager::load_plugins() {
47 // scan for .so or .dll for each path.
48 size_t loaded = 0;
49
50 for (const auto &path : plugin_paths_) {
51 try {
52 // read dir content..
53 for (const auto &entry : fs::directory_iterator(path)) {
54 if (not fs::is_regular_file(entry.status()))
55 continue;
56
57#ifdef _WIN32
58
59 if (entry.path().extension() != ".dll")
60 continue;
61
62 // open .dll
63 std::string dllPath = entry.path().string();
64
65 HMODULE hndl = LoadLibraryA(dllPath.c_str());
66 if (hndl == nullptr) {
67 DWORD errorCode = GetLastError();
68 LPSTR buffer = nullptr;
69 DWORD size = FormatMessageA(
70 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
71 FORMAT_MESSAGE_IGNORE_INSERTS,
72 nullptr,
73 errorCode,
74 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
75 reinterpret_cast<LPSTR>(&buffer),
76 0,
77 nullptr);
78 std::string errorMsg(buffer, size);
79 LocalFree(buffer);
80 spdlog::warn("{} {}", __PRETTY_FUNCTION__, errorMsg);
81 continue;
82 }
83
84 plugin_factory_collection_ptr pfcp;
85 pfcp = reinterpret_cast<plugin_factory_collection_ptr>(
86 GetProcAddress(hndl, "plugin_factory_collection_ptr"));
87
88 if (pfcp == nullptr) {
89 spdlog::debug("{} {}", __PRETTY_FUNCTION__, GetLastErrorAsString());
90 FreeLibrary(hndl);
91 continue;
92 }
93#else
94 if (entry.path().extension() != ".so" && entry.path().extension() != ".dylib")
95 continue;
96 // only want .so / .dylib
97 // clear any errors..
98 dlerror();
99
100 // open .so
101 void *hndl = dlopen(entry.path().c_str(), RTLD_NOW);
102 if (hndl == nullptr) {
103 spdlog::warn("{} {}", __PRETTY_FUNCTION__, dlerror());

Callers 2

TESTFunction · 0.80
PluginManagerActorMethod · 0.80

Calls 10

GetLastErrorAsStringFunction · 0.85
PluginEntryClass · 0.85
whatMethod · 0.80
to_stringFunction · 0.50
statusMethod · 0.45
pathMethod · 0.45
stringMethod · 0.45
countMethod · 0.45
uuidMethod · 0.45
nameMethod · 0.45

Tested by 1

TESTFunction · 0.64