Skip to content

Commit 41792cb

Browse files
authored
Migrate to '--ros-args ... [--]'-based ROS args extraction (ros2#477)
* Migrate to '--ros-args ... [--]'-based ROS args extraction Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com> * Extend rcl arguments API to retrieve unparsed ROS args. Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com> * Adapt rcl arguments tests. Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com> * Complete unparsed ROS args functionality. Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com> * Address peer review comments. Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com> * Extend rcl arguments test coverage. Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com> * Adapt more rcl tests to use --ros-args. Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com> * Address peer review comments. Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com> * Ignore duplicate --ros-args flags. Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
1 parent 6f20cd9 commit 41792cb

File tree

6 files changed

+552
-196
lines changed

6 files changed

+552
-196
lines changed

rcl/include/rcl/arguments.h

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ typedef struct rcl_arguments_t
3434
struct rcl_arguments_impl_t * impl;
3535
} rcl_arguments_t;
3636

37+
#define RCL_ROS_ARGS_FLAG "--ros-args"
38+
#define RCL_ROS_ARGS_EXPLICIT_END_TOKEN "--"
39+
3740
#define RCL_LOG_LEVEL_ARG_RULE "__log_level:="
3841
#define RCL_EXTERNAL_LOG_CONFIG_ARG_RULE "__log_config_file:="
3942
#define RCL_LOG_DISABLE_STDOUT_ARG_RULE "__log_disable_stdout:="
@@ -97,7 +100,7 @@ rcl_parse_arguments(
97100
rcl_allocator_t allocator,
98101
rcl_arguments_t * args_output);
99102

100-
/// Return the number of arguments that were not successfully parsed.
103+
/// Return the number of arguments that were not ROS specific arguments.
101104
/**
102105
* <hr>
103106
* Attribute | Adherence
@@ -117,10 +120,10 @@ int
117120
rcl_arguments_get_count_unparsed(
118121
const rcl_arguments_t * args);
119122

120-
/// Return a list of indexes that weren't successfully parsed.
123+
/// Return a list of indices to non ROS specific arguments.
121124
/**
122-
* Some arguments may not have been successfully parsed, or were not intended as ROS arguments.
123-
* This function populates an array of indexes to these arguments in the original argv array.
125+
* Non ROS specific arguments may have been provided i.e. arguments outside a '--ros-args' scope.
126+
* This function populates an array of indices to these arguments in the original argv array.
124127
* Since the first argument is always assumed to be a process name, the list will always contain
125128
* the index 0.
126129
*
@@ -150,6 +153,58 @@ rcl_arguments_get_unparsed(
150153
rcl_allocator_t allocator,
151154
int ** output_unparsed_indices);
152155

156+
/// Return the number of ROS specific arguments that were not successfully parsed.
157+
/**
158+
* <hr>
159+
* Attribute | Adherence
160+
* ------------------ | -------------
161+
* Allocates Memory | No
162+
* Thread-Safe | Yes
163+
* Uses Atomics | No
164+
* Lock-Free | Yes
165+
*
166+
* \param[in] args An arguments structure that has been parsed.
167+
* \return number of unparsed ROS specific arguments, or
168+
* \return -1 if args is `NULL` or zero initialized.
169+
*/
170+
RCL_PUBLIC
171+
RCL_WARN_UNUSED
172+
int
173+
rcl_arguments_get_count_unparsed_ros(
174+
const rcl_arguments_t * args);
175+
176+
/// Return a list of indices to ROS specific arguments that were not successfully parsed.
177+
/**
178+
* Some ROS specific arguments may not have been successfully parsed, or were not intended to be
179+
* parsed by rcl.
180+
* This function populates an array of indices to these arguments in the original argv array.
181+
*
182+
* <hr>
183+
* Attribute | Adherence
184+
* ------------------ | -------------
185+
* Allocates Memory | Yes
186+
* Thread-Safe | Yes
187+
* Uses Atomics | No
188+
* Lock-Free | Yes
189+
*
190+
* \param[in] args An arguments structure that has been parsed.
191+
* \param[in] allocator A valid allocator.
192+
* \param[out] output_unparsed_indices An allocated array of indices into the original argv array.
193+
* This array must be deallocated by the caller using the given allocator.
194+
* If there are no unparsed ROS specific arguments then the output will be set to NULL.
195+
* \return `RCL_RET_OK` if everything goes correctly, or
196+
* \return `RCL_RET_INVALID_ARGUMENT` if any function arguments are invalid, or
197+
* \return `RCL_RET_BAD_ALLOC` if allocating memory failed, or
198+
* \return `RCL_RET_ERROR` if an unspecified error occurs.
199+
*/
200+
RCL_PUBLIC
201+
RCL_WARN_UNUSED
202+
rcl_ret_t
203+
rcl_arguments_get_unparsed_ros(
204+
const rcl_arguments_t * args,
205+
rcl_allocator_t allocator,
206+
int ** output_unparsed_ros_indices);
207+
153208
/// Return the number of parameter yaml files given in the arguments.
154209
/**
155210
* <hr>

0 commit comments

Comments
 (0)