Skip to content

Commit

Permalink
Decouple rosout publisher init from node init. (#1121)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoya.Fujita <[email protected]>
  • Loading branch information
fujitatomoya authored Sep 22, 2023
1 parent 0a02395 commit 827d597
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions rclpy/src/rclpy/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <rcl_action/rcl_action.h>
#include <rcl/error_handling.h>
#include <rcl/graph.h>
#include <rcl/logging.h>
#include <rcl/logging_rosout.h>
#include <rcl/types.h>
#include <rcl_interfaces/msg/parameter_type.h>
#include <rcl_yaml_param_parser/parser.h>
Expand Down Expand Up @@ -439,9 +441,24 @@ Node::Node(

rcl_node_ = std::shared_ptr<rcl_node_t>(
new rcl_node_t,
[](rcl_node_t * node)
[enable_rosout](rcl_node_t * node)
{
rcl_ret_t ret = rcl_node_fini(node);
rcl_ret_t ret;
{
rclpy::LoggingGuard scoped_logging_guard;
if (rcl_logging_rosout_enabled() && enable_rosout) {
ret = rcl_logging_rosout_fini_publisher_for_node(node);
if (ret != RCL_RET_OK) {
// Warning should use line number of the current stack frame
int stack_level = 1;
PyErr_WarnFormat(
PyExc_RuntimeWarning, stack_level, "Failed to fini rosout publisher: %s",
rcl_get_error_string().str);
rcl_reset_error();
}
}
}
ret = rcl_node_fini(node);
if (RCL_RET_OK != ret) {
// Warning should use line number of the current stack frame
int stack_level = 1;
Expand All @@ -459,11 +476,8 @@ Node::Node(
options.arguments = arguments;
options.enable_rosout = enable_rosout;

{
rclpy::LoggingGuard scoped_logging_guard;
ret = rcl_node_init(
rcl_node_.get(), node_name, namespace_, context.rcl_ptr(), &options);
}
ret = rcl_node_init(
rcl_node_.get(), node_name, namespace_, context.rcl_ptr(), &options);

if (RCL_RET_BAD_ALLOC == ret) {
rcl_reset_error();
Expand All @@ -478,6 +492,14 @@ Node::Node(
if (RCL_RET_OK != ret) {
throw RCLError("error creating node");
}

if (rcl_logging_rosout_enabled() && enable_rosout) {
rclpy::LoggingGuard scoped_logging_guard;
ret = rcl_logging_rosout_init_publisher_for_node(rcl_node_.get());
if (ret != RCL_RET_OK) {
throw RCLError("failed to initialize rosout publisher");
}
}
}

py::list
Expand Down

0 comments on commit 827d597

Please sign in to comment.