diff --git a/rclcpp/include/rclcpp/subscription_base.hpp b/rclcpp/include/rclcpp/subscription_base.hpp index 8f13318..35255da 100644 --- a/rclcpp/include/rclcpp/subscription_base.hpp +++ b/rclcpp/include/rclcpp/subscription_base.hpp @@ -98,6 +98,20 @@ public: const std::vector> & get_event_handlers() const; + /// Get the actual QoS settings, after the defaults have been determined. + /** + * The actual configuration applied when using RMW_QOS_POLICY_*_SYSTEM_DEFAULT + * can only be resolved after the creation of the publisher, and it + * depends on the underlying rmw implementation. + * If the underlying setting in use can't be represented in ROS terms, + * it will be set to RMW_QOS_POLICY_*_UNKNOWN. + * May throw runtime_error when an unexpected error occurs. + * \return The actual qos settings. + */ + RCLCPP_PUBLIC + rmw_qos_profile_t + get_actual_qos() const; + /// Borrow a new message. /** \return Shared pointer to the fresh message. */ virtual std::shared_ptr diff --git a/rclcpp/src/rclcpp/subscription_base.cpp b/rclcpp/src/rclcpp/subscription_base.cpp index 9b02141..5189150 100644 --- a/rclcpp/src/rclcpp/subscription_base.cpp +++ b/rclcpp/src/rclcpp/subscription_base.cpp @@ -128,6 +128,18 @@ SubscriptionBase::get_event_handlers() const return event_handlers_; } +rmw_qos_profile_t +SubscriptionBase::get_actual_qos() const +{ + const rmw_qos_profile_t * qos = rcl_subscription_get_actual_qos(subscription_handle_.get()); + if (!qos) { + auto msg = std::string("failed to get qos settings: ") + rcl_get_error_string().str; + rcl_reset_error(); + throw std::runtime_error(msg); + } + return *qos; +} + const rosidl_message_type_support_t & SubscriptionBase::get_message_type_support_handle() const {