Skip to content

Commit e25cf2b

Browse files
committed
Decoupled the additional feature from rcl to rcutils, reflecting on the pointing out below.
ros2/rclcpp#2205 (comment) Signed-off-by: Shoji Morita <[email protected]>
1 parent 73718ca commit e25cf2b

File tree

15 files changed

+77
-271
lines changed

15 files changed

+77
-271
lines changed

rcl/include/rcl/arguments.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "rcl/types.h"
2424
#include "rcl/visibility_control.h"
2525
#include "rcl_yaml_param_parser/types.h"
26+
#include "rcutils/thread_attr.h"
2627

2728
#ifdef __cplusplus
2829
extern "C"
@@ -86,7 +87,7 @@ typedef struct rcl_arguments_s
8687
/// The ROS flag that precedes the ROS thread attribute file path.
8788
#define RCL_THREAD_ATTRS_FILE_FLAG "--thread-attrs-file"
8889

89-
/// The ROS flag that precedes the ROS logging thread attribute.
90+
/// The ROS flag that precedes the ROS thread attribute.
9091
#define RCL_THREAD_ATTRS_VALUE_FLAG "--thread-attrs-value"
9192

9293
/// Return a rcl_arguments_t struct with members initialized to `NULL`.
@@ -469,7 +470,7 @@ RCL_WARN_UNUSED
469470
rcl_ret_t
470471
rcl_arguments_get_thread_attrs(
471472
const rcl_arguments_t * arguments,
472-
rcl_thread_attrs_t ** thread_attrs);
473+
rcutils_thread_attrs_t ** thread_attrs);
473474

474475
#ifdef __cplusplus
475476
}

rcl/include/rcl/context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ RCL_WARN_UNUSED
329329
rcl_ret_t
330330
rcl_context_get_thread_attrs(
331331
const rcl_context_t * context,
332-
rcl_thread_attrs_t ** thread_attrs);
332+
rcutils_thread_attrs_t ** thread_attrs);
333333

334334
#ifdef __cplusplus
335335
}

rcl/include/rcl/thread_attr.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extern "C"
2828
#include "rcl/macros.h"
2929
#include "rcl/types.h"
3030
#include "rcl/visibility_control.h"
31-
#include "rcl_yaml_param_parser/types.h"
31+
#include "rcutils/thread_attr.h"
3232

3333
extern const char * const RCL_THREAD_ATTR_VALUE_ENV_VAR;
3434
extern const char * const RCL_THREAD_ATTR_FILE_ENV_VAR;
@@ -43,7 +43,7 @@ extern const char * const RCL_THREAD_ATTR_FILE_ENV_VAR;
4343
RCL_PUBLIC
4444
rcl_ret_t
4545
rcl_get_default_thread_attrs_from_value(
46-
rcl_thread_attrs_t * thread_attrs,
46+
rcutils_thread_attrs_t * thread_attrs,
4747
rcl_allocator_t allocator);
4848

4949
/// Determine the default thread attribute from file path, based on the environment.
@@ -56,7 +56,7 @@ rcl_get_default_thread_attrs_from_value(
5656
RCL_PUBLIC
5757
rcl_ret_t
5858
rcl_get_default_thread_attrs_from_file(
59-
rcl_thread_attrs_t * thread_attrs,
59+
rcutils_thread_attrs_t * thread_attrs,
6060
rcl_allocator_t allocator);
6161

6262
#ifdef __cplusplus

rcl/src/rcl/arguments.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "rcutils/logging.h"
3434
#include "rcutils/logging_macros.h"
3535
#include "rcutils/strdup.h"
36+
#include "rcutils/thread_attr.h"
3637
#include "rmw/validate_namespace.h"
3738
#include "rmw/validate_node_name.h"
3839

@@ -287,8 +288,8 @@ rcl_parse_arguments(
287288
goto fail;
288289
}
289290

290-
args_impl->thread_attrs = rcl_get_zero_initialized_thread_attrs();
291-
ret = rcl_thread_attrs_init(&args_impl->thread_attrs, allocator);
291+
args_impl->thread_attrs = rcutils_get_zero_initialized_thread_attrs();
292+
ret = rcutils_thread_attrs_init(&args_impl->thread_attrs, allocator);
292293
if (RCL_RET_OK != ret) {
293294
goto fail;
294295
}
@@ -1062,8 +1063,8 @@ rcl_arguments_fini(
10621063
args->impl->external_log_config_file = NULL;
10631064
}
10641065

1065-
rcl_ret_t thread_ret = rcl_thread_attrs_fini(&args->impl->thread_attrs);
1066-
if (thread_ret != RCL_RET_OK) {
1066+
rcl_ret_t thread_ret = rcutils_thread_attrs_fini(&args->impl->thread_attrs);
1067+
if (RCL_RET_OK != thread_ret) {
10671068
ret = thread_ret;
10681069
RCUTILS_LOG_ERROR_NAMED(
10691070
ROS_PACKAGE_NAME,
@@ -2149,7 +2150,7 @@ _rcl_allocate_initialized_arguments_impl(rcl_arguments_t * args, rcl_allocator_t
21492150
args_impl->log_rosout_disabled = false;
21502151
args_impl->log_ext_lib_disabled = false;
21512152
args_impl->enclave = NULL;
2152-
args_impl->thread_attrs = rcl_get_zero_initialized_thread_attrs();
2153+
args_impl->thread_attrs = rcutils_get_zero_initialized_thread_attrs();
21532154
args_impl->allocator = *allocator;
21542155

21552156
return RCL_RET_OK;
@@ -2158,7 +2159,7 @@ _rcl_allocate_initialized_arguments_impl(rcl_arguments_t * args, rcl_allocator_t
21582159
rcl_ret_t
21592160
rcl_arguments_get_thread_attrs(
21602161
const rcl_arguments_t * arguments,
2161-
rcl_thread_attrs_t ** thread_attrs)
2162+
rcutils_thread_attrs_t ** thread_attrs)
21622163
{
21632164
RCL_CHECK_ARGUMENT_FOR_NULL(arguments, RCL_RET_INVALID_ARGUMENT);
21642165
RCL_CHECK_ARGUMENT_FOR_NULL(arguments->impl, RCL_RET_INVALID_ARGUMENT);

rcl/src/rcl/arguments_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct rcl_arguments_impl_s
5252
int num_remap_rules;
5353

5454
/// thread attribute.
55-
rcl_thread_attrs_t thread_attrs;
55+
rcutils_thread_attrs_t thread_attrs;
5656

5757
/// Log levels parsed from arguments.
5858
rcl_log_levels_t log_levels;

rcl/src/rcl/context.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,11 @@ rcl_context_get_rmw_context(rcl_context_t * context)
109109
rcl_ret_t
110110
rcl_context_get_thread_attrs(
111111
const rcl_context_t * context,
112-
rcl_thread_attrs_t ** thread_attrs)
112+
rcutils_thread_attrs_t ** thread_attrs)
113113
{
114114
RCL_CHECK_ARGUMENT_FOR_NULL(context, RCL_RET_INVALID_ARGUMENT);
115115
RCL_CHECK_ARGUMENT_FOR_NULL(context->impl, RCL_RET_INVALID_ARGUMENT);
116+
RCL_CHECK_ARGUMENT_FOR_NULL(thread_attrs, RCL_RET_INVALID_ARGUMENT);
116117

117118
if (0 < context->impl->thread_attrs.num_attributes) {
118119
*thread_attrs = &context->impl->thread_attrs;
@@ -165,7 +166,7 @@ __cleanup_context(rcl_context_t * context)
165166

166167
// clean up thread_attrs_context
167168
rcl_ret_t thread_attrs_context_fini_ret =
168-
rcl_thread_attrs_fini(&(context->impl->thread_attrs));
169+
rcutils_thread_attrs_fini(&(context->impl->thread_attrs));
169170
if (RCL_RET_OK != thread_attrs_context_fini_ret) {
170171
if (RCL_RET_OK == ret) {
171172
ret = thread_attrs_context_fini_ret;

rcl/src/rcl/context_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct rcl_context_impl_s
4040
/// rmw context.
4141
rmw_context_t rmw_context;
4242
/// thread attributes.
43-
rcl_thread_attrs_t thread_attrs;
43+
rcutils_thread_attrs_t thread_attrs;
4444
};
4545

4646
RCL_LOCAL

rcl/src/rcl/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ rcl_init(
9696
context->impl->rmw_context = rmw_get_zero_initialized_context();
9797

9898
// Zero initialize thread attribute context first so its validity can by checked in cleanup.
99-
context->impl->thread_attrs = rcl_get_zero_initialized_thread_attrs();
99+
context->impl->thread_attrs = rcutils_get_zero_initialized_thread_attrs();
100100

101101
// Store the allocator.
102102
context->impl->allocator = allocator;
@@ -261,7 +261,7 @@ rcl_init(
261261
"\t%s", discovery_options->static_peers[ii].peer_address);
262262
}
263263

264-
ret = rcl_thread_attrs_init(&(context->impl->thread_attrs), allocator);
264+
ret = rcutils_thread_attrs_init(&(context->impl->thread_attrs), allocator);
265265
if (RCL_RET_OK != ret) {
266266
fail_ret = ret;
267267
goto fail;

rcl/src/rcl/thread_attr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
#include "rcl/error_handling.h"
2020
#include "rcl/macros.h"
2121
#include "rcl_yaml_param_parser/parser_thread_attr.h"
22-
#include "rcl_yaml_param_parser/types.h"
2322
#include "rcutils/env.h"
2423
#include "rcutils/strdup.h"
24+
#include "rcutils/thread_attr.h"
2525

2626
const char * const RCL_THREAD_ATTRS_FILE_ENV_VAR = "ROS_THREAD_ATTRS_FILE";
2727
const char * const RCL_THREAD_ATTRS_VALUE_ENV_VAR = "ROS_THREAD_ATTRS_VALUE";
2828

2929
rcl_ret_t
3030
rcl_get_default_thread_attrs_from_value(
31-
rcl_thread_attrs_t * thread_attrs,
31+
rcutils_thread_attrs_t * thread_attrs,
3232
rcl_allocator_t allocator)
3333
{
3434
RCUTILS_CAN_SET_MSG_AND_RETURN_WITH_ERROR_OF(RCL_RET_INVALID_ARGUMENT);
@@ -59,7 +59,7 @@ rcl_get_default_thread_attrs_from_value(
5959

6060
rcl_ret_t
6161
rcl_get_default_thread_attrs_from_file(
62-
rcl_thread_attrs_t * thread_attrs,
62+
rcutils_thread_attrs_t * thread_attrs,
6363
rcl_allocator_t allocator)
6464
{
6565
RCUTILS_CAN_SET_MSG_AND_RETURN_WITH_ERROR_OF(RCL_RET_INVALID_ARGUMENT);

rcl_yaml_param_parser/include/rcl_yaml_param_parser/parser_thread_attr.h

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,78 +18,36 @@
1818
#include <stddef.h>
1919

2020

21-
#include "rcl_yaml_param_parser/types.h"
2221
#include "rcl_yaml_param_parser/visibility_control.h"
2322

2423
#include "rcutils/allocator.h"
2524
#include "rcutils/macros.h"
25+
#include "rcutils/thread_attr.h"
2626
#include "rcutils/types/rcutils_ret.h"
2727

2828
#ifdef __cplusplus
2929
extern "C"
3030
{
3131
#endif
3232

33-
/// \brief Return a rcl_thread_attrs_t struct with members initialized to zero value.
34-
/// \return a rcl_thread_attrs_t struct with members initialized to zero value.
35-
RCL_YAML_PARAM_PARSER_PUBLIC
36-
rcl_thread_attrs_t
37-
rcl_get_zero_initialized_thread_attrs(void);
38-
39-
/// \brief Initialize list of thread attributes
40-
/// \param[out] thread_attrs the list of thread attributes to be initialized
41-
/// \param[in] allocator memory allocator to be used
42-
/// \return #RCUTILS_RET_OK if the structure was initialized succeessfully, or
43-
/// \return #RCUTILS_RET_INVALID_ARGUMENT if any function arguments are invalid, or
44-
/// \return #RCUTILS_RET_BAD_ALLOC if allocating memory failed, or
45-
/// \return #RCUTILS_RET_ERROR an unspecified error occur.
46-
RCL_YAML_PARAM_PARSER_PUBLIC
47-
rcutils_ret_t
48-
rcl_thread_attrs_init(
49-
rcl_thread_attrs_t * thread_attrs,
50-
rcutils_allocator_t allocator);
51-
52-
/// \brief Initialize list of thread attributes with a capacity
53-
/// \param[out] thread_attrs the list of thread attributes to be initialized
54-
/// \param[in] allocator memory allocator to be used
55-
/// \return #RCUTILS_RET_OK if the structure was initialized succeessfully, or
56-
/// \return #RCUTILS_RET_INVALID_ARGUMENT if any function arguments are invalid, or
57-
/// \return #RCUTILS_RET_BAD_ALLOC if allocating memory failed, or
58-
/// \return #RCUTILS_RET_ERROR an unspecified error occur.
59-
RCL_YAML_PARAM_PARSER_PUBLIC
60-
rcutils_ret_t
61-
rcl_thread_attrs_init_with_capacity(
62-
rcl_thread_attrs_t * thread_attrs,
63-
rcutils_allocator_t allocator,
64-
size_t capacity);
65-
66-
/// \brief Free list of thread attributes
67-
/// \param[in] thread_attrs The structure to be deallocated.
68-
/// \return #RCUTILS_RET_OK if the memory was successfully freed, or
69-
/// \return #RCUTILS_RET_INVALID_ARGUMENT if any function arguments are invalid
70-
RCL_YAML_PARAM_PARSER_PUBLIC
71-
rcutils_ret_t
72-
rcl_thread_attrs_fini(
73-
rcl_thread_attrs_t * thread_attrs);
74-
7533
/// \brief Parse the YAML file and populate \p thread_attrs
7634
/// \pre Given \p thread_attrs must be a valid thread attribute struct
7735
/// \param[in] file_path is the path to the YAML file
78-
/// \param[inout] thread_attrs points to the struct to be populated
36+
/// \param[in,out] thread_attrs points to the struct to be populated
7937
/// \return true on success and false on failure
8038
RCL_YAML_PARAM_PARSER_PUBLIC
8139
rcutils_ret_t rcl_parse_yaml_thread_attrs_file(
8240
const char * file_path,
83-
rcl_thread_attrs_t * thread_attrs);
41+
rcutils_thread_attrs_t * thread_attrs);
8442

8543
/// \brief Parse a thread attribute value as a YAML string, updating thread_attrs accordingly
8644
/// \param[in] yaml_value is the thread attribute value as a YAML string to be parsed
87-
/// \param[inout] thread_attrs points to the thread attribute struct
45+
/// \param[in,out] thread_attrs points to the thread attribute struct
8846
/// \return true on success and false on failure
8947
RCL_YAML_PARAM_PARSER_PUBLIC
9048
rcutils_ret_t rcl_parse_yaml_thread_attrs_value(
9149
const char * yaml_value,
92-
rcl_thread_attrs_t * thread_attrs);
50+
rcutils_thread_attrs_t * thread_attrs);
9351

9452
#ifdef __cplusplus
9553
}

0 commit comments

Comments
 (0)