Skip to content

Commit

Permalink
Add function to get publisher actual qos settings (ros2#667)
Browse files Browse the repository at this point in the history
* Added get_actual_qos method to publisher.

Signed-off-by: ivanpauno <ivanpauno@ekumenlabs.com>
  • Loading branch information
ivanpauno authored and christopherho-ApexAI committed Jun 3, 2019
1 parent c900979 commit b2a94f9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
14 changes: 14 additions & 0 deletions rclcpp/include/rclcpp/publisher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ class PublisherBase
size_t
get_intra_process_subscription_count() 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;

/// Compare this publisher to a gid.
/**
* Note that this function calls the next function.
Expand Down
14 changes: 13 additions & 1 deletion rclcpp/src/rclcpp/publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ PublisherBase::get_subscription_count() const
{
size_t inter_process_subscription_count = 0;

rmw_ret_t status = rcl_publisher_get_subscription_count(
rcl_ret_t status = rcl_publisher_get_subscription_count(
&publisher_handle_,
&inter_process_subscription_count);

Expand Down Expand Up @@ -197,6 +197,18 @@ PublisherBase::get_intra_process_subscription_count() const
return ipm->get_subscription_count(intra_process_publisher_id_);
}

rmw_qos_profile_t
PublisherBase::get_actual_qos() const
{
const rmw_qos_profile_t * qos = rcl_publisher_get_actual_qos(&publisher_handle_);
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;
}

bool
PublisherBase::operator==(const rmw_gid_t & gid) const
{
Expand Down

0 comments on commit b2a94f9

Please sign in to comment.