| 432 | } |
| 433 | |
| 434 | static std::shared_ptr<PluginLibrary> LoadFromPath(const std::string& path, |
| 435 | const std::string& type) { |
| 436 | std::shared_ptr<SharedLibrary> library(new SharedLibrary(path)); |
| 437 | typedef const opencc_segmentation_plugin_v2* (*EntryPoint)(void); |
| 438 | EntryPoint entryPoint = reinterpret_cast<EntryPoint>( |
| 439 | library->FindSymbol("opencc_get_segmentation_plugin_v2")); |
| 440 | const opencc_segmentation_plugin_v2* descriptor = entryPoint(); |
| 441 | if (descriptor == nullptr) { |
| 442 | throw Exception("Plugin returned null descriptor."); |
| 443 | } |
| 444 | if (descriptor->struct_size < RequiredDescriptorSize()) { |
| 445 | throw Exception("Plugin descriptor is too small."); |
| 446 | } |
| 447 | if (descriptor->abi_major != OPENCC_SEGMENTATION_PLUGIN_ABI_MAJOR) { |
| 448 | throw Exception("Plugin ABI major version mismatch."); |
| 449 | } |
| 450 | if (descriptor->abi_minor < OPENCC_SEGMENTATION_PLUGIN_ABI_MINOR) { |
| 451 | throw Exception("Plugin ABI minor version is older than required by the host."); |
| 452 | } |
| 453 | if (descriptor->segmentation_type == nullptr || |
| 454 | type != descriptor->segmentation_type) { |
| 455 | throw Exception("Plugin type mismatch."); |
| 456 | } |
| 457 | std::shared_ptr<PluginLibrary> plugin(new PluginLibrary); |
| 458 | plugin->library = library; |
| 459 | plugin->descriptor = descriptor; |
| 460 | return plugin; |
| 461 | } |
| 462 | |
| 463 | std::mutex mutex_; |
| 464 | std::unordered_map<std::string, std::shared_ptr<PluginLibrary>> cache_; |
nothing calls this directly
no test coverage detected