Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templatize so it works both before and after RMW changes #2

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 45 additions & 17 deletions rmw_cyclonedds_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,14 +1085,13 @@ extern "C" rmw_ret_t rmw_fini_publisher_allocation(rmw_publisher_allocation_t *
return RMW_RET_ERROR;
}

extern "C" rmw_publisher_t * rmw_create_publisher(
const rmw_node_t * node,
const rosidl_message_type_support_t * type_supports, const char * topic_name,
const rmw_qos_profile_t * qos_policies, const rmw_publisher_options_t * publisher_options)
rmw_publisher_t * rmw_create_publisher(
const rmw_node_t * node, const rosidl_message_type_support_t * type_supports,
const char * topic_name, const rmw_qos_profile_t * qos_policies)
{
// until https://github.com/ros2/rmw/pull/187
CddsPublisher * pub;
rmw_publisher_t * rmw_publisher;
RET_NULL_X(publisher_options, return nullptr);
if ((pub = create_cdds_publisher(node, type_supports, topic_name, qos_policies)) == nullptr) {
goto fail_common_init;
}
Expand All @@ -1103,7 +1102,6 @@ extern "C" rmw_publisher_t * rmw_create_publisher(
rmw_publisher->topic_name = reinterpret_cast<char *>(rmw_allocate(strlen(topic_name) + 1));
RET_ALLOC_X(rmw_publisher->topic_name, goto fail_topic_name);
memcpy(const_cast<char *>(rmw_publisher->topic_name), topic_name, strlen(topic_name) + 1);
rmw_publisher->options = *publisher_options;
return rmw_publisher;
fail_topic_name:
rmw_publisher_free(rmw_publisher);
Expand All @@ -1116,6 +1114,22 @@ extern "C" rmw_publisher_t * rmw_create_publisher(
return nullptr;
}

template<typename T_rmw_publisher, typename T_rmw_publisher_options>
rmw_publisher_t * rmw_create_publisher(
const rmw_node_t * node, const rosidl_message_type_support_t * type_supports,
const char * topic_name, const rmw_qos_profile_t * qos_policies,
const T_rmw_publisher_options * publisher_options)
{
// since https://github.com/ros2/rmw/pull/187
RET_NULL_X(publisher_options, return nullptr);
T_rmw_publisher rmw_publisher =
rmw_create_publisher(node, type_supports, topic_name, qos_policies);
if (rmw_publisher != nullptr) {
rmw_publisher.options = publisher_options;
}
return rmw_publisher;
}

extern "C" rmw_ret_t rmw_get_gid_for_publisher(const rmw_publisher_t * publisher, rmw_gid_t * gid)
{
RET_WRONG_IMPLID(publisher);
Expand Down Expand Up @@ -1272,17 +1286,16 @@ extern "C" rmw_ret_t rmw_fini_subscription_allocation(rmw_subscription_allocatio
return RMW_RET_ERROR;
}

extern "C" rmw_subscription_t * rmw_create_subscription(
const rmw_node_t * node,
const rosidl_message_type_support_t * type_supports, const char * topic_name,
const rmw_qos_profile_t * qos_policies, const rmw_subscription_options_t * subscription_options)
rmw_subscription_t * rmw_create_subscription(
const rmw_node_t * node, const rosidl_message_type_support_t * type_supports,
const char * topic_name, const rmw_qos_profile_t * qos_policies, bool ignore_local_publications)
{
// until https://github.com/ros2/rmw/pull/187
CddsSubscription * sub;
rmw_subscription_t * rmw_subscription;
RET_NULL_X(subscription_options, return nullptr);
if ((sub =
create_cdds_subscription(node, type_supports, topic_name, qos_policies,
subscription_options->ignore_local_publications)) == nullptr)
if (
(sub = create_cdds_subscription(
node, type_supports, topic_name, qos_policies, ignore_local_publications)) == nullptr)
{
goto fail_common_init;
}
Expand All @@ -1294,14 +1307,13 @@ extern "C" rmw_subscription_t * rmw_create_subscription(
reinterpret_cast<const char *>(rmw_allocate(strlen(topic_name) + 1));
RET_ALLOC_X(rmw_subscription->topic_name, goto fail_topic_name);
memcpy(const_cast<char *>(rmw_subscription->topic_name), topic_name, strlen(topic_name) + 1);
rmw_subscription->options = *subscription_options;
return rmw_subscription;
fail_topic_name:
rmw_subscription_free(rmw_subscription);
fail_subscription:
if (dds_delete(sub->rdcondh) < 0) {
RCUTILS_LOG_ERROR_NAMED("rmw_cyclonedds_cpp",
"failed to delete readcondition during error handling");
RCUTILS_LOG_ERROR_NAMED(
"rmw_cyclonedds_cpp", "failed to delete readcondition during error handling");
}
if (dds_delete(sub->subh) < 0) {
RCUTILS_LOG_ERROR_NAMED("rmw_cyclonedds_cpp", "failed to delete reader during error handling");
Expand All @@ -1311,6 +1323,22 @@ extern "C" rmw_subscription_t * rmw_create_subscription(
return nullptr;
}

template<typename T_rmw_subscription, typename T_rmw_subscription_options>
rmw_subscription_t * rmw_create_subscription(
const rmw_node_t * node, const rosidl_message_type_support_t * type_supports,
const char * topic_name, const rmw_qos_profile_t * qos_policies,
const T_rmw_subscription_options * subscription_options)
{
// since https://github.com/ros2/rmw/pull/187
RET_NULL_X(subscription_options, return nullptr);
T_rmw_subscription * rmw_subscription = rmw_create_subscription(
node, type_supports, topic_name, qos_policies, subscription_options->ignore_local_publication);
if (rmw_subscription != nullptr) {
rmw_subscription->options = *subscription_options;
}
return rmw_subscription;
}

extern "C" rmw_ret_t rmw_subscription_count_matched_publishers(
const rmw_subscription_t * subscription, size_t * publisher_count)
{
Expand Down