17 #include "rcutils/error_handling.h"
18 #include "rcutils/logging_macros.h"
19 #include "rcutils/types/string_map.h"
21 #include "rmw/error_handling.h"
22 #include "rmw/validate_full_topic_name.h"
24 #include "rcl/error_handling.h"
28 #include "./remap_impl.h"
35 const char * input_topic_name,
36 const char * node_name,
37 const char * node_namespace,
41 char ** output_topic_name)
46 rcutils_string_map_t substitutions_map = rcutils_get_zero_initialized_string_map();
47 rcutils_ret_t rcutils_ret = rcutils_string_map_init(&substitutions_map, 0, allocator);
48 if (rcutils_ret != RCUTILS_RET_OK) {
49 rcutils_error_string_t error = rcutils_get_error_string();
50 rcutils_reset_error();
51 RCL_SET_ERROR_MSG(error.str);
52 if (RCUTILS_RET_BAD_ALLOC == rcutils_ret) {
57 char * expanded_topic_name = NULL;
58 char * remapped_topic_name = NULL;
73 &expanded_topic_name);
80 local_args, global_args, is_service ? RCL_SERVICE_REMAP : RCL_TOPIC_REMAP,
81 expanded_topic_name, node_name, node_namespace, &substitutions_map, allocator,
82 &remapped_topic_name);
87 if (NULL == remapped_topic_name) {
88 remapped_topic_name = expanded_topic_name;
89 expanded_topic_name = NULL;
92 int validation_result;
93 rmw_ret_t rmw_ret = rmw_validate_full_topic_name(remapped_topic_name, &validation_result, NULL);
94 if (rmw_ret != RMW_RET_OK) {
95 rcutils_error_string_t error = rmw_get_error_string();
97 RCL_SET_ERROR_MSG(error.str);
101 if (validation_result != RMW_TOPIC_VALID) {
102 RCL_SET_ERROR_MSG(rmw_full_topic_name_validation_result_string(validation_result));
106 *output_topic_name = remapped_topic_name;
107 remapped_topic_name = NULL;
110 rcutils_ret = rcutils_string_map_fini(&substitutions_map);
111 if (rcutils_ret != RCUTILS_RET_OK) {
112 rcutils_error_string_t error = rcutils_get_error_string();
113 rcutils_reset_error();
115 RCL_SET_ERROR_MSG(error.str);
118 RCUTILS_LOG_ERROR_NAMED(
120 "failed to fini string_map (%d) during error handling: %s",
125 allocator.deallocate(expanded_topic_name, allocator.state);
126 allocator.deallocate(remapped_topic_name, allocator.state);
136 const char * input_topic_name,
140 char ** output_topic_name)
144 if (NULL == node_options) {
152 return rcl_resolve_name(
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 const rcl_node_options_t * rcl_node_get_options(const rcl_node_t *node)
Return the rcl node options.
RCL_PUBLIC RCL_WARN_UNUSED const char * rcl_node_get_name(const rcl_node_t *node)
Return the name of the node.
RCL_PUBLIC RCL_WARN_UNUSED const char * rcl_node_get_namespace(const rcl_node_t *node)
Return the namespace of the node.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_node_resolve_name(const rcl_node_t *node, const char *input_name, rcl_allocator_t allocator, bool is_service, bool only_expand, char **output_name)
Expand a given name into a fully-qualified topic name and apply remapping rules.
Hold output of parsing command line arguments.
rcl_arguments_t global_arguments
Global arguments for all nodes which share this context.
Structure which encapsulates the options for creating a rcl_node_t.
bool use_global_arguments
If false then only use arguments in this struct, otherwise use global arguments also.
rcl_arguments_t arguments
Command line arguments that apply only to this node.
Structure which encapsulates a ROS Node.
rcl_context_t * context
Context associated with this node.
#define RCL_RET_SERVICE_NAME_INVALID
Service name (same as topic name) does not pass validation.
#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_TOPIC_NAME_INVALID
Topic name does not pass validation.
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.