Skip to content

Commit

Permalink
micro-ROS Rolling patch
Browse files Browse the repository at this point in the history
* Avoid logging on build time based on RCutils flags (#6)

* Add RCL_YAML_PARSER and RCL_LOGGING CMake options.

* Replace RCL_YAML_PARSER by RCL_COMMAND_LINE_ENABLED and RCL_LOGGING by RCL_LOGGING_ENABLED.

* Disabled logging fix

* Fix remapping (#7)

Co-authored-by: Pablo Garrido <pablogs9@gmail.com>
Co-authored-by: julibert <julianbermudez@eprosima.com>

Updates 17092020

*Release micro-ROS Foxy (#9)

Cleaning


Update


Update


Update
  • Loading branch information
pablogs9 authored and Your Name committed Jan 26, 2021
1 parent 2883ce4 commit 345bca9
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 14 deletions.
53 changes: 42 additions & 11 deletions rcl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
$<$<BOOL:${RCL_COMMAND_LINE_ENABLED}>:src/rcl/arguments.c>
src/rcl/client.c
src/rcl/common.c
src/rcl/context.c
Expand All @@ -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
$<$<BOOL:${RCL_LOGGING_ENABLED}>:src/rcl/logging_rosout.c>
$<$<BOOL:${RCL_LOGGING_ENABLED}>:src/rcl/logging.c>
$<$<BOOL:${RCL_LOGGING_ENABLED}>:src/rcl/log_level.c>
src/rcl/node.c
src/rcl/node_options.c
src/rcl/publisher.c
Expand All @@ -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
$<$<BOOL:${RCL_COMMAND_LINE_ENABLED}>:RCL_COMMAND_LINE_ENABLED>
$<$<BOOL:${RCL_LOGGING_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")
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions rcl/include/rcl/arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions rcl/include/rcl/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions rcl/include/rcl/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ extern "C"
#include <stdint.h>

#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"
Expand Down
5 changes: 5 additions & 0 deletions rcl/include/rcl/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions rcl/src/rcl/arguments_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions rcl/src/rcl/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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));
Expand All @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions rcl/src/rcl/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -123,13 +131,15 @@ 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) {
fail_ret = ret;
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);
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions rcl/src/rcl/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading

0 comments on commit 345bca9

Please sign in to comment.