Skip to content

Commit

Permalink
Added get_actual_qos method to publisher.
Browse files Browse the repository at this point in the history
Signed-off-by: ivanpauno <ivanpauno@ekumenlabs.com>
  • Loading branch information
ivanpauno committed Mar 25, 2019
1 parent 0a44344 commit f5fac60
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions rclcpp/include/rclcpp/publisher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ class PublisherBase
size_t
get_intra_process_subscription_count() const;

/// Get actual qos settings
/** \return The number of subscriptions. */
RCLCPP_PUBLIC
std::shared_ptr<rmw_qos_profile_t>
get_actual_qos() const;

/// Compare this publisher to a gid.
/**
* Note that this function calls the next function.
Expand Down
26 changes: 25 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,30 @@ PublisherBase::get_intra_process_subscription_count() const
return ipm->get_subscription_count(intra_process_publisher_id_);
}

std::shared_ptr<rmw_qos_profile_t>
PublisherBase::get_actual_qos() const
{
auto qos = std::make_shared<rmw_qos_profile_t>();

rcl_ret_t status = rcl_publisher_get_actual_qos(
&publisher_handle_,
qos.get());
if (RCL_RET_PUBLISHER_INVALID == status) {
rcl_reset_error(); /* next call will reset error message if not context */
if (rcl_publisher_is_valid_except_context(&publisher_handle_)) {
rcl_context_t * context = rcl_publisher_get_context(&publisher_handle_);
if (nullptr != context && !rcl_context_is_valid(context)) {
/* publisher is invalid due to context being shutdown */
return 0;
}
}
}
if (RCL_RET_OK != status) {
rclcpp::exceptions::throw_from_rcl_error(status, "failed to get qos settings");
}
return qos;
}

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

0 comments on commit f5fac60

Please sign in to comment.