Skip to content

Commit

Permalink
Not creating rosout publisher instance unless required.
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoya.Fujita <Tomoya.Fujita@sony.com>
  • Loading branch information
fujitatomoya committed Oct 15, 2019
1 parent 8e0b72e commit 2981128
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
2 changes: 2 additions & 0 deletions rcl/include/rcl/logging_rosout.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "rcl/types.h"
#include "rcl/visibility_control.h"

extern bool g_rcl_logging_rosout_enabled;

#ifdef __cplusplus
extern "C"
{
Expand Down
1 change: 0 additions & 1 deletion rcl/src/rcl/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ static rcutils_logging_output_handler_t
static uint8_t g_rcl_logging_num_out_handlers = 0;
static rcl_allocator_t g_logging_allocator;
static bool g_rcl_logging_stdout_enabled = false;
static bool g_rcl_logging_rosout_enabled = false;
static bool g_rcl_logging_ext_lib_enabled = false;

/**
Expand Down
2 changes: 2 additions & 0 deletions rcl/src/rcl/logging_rosout.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "rcutils/types/rcutils_ret.h"
#include "rosidl_generator_c/string_functions.h"

bool g_rcl_logging_rosout_enabled = false;

#ifdef __cplusplus
extern "C"
{
Expand Down
24 changes: 15 additions & 9 deletions rcl/src/rcl/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern "C"

#include "rcl/arguments.h"
#include "rcl/error_handling.h"
#include "rcl/logging.h"
#include "rcl/logging_rosout.h"
#include "rcl/rcl.h"
#include "rcl/remap.h"
Expand Down Expand Up @@ -355,17 +356,19 @@ rcl_node_init(
}
// The initialization for the rosout publisher requires the node to be in initialized to a point
// that it can create new topic publishers
ret = rcl_logging_rosout_init_publisher_for_node(node);
if (ret != RCL_RET_OK) {
// error message already set
goto fail;
if (g_rcl_logging_rosout_enabled) {
ret = rcl_logging_rosout_init_publisher_for_node(node);
if (ret != RCL_RET_OK) {
// error message already set
goto fail;
}
}
RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Node initialized");
ret = RCL_RET_OK;
goto cleanup;
fail:
if (node->impl) {
if (node->impl->logger_name) {
if (g_rcl_logging_rosout_enabled && node->impl->logger_name) {
ret = rcl_logging_rosout_fini_publisher_for_node(node);
RCUTILS_LOG_ERROR_EXPRESSION_NAMED((ret != RCL_RET_OK && ret != RCL_RET_NOT_INIT),
ROS_PACKAGE_NAME, "Failed to fini publisher for node: %i", ret);
Expand Down Expand Up @@ -431,10 +434,13 @@ rcl_node_fini(rcl_node_t * node)
}
rcl_allocator_t allocator = node->impl->options.allocator;
rcl_ret_t result = RCL_RET_OK;
rcl_ret_t rcl_ret = rcl_logging_rosout_fini_publisher_for_node(node);
if (rcl_ret != RCL_RET_OK && rcl_ret != RCL_RET_NOT_INIT) {
RCL_SET_ERROR_MSG("Unable to fini publisher for node.");
result = RCL_RET_ERROR;
rcl_ret_t rcl_ret = RCL_RET_OK;
if (g_rcl_logging_rosout_enabled) {
rcl_ret = rcl_logging_rosout_fini_publisher_for_node(node);
if (rcl_ret != RCL_RET_OK && rcl_ret != RCL_RET_NOT_INIT) {
RCL_SET_ERROR_MSG("Unable to fini publisher for node.");
result = RCL_RET_ERROR;
}
}
rmw_ret_t rmw_ret = rmw_destroy_node(node->impl->rmw_node_handle);
if (rmw_ret != RMW_RET_OK) {
Expand Down

0 comments on commit 2981128

Please sign in to comment.