Skip to content

Commit 245c1fb

Browse files
committed
Not creating rosout publisher instance unless required.
Signed-off-by: Tomoya.Fujita <[email protected]>
1 parent d655147 commit 245c1fb

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

rcl/include/rcl/logging_rosout.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "rcl/types.h"
2222
#include "rcl/visibility_control.h"
2323

24+
extern bool g_rcl_logging_rosout_enabled;
25+
2426
#ifdef __cplusplus
2527
extern "C"
2628
{

rcl/src/rcl/logging.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ static rcutils_logging_output_handler_t
4040
static uint8_t g_rcl_logging_num_out_handlers = 0;
4141
static rcl_allocator_t g_logging_allocator;
4242
static bool g_rcl_logging_stdout_enabled = false;
43-
static bool g_rcl_logging_rosout_enabled = false;
4443
static bool g_rcl_logging_ext_lib_enabled = false;
4544

4645
/**

rcl/src/rcl/logging_rosout.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "rcutils/types/rcutils_ret.h"
2929
#include "rosidl_generator_c/string_functions.h"
3030

31+
bool g_rcl_logging_rosout_enabled = false;
32+
3133
#ifdef __cplusplus
3234
extern "C"
3335
{

rcl/src/rcl/node.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extern "C"
2626

2727
#include "rcl/arguments.h"
2828
#include "rcl/error_handling.h"
29+
#include "rcl/logging.h"
2930
#include "rcl/logging_rosout.h"
3031
#include "rcl/rcl.h"
3132
#include "rcl/remap.h"
@@ -355,17 +356,19 @@ rcl_node_init(
355356
}
356357
// The initialization for the rosout publisher requires the node to be in initialized to a point
357358
// that it can create new topic publishers
358-
ret = rcl_logging_rosout_init_publisher_for_node(node);
359-
if (ret != RCL_RET_OK) {
360-
// error message already set
361-
goto fail;
359+
if (g_rcl_logging_rosout_enabled) {
360+
ret = rcl_logging_rosout_init_publisher_for_node(node);
361+
if (ret != RCL_RET_OK) {
362+
// error message already set
363+
goto fail;
364+
}
362365
}
363366
RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Node initialized");
364367
ret = RCL_RET_OK;
365368
goto cleanup;
366369
fail:
367370
if (node->impl) {
368-
if (node->impl->logger_name) {
371+
if (g_rcl_logging_rosout_enabled && node->impl->logger_name) {
369372
ret = rcl_logging_rosout_fini_publisher_for_node(node);
370373
RCUTILS_LOG_ERROR_EXPRESSION_NAMED((ret != RCL_RET_OK && ret != RCL_RET_NOT_INIT),
371374
ROS_PACKAGE_NAME, "Failed to fini publisher for node: %i", ret);
@@ -431,10 +434,13 @@ rcl_node_fini(rcl_node_t * node)
431434
}
432435
rcl_allocator_t allocator = node->impl->options.allocator;
433436
rcl_ret_t result = RCL_RET_OK;
434-
rcl_ret_t rcl_ret = rcl_logging_rosout_fini_publisher_for_node(node);
435-
if (rcl_ret != RCL_RET_OK && rcl_ret != RCL_RET_NOT_INIT) {
436-
RCL_SET_ERROR_MSG("Unable to fini publisher for node.");
437-
result = RCL_RET_ERROR;
437+
rcl_ret_t rcl_ret = RCL_RET_OK;
438+
if (g_rcl_logging_rosout_enabled) {
439+
rcl_ret = rcl_logging_rosout_fini_publisher_for_node(node);
440+
if (rcl_ret != RCL_RET_OK && rcl_ret != RCL_RET_NOT_INIT) {
441+
RCL_SET_ERROR_MSG("Unable to fini publisher for node.");
442+
result = RCL_RET_ERROR;
443+
}
438444
}
439445
rmw_ret_t rmw_ret = rmw_destroy_node(node->impl->rmw_node_handle);
440446
if (rmw_ret != RMW_RET_OK) {

0 commit comments

Comments
 (0)