diff --git a/rcl/CMakeLists.txt b/rcl/CMakeLists.txt index 273c8315d3..3110d7641a 100644 --- a/rcl/CMakeLists.txt +++ b/rcl/CMakeLists.txt @@ -2,20 +2,29 @@ cmake_minimum_required(VERSION 3.5) project(rcl) +option(RCL_COMMAND_LINE_ENABLED "Enable/disable the rcl_yaml_param_parser tool" OFF) +option(RCL_LOGGING_ENABLED "Enable/disable logging" OFF) + find_package(ament_cmake_ros REQUIRED) find_package(rcl_interfaces REQUIRED) find_package(rcl_logging_interface REQUIRED) -find_package(rcl_yaml_param_parser REQUIRED) find_package(rcutils REQUIRED) find_package(rmw REQUIRED) find_package(rmw_implementation REQUIRED) find_package(rosidl_runtime_c REQUIRED) find_package(tracetools REQUIRED) +if(RCL_COMMAND_LINE_ENABLED) + find_package(rcl_yaml_param_parser REQUIRED) +endif() + include(cmake/rcl_set_symbol_visibility_hidden.cmake) -include(cmake/get_default_rcl_logging_implementation.cmake) -get_default_rcl_logging_implementation(RCL_LOGGING_IMPL) + +if(RCL_LOGGING_ENABLED) + include(cmake/get_default_rcl_logging_implementation.cmake) + get_default_rcl_logging_implementation(RCL_LOGGING_IMPL) +endif() # Default to C11 if(NOT CMAKE_C_STANDARD) @@ -32,7 +41,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") endif() set(${PROJECT_NAME}_sources - src/rcl/arguments.c + $<$:src/rcl/arguments.c> src/rcl/client.c src/rcl/common.c src/rcl/context.c @@ -46,9 +55,9 @@ set(${PROJECT_NAME}_sources src/rcl/lexer.c src/rcl/lexer_lookahead.c src/rcl/localhost.c - src/rcl/logging_rosout.c - src/rcl/logging.c - src/rcl/log_level.c + $<$:src/rcl/logging_rosout.c> + $<$:src/rcl/logging.c> + $<$:src/rcl/log_level.c> src/rcl/node.c src/rcl/node_options.c src/rcl/publisher.c @@ -73,15 +82,31 @@ target_include_directories(${PROJECT_NAME} PUBLIC ament_target_dependencies(${PROJECT_NAME} "rcl_interfaces" "rcl_logging_interface" - "rcl_yaml_param_parser" "rcutils" "rmw" "rmw_implementation" - ${RCL_LOGGING_IMPL} "rosidl_runtime_c" "tracetools" ) +if(RCL_COMMAND_LINE_ENABLED) + ament_target_dependencies(${PROJECT_NAME} + "rcl_yaml_param_parser" + ) +endif() + +if(RCL_LOGGING_ENABLED) + ament_target_dependencies(${PROJECT_NAME} + ${RCL_LOGGING_IMPL} + ) +endif() + +target_compile_definitions(${PROJECT_NAME} + PRIVATE + $<$:RCL_COMMAND_LINE_ENABLED> + $<$:RCL_LOGGING_ENABLED> + ) + # Causes the visibility macros to use dllexport rather than dllimport, # which is appropriate when building the dll but not consuming it. target_compile_definitions(${PROJECT_NAME} PRIVATE "RCL_BUILDING_DLL") @@ -111,14 +136,20 @@ ament_export_targets(${PROJECT_NAME}) ament_export_dependencies(ament_cmake) ament_export_dependencies(rcl_interfaces) ament_export_dependencies(rcl_logging_interface) -ament_export_dependencies(rcl_yaml_param_parser) ament_export_dependencies(rmw_implementation) ament_export_dependencies(rmw) ament_export_dependencies(rcutils) -ament_export_dependencies(${RCL_LOGGING_IMPL}) ament_export_dependencies(rosidl_runtime_c) ament_export_dependencies(tracetools) +if(RCL_COMMAND_LINE_ENABLED) + ament_export_dependencies(rcl_yaml_param_parser) +endif() + +if(RCL_LOGGING_ENABLED) + ament_export_dependencies(${RCL_LOGGING_IMPL}) +endif() + if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) ament_lint_auto_find_test_dependencies() diff --git a/rcl/include/rcl/arguments.h b/rcl/include/rcl/arguments.h index bd2c25d965..1f4e37df22 100644 --- a/rcl/include/rcl/arguments.h +++ b/rcl/include/rcl/arguments.h @@ -20,7 +20,11 @@ #include "rcl/macros.h" #include "rcl/types.h" #include "rcl/visibility_control.h" +#ifdef RCL_COMMAND_LINE_ENABLED #include "rcl_yaml_param_parser/types.h" +#else +typedef bool rcl_params_t; +#endif // RCL_COMMAND_LINE_ENABLED #ifdef __cplusplus extern "C" diff --git a/rcl/include/rcl/context.h b/rcl/include/rcl/context.h index 9275364dba..8b15045ec0 100644 --- a/rcl/include/rcl/context.h +++ b/rcl/include/rcl/context.h @@ -23,7 +23,9 @@ extern "C" #include "rmw/init.h" #include "rcl/allocator.h" +#ifdef RCL_COMMAND_LINE_ENABLED #include "rcl/arguments.h" +#endif // RCL_COMMAND_LINE_ENABLED #include "rcl/init_options.h" #include "rcl/macros.h" #include "rcl/types.h" @@ -107,9 +109,11 @@ struct rcl_context_impl_t; */ typedef struct rcl_context_t { +#ifdef RCL_COMMAND_LINE_ENABLED /// Global arguments for all nodes which share this context. /** Typically generated by the parsing of argc/argv in `rcl_init()`. */ rcl_arguments_t global_arguments; +#endif // RCL_COMMAND_LINE_ENABLED /// Implementation specific pointer. struct rcl_context_impl_t * impl; diff --git a/rcl/include/rcl/node.h b/rcl/include/rcl/node.h index 011347fd35..f2031c0209 100644 --- a/rcl/include/rcl/node.h +++ b/rcl/include/rcl/node.h @@ -23,7 +23,9 @@ extern "C" #include #include "rcl/allocator.h" +#ifdef RCL_COMMAND_LINE_ENABLED #include "rcl/arguments.h" +#endif // RCL_COMMAND_LINE_ENABLED #include "rcl/context.h" #include "rcl/macros.h" #include "rcl/node_options.h" diff --git a/rcl/include/rcl/node_options.h b/rcl/include/rcl/node_options.h index acb3f1a746..c4c839fe51 100644 --- a/rcl/include/rcl/node_options.h +++ b/rcl/include/rcl/node_options.h @@ -21,7 +21,10 @@ extern "C" #endif #include "rcl/allocator.h" +#ifdef RCL_COMMAND_LINE_ENABLED #include "rcl/arguments.h" +#endif // RCL_COMMAND_LINE_ENABLED +#include "rcl/macros.h" #include "rcl/domain_id.h" @@ -44,8 +47,10 @@ typedef struct rcl_node_options_t /// If false then only use arguments in this struct, otherwise use global arguments also. bool use_global_arguments; +#ifdef RCL_COMMAND_LINE_ENABLED /// Command line arguments that apply only to this node. rcl_arguments_t arguments; +#endif // RCL_COMMAND_LINE_ENABLED /// Flag to enable rosout for this node bool enable_rosout; diff --git a/rcl/src/rcl/arguments_impl.h b/rcl/src/rcl/arguments_impl.h index 18b8cd781f..2b7ee59dce 100644 --- a/rcl/src/rcl/arguments_impl.h +++ b/rcl/src/rcl/arguments_impl.h @@ -17,7 +17,11 @@ #include "rcl/arguments.h" #include "rcl/log_level.h" +#ifdef RCL_COMMAND_LINE_ENABLED #include "rcl_yaml_param_parser/types.h" +#else +typedef bool rcl_params_t; +#endif // RCL_COMMAND_LINE_ENABLED #include "./remap_impl.h" #ifdef __cplusplus diff --git a/rcl/src/rcl/context.c b/rcl/src/rcl/context.c index 5414cc5e94..67cd89d9f1 100644 --- a/rcl/src/rcl/context.c +++ b/rcl/src/rcl/context.c @@ -33,7 +33,9 @@ rcl_get_zero_initialized_context(void) .instance_id_storage = {0}, }; // this is not constexpr so it cannot be in the struct initialization +#ifdef RCL_COMMAND_LINE_ENABLED context.global_arguments = rcl_get_zero_initialized_arguments(); +#endif // RCL_COMMAND_LINE_ENABLED // ensure assumption about static storage static_assert( sizeof(context.instance_id_storage) >= sizeof(atomic_uint_least64_t), @@ -112,6 +114,7 @@ __cleanup_context(rcl_context_t * context) // reset the instance id to 0 to indicate "invalid" (should already be 0, but this is defensive) rcutils_atomic_store((atomic_uint_least64_t *)(&context->instance_id_storage), 0); +#ifdef RCL_COMMAND_LINE_ENABLED // clean up global_arguments if initialized if (NULL != context->global_arguments.impl) { ret = rcl_arguments_fini(&(context->global_arguments)); @@ -124,6 +127,7 @@ __cleanup_context(rcl_context_t * context) rcl_reset_error(); } } +#endif // RCL_COMMAND_LINE_ENABLED // if impl is null, nothing else can be cleaned up if (NULL != context->impl) { diff --git a/rcl/src/rcl/init.c b/rcl/src/rcl/init.c index d8f7dd44ac..b642424fe7 100644 --- a/rcl/src/rcl/init.c +++ b/rcl/src/rcl/init.c @@ -27,15 +27,21 @@ extern "C" #include "tracetools/tracetools.h" +#ifdef RCL_COMMAND_LINE_ENABLED #include "rcl/arguments.h" +#endif // RCL_COMMAND_LINE_ENABLED #include "rcl/domain_id.h" #include "rcl/error_handling.h" #include "rcl/localhost.h" +#ifdef RCL_LOGGING_ENABLED #include "rcl/logging.h" +#endif // RCL_LOGGING_ENABLED #include "rcl/security.h" #include "rcl/validate_enclave_name.h" +#ifdef RCL_COMMAND_LINE_ENABLED #include "./arguments_impl.h" +#endif // RCL_COMMAND_LINE_ENABLED #include "./common.h" #include "./context_impl.h" #include "./init_options_impl.h" @@ -80,8 +86,10 @@ rcl_init( return RCL_RET_ALREADY_INIT; } +#ifdef RCL_COMMAND_LINE_ENABLED // Zero initialize global arguments. context->global_arguments = rcl_get_zero_initialized_arguments(); +#endif // RCL_COMMAND_LINE_ENABLED // Setup impl for context. // use zero_allocate so the cleanup function will not try to clean up uninitialized parts later @@ -123,6 +131,7 @@ rcl_init( } } +#ifdef RCL_COMMAND_LINE_ENABLED // Parse the ROS specific arguments. ret = rcl_parse_arguments(argc, argv, allocator, &context->global_arguments); if (RCL_RET_OK != ret) { @@ -130,6 +139,7 @@ rcl_init( RCUTILS_LOG_ERROR_NAMED(ROS_PACKAGE_NAME, "Failed to parse global arguments"); goto fail; } +#endif // RCL_COMMAND_LINE_ENABLED // Set the instance id. uint64_t next_instance_id = rcutils_atomic_fetch_add_uint64_t(&__rcl_next_unique_id, 1); @@ -164,6 +174,7 @@ rcl_init( } } +#ifdef RCL_COMMAND_LINE_ENABLED if (context->global_arguments.impl->enclave) { context->impl->init_options.impl->rmw_init_options.enclave = rcutils_strdup( context->global_arguments.impl->enclave, @@ -178,6 +189,7 @@ rcl_init( fail_ret = RCL_RET_BAD_ALLOC; goto fail; } +#endif //RCL_COMMAND_LINE_ENABLED int validation_result; size_t invalid_index; diff --git a/rcl/src/rcl/logging.c b/rcl/src/rcl/logging.c index 7fa76442bd..869f7edfae 100644 --- a/rcl/src/rcl/logging.c +++ b/rcl/src/rcl/logging.c @@ -67,9 +67,13 @@ rcl_logging_configure_with_output_handler( int default_level = -1; rcl_log_levels_t * log_levels = &global_args->impl->log_levels; const char * config_file = global_args->impl->external_log_config_file; - g_rcl_logging_stdout_enabled = !global_args->impl->log_stdout_disabled; - g_rcl_logging_rosout_enabled = !global_args->impl->log_rosout_disabled; - g_rcl_logging_ext_lib_enabled = !global_args->impl->log_ext_lib_disabled; + bool global_disable = false; + #ifdef RCUTILS_NO_LOGGING + global_disable = true; + #endif + g_rcl_logging_stdout_enabled = !global_args->impl->log_stdout_disabled && !global_disable; + g_rcl_logging_rosout_enabled = !global_args->impl->log_rosout_disabled && !global_disable; + g_rcl_logging_ext_lib_enabled = !global_args->impl->log_ext_lib_disabled && !global_disable; rcl_ret_t status = RCL_RET_OK; g_rcl_logging_num_out_handlers = 0; diff --git a/rcl/src/rcl/node.c b/rcl/src/rcl/node.c index fe8a947fb3..870a6b63a6 100644 --- a/rcl/src/rcl/node.c +++ b/rcl/src/rcl/node.c @@ -24,12 +24,16 @@ extern "C" #include #include +#ifdef RCL_COMMAND_LINE_ENABLED #include "rcl/arguments.h" +#endif // RCL_COMMAND_LINE_ENABLED #include "rcl/error_handling.h" #include "rcl/init_options.h" #include "rcl/localhost.h" +#ifdef RCL_LOGGING_ENABLED #include "rcl/logging.h" #include "rcl/logging_rosout.h" +#endif // RCL_LOGGING_ENABLED #include "rcl/rcl.h" #include "rcl/remap.h" #include "rcl/security.h" @@ -212,6 +216,7 @@ rcl_node_init( goto fail; } +#ifdef RCL_COMMAND_LINE_ENABLED // Remap the node name and namespace if remap rules are given rcl_arguments_t * global_args = NULL; if (node->impl->options.use_global_arguments) { @@ -238,6 +243,7 @@ rcl_node_init( should_free_local_namespace_ = true; local_namespace_ = remapped_namespace; } +#endif // RCL_COMMAND_LINE_ENABLED // compute fully qualfied name of the node. if ('/' == local_namespace_[strlen(local_namespace_) - 1]) { @@ -282,6 +288,7 @@ rcl_node_init( // error message already set goto fail; } +#ifdef RCL_LOGGING_ENABLED // The initialization for the rosout publisher requires the node to be in initialized to a point // that it can create new topic publishers if (rcl_logging_rosout_enabled() && node->impl->options.enable_rosout) { @@ -291,6 +298,7 @@ rcl_node_init( goto fail; } } +#endif // RCL_LOGGING_ENABLED RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Node initialized"); ret = RCL_RET_OK; TRACEPOINT( @@ -302,6 +310,7 @@ rcl_node_init( goto cleanup; fail: if (node->impl) { +#ifdef RCL_LOGGING_ENABLED if (rcl_logging_rosout_enabled() && node->impl->options.enable_rosout && node->impl->logger_name) @@ -312,6 +321,7 @@ rcl_node_init( ROS_PACKAGE_NAME, "Failed to fini publisher for node: %i", ret); allocator->deallocate((char *)node->impl->logger_name, allocator->state); } +#endif // RCL_LOGGING_ENABLED if (node->impl->fq_name) { allocator->deallocate((char *)node->impl->fq_name, allocator->state); } @@ -334,6 +344,8 @@ rcl_node_init( } allocator->deallocate(node->impl->graph_guard_condition, allocator->state); } + +#ifdef RCL_COMMAND_LINE_ENABLED if (NULL != node->impl->options.arguments.impl) { ret = rcl_arguments_fini(&(node->impl->options.arguments)); if (ret != RCL_RET_OK) { @@ -343,6 +355,7 @@ rcl_node_init( ); } } +#endif // RCL_COMMAND_LINE_ENABLED allocator->deallocate(node->impl, allocator->state); } *node = rcl_get_zero_initialized_node(); @@ -372,6 +385,7 @@ 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_RET_OK; +#ifdef RCL_LOGGING_ENABLED if (rcl_logging_rosout_enabled() && node->impl->options.enable_rosout) { rcl_ret = rcl_logging_rosout_fini_publisher_for_node(node); if (rcl_ret != RCL_RET_OK && rcl_ret != RCL_RET_NOT_INIT) { @@ -379,6 +393,7 @@ rcl_node_fini(rcl_node_t * node) result = RCL_RET_ERROR; } } +#endif // RCL_LOGGING_ENABLED rmw_ret_t rmw_ret = rmw_destroy_node(node->impl->rmw_node_handle); if (rmw_ret != RMW_RET_OK) { RCL_SET_ERROR_MSG(rmw_get_error_string().str); @@ -393,12 +408,14 @@ rcl_node_fini(rcl_node_t * node) // assuming that allocate and deallocate are ok since they are checked in init allocator.deallocate((char *)node->impl->logger_name, allocator.state); allocator.deallocate((char *)node->impl->fq_name, allocator.state); +#ifdef RCL_COMMAND_LINE_ENABLED if (NULL != node->impl->options.arguments.impl) { rcl_ret_t ret = rcl_arguments_fini(&(node->impl->options.arguments)); if (ret != RCL_RET_OK) { return ret; } } +#endif // RCL_COMMAND_LINE_ENABLED allocator.deallocate(node->impl, allocator.state); node->impl = NULL; RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Node finalized"); diff --git a/rcl/src/rcl/node_options.c b/rcl/src/rcl/node_options.c index 34408f18b4..20832f881d 100644 --- a/rcl/src/rcl/node_options.c +++ b/rcl/src/rcl/node_options.c @@ -21,10 +21,14 @@ extern "C" #include "rcl/node_options.h" +#ifdef RCL_COMMAND_LINE_ENABLED #include "rcl/arguments.h" +#endif // RCL_COMMAND_LINE_ENABLED #include "rcl/domain_id.h" #include "rcl/error_handling.h" +#ifdef RCL_LOGGING_ENABLED #include "rcl/logging_rosout.h" +#endif // RCL_LOGGING_ENABLED rcl_node_options_t rcl_node_get_default_options() @@ -33,9 +37,15 @@ rcl_node_get_default_options() rcl_node_options_t default_options = { .allocator = rcl_get_default_allocator(), .use_global_arguments = true, + #ifdef RCL_COMMAND_LINE_ENABLED .arguments = rcl_get_zero_initialized_arguments(), + #endif // RCL_COMMAND_LINE_ENABLED + #ifdef RCL_LOGGING_ENABLED .enable_rosout = true, .rosout_qos = rcl_qos_profile_rosout_default, + #else + .enable_rosout = false, + #endif // RCL_LOGGING_ENABLED }; return default_options; } @@ -53,17 +63,22 @@ rcl_node_options_copy( RCL_SET_ERROR_MSG("Attempted to copy options into itself"); return RCL_RET_INVALID_ARGUMENT; } +#ifdef RCL_COMMAND_LINE_ENABLED if (NULL != options_out->arguments.impl) { RCL_SET_ERROR_MSG("Options out must be zero initialized"); return RCL_RET_INVALID_ARGUMENT; } +#endif // RCL_COMMAND_LINE_ENABLED + options_out->allocator = options->allocator; options_out->use_global_arguments = options->use_global_arguments; options_out->enable_rosout = options->enable_rosout; options_out->rosout_qos = options->rosout_qos; +#ifdef RCL_COMMAND_LINE_ENABLED if (NULL != options->arguments.impl) { return rcl_arguments_copy(&(options->arguments), &(options_out->arguments)); } +#endif // RCL_COMMAND_LINE_ENABLED return RCL_RET_OK; } @@ -75,6 +90,7 @@ rcl_node_options_fini( rcl_allocator_t allocator = options->allocator; RCL_CHECK_ALLOCATOR(&allocator, return RCL_RET_INVALID_ARGUMENT); +#ifdef RCL_COMMAND_LINE_ENABLED if (options->arguments.impl) { rcl_ret_t ret = rcl_arguments_fini(&options->arguments); if (RCL_RET_OK != ret) { @@ -82,6 +98,7 @@ rcl_node_options_fini( return ret; } } +#endif // RCL_COMMAND_LINE_ENABLED return RCL_RET_OK; } diff --git a/rcl/src/rcl/node_resolve_name.c b/rcl/src/rcl/node_resolve_name.c index 9c2667669a..5f01de4be5 100644 --- a/rcl/src/rcl/node_resolve_name.c +++ b/rcl/src/rcl/node_resolve_name.c @@ -75,6 +75,7 @@ rcl_resolve_name( goto cleanup; } // remap topic name +#ifdef RCL_COMMAND_LINE_ENABLED if (!only_expand) { ret = rcl_remap_name( local_args, global_args, is_service ? RCL_SERVICE_REMAP : RCL_TOPIC_REMAP, @@ -84,6 +85,7 @@ rcl_resolve_name( goto cleanup; } } +#endif // RCL_COMMAND_LINE_ENABLED if (NULL == remapped_topic_name) { remapped_topic_name = expanded_topic_name; expanded_topic_name = NULL; @@ -145,12 +147,18 @@ rcl_node_resolve_name( return RCL_RET_ERROR; } rcl_arguments_t * global_args = NULL; +#ifdef RCL_COMMAND_LINE_ENABLED if (node_options->use_global_arguments) { global_args = &(node->context->global_arguments); } +#endif // RCL_COMMAND_LINE_ENABLED return rcl_resolve_name( +#ifdef RCL_COMMAND_LINE_ENABLED &(node_options->arguments), +#else + NULL, +#endif // RCL_COMMAND_LINE_ENABLED global_args, input_topic_name, rcl_node_get_name(node),