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

Method Initialize

src/plugins/net_plugin/net_plugin.cc:99–266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99bool NetPlugin::Initialize(runtime::core::AimRTCore* core_ptr) noexcept {
100 try {
101 core_ptr_ = core_ptr;
102
103 YAML::Node plugin_options_node = core_ptr_->GetPluginManager().GetPluginOptionsNode(Name());
104
105 if (plugin_options_node && !plugin_options_node.IsNull()) {
106 options_ = plugin_options_node.as<Options>();
107 }
108
109 init_flag_ = true;
110
111 asio_executor_ptr_ = std::make_shared<aimrt::common::net::AsioExecutor>(options_.thread_num);
112
113 core_ptr_->RegisterHookFunc(runtime::core::AimRTCore::State::kPostInitLog,
114 [this] { SetPluginLogger(); });
115
116 // http
117 http_cli_pool_ptr_ = std::make_shared<aimrt::common::net::AsioHttpClientPool>(asio_executor_ptr_->IO());
118
119 core_ptr_->RegisterHookFunc(
120 runtime::core::AimRTCore::State::kPreStart,
121 [this] {
122 http_cli_pool_ptr_->SetLogger(WrapAimRTLoggerRef(GetLogger()));
123 http_cli_pool_ptr_->Initialize(aimrt::common::net::AsioHttpClientPool::Options{});
124 http_cli_pool_ptr_->Start();
125 });
126
127 core_ptr_->RegisterHookFunc(
128 runtime::core::AimRTCore::State::kPostShutdown,
129 [this] {
130 http_cli_pool_ptr_->Shutdown();
131 });
132
133 core_ptr_->RegisterHookFunc(runtime::core::AimRTCore::State::kPreInitRpc,
134 [this] { RegisterHttpRpcBackend(); });
135
136 core_ptr_->RegisterHookFunc(runtime::core::AimRTCore::State::kPreInitChannel,
137 [this] { RegisterHttpChannelBackend(); });
138
139 if (options_.http_options) {
140 http_svr_ptr_ = std::make_shared<aimrt::common::net::AsioHttpServer>(asio_executor_ptr_->IO());
141 core_ptr_->RegisterHookFunc(
142 runtime::core::AimRTCore::State::kPreStart,
143 [this] {
144 http_svr_ptr_->SetLogger(WrapAimRTLoggerRef(GetLogger()));
145 http_svr_ptr_->Initialize(aimrt::common::net::AsioHttpServer::Options{
146 .ep = {boost::asio::ip::make_address_v4(options_.http_options->listen_ip),
147 options_.http_options->listen_port}});
148 http_svr_ptr_->Start();
149 });
150 core_ptr_->RegisterHookFunc(
151 runtime::core::AimRTCore::State::kPostShutdown,
152 [this] {
153 http_svr_ptr_->Shutdown();
154 });
155 }
156

Callers

nothing calls this directly

Calls 13

GetPluginOptionsNodeMethod · 0.80
RegisterHookFuncMethod · 0.80
IOMethod · 0.80
GetMsgHandleFuncMethod · 0.80
JoinMethod · 0.80
whatMethod · 0.80
WrapAimRTLoggerRefFunction · 0.70
GetLoggerFunction · 0.70
SetLoggerMethod · 0.45
StartMethod · 0.45
ShutdownMethod · 0.45

Tested by

no test coverage detected