Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Hernandez Cordero <[email protected]>
  • Loading branch information
ahcorde committed Nov 4, 2024
1 parent 9b06a22 commit 7bb8d5a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 32 deletions.
63 changes: 34 additions & 29 deletions rmw_zenoh_cpp/src/detail/rmw_context_impl_s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "identifier.hpp"
#include "liveliness_utils.hpp"
#include "logging_macros.hpp"
#include "rmw_data_types.hpp"
#include "zenoh_config.hpp"
#include "zenoh_router_check.hpp"

Expand Down Expand Up @@ -123,8 +124,12 @@ rmw_ret_t rmw_context_impl_s::Data::subscribe_to_ros_graph()
// rmw_context_fini() to destroy rmw_context_impl_s, the locked
// 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);
z_owned_closure_sample_t callback =
rmw_zenoh_cpp::make_z_closure<z_owned_closure_sample_t, const z_sample_t>(
static_cast<void *>(this),
rmw_context_impl_s::graph_sub_data_handler,
nullptr
);
graph_subscriber_ = zc_liveliness_declare_subscriber(
z_loan(session_),
z_keyexpr(liveliness_str_.c_str()),
Expand Down Expand Up @@ -205,11 +210,11 @@ rmw_context_impl_s::rmw_context_impl_s(
}

// Check if shm is enabled.
z_owned_str_t shm_enabled = zc_config_get(z_loan(config), "transport/shared_memory/enabled");
auto always_free_shm_enabled = rcpputils::make_scope_exit(
[&shm_enabled]() {
z_drop(z_move(shm_enabled));
});
// z_owned_str_t shm_enabled = zc_config_get(z_loan(config), "transport/shared_memory/enabled");
// auto always_free_shm_enabled = rcpputils::make_scope_exit(
// [&shm_enabled]() {
// z_drop(z_move(shm_enabled));
// });

// Initialize the zenoh session.
z_owned_session_t session = z_open(z_move(config));
Expand Down Expand Up @@ -293,28 +298,28 @@ rmw_context_impl_s::rmw_context_impl_s(

// Initialize the shm manager if shared_memory is enabled in the config.
std::optional<zc_owned_shm_manager_t> shm_manager = std::nullopt;
if (shm_enabled._cstr != nullptr &&
strcmp(shm_enabled._cstr, "true") == 0)
{
char idstr[sizeof(zid.id) * 2 + 1]; // 2 bytes for each byte of the id, plus the trailing \0
static constexpr size_t max_size_of_each = 3; // 2 for each byte, plus the trailing \0
for (size_t i = 0; i < sizeof(zid.id); ++i) {
snprintf(idstr + 2 * i, max_size_of_each, "%02x", zid.id[i]);
}
idstr[sizeof(zid.id) * 2] = '\0';
// TODO(yadunund): Can we get the size of the shm from the config even though it's not
// a standard parameter?
shm_manager =
zc_shm_manager_new(
z_loan(session),
idstr,
SHM_BUFFER_SIZE_MB * 1024 * 1024);
if (!shm_manager.has_value() ||
!zc_shm_manager_check(&shm_manager.value()))
{
throw std::runtime_error("Unable to create shm manager.");
}
}
// if (shm_enabled._cstr != nullptr &&
// strcmp(shm_enabled._cstr, "true") == 0)
// {
// char idstr[sizeof(zid.id) * 2 + 1]; // 2 bytes for each byte of the id, plus the trailing \0
// static constexpr size_t max_size_of_each = 3; // 2 for each byte, plus the trailing \0
// for (size_t i = 0; i < sizeof(zid.id); ++i) {
// snprintf(idstr + 2 * i, max_size_of_each, "%02x", zid.id[i]);
// }
// idstr[sizeof(zid.id) * 2] = '\0';
// // TODO(yadunund): Can we get the size of the shm from the config even though it's not
// // a standard parameter?
// shm_manager =
// zc_shm_manager_new(
// z_loan(session),
// idstr,
// SHM_BUFFER_SIZE_MB * 1024 * 1024);
// if (!shm_manager.has_value() ||
// !zc_shm_manager_check(&shm_manager.value()))
// {
// throw std::runtime_error("Unable to create shm manager.");
// }
// }
auto free_shm_manager = rcpputils::make_scope_exit(
[&shm_manager]() {
if (shm_manager.has_value()) {
Expand Down
1 change: 0 additions & 1 deletion rmw_zenoh_cpp/src/detail/rmw_data_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,4 @@ void client_data_drop(void * data)
}
}
}

} // namespace rmw_zenoh_cpp
7 changes: 6 additions & 1 deletion rmw_zenoh_cpp/src/detail/rmw_service_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "attachment_helpers.hpp"
#include "cdr.hpp"
#include "rmw_context_impl_s.hpp"
#include "rmw_data_types.hpp"
#include "message_type_support.hpp"
#include "logging_macros.hpp"
#include "qos.hpp"
Expand Down Expand Up @@ -157,7 +158,11 @@ std::shared_ptr<ServiceData> ServiceData::make(

// TODO(Yadunund): Instead of passing a rawptr, rely on capturing weak_ptr<ServiceData>
// in the closure callback once we switch to zenoh-cpp.
z_owned_closure_query_t callback = z_closure(service_data_handler, nullptr, service_data.get());
z_owned_closure_query_t callback =
rmw_zenoh_cpp::make_z_closure<z_owned_closure_query_t, const z_query_t>(
static_cast<void *>(service_data.get()),
&rmw_zenoh_cpp::service_data_handler,
nullptr);
service_data->keyexpr_ =
z_keyexpr_new(service_data->entity_->topic_info().value().topic_keyexpr_.c_str());
auto free_ros_keyexpr = rcpputils::make_scope_exit(
Expand Down
6 changes: 5 additions & 1 deletion rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "cdr.hpp"
#include "identifier.hpp"
#include "rmw_context_impl_s.hpp"
#include "rmw_data_types.hpp"
#include "message_type_support.hpp"
#include "logging_macros.hpp"
#include "qos.hpp"
Expand Down Expand Up @@ -224,7 +225,10 @@ bool SubscriptionData::init()
{
// TODO(Yadunund): Instead of passing a rawptr, rely on capturing weak_ptr<SubscriptionData>
// in the closure callback once we switch to zenoh-cpp.
z_owned_closure_sample_t callback = z_closure(sub_data_handler, nullptr, this);
z_owned_closure_sample_t callback =
rmw_zenoh_cpp::make_z_closure<z_owned_closure_sample_t, const z_sample_t>(
static_cast<void *>(this), sub_data_handler, nullptr
);
z_owned_keyexpr_t keyexpr =
z_keyexpr_new(entity_->topic_info()->topic_keyexpr_.c_str());
auto always_free_ros_keyexpr = rcpputils::make_scope_exit(
Expand Down

0 comments on commit 7bb8d5a

Please sign in to comment.