MCPcopy Create free account
hub / github.com/AimRT/AimRT / Initialize

Method Initialize

src/runtime/core/plugin/plugin_manager.cc:52–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50namespace aimrt::runtime::core::plugin {
51
52void PluginManager::Initialize(YAML::Node options_node) {
53 AIMRT_CHECK_ERROR_THROW(
54 core_ptr_,
55 "AimRT core point is not set before PluginManager initialize.");
56
57 AIMRT_CHECK_ERROR_THROW(
58 std::atomic_exchange(&state_, State::kInit) == State::kPreInit,
59 "Plugin manager can only be initialized once.");
60
61 if (options_node && !options_node.IsNull())
62 options_ = options_node.as<Options>();
63
64 auto tmp_registered_plugin_vec = registered_plugin_vec_;
65
66 // Load and initialize all plugins
67 for (auto& plugin_options : options_.plugins_options) {
68 // Check duplicate plugin name
69 auto finditr = std::find_if(
70 options_.plugins_options.begin(), options_.plugins_options.end(),
71 [&plugin_options](const auto& op) {
72 if (&plugin_options == &op) return false;
73 return op.name == plugin_options.name;
74 });
75 AIMRT_CHECK_ERROR_THROW(finditr == options_.plugins_options.end(),
76 "Duplicate plugin name {}", plugin_options.name);
77
78 AimRTCorePluginBase* plugin_ptr = nullptr;
79
80 if (!plugin_options.path.empty()) {
81 // Loading plugins
82 auto plugin_loader_ptr = std::make_unique<PluginLoader>();
83 plugin_loader_ptr->SetLogger(logger_ptr_);
84 plugin_loader_ptr->LoadPlugin(plugin_options.path);
85
86 plugin_ptr = plugin_loader_ptr->GetPlugin();
87
88 auto plugin_name = plugin_ptr->Name();
89
90 // Check the plugin name
91 AIMRT_CHECK_ERROR_THROW(
92 plugin_name == plugin_options.name,
93 "Require plugin name '{}', but get plugin name '{}' in lib {}.",
94 plugin_options.name, plugin_name, plugin_options.path);
95
96 plugin_options.path = plugin_loader_ptr->GetDynamicLib().GetLibFullPath();
97
98 plugin_loader_vec_.emplace_back(std::move(plugin_loader_ptr));
99
100 } else {
101 // Find in directly registered plugins
102 auto finditr = std::find_if(
103 tmp_registered_plugin_vec.begin(), tmp_registered_plugin_vec.end(),
104 [&plugin_options](const AimRTCorePluginBase* plugin) {
105 return plugin->Name() == plugin_options.name;
106 });
107
108 AIMRT_CHECK_ERROR_THROW(finditr != tmp_registered_plugin_vec.end(),
109 "Can not find plugin {}", plugin_options.name);

Callers

nothing calls this directly

Calls 5

JoinVecFunction · 0.85
LoadPluginMethod · 0.80
GetPluginMethod · 0.80
SetLoggerMethod · 0.45
NameMethod · 0.45

Tested by

no test coverage detected