avoid streaming directly to std::cerr

This commit is contained in:
William Woodall 2015-07-01 14:45:38 -07:00
parent 2d5afac3a6
commit 16323b3f92
6 changed files with 33 additions and 25 deletions

View file

@ -19,6 +19,7 @@
#include <iostream> #include <iostream>
#include <map> #include <map>
#include <memory> #include <memory>
#include <sstream>
#include <utility> #include <utility>
#include <rmw/error_handling.h> #include <rmw/error_handling.h>
@ -56,12 +57,9 @@ public:
~ClientBase() ~ClientBase()
{ {
if (client_handle_) { if (client_handle_) {
if (rmw_destroy_client(client_handle_) == RMW_RET_ERROR) { if (rmw_destroy_client(client_handle_) != RMW_RET_OK) {
// *INDENT-OFF* fprintf(stderr,
std::cerr << "Error in destruction of rmw client handle: " "Error in destruction of rmw client handle: %s\n", rmw_get_error_string_safe());
<< rmw_get_error_string_safe()
<< std::endl;
// *INDENT-ON*
} }
} }
} }

View file

@ -18,6 +18,7 @@
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <sstream>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
@ -51,10 +52,11 @@ Node::Node(std::string node_name, context::Context::SharedPtr context)
auto ret = rmw_destroy_node(node); auto ret = rmw_destroy_node(node);
if (ret != RMW_RET_OK) { if (ret != RMW_RET_OK) {
// *INDENT-OFF* // *INDENT-OFF*
std::cerr << "Error in destruction of rmw node handle: " std::stringstream ss;
<< rmw_get_error_string_safe() ss << "Error in destruction of rmw node handle: "
<< std::endl; << rmw_get_error_string_safe() << '\n';
// *INDENT-ON* // *INDENT-ON*
(std::cerr << ss.str()).flush();
} }
} }
}); });

View file

@ -17,6 +17,7 @@
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <sstream>
#include <rmw/error_handling.h> #include <rmw/error_handling.h>
#include <rmw/rmw.h> #include <rmw/rmw.h>
@ -47,12 +48,13 @@ public:
~Publisher() ~Publisher()
{ {
if (publisher_handle_) { 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* // *INDENT-OFF*
std::cerr << "Error in destruction of rmw publisher handle: " std::stringstream ss;
<< rmw_get_error_string_safe() ss << "Error in destruction of rmw publisher handle: "
<< std::endl; << rmw_get_error_string_safe() << '\n';
// *INDENT-ON* // *INDENT-ON*
(std::cerr << ss.str()).flush();
} }
} }
} }

View file

@ -18,6 +18,7 @@
#include <functional> #include <functional>
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <sstream>
#include <string> #include <string>
#include <rmw/error_handling.h> #include <rmw/error_handling.h>
@ -55,10 +56,11 @@ public:
~ServiceBase() ~ServiceBase()
{ {
if (service_handle_) { if (service_handle_) {
if (rmw_destroy_service(service_handle_) == RMW_RET_ERROR) { if (rmw_destroy_service(service_handle_) != RMW_RET_OK) {
std::cerr << "Error in destruction of rmw service_handle_ handle: " << std::stringstream ss;
rmw_get_error_string_safe() << ss << "Error in destruction of rmw service_handle_ handle: " <<
std::endl; rmw_get_error_string_safe() << '\n';
(std::cerr << ss.str()).flush();
} }
} }
} }

View file

@ -18,6 +18,7 @@
#include <functional> #include <functional>
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <sstream>
#include <string> #include <string>
#include <rmw/error_handling.h> #include <rmw/error_handling.h>
@ -61,10 +62,11 @@ public:
~SubscriptionBase() ~SubscriptionBase()
{ {
if (subscription_handle_) { if (subscription_handle_) {
if (rmw_destroy_subscription(node_handle_.get(), subscription_handle_) == RMW_RET_ERROR) { if (rmw_destroy_subscription(node_handle_.get(), subscription_handle_) != RMW_RET_OK) {
std::cerr << "Error in destruction of rmw subscription handle: " << std::stringstream ss;
rmw_get_error_string_safe() << ss << "Error in destruction of rmw subscription handle: " <<
std::endl; rmw_get_error_string_safe() << '\n';
(std::cerr << ss.str()).flush();
} }
} }
} }

View file

@ -18,6 +18,7 @@
#include <chrono> #include <chrono>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <sstream>
#include <thread> #include <thread>
#include <rmw/error_handling.h> #include <rmw/error_handling.h>
@ -66,10 +67,11 @@ public:
~TimerBase() ~TimerBase()
{ {
if (guard_condition_) { if (guard_condition_) {
if (rmw_destroy_guard_condition(guard_condition_) == RMW_RET_ERROR) { if (rmw_destroy_guard_condition(guard_condition_) != RMW_RET_OK) {
std::cerr << "Error in TimerBase destructor, rmw_destroy_guard_condition failed: " << std::stringstream ss;
rmw_get_error_string_safe() << ss << "Error in TimerBase destructor, rmw_destroy_guard_condition failed: " <<
std::endl; rmw_get_error_string_safe() << '\n';
(std::cerr << ss.str()).flush();
} }
} }
} }