17 #include "./arguments_impl.h"
18 #include "./remap_impl.h"
19 #include "rcl/error_handling.h"
21 #include "rcutils/allocator.h"
22 #include "rcutils/macros.h"
23 #include "rcutils/strdup.h"
24 #include "rcutils/types/string_map.h"
51 if (NULL != rule_out->
impl) {
52 RCL_SET_ERROR_MSG(
"rule_out must be zero initialized");
59 if (NULL == rule_out->
impl) {
66 rule_out->
impl->
type = RCL_UNKNOWN_REMAP;
94 RCL_SET_ERROR_MSG(
"Error while finalizing remap rule due to another error");
103 rcl_remap_first_match(
106 rcl_remap_type_t type_bitmask,
108 const char * node_name,
109 const char * node_namespace,
110 const rcutils_string_map_t * substitutions,
111 rcutils_allocator_t allocator,
115 for (
int i = 0; i < num_rules; ++i) {
117 if (!(rule->
impl->
type & type_bitmask)) {
125 bool matched =
false;
126 if (rule->
impl->
type & (RCL_TOPIC_REMAP | RCL_SERVICE_REMAP)) {
128 char * expanded_match = NULL;
130 rule->
impl->
match, node_name, node_namespace,
131 substitutions, allocator, &expanded_match);
148 matched = (0 == strcmp(expanded_match, name));
150 allocator.deallocate(expanded_match, allocator.state);
169 rcl_remap_type_t type_bitmask,
171 const char * node_name,
172 const char * node_namespace,
173 const rcutils_string_map_t * substitutions,
179 if (NULL != local_arguments && NULL == local_arguments->
impl) {
180 local_arguments = NULL;
182 if (NULL != global_arguments && NULL == global_arguments->
impl) {
183 global_arguments = NULL;
185 if (NULL == local_arguments && NULL == global_arguments) {
186 RCL_SET_ERROR_MSG(
"local_arguments invalid and not using global arguments");
194 if (NULL != local_arguments) {
197 name, node_name, node_namespace, substitutions, allocator, &rule);
203 if (NULL == rule && NULL != global_arguments) {
206 name, node_name, node_namespace, substitutions, allocator, &rule);
213 if (rule->
impl->
type & (RCL_TOPIC_REMAP | RCL_SERVICE_REMAP)) {
216 rule->
impl->
replacement, node_name, node_namespace, substitutions, allocator, output_name);
224 if (NULL == *output_name) {
225 RCL_SET_ERROR_MSG(
"Failed to set output");
236 const char * topic_name,
237 const char * node_name,
238 const char * node_namespace,
245 rcutils_string_map_t substitutions = rcutils_get_zero_initialized_string_map();
246 rcutils_ret_t rcutils_ret = rcutils_string_map_init(&substitutions, 0, allocator);
248 if (RCUTILS_RET_OK == rcutils_ret) {
251 ret = rcl_remap_name(
252 local_arguments, global_arguments, RCL_TOPIC_REMAP, topic_name, node_name,
253 node_namespace, &substitutions, allocator, output_name);
256 if (RCUTILS_RET_OK != rcutils_string_map_fini(&substitutions)) {
266 const char * service_name,
267 const char * node_name,
268 const char * node_namespace,
275 rcutils_string_map_t substitutions = rcutils_get_zero_initialized_string_map();
276 rcutils_ret_t rcutils_ret = rcutils_string_map_init(&substitutions, 0, allocator);
278 if (rcutils_ret == RCUTILS_RET_OK) {
281 ret = rcl_remap_name(
282 local_arguments, global_arguments, RCL_SERVICE_REMAP, service_name, node_name,
283 node_namespace, &substitutions, allocator, output_name);
286 if (RCUTILS_RET_OK != rcutils_string_map_fini(&substitutions)) {
296 const char * node_name,
307 return rcl_remap_name(
308 local_arguments, global_arguments, RCL_NODENAME_REMAP, NULL, node_name, NULL, NULL,
309 allocator, output_name);
316 const char * node_name,
318 char ** output_namespace)
327 return rcl_remap_name(
328 local_arguments, global_arguments, RCL_NAMESPACE_REMAP, NULL, node_name, NULL, NULL,
329 allocator, output_namespace);
358 RCL_SET_ERROR_MSG(
"rcl_remap_t finalized twice");
#define RCL_CHECK_ALLOCATOR_WITH_MSG(allocator, msg, fail_statement)
Check that the given allocator is initialized, or fail with a message.
rcutils_allocator_t rcl_allocator_t
Encapsulation of an allocator.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_expand_topic_name(const char *input_topic_name, const char *node_name, const char *node_namespace, const rcutils_string_map_t *substitutions, rcl_allocator_t allocator, char **output_topic_name)
Expand a given topic name into a fully-qualified topic name.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_get_default_topic_name_substitutions(rcutils_string_map_t *string_map)
Fill a given string map with the default substitution pairs.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_remap_node_namespace(const rcl_arguments_t *local_arguments, const rcl_arguments_t *global_arguments, const char *node_name, rcl_allocator_t allocator, char **output_namespace)
Remap a namespace based on given rules.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_remap_fini(rcl_remap_t *remap)
Reclaim resources held inside rcl_remap_t structure.
RCL_PUBLIC RCL_WARN_UNUSED rcl_remap_t rcl_get_zero_initialized_remap(void)
Return a rcl_remap_t struct with members initialized to NULL.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_remap_service_name(const rcl_arguments_t *local_arguments, const rcl_arguments_t *global_arguments, const char *service_name, const char *node_name, const char *node_namespace, rcl_allocator_t allocator, char **output_name)
Remap a service name based on given rules.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_remap_copy(const rcl_remap_t *rule, rcl_remap_t *rule_out)
Copy one remap structure into another.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_remap_topic_name(const rcl_arguments_t *local_arguments, const rcl_arguments_t *global_arguments, const char *topic_name, const char *node_name, const char *node_namespace, rcl_allocator_t allocator, char **output_name)
Remap a topic name based on given rules.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_remap_node_name(const rcl_arguments_t *local_arguments, const rcl_arguments_t *global_arguments, const char *node_name, rcl_allocator_t allocator, char **output_name)
Remap a node name based on given rules.
rcl_remap_t * remap_rules
Array of rules for name remapping.
int num_remap_rules
Length of remap_rules.
Hold output of parsing command line arguments.
rcl_arguments_impl_t * impl
Private implementation pointer.
char * replacement
Replacement portion of a rule.
char * node_name
A node name that this rule is limited to, or NULL if it applies to any node.
rcl_allocator_t allocator
Allocator used to allocate objects in this struct.
char * match
Match portion of a rule, or NULL if node name or namespace replacement.
rcl_remap_type_t type
Bitmask indicating what type of rule this is.
rcl_remap_impl_t * impl
Private implementation pointer.
#define RCL_RET_NODE_INVALID_NAMESPACE
Invalid node namespace return code.
#define RCL_RET_OK
Success return code.
#define RCL_RET_BAD_ALLOC
Failed to allocate memory return code.
#define RCL_RET_INVALID_ARGUMENT
Invalid argument return code.
#define RCL_RET_ERROR
Unspecified error return code.
#define RCL_RET_NODE_INVALID_NAME
Invalid node name return code.
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.