Functor operator, gets invoked on directory traversal
| 30 | |
| 31 | // Functor operator, gets invoked on directory traversal |
| 32 | void ModuleLoader::processModuleFile(const fs::path& file) |
| 33 | { |
| 34 | // Check for the correct extension of the visited file |
| 35 | if (string::to_lower_copy(file.extension().string()) != MODULE_FILE_EXTENSION) return; |
| 36 | |
| 37 | std::string fullName = file.string(); |
| 38 | rMessage() << "ModuleLoader: Loading module '" << fullName << "'" << std::endl; |
| 39 | |
| 40 | // Skip the core module binary |
| 41 | if (file.filename() == CoreModule::Filename()) |
| 42 | { |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | // Create the encapsulator class |
| 47 | auto library = std::make_shared<DynamicLibrary>(fullName); |
| 48 | |
| 49 | // greebo: Try to find our entry point and invoke it and add the library to the list |
| 50 | // on success. If the load fails, the shared pointer won't be added and |
| 51 | // self-destructs at the end of this scope. |
| 52 | if (library->failed()) |
| 53 | { |
| 54 | rError() << "WARNING: Failed to load module " << library->getName() << ":" << std::endl; |
| 55 | |
| 56 | #ifdef __linux__ |
| 57 | rConsoleError() << dlerror() << std::endl; |
| 58 | #endif |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | // Library was successfully loaded, lookup the symbol |
| 63 | auto funcPtr = library->findSymbol(SYMBOL_REGISTER_MODULE); |
| 64 | |
| 65 | if (funcPtr == nullptr) |
| 66 | { |
| 67 | // Symbol lookup error |
| 68 | rError() << "WARNING: Could not find symbol " << SYMBOL_REGISTER_MODULE |
| 69 | << " in module " << library->getName() << ":" << std::endl; |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | // Brute-force conversion of the pointer to the desired type |
| 74 | auto regFunc = reinterpret_cast<RegisterModulesFunc>(funcPtr); |
| 75 | |
| 76 | try |
| 77 | { |
| 78 | // Call the symbol and pass a reference to the ModuleRegistry |
| 79 | // This method might throw a ModuleCompatibilityException in its |
| 80 | // module::performDefaultInitialisation() routine. |
| 81 | regFunc(_registry); |
| 82 | |
| 83 | // Add the library to the static list (for later reference) |
| 84 | _dynamicLibraryList.push_back(library); |
| 85 | } |
| 86 | catch (module::ModuleCompatibilityException&) |
| 87 | { |
| 88 | // Report this error and don't add the module to the _dynamicLibraryList |
| 89 | rError() << "Compatibility mismatch loading library " << library->getName() << std::endl; |
nothing calls this directly
no test coverage detected