| 162 | } |
| 163 | |
| 164 | bool load (const std::string& inPath, std::string& errorDescription) override |
| 165 | { |
| 166 | auto modulePath = getSOPath (inPath); |
| 167 | if (!modulePath) |
| 168 | { |
| 169 | errorDescription = inPath + " is not a module directory."; |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | mModule = dlopen (reinterpret_cast<const char*> (modulePath->generic_string ().data ()), |
| 174 | RTLD_LAZY); |
| 175 | if (!mModule) |
| 176 | { |
| 177 | errorDescription = "dlopen failed.\n"; |
| 178 | errorDescription += dlerror (); |
| 179 | return false; |
| 180 | } |
| 181 | // ModuleEntry is mandatory |
| 182 | auto moduleEntry = getFunctionPointer<ModuleEntryFunc> ("ModuleEntry"); |
| 183 | if (!moduleEntry) |
| 184 | { |
| 185 | errorDescription = |
| 186 | "The shared library does not export the required 'ModuleEntry' function"; |
| 187 | return false; |
| 188 | } |
| 189 | // ModuleExit is mandatory |
| 190 | auto moduleExit = getFunctionPointer<ModuleExitFunc> ("ModuleExit"); |
| 191 | if (!moduleExit) |
| 192 | { |
| 193 | errorDescription = |
| 194 | "The shared library does not export the required 'ModuleExit' function"; |
| 195 | return false; |
| 196 | } |
| 197 | auto factoryProc = getFunctionPointer<GetFactoryProc> ("GetPluginFactory"); |
| 198 | if (!factoryProc) |
| 199 | { |
| 200 | errorDescription = |
| 201 | "The shared library does not export the required 'GetPluginFactory' function"; |
| 202 | return false; |
| 203 | } |
| 204 | |
| 205 | if (!moduleEntry (mModule)) |
| 206 | { |
| 207 | errorDescription = "Calling 'ModuleEntry' failed"; |
| 208 | return false; |
| 209 | } |
| 210 | auto f = Steinberg::FUnknownPtr<Steinberg::IPluginFactory> (owned (factoryProc ())); |
| 211 | if (!f) |
| 212 | { |
| 213 | errorDescription = "Calling 'GetPluginFactory' returned nullptr"; |
| 214 | return false; |
| 215 | } |
| 216 | factory = PluginFactory (f); |
| 217 | return true; |
| 218 | } |
| 219 | |
| 220 | void* mModule {nullptr}; |
| 221 | }; |