| 73 | namespace aimrt::plugins::echo_plugin { |
| 74 | |
| 75 | bool EchoPlugin::Initialize(runtime::core::AimRTCore* core_ptr) noexcept { |
| 76 | try { |
| 77 | core_ptr_ = core_ptr; |
| 78 | |
| 79 | YAML::Node plugin_options_node = core_ptr_->GetPluginManager().GetPluginOptionsNode(Name()); |
| 80 | |
| 81 | if (plugin_options_node && !plugin_options_node.IsNull()) { |
| 82 | options_ = plugin_options_node.as<Options>(); |
| 83 | AIMRT_TRACE("Load plugin options."); |
| 84 | } |
| 85 | |
| 86 | init_flag_ = true; |
| 87 | // type support |
| 88 | for (auto& type_support_pkg : options_.type_support_pkgs) { |
| 89 | // check duplicate pkg |
| 90 | auto finditr = std::find_if( |
| 91 | options_.type_support_pkgs.begin(), options_.type_support_pkgs.end(), |
| 92 | [&type_support_pkg](const auto& op) { |
| 93 | if (&type_support_pkg == &op) return false; |
| 94 | return op.path == type_support_pkg.path; |
| 95 | }); |
| 96 | AIMRT_CHECK_ERROR_THROW(finditr == options_.type_support_pkgs.end(), |
| 97 | "Duplicate pkg path {}", type_support_pkg.path); |
| 98 | |
| 99 | InitTypeSupport(type_support_pkg); |
| 100 | } |
| 101 | AIMRT_TRACE("Load {} pkg and {} type.", |
| 102 | type_support_pkg_loader_vec_.size(), type_support_map_.size()); |
| 103 | |
| 104 | for (auto& topic_meta : options_.topic_meta_list) { |
| 105 | // check msg type |
| 106 | auto finditr = type_support_map_.find(topic_meta.msg_type); |
| 107 | AIMRT_CHECK_ERROR_THROW(finditr != type_support_map_.end(), |
| 108 | "Can not find type '{}' in any type support pkg!", topic_meta.msg_type); |
| 109 | } |
| 110 | |
| 111 | // check duplicate topic |
| 112 | for (auto& topic_meta_option : options_.topic_meta_list) { |
| 113 | runtime::core::util::TopicMetaKey key{ |
| 114 | .topic_name = topic_meta_option.topic_name, |
| 115 | .msg_type = topic_meta_option.msg_type}; |
| 116 | |
| 117 | AIMRT_CHECK_ERROR_THROW( |
| 118 | topic_meta_map_.find(key) == topic_meta_map_.end(), |
| 119 | "Duplicate topic meta, topic name: {}, msg type: {}.", |
| 120 | topic_meta_option.topic_name, topic_meta_option.msg_type); |
| 121 | |
| 122 | TopicMeta topic_meta{ |
| 123 | .topic_name = topic_meta_option.topic_name, |
| 124 | .msg_type = topic_meta_option.msg_type, |
| 125 | .echo_type = topic_meta_option.echo_type, |
| 126 | }; |
| 127 | topic_meta_map_.emplace(key, topic_meta); |
| 128 | } |
| 129 | |
| 130 | core_ptr_->RegisterHookFunc( |
| 131 | runtime::core::AimRTCore::State::kPostInitLog, |
| 132 | [this] { |
nothing calls this directly
no test coverage detected