| 12 | static constexpr const char* kDynlibDestroyCorePluginFuncName = "AimRTDynlibDestroyCorePluginHandle"; |
| 13 | |
| 14 | void PluginLoader::LoadPlugin(std::string_view plugin_path) { |
| 15 | plugin_path_ = plugin_path; |
| 16 | |
| 17 | AIMRT_CHECK_ERROR_THROW(dynamic_lib_.Load(plugin_path_), |
| 18 | "Load dynamic lib failed, lib path {}, error info {}", |
| 19 | plugin_path_, aimrt::common::util::DynamicLib::GetErr()); |
| 20 | |
| 21 | auto* create_func = dynamic_lib_.GetSymbol(kDynlibCreateCorePluginFuncName); |
| 22 | AIMRT_CHECK_ERROR_THROW(create_func != nullptr, |
| 23 | "Cannot find symbol '{}' in lib {}.", |
| 24 | kDynlibCreateCorePluginFuncName, plugin_path_); |
| 25 | |
| 26 | destroy_func_ = dynamic_lib_.GetSymbol(kDynlibDestroyCorePluginFuncName); |
| 27 | AIMRT_CHECK_ERROR_THROW(destroy_func_ != nullptr, |
| 28 | "Cannot find symbol '{}' in lib {}.", |
| 29 | kDynlibDestroyCorePluginFuncName, plugin_path_); |
| 30 | |
| 31 | // Loading plugin |
| 32 | plugin_ptr_ = ((DynlibCreateCorePluginFunc)create_func)(); |
| 33 | |
| 34 | AIMRT_CHECK_ERROR_THROW(plugin_ptr_ != nullptr, |
| 35 | "Cannot create plugin in lib {}.", plugin_path_); |
| 36 | } |
| 37 | |
| 38 | void PluginLoader::UnLoadPlugin() { |
| 39 | if (!dynamic_lib_.IsLoaded()) return; |
no test coverage detected