From 16323b3f92ccb3126a09922ca095745045d5ad87 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Wed, 1 Jul 2015 14:45:38 -0700 Subject: [PATCH] avoid streaming directly to std::cerr --- rclcpp/include/rclcpp/client.hpp | 10 ++++------ rclcpp/include/rclcpp/node_impl.hpp | 8 +++++--- rclcpp/include/rclcpp/publisher.hpp | 10 ++++++---- rclcpp/include/rclcpp/service.hpp | 10 ++++++---- rclcpp/include/rclcpp/subscription.hpp | 10 ++++++---- rclcpp/include/rclcpp/timer.hpp | 10 ++++++---- 6 files changed, 33 insertions(+), 25 deletions(-) diff --git a/rclcpp/include/rclcpp/client.hpp b/rclcpp/include/rclcpp/client.hpp index ee09193..1a70723 100644 --- a/rclcpp/include/rclcpp/client.hpp +++ b/rclcpp/include/rclcpp/client.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -56,12 +57,9 @@ public: ~ClientBase() { if (client_handle_) { - if (rmw_destroy_client(client_handle_) == RMW_RET_ERROR) { - // *INDENT-OFF* - std::cerr << "Error in destruction of rmw client handle: " - << rmw_get_error_string_safe() - << std::endl; - // *INDENT-ON* + if (rmw_destroy_client(client_handle_) != RMW_RET_OK) { + fprintf(stderr, + "Error in destruction of rmw client handle: %s\n", rmw_get_error_string_safe()); } } } diff --git a/rclcpp/include/rclcpp/node_impl.hpp b/rclcpp/include/rclcpp/node_impl.hpp index 970ecdd..7e18dae 100644 --- a/rclcpp/include/rclcpp/node_impl.hpp +++ b/rclcpp/include/rclcpp/node_impl.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -51,10 +52,11 @@ Node::Node(std::string node_name, context::Context::SharedPtr context) auto ret = rmw_destroy_node(node); if (ret != RMW_RET_OK) { // *INDENT-OFF* - std::cerr << "Error in destruction of rmw node handle: " - << rmw_get_error_string_safe() - << std::endl; + std::stringstream ss; + ss << "Error in destruction of rmw node handle: " + << rmw_get_error_string_safe() << '\n'; // *INDENT-ON* + (std::cerr << ss.str()).flush(); } } }); diff --git a/rclcpp/include/rclcpp/publisher.hpp b/rclcpp/include/rclcpp/publisher.hpp index a16bbcb..e481bfd 100644 --- a/rclcpp/include/rclcpp/publisher.hpp +++ b/rclcpp/include/rclcpp/publisher.hpp @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -47,12 +48,13 @@ public: ~Publisher() { if (publisher_handle_) { - if (rmw_destroy_publisher(node_handle_.get(), publisher_handle_) == RMW_RET_ERROR) { + if (rmw_destroy_publisher(node_handle_.get(), publisher_handle_) != RMW_RET_OK) { // *INDENT-OFF* - std::cerr << "Error in destruction of rmw publisher handle: " - << rmw_get_error_string_safe() - << std::endl; + std::stringstream ss; + ss << "Error in destruction of rmw publisher handle: " + << rmw_get_error_string_safe() << '\n'; // *INDENT-ON* + (std::cerr << ss.str()).flush(); } } } diff --git a/rclcpp/include/rclcpp/service.hpp b/rclcpp/include/rclcpp/service.hpp index 0c54fff..c05282e 100644 --- a/rclcpp/include/rclcpp/service.hpp +++ b/rclcpp/include/rclcpp/service.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -55,10 +56,11 @@ public: ~ServiceBase() { if (service_handle_) { - if (rmw_destroy_service(service_handle_) == RMW_RET_ERROR) { - std::cerr << "Error in destruction of rmw service_handle_ handle: " << - rmw_get_error_string_safe() << - std::endl; + if (rmw_destroy_service(service_handle_) != RMW_RET_OK) { + std::stringstream ss; + ss << "Error in destruction of rmw service_handle_ handle: " << + rmw_get_error_string_safe() << '\n'; + (std::cerr << ss.str()).flush(); } } } diff --git a/rclcpp/include/rclcpp/subscription.hpp b/rclcpp/include/rclcpp/subscription.hpp index 63a8fac..b327ba0 100644 --- a/rclcpp/include/rclcpp/subscription.hpp +++ b/rclcpp/include/rclcpp/subscription.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -61,10 +62,11 @@ public: ~SubscriptionBase() { if (subscription_handle_) { - if (rmw_destroy_subscription(node_handle_.get(), subscription_handle_) == RMW_RET_ERROR) { - std::cerr << "Error in destruction of rmw subscription handle: " << - rmw_get_error_string_safe() << - std::endl; + if (rmw_destroy_subscription(node_handle_.get(), subscription_handle_) != RMW_RET_OK) { + std::stringstream ss; + ss << "Error in destruction of rmw subscription handle: " << + rmw_get_error_string_safe() << '\n'; + (std::cerr << ss.str()).flush(); } } } diff --git a/rclcpp/include/rclcpp/timer.hpp b/rclcpp/include/rclcpp/timer.hpp index 0eec801..3e464f5 100644 --- a/rclcpp/include/rclcpp/timer.hpp +++ b/rclcpp/include/rclcpp/timer.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -66,10 +67,11 @@ public: ~TimerBase() { if (guard_condition_) { - if (rmw_destroy_guard_condition(guard_condition_) == RMW_RET_ERROR) { - std::cerr << "Error in TimerBase destructor, rmw_destroy_guard_condition failed: " << - rmw_get_error_string_safe() << - std::endl; + if (rmw_destroy_guard_condition(guard_condition_) != RMW_RET_OK) { + std::stringstream ss; + ss << "Error in TimerBase destructor, rmw_destroy_guard_condition failed: " << + rmw_get_error_string_safe() << '\n'; + (std::cerr << ss.str()).flush(); } } }