Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Yadunund <[email protected]>
  • Loading branch information
Yadunund committed Sep 6, 2024
1 parent ec4b036 commit 6ad087c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "rmw_context_impl_s.hpp"

#include <mutex>
#include <optional>
#include <string>
#include <thread>
#include <utility>

Expand Down Expand Up @@ -101,8 +103,9 @@ rmw_context_impl_s::Data::Data(
}

///=============================================================================
rmw_ret_t rmw_context_impl_s::Data::subscribe()
rmw_ret_t rmw_context_impl_s::Data::subscribe_to_ros_graph()
{
std::lock_guard<std::mutex> lock(mutex_);
if (is_initialized_) {
return RMW_RET_OK;
}
Expand All @@ -120,8 +123,7 @@ rmw_ret_t rmw_context_impl_s::Data::subscribe()
// shared_ptr<Data> would live on until the graph_sub_data_handler callback.
auto sub_options = zc_liveliness_subscriber_options_null();
z_owned_closure_sample_t callback = z_closure(
rmw_context_impl_s::graph_sub_data_handler, nullptr,
this->shared_from_this().get());
rmw_context_impl_s::graph_sub_data_handler, nullptr, this);
graph_subscriber_ = zc_liveliness_declare_subscriber(
z_loan(session_),
z_keyexpr(liveliness_str_.c_str()),
Expand Down Expand Up @@ -186,6 +188,11 @@ rmw_context_impl_s::rmw_context_impl_s(
const std::size_t domain_id,
const std::string & enclave)
{
// Check if allocator is valid.
if (!rcutils_allocator_is_valid(allocator)) {
throw std::runtime_error("Invalid allocator passed to rmw_context_impl_s.");
}

// Initialize the zenoh configuration.
z_owned_config_t config;
rmw_ret_t ret;
Expand Down Expand Up @@ -366,7 +373,7 @@ rmw_context_impl_s::rmw_context_impl_s(
std::move(graph_cache),
graph_guard_condition);

ret = data_->subscribe();
ret = data_->subscribe_to_ros_graph();
if (ret != RMW_RET_OK) {
throw std::runtime_error("Unable to subscribe to ROS Graph updates.");
}
Expand Down
2 changes: 1 addition & 1 deletion rmw_zenoh_cpp/src/detail/rmw_context_impl_s.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class rmw_context_impl_s final
rmw_guard_condition_t * graph_guard_condition);

// Subscribe to the ROS graph.
rmw_ret_t subscribe();
rmw_ret_t subscribe_to_ros_graph();

// Shutdown the Zenoh session.
rmw_ret_t shutdown();
Expand Down

0 comments on commit 6ad087c

Please sign in to comment.