Skip to content

Commit

Permalink
Allow to create topics with "exact" topic name from rcl ros2#496
Browse files Browse the repository at this point in the history
This is a naive implementation of the feature request documented here: ros2/ros2#496
  • Loading branch information
guillaumeautran committed May 17, 2022
1 parent 493ebf3 commit a6f6b90
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
32 changes: 19 additions & 13 deletions rcl/src/rcl/publisher.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern "C"
#include "rcl/node.h"
#include "rcutils/logging_macros.h"
#include "rcutils/macros.h"
#include "rcutils/strdup.h"
#include "rcl/time.h"
#include "rmw/time.h"
#include "rmw/error_handling.h"
Expand Down Expand Up @@ -80,20 +81,25 @@ rcl_publisher_init(

// Expand and remap the given topic name.
char * remapped_topic_name = NULL;
rcl_ret_t ret = rcl_node_resolve_name(
node,
topic_name,
*allocator,
false,
false,
&remapped_topic_name);
if (ret != RCL_RET_OK) {
if (ret == RCL_RET_TOPIC_NAME_INVALID || ret == RCL_RET_UNKNOWN_SUBSTITUTION) {
ret = RCL_RET_TOPIC_NAME_INVALID;
} else if (ret != RCL_RET_BAD_ALLOC) {
ret = RCL_RET_ERROR;
rcl_ret_t ret;
if (!options->qos.avoid_ros_namespace_conventions) {
ret = rcl_node_resolve_name(
node,
topic_name,
*allocator,
false,
false,
&remapped_topic_name);
if (ret != RCL_RET_OK) {
if (ret == RCL_RET_TOPIC_NAME_INVALID || ret == RCL_RET_UNKNOWN_SUBSTITUTION) {
ret = RCL_RET_TOPIC_NAME_INVALID;
} else if (ret != RCL_RET_BAD_ALLOC) {
ret = RCL_RET_ERROR;
}
goto cleanup;
}
goto cleanup;
} else {
remapped_topic_name = rcutils_strdup(topic_name, *allocator);
}
RCUTILS_LOG_DEBUG_NAMED(
ROS_PACKAGE_NAME, "Expanded and remapped topic name '%s'", remapped_topic_name);
Expand Down
31 changes: 18 additions & 13 deletions rcl/src/rcl/subscription.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,25 @@ rcl_subscription_init(

// Expand and remap the given topic name.
char * remapped_topic_name = NULL;
rcl_ret_t ret = rcl_node_resolve_name(
node,
topic_name,
*allocator,
false,
false,
&remapped_topic_name);
if (ret != RCL_RET_OK) {
if (ret == RCL_RET_TOPIC_NAME_INVALID || ret == RCL_RET_UNKNOWN_SUBSTITUTION) {
ret = RCL_RET_TOPIC_NAME_INVALID;
} else if (ret != RCL_RET_BAD_ALLOC) {
ret = RCL_RET_ERROR;
rcl_ret_t ret;
if (!options->qos.avoid_ros_namespace_conventions) {
ret = rcl_node_resolve_name(
node,
topic_name,
*allocator,
false,
false,
&remapped_topic_name);
if (ret != RCL_RET_OK) {
if (ret == RCL_RET_TOPIC_NAME_INVALID || ret == RCL_RET_UNKNOWN_SUBSTITUTION) {
ret = RCL_RET_TOPIC_NAME_INVALID;
} else if (ret != RCL_RET_BAD_ALLOC) {
ret = RCL_RET_ERROR;
}
goto cleanup;
}
goto cleanup;
} else {
remapped_topic_name = rcutils_strdup(topic_name, *allocator);
}
RCUTILS_LOG_DEBUG_NAMED(
ROS_PACKAGE_NAME, "Expanded and remapped topic name '%s'", remapped_topic_name);
Expand Down

0 comments on commit a6f6b90

Please sign in to comment.