From b992e51d4486afbcebae79d13a47ded87f01ca02 Mon Sep 17 00:00:00 2001 From: yuanyuyuan Date: Mon, 25 Nov 2024 16:07:01 +0800 Subject: [PATCH] Revert "Don't shutdown contained entities. (#313)" This reverts commit 536695758b3e6ddbb7ccc341976280367262532c. --- .../src/detail/rmw_context_impl_s.cpp | 13 +++++ rmw_zenoh_cpp/src/detail/rmw_node_data.cpp | 50 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp b/rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp index 973862f8..bcbd1d6f 100644 --- a/rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp +++ b/rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp @@ -218,6 +218,19 @@ class rmw_context_impl_s::Data final return ret; } + // Shutdown all the nodes in this context. + for (auto node_it = nodes_.begin(); node_it != nodes_.end(); ++node_it) { + ret = node_it->second->shutdown(); + if (ret != RMW_RET_OK) { + RMW_ZENOH_LOG_ERROR_NAMED( + "rmw_zenoh_cpp", + "Unable to shutdown node with id %zu. rmw_ret_t code: %zu.", + node_it->second->id(), + ret + ); + } + } + z_undeclare_subscriber(z_move(graph_subscriber_)); #ifdef RMW_ZENOH_BUILD_WITH_SHARED_MEMORY // drop SHM subsystem if used diff --git a/rmw_zenoh_cpp/src/detail/rmw_node_data.cpp b/rmw_zenoh_cpp/src/detail/rmw_node_data.cpp index 96d95191..24f2c1f0 100644 --- a/rmw_zenoh_cpp/src/detail/rmw_node_data.cpp +++ b/rmw_zenoh_cpp/src/detail/rmw_node_data.cpp @@ -401,6 +401,56 @@ rmw_ret_t NodeData::shutdown() return ret; } + // Shutdown all the entities within this node. + for (auto pub_it = pubs_.begin(); pub_it != pubs_.end(); ++pub_it) { + ret = pub_it->second->shutdown(); + if (ret != RMW_RET_OK) { + RMW_ZENOH_LOG_ERROR_NAMED( + "rmw_zenoh_cpp", + "Unable to shutdown publisher %s within id %zu. rmw_ret_t code: %zu.", + pub_it->second->topic_info().name_.c_str(), + id_, + ret + ); + } + } + for (auto sub_it = subs_.begin(); sub_it != subs_.end(); ++sub_it) { + ret = sub_it->second->shutdown(); + if (ret != RMW_RET_OK) { + RMW_ZENOH_LOG_ERROR_NAMED( + "rmw_zenoh_cpp", + "Unable to shutdown subscription %s within id %zu. rmw_ret_t code: %zu.", + sub_it->second->topic_info().name_.c_str(), + id_, + ret + ); + } + } + for (auto srv_it = services_.begin(); srv_it != services_.end(); ++srv_it) { + ret = srv_it->second->shutdown(); + if (ret != RMW_RET_OK) { + RMW_ZENOH_LOG_ERROR_NAMED( + "rmw_zenoh_cpp", + "Unable to shutdown service %s within id %zu. rmw_ret_t code: %zu.", + srv_it->second->topic_info().name_.c_str(), + id_, + ret + ); + } + } + for (auto cli_it = clients_.begin(); cli_it != clients_.end(); ++cli_it) { + ret = cli_it->second->shutdown(); + if (ret != RMW_RET_OK) { + RMW_ZENOH_LOG_ERROR_NAMED( + "rmw_zenoh_cpp", + "Unable to shutdown client %s within id %zu. rmw_ret_t code: %zu.", + cli_it->second->topic_info().name_.c_str(), + id_, + ret + ); + } + } + // Unregister this node from the ROS graph. zc_liveliness_undeclare_token(z_move(token_));