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"
52 if (NULL != rule_out->
impl) {
53 RCL_SET_ERROR_MSG(
"rule_out must be zero initialized");
60 if (NULL == rule_out->
impl) {
67 rule_out->
impl->
type = RCL_UNKNOWN_REMAP;
95 RCL_SET_ERROR_MSG(
"Error while finalizing remap rule due to another error");
104 rcl_remap_first_match(
107 rcl_remap_type_t type_bitmask,
109 const char * node_name,
110 const char * node_namespace,
111 const rcutils_string_map_t * substitutions,
112 rcutils_allocator_t allocator,
116 for (
int i = 0; i < num_rules; ++i) {
118 if (!(rule->
impl->
type & type_bitmask)) {
126 bool matched =
false;
127 if (rule->
impl->
type & (RCL_TOPIC_REMAP | RCL_SERVICE_REMAP)) {
129 char * expanded_match = NULL;
131 rule->
impl->
match, node_name, node_namespace,
132 substitutions, allocator, &expanded_match);
149 matched = (0 == strcmp(expanded_match, name));
151 allocator.deallocate(expanded_match, allocator.state);
170 rcl_remap_type_t type_bitmask,
172 const char * node_name,
173 const char * node_namespace,
174 const rcutils_string_map_t * substitutions,
180 if (NULL != local_arguments && NULL == local_arguments->
impl) {
181 local_arguments = NULL;
183 if (NULL != global_arguments && NULL == global_arguments->
impl) {
184 global_arguments = NULL;
186 if (NULL == local_arguments && NULL == global_arguments) {
187 RCL_SET_ERROR_MSG(
"local_arguments invalid and not using global arguments");
195 if (NULL != local_arguments) {
198 name, node_name, node_namespace, substitutions, allocator, &rule);
204 if (NULL == rule && NULL != global_arguments) {
207 name, node_name, node_namespace, substitutions, allocator, &rule);
214 if (rule->
impl->
type & (RCL_TOPIC_REMAP | RCL_SERVICE_REMAP)) {
217 rule->
impl->
replacement, node_name, node_namespace, substitutions, allocator, output_name);
225 if (NULL == *output_name) {
226 RCL_SET_ERROR_MSG(
"Failed to set output");
237 const char * topic_name,
238 const char * node_name,
239 const char * node_namespace,
246 rcutils_string_map_t substitutions = rcutils_get_zero_initialized_string_map();
247 rcutils_ret_t rcutils_ret = rcutils_string_map_init(&substitutions, 0, allocator);
249 if (RCUTILS_RET_OK == rcutils_ret) {
252 ret = rcl_remap_name(
253 local_arguments, global_arguments, RCL_TOPIC_REMAP, topic_name, node_name,
254 node_namespace, &substitutions, allocator, output_name);
257 if (RCUTILS_RET_OK != rcutils_string_map_fini(&substitutions)) {
267 const char * service_name,
268 const char * node_name,
269 const char * node_namespace,
276 rcutils_string_map_t substitutions = rcutils_get_zero_initialized_string_map();
277 rcutils_ret_t rcutils_ret = rcutils_string_map_init(&substitutions, 0, allocator);
279 if (rcutils_ret == RCUTILS_RET_OK) {
282 ret = rcl_remap_name(
283 local_arguments, global_arguments, RCL_SERVICE_REMAP, service_name, node_name,
284 node_namespace, &substitutions, allocator, output_name);
287 if (RCUTILS_RET_OK != rcutils_string_map_fini(&substitutions)) {
297 const char * node_name,
308 return rcl_remap_name(
309 local_arguments, global_arguments, RCL_NODENAME_REMAP, NULL, node_name, NULL, NULL,
310 allocator, output_name);
317 const char * node_name,
319 char ** output_namespace)
328 return rcl_remap_name(
329 local_arguments, global_arguments, RCL_NAMESPACE_REMAP, NULL, node_name, NULL, NULL,
330 allocator, output_namespace);
359 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.