From 8457b00536b44bca29b83fd7b0c4cbcee80169c9 Mon Sep 17 00:00:00 2001 From: "M. M" Date: Wed, 12 Jun 2019 08:50:27 -0700 Subject: [PATCH] Implement get_actual_qos() for subscriptions (#271) * add get_actual_qos() feature to subscriptions Signed-off-by: Miaofei * reduce duplicate code Signed-off-by: Miaofei * remove duplicate check Signed-off-by: Miaofei * use visibility macros Signed-off-by: Miaofei --- rmw_opensplice_cpp/src/qos.cpp | 93 +++++++++++++++++++++ rmw_opensplice_cpp/src/qos.hpp | 24 +++++- rmw_opensplice_cpp/src/rmw_publisher.cpp | 65 +------------- rmw_opensplice_cpp/src/rmw_subscription.cpp | 30 +++++++ 4 files changed, 146 insertions(+), 66 deletions(-) diff --git a/rmw_opensplice_cpp/src/qos.cpp b/rmw_opensplice_cpp/src/qos.cpp index 3b7f1a0f..ce0c4d37 100644 --- a/rmw_opensplice_cpp/src/qos.cpp +++ b/rmw_opensplice_cpp/src/qos.cpp @@ -188,3 +188,96 @@ bool get_datawriter_qos( return set_entity_qos_from_profile(qos_profile, datawriter_qos); } + +void +dds_qos_lifespan_to_rmw_qos_lifespan( + const DDS::DataWriterQos & dds_qos, + rmw_qos_profile_t * qos) +{ + qos->lifespan.sec = dds_qos.lifespan.duration.sec; + qos->lifespan.nsec = dds_qos.lifespan.duration.nanosec; +} + +void +dds_qos_lifespan_to_rmw_qos_lifespan( + const DDS::DataReaderQos & /*dds_qos*/, + rmw_qos_profile_t * /*qos*/) +{ + // lifespan does does not exist in DataReader, so no-op here +} + +template +void +dds_qos_to_rmw_qos( + const AttributeT & dds_qos, + rmw_qos_profile_t * qos) +{ + switch (dds_qos.history.kind) { + case DDS::KEEP_LAST_HISTORY_QOS: + qos->history = RMW_QOS_POLICY_HISTORY_KEEP_LAST; + break; + case DDS::KEEP_ALL_HISTORY_QOS: + qos->history = RMW_QOS_POLICY_HISTORY_KEEP_ALL; + break; + default: + qos->history = RMW_QOS_POLICY_HISTORY_UNKNOWN; + break; + } + qos->depth = static_cast(dds_qos.history.depth); + + switch (dds_qos.reliability.kind) { + case DDS::BEST_EFFORT_RELIABILITY_QOS: + qos->reliability = RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT; + break; + case DDS::RELIABLE_RELIABILITY_QOS: + qos->reliability = RMW_QOS_POLICY_RELIABILITY_RELIABLE; + break; + default: + qos->reliability = RMW_QOS_POLICY_RELIABILITY_UNKNOWN; + break; + } + + switch (dds_qos.durability.kind) { + case DDS::TRANSIENT_LOCAL_DURABILITY_QOS: + qos->durability = RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL; + break; + case DDS::VOLATILE_DURABILITY_QOS: + qos->durability = RMW_QOS_POLICY_DURABILITY_VOLATILE; + break; + default: + qos->durability = RMW_QOS_POLICY_DURABILITY_UNKNOWN; + break; + } + + qos->deadline.sec = dds_qos.deadline.period.sec; + qos->deadline.nsec = dds_qos.deadline.period.nanosec; + + dds_qos_lifespan_to_rmw_qos_lifespan(dds_qos, qos); + + switch (dds_qos.liveliness.kind) { + case DDS::AUTOMATIC_LIVELINESS_QOS: + qos->liveliness = RMW_QOS_POLICY_LIVELINESS_AUTOMATIC; + break; + case DDS::MANUAL_BY_PARTICIPANT_LIVELINESS_QOS: + qos->liveliness = RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_NODE; + break; + case DDS::MANUAL_BY_TOPIC_LIVELINESS_QOS: + qos->liveliness = RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_TOPIC; + break; + default: + qos->liveliness = RMW_QOS_POLICY_LIVELINESS_UNKNOWN; + break; + } + qos->liveliness_lease_duration.sec = dds_qos.liveliness.lease_duration.sec; + qos->liveliness_lease_duration.nsec = dds_qos.liveliness.lease_duration.nanosec; +} + +template +void dds_qos_to_rmw_qos( + const DDS::DataWriterQos & dds_qos, + rmw_qos_profile_t * qos); + +template +void dds_qos_to_rmw_qos( + const DDS::DataReaderQos & dds_qos, + rmw_qos_profile_t * qos); diff --git a/rmw_opensplice_cpp/src/qos.hpp b/rmw_opensplice_cpp/src/qos.hpp index a27f98d6..9dd48996 100644 --- a/rmw_opensplice_cpp/src/qos.hpp +++ b/rmw_opensplice_cpp/src/qos.hpp @@ -36,15 +36,35 @@ #include "rmw/rmw.h" RMW_LOCAL -bool get_datareader_qos( +bool +get_datareader_qos( DDS::Subscriber * subscriber, const rmw_qos_profile_t & qos_profile, DDS::DataReaderQos & datareader_qos); RMW_LOCAL -bool get_datawriter_qos( +bool +get_datawriter_qos( DDS::Publisher * publisher, const rmw_qos_profile_t & qos_profile, DDS::DataWriterQos & datawriter_qos); +template +void +dds_qos_to_rmw_qos( + const AttributeT & dds_qos, + rmw_qos_profile_t * qos); + +extern template RMW_LOCAL +void +dds_qos_to_rmw_qos( + const DDS::DataWriterQos & dds_qos, + rmw_qos_profile_t * qos); + +extern template RMW_LOCAL +void +dds_qos_to_rmw_qos( + const DDS::DataReaderQos & dds_qos, + rmw_qos_profile_t * qos); + #endif // QOS_HPP_ diff --git a/rmw_opensplice_cpp/src/rmw_publisher.cpp b/rmw_opensplice_cpp/src/rmw_publisher.cpp index df3e3600..784a7372 100644 --- a/rmw_opensplice_cpp/src/rmw_publisher.cpp +++ b/rmw_opensplice_cpp/src/rmw_publisher.cpp @@ -344,70 +344,7 @@ rmw_publisher_get_actual_qos( return RMW_RET_ERROR; } - if (!data_writer) { - RMW_SET_ERROR_MSG("publisher internal dds publisher is invalid"); - return RMW_RET_ERROR; - } - - switch (dds_qos.history.kind) { - case DDS::KEEP_LAST_HISTORY_QOS: - qos->history = RMW_QOS_POLICY_HISTORY_KEEP_LAST; - break; - case DDS::KEEP_ALL_HISTORY_QOS: - qos->history = RMW_QOS_POLICY_HISTORY_KEEP_ALL; - break; - default: - qos->history = RMW_QOS_POLICY_HISTORY_UNKNOWN; - break; - } - qos->depth = static_cast(dds_qos.history.depth); - - switch (dds_qos.reliability.kind) { - case DDS::BEST_EFFORT_RELIABILITY_QOS: - qos->reliability = RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT; - break; - case DDS::RELIABLE_RELIABILITY_QOS: - qos->reliability = RMW_QOS_POLICY_RELIABILITY_RELIABLE; - break; - default: - qos->reliability = RMW_QOS_POLICY_RELIABILITY_UNKNOWN; - break; - } - - switch (dds_qos.durability.kind) { - case DDS::TRANSIENT_LOCAL_DURABILITY_QOS: - qos->durability = RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL; - break; - case DDS::VOLATILE_DURABILITY_QOS: - qos->durability = RMW_QOS_POLICY_DURABILITY_VOLATILE; - break; - default: - qos->durability = RMW_QOS_POLICY_DURABILITY_UNKNOWN; - break; - } - - qos->deadline.sec = dds_qos.deadline.period.sec; - qos->deadline.nsec = dds_qos.deadline.period.nanosec; - - qos->lifespan.sec = dds_qos.lifespan.duration.sec; - qos->lifespan.nsec = dds_qos.lifespan.duration.nanosec; - - switch (dds_qos.liveliness.kind) { - case DDS::AUTOMATIC_LIVELINESS_QOS: - qos->liveliness = RMW_QOS_POLICY_LIVELINESS_AUTOMATIC; - break; - case DDS::MANUAL_BY_PARTICIPANT_LIVELINESS_QOS: - qos->liveliness = RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_NODE; - break; - case DDS::MANUAL_BY_TOPIC_LIVELINESS_QOS: - qos->liveliness = RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_TOPIC; - break; - default: - qos->liveliness = RMW_QOS_POLICY_LIVELINESS_UNKNOWN; - break; - } - qos->liveliness_lease_duration.sec = dds_qos.liveliness.lease_duration.sec; - qos->liveliness_lease_duration.nsec = dds_qos.liveliness.lease_duration.nanosec; + dds_qos_to_rmw_qos(dds_qos, qos); return RMW_RET_OK; } diff --git a/rmw_opensplice_cpp/src/rmw_subscription.cpp b/rmw_opensplice_cpp/src/rmw_subscription.cpp index 6626b4f1..f9eff272 100644 --- a/rmw_opensplice_cpp/src/rmw_subscription.cpp +++ b/rmw_opensplice_cpp/src/rmw_subscription.cpp @@ -325,6 +325,36 @@ rmw_subscription_count_matched_publishers( return RMW_RET_OK; } +rmw_ret_t +rmw_subscription_get_actual_qos( + const rmw_subscription_t * subscription, + rmw_qos_profile_t * qos) +{ + RMW_CHECK_ARGUMENT_FOR_NULL(subscription, RMW_RET_INVALID_ARGUMENT); + RMW_CHECK_ARGUMENT_FOR_NULL(qos, RMW_RET_INVALID_ARGUMENT); + + auto info = static_cast(subscription->data); + if (!info) { + RMW_SET_ERROR_MSG("subscription internal data is invalid"); + return RMW_RET_ERROR; + } + DDS::DataReader * data_reader = info->topic_reader; + if (!data_reader) { + RMW_SET_ERROR_MSG("subscription internal data reader is invalid"); + return RMW_RET_ERROR; + } + DDS::DataReaderQos dds_qos; + DDS::ReturnCode_t status = data_reader->get_qos(dds_qos); + if (DDS::RETCODE_OK != status) { + RMW_SET_ERROR_MSG("subscription can't get data reader qos policies"); + return RMW_RET_ERROR; + } + + dds_qos_to_rmw_qos(dds_qos, qos); + + return RMW_RET_OK; +} + rmw_ret_t rmw_destroy_subscription(rmw_node_t * node, rmw_subscription_t * subscription) {