| 314 | */ |
| 315 | template <typename T> |
| 316 | bool PluginManager<T>::loadByPath(const std::string& path) |
| 317 | { |
| 318 | if (libraryLoaded(path)) |
| 319 | return true; |
| 320 | |
| 321 | m_log->get(LogLevel::Debug) << "Attempting to load plugin '" << |
| 322 | path << "'." << std::endl; |
| 323 | DynamicLibrary *d = loadLibrary(path); |
| 324 | if (!d) |
| 325 | return false; |
| 326 | |
| 327 | m_log->get(LogLevel::Debug) << "Loaded plugin '" << path << |
| 328 | "'." << std::endl; |
| 329 | PF_InitFunc initFunc; |
| 330 | |
| 331 | // This awfulness is to work around a warning that some compilers |
| 332 | // generate when casting a void * to a function *. See the example |
| 333 | // in the dlsym manpage. |
| 334 | *(void **)(&initFunc) = d->getSymbol("PF_initPlugin"); |
| 335 | if (!initFunc) |
| 336 | { |
| 337 | m_log->get(LogLevel::Debug) << "No symbol 'PF_initPlugin' found " |
| 338 | "in plugin '" << path << "'." << std::endl; |
| 339 | return false; |
| 340 | } |
| 341 | initFunc(); |
| 342 | m_log->get(LogLevel::Debug) << "Initialized plugin '" << |
| 343 | path << "'." << std::endl; |
| 344 | |
| 345 | return true; |
| 346 | } |
| 347 | |
| 348 | |
| 349 | template <typename T> |