Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shutdown explicitly while existing #623

Open
wants to merge 2 commits into
base: ros2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ros_gz_sim/src/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,13 @@ int main(int _argc, char ** _argv)

if (!executed) {
RCLCPP_INFO(ros2_node->get_logger(), "Timed out when getting world names.");
rclcpp::shutdown();
return -1;
}

if (!result || worlds_msg.data().empty()) {
RCLCPP_INFO(ros2_node->get_logger(), "Failed to get world names.");
rclcpp::shutdown();
return -1;
}

Expand All @@ -185,6 +187,7 @@ int main(int _argc, char ** _argv)
} else if (!topic_name.empty()) {
// set XML string by fetching it from the given topic
if (!set_XML_from_topic(topic_name, ros2_node, req)) {
rclcpp::shutdown();
return -1;
}
} else if (filtered_arguments.size() > 1) {
Expand All @@ -200,25 +203,29 @@ int main(int _argc, char ** _argv)
} else {
RCLCPP_ERROR(
ros2_node->get_logger(), "Failed to get XML from param [%s].", FLAGS_param.c_str());
rclcpp::shutdown();
return -1;
}
} else if (!FLAGS_string.empty()) { // string
req.set_sdf(FLAGS_string);
} else if (!FLAGS_topic.empty()) { // topic
// set XML string by fetching it from the given topic
if (!set_XML_from_topic(FLAGS_topic, ros2_node, req)) {
rclcpp::shutdown();
return -1;
}
} else {
RCLCPP_ERROR(
ros2_node->get_logger(), "Must specify either -file, -param, -string or -topic");
rclcpp::shutdown();
return -1;
}
// TODO(azeey) Deprecate use of command line flags in ROS 2 K-turtle in
// favor of ROS 2 parameters.
} else {
RCLCPP_ERROR(
ros2_node->get_logger(), "Must specify either file, string or topic as ROS 2 parameters");
rclcpp::shutdown();
return -1;
}

Expand Down Expand Up @@ -261,11 +268,13 @@ int main(int _argc, char ** _argv)
if (node.Request(service, req, timeout, rep, result)) {
if (result && rep.data()) {
RCLCPP_INFO(ros2_node->get_logger(), "Entity creation successfull.");
rclcpp::shutdown();
return 0;
} else {
RCLCPP_ERROR(
ros2_node->get_logger(), "Entity creation failed.\n %s",
req.DebugString().c_str());
rclcpp::shutdown();
return 1;
}
} else {
Expand All @@ -275,5 +284,6 @@ int main(int _argc, char ** _argv)
}
}
RCLCPP_INFO(ros2_node->get_logger(), "Entity creation was interrupted.");
rclcpp::shutdown();
return 0;
}