Skip to content

Commit

Permalink
Revert "Don't shutdown contained entities. (ros2#313)"
Browse files Browse the repository at this point in the history
This reverts commit 5366957.
  • Loading branch information
YuanYuYuan authored and imstevenpmwork committed Dec 5, 2024
1 parent d395c37 commit b992e51
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
13 changes: 13 additions & 0 deletions rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions rmw_zenoh_cpp/src/detail/rmw_node_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_));

Expand Down

0 comments on commit b992e51

Please sign in to comment.