Skip to content

Commit

Permalink
zenoh_c to zenoh_cpp
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Hernández Cordero <[email protected]>
  • Loading branch information
ahcorde committed Nov 18, 2024
1 parent 2743344 commit a3fdb1f
Show file tree
Hide file tree
Showing 24 changed files with 250 additions and 178 deletions.
4 changes: 3 additions & 1 deletion rmw_zenoh_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ find_package(rcutils REQUIRED)
find_package(rosidl_typesupport_fastrtps_c REQUIRED)
find_package(rosidl_typesupport_fastrtps_cpp REQUIRED)
find_package(rmw REQUIRED)
find_package(zenoh_c_vendor REQUIRED)
find_package(zenoh_cpp_vendor REQUIRED)

add_library(rmw_zenoh_cpp SHARED
src/detail/attachment_helpers.cpp
Expand Down Expand Up @@ -69,6 +69,7 @@ target_link_libraries(rmw_zenoh_cpp
rosidl_typesupport_fastrtps_cpp::rosidl_typesupport_fastrtps_cpp
rmw::rmw
zenohc::lib
zenohcxx::zenohc
)

configure_rmw_library(rmw_zenoh_cpp)
Expand Down Expand Up @@ -131,6 +132,7 @@ target_link_libraries(rmw_zenohd
rcpputils::rcpputils
rmw::rmw
zenohc::lib
zenohcxx::zenohc
)

install(
Expand Down
4 changes: 2 additions & 2 deletions rmw_zenoh_cpp/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

<buildtool_depend>ament_cmake</buildtool_depend>

<build_depend>zenoh_c_vendor</build_depend>
<build_export_depend>zenoh_c_vendor</build_export_depend>
<build_depend>zenoh_cpp_vendor</build_depend>
<build_export_depend>zenoh_cpp_vendor</build_export_depend>

<depend>ament_index_cpp</depend>
<depend>fastcdr</depend>
Expand Down
5 changes: 3 additions & 2 deletions rmw_zenoh_cpp/src/detail/graph_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ TopicData::TopicData(ConstEntityPtr entity)
}

///=============================================================================
GraphCache::GraphCache(const z_id_t & zid)
: zid_str_(liveliness::zid_to_str(zid))
GraphCache::GraphCache(const std::string & zid)
: zid_str_(zid)
{
// Do nothing.
}
Expand Down Expand Up @@ -364,6 +364,7 @@ void GraphCache::parse_put(
{entity->node_name(), node}};
graph_.emplace(std::make_pair(entity->node_namespace(), std::move(node_map)));
update_topic_maps_for_put(node, entity);

total_nodes_in_graph_ += 1;
return;
}
Expand Down
2 changes: 1 addition & 1 deletion rmw_zenoh_cpp/src/detail/graph_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class GraphCache final
/// @param id The id of the zenoh session that is building the graph cache.
/// This is used to infer which entities originated from the current session
/// so that appropriate event callbacks may be triggered.
explicit GraphCache(const z_id_t & zid);
explicit GraphCache(const std::string & zid);

// Parse a PUT message over a token's key-expression and update the graph.
void parse_put(const std::string & keyexpr, bool ignore_from_current_session = false);
Expand Down
35 changes: 35 additions & 0 deletions rmw_zenoh_cpp/src/detail/liveliness_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,41 @@ Entity::Entity(
}

///=============================================================================
std::shared_ptr<Entity> Entity::make(
zenoh::Id zid,
const std::string & nid,
const std::string & id,
EntityType type,
NodeInfo node_info,
std::optional<TopicInfo> topic_info)
{
if (id.empty()) {
RCUTILS_SET_ERROR_MSG("Invalid id.");
return nullptr;
}
if (entity_to_str.find(type) == entity_to_str.end()) {
RCUTILS_SET_ERROR_MSG("Invalid entity type.");
return nullptr;
}
if (node_info.ns_.empty() || node_info.name_.empty()) {
RCUTILS_SET_ERROR_MSG("Invalid node_info for entity.");
return nullptr;
}
if (type != EntityType::Node && !topic_info.has_value()) {
RCUTILS_SET_ERROR_MSG("Invalid topic_info for entity.");
return nullptr;
}

return std::make_shared<Entity>(
Entity{
std::string(zid.to_string()),
nid,
id,
std::move(type),
std::move(node_info),
std::move(topic_info)});
}

std::shared_ptr<Entity> Entity::make(
z_id_t zid,
const std::string & nid,
Expand Down
10 changes: 9 additions & 1 deletion rmw_zenoh_cpp/src/detail/liveliness_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef DETAIL__LIVELINESS_UTILS_HPP_
#define DETAIL__LIVELINESS_UTILS_HPP_

#include <zenoh.h>
#include <zenoh.hxx>

#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -125,6 +125,14 @@ class Entity
/// @param node_info The node information that is required for all entities.
/// @param topic_info An optional topic information for relevant entities.
/// @return An entity if all inputs are valid. This way no invalid entities can be created.
static EntityPtr make(
zenoh::Id zid,
const std::string & nid,
const std::string & id,
EntityType type,
NodeInfo node_info,
std::optional<TopicInfo> topic_info = std::nullopt);

static EntityPtr make(
z_id_t zid,
const std::string & nid,
Expand Down
6 changes: 3 additions & 3 deletions rmw_zenoh_cpp/src/detail/rmw_client_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ namespace rmw_zenoh_cpp
{
///=============================================================================
std::shared_ptr<ClientData> ClientData::make(
const z_loaned_session_t * session,
const std::shared_ptr<zenoh::Session> & session,
const rmw_node_t * const node,
const rmw_client_t * client,
liveliness::NodeInfo node_info,
Expand Down Expand Up @@ -162,7 +162,7 @@ std::shared_ptr<ClientData> ClientData::make(

std::size_t domain_id = node_info.domain_id_;
auto entity = liveliness::Entity::make(
z_info_zid(session),
session->get_zid(),
std::to_string(node_id),
std::to_string(service_id),
liveliness::EntityType::Client,
Expand Down Expand Up @@ -193,7 +193,7 @@ std::shared_ptr<ClientData> ClientData::make(
response_type_support
});

if (!client_data->init(session)) {
if (!client_data->init(z_loan(session->_0))) {
// init() already set the error.
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion rmw_zenoh_cpp/src/detail/rmw_client_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ClientData final : public std::enable_shared_from_this<ClientData>
public:
// Make a shared_ptr of ClientData.
static std::shared_ptr<ClientData> make(
const z_loaned_session_t * session,
const std::shared_ptr<zenoh::Session> & session,
const rmw_node_t * const node,
const rmw_client_t * client,
liveliness::NodeInfo node_info,
Expand Down
Loading

0 comments on commit a3fdb1f

Please sign in to comment.