| 23 | |
| 24 | namespace aimrt::plugins::topic_logger_plugin { |
| 25 | bool TopicLoggerPlugin::Initialize(runtime::core::AimRTCore* core_ptr) noexcept { |
| 26 | try { |
| 27 | core_ptr_ = core_ptr; |
| 28 | |
| 29 | YAML::Node plugin_options_node = core_ptr_->GetPluginManager().GetPluginOptionsNode(Name()); |
| 30 | |
| 31 | if (plugin_options_node && !plugin_options_node.IsNull()) { |
| 32 | options_ = plugin_options_node.as<Options>(); |
| 33 | } |
| 34 | |
| 35 | init_flag_ = true; |
| 36 | |
| 37 | core_ptr_->RegisterHookFunc(runtime::core::AimRTCore::State::kPreInitLog, |
| 38 | [this] { |
| 39 | RegisterTopicLoggerBackend(); |
| 40 | }); |
| 41 | |
| 42 | core_ptr_->RegisterHookFunc(runtime::core::AimRTCore::State::kPostInitChannel, |
| 43 | [this] {for (const auto& task : post_init_channel_hook_task_vec_) task(); }); |
| 44 | |
| 45 | core_ptr_->RegisterHookFunc(runtime::core::AimRTCore::State::kPreStart, |
| 46 | [this] {for (const auto& task : pre_start_hook_task_vec_) task(); }); |
| 47 | |
| 48 | core_ptr_->RegisterHookFunc(runtime::core::AimRTCore::State::kPostStartChannel, |
| 49 | [this] {for (const auto& task : post_start_channel_hook_task_vec_) task(); }); |
| 50 | |
| 51 | core_ptr_->RegisterHookFunc(runtime::core::AimRTCore::State::kPreShutdownChannel, |
| 52 | [this] { for (const auto& task : pre_shutdown_channel_hook_task_vec_) task(); }); |
| 53 | |
| 54 | plugin_options_node = options_; |
| 55 | core_ptr_->GetPluginManager().UpdatePluginOptionsNode(Name(), plugin_options_node); |
| 56 | |
| 57 | return true; |
| 58 | |
| 59 | } catch (const std::exception& e) { |
| 60 | (void)fprintf(stderr, "TopicLoggerPlugin initialize failed: %s\n", e.what()); |
| 61 | return false; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | void TopicLoggerPlugin::Shutdown() noexcept { |
| 66 | try { |
nothing calls this directly
no test coverage detected