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

Method Initialize

src/plugins/proxy_plugin/proxy_plugin.cc:72–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70namespace aimrt::plugins::proxy_plugin {
71
72bool ProxyPlugin::Initialize(runtime::core::AimRTCore* core_ptr) noexcept {
73 try {
74 core_ptr_ = core_ptr;
75
76 YAML::Node plugin_options_node = core_ptr_->GetPluginManager().GetPluginOptionsNode(Name());
77
78 if (plugin_options_node && !plugin_options_node.IsNull()) {
79 options_ = plugin_options_node.as<Options>();
80 AIMRT_TRACE("Load plugin options.");
81 }
82
83 init_flag_ = true;
84 // type support
85 for (auto& type_support_pkg : options_.type_support_pkgs) {
86 // check duplicate pkg
87 auto finditr = std::find_if(
88 options_.type_support_pkgs.begin(), options_.type_support_pkgs.end(),
89 [&type_support_pkg](const auto& op) {
90 if (&type_support_pkg == &op) return false;
91 return op.path == type_support_pkg.path;
92 });
93 AIMRT_CHECK_ERROR_THROW(finditr == options_.type_support_pkgs.end(),
94 "Duplicate pkg path {}", type_support_pkg.path);
95 InitTypeSupport(type_support_pkg);
96 }
97 AIMRT_TRACE("Load {} pkg and {} type.",
98 type_support_pkg_loader_vec_.size(), type_support_map_.size());
99
100 // proxy action
101 for (auto& proxy_action : options_.proxy_actions) {
102 // check duplicate proxy action name
103 auto finditr = std::find_if(
104 options_.proxy_actions.begin(), options_.proxy_actions.end(),
105 [&proxy_action](const auto& op) {
106 if (&proxy_action == &op) return false;
107 return op.name == proxy_action.name;
108 });
109 AIMRT_CHECK_ERROR_THROW(finditr == options_.proxy_actions.end(),
110 "Duplicate proxy action name {}", proxy_action.name);
111
112 auto action_ptr = std::make_unique<ProxyAction>();
113
114 action_ptr->RegisterGetExecutorFunc([this](std::string_view name) -> aimrt::executor::ExecutorRef {
115 return core_ptr_->GetExecutorManager().GetExecutor(name);
116 });
117 action_ptr->RegisterGetTypeSupportFunc([this](std::string_view name) -> aimrt::util::TypeSupportRef {
118 auto finditr = type_support_map_.find(name);
119 AIMRT_CHECK_ERROR_THROW(finditr != type_support_map_.end(),
120 "Can not find type support for msg type '{}'.", name);
121 return finditr->second.type_support_ref;
122 });
123 action_ptr->Initialize(proxy_action.options);
124
125 proxy_action_map_.emplace(proxy_action.name, std::move(action_ptr));
126 }
127
128 core_ptr_->RegisterHookFunc(
129 runtime::core::AimRTCore::State::kPostInitLog,

Callers

nothing calls this directly

Calls 13

LoggerRefClass · 0.85
GetSimpleLoggerRefFunction · 0.85
GetPluginOptionsNodeMethod · 0.80
GetExecutorManagerMethod · 0.80
RegisterHookFuncMethod · 0.80
whatMethod · 0.80
SetLoggerFunction · 0.70
GetExecutorMethod · 0.45
NativeHandleMethod · 0.45

Tested by

no test coverage detected