Skip to content

Commit

Permalink
Updates to compile against Humble.
Browse files Browse the repository at this point in the history
There are 5 main changes in here:
1.  Humble does not support type hashes.  Rather than change
all of the liveliness token handling (which will make backports
in the future harder), we just remove the code that computes it,
and instead set it to a constant string.
2.  The definition of RMW_GID_STORAGE_SIZE in Humble is wonky,
and set to 24 for some ancient historical reasons.  We don't
actually want to do that, so just hard-code 16.
3.  Some of the events in modern ROS 2 aren't supported in Humble,
so remove the code for handling them.
4.  There are a few APIs dealing with dynamic messages that aren't
supported in Humble.
5.  There is at least one QOS policy (best available) which doesn't
exist in Humble.

With all of these changes in, I'm able to compile and run basic
programs against Humble.

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette committed Jan 2, 2025
1 parent fb06619 commit cfc8b09
Showing 19 changed files with 59 additions and 213 deletions.
6 changes: 3 additions & 3 deletions rmw_zenoh_cpp/src/detail/attachment_helpers.cpp
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ namespace rmw_zenoh_cpp
AttachmentData::AttachmentData(
const int64_t sequence_number,
const int64_t source_timestamp,
const std::array<uint8_t, RMW_GID_STORAGE_SIZE> source_gid)
const std::array<uint8_t, 16> source_gid)
: sequence_number_(sequence_number),
source_timestamp_(source_timestamp),
source_gid_(source_gid),
@@ -61,7 +61,7 @@ int64_t AttachmentData::source_timestamp() const
}

///=============================================================================
std::array<uint8_t, RMW_GID_STORAGE_SIZE> AttachmentData::copy_gid() const
std::array<uint8_t, 16> AttachmentData::copy_gid() const
{
return source_gid_;
}
@@ -103,7 +103,7 @@ AttachmentData::AttachmentData(const zenoh::Bytes & bytes)
if (source_gid_str != "source_gid") {
throw std::runtime_error("source_gid is not found in the attachment.");
}
this->source_gid_ = deserializer.deserialize<std::array<uint8_t, RMW_GID_STORAGE_SIZE>>();
this->source_gid_ = deserializer.deserialize<std::array<uint8_t, 16>>();
gid_hash_ = hash_gid(this->source_gid_);
}
} // namespace rmw_zenoh_cpp
6 changes: 3 additions & 3 deletions rmw_zenoh_cpp/src/detail/attachment_helpers.hpp
Original file line number Diff line number Diff line change
@@ -31,22 +31,22 @@ class AttachmentData final
AttachmentData(
const int64_t sequence_number,
const int64_t source_timestamp,
const std::array<uint8_t, RMW_GID_STORAGE_SIZE> source_gid);
const std::array<uint8_t, 16> source_gid);

explicit AttachmentData(const zenoh::Bytes & bytes);
explicit AttachmentData(AttachmentData && data);

int64_t sequence_number() const;
int64_t source_timestamp() const;
std::array<uint8_t, RMW_GID_STORAGE_SIZE> copy_gid() const;
std::array<uint8_t, 16> copy_gid() const;
size_t gid_hash() const;

zenoh::Bytes serialize_to_zbytes();

private:
int64_t sequence_number_;
int64_t source_timestamp_;
std::array<uint8_t, RMW_GID_STORAGE_SIZE> source_gid_;
std::array<uint8_t, 16> source_gid_;
size_t gid_hash_;
};
} // namespace rmw_zenoh_cpp
5 changes: 0 additions & 5 deletions rmw_zenoh_cpp/src/detail/event.cpp
Original file line number Diff line number Diff line change
@@ -33,11 +33,6 @@ static const std::unordered_map<rmw_event_type_t, rmw_zenoh_cpp::rmw_zenoh_event
{RMW_EVENT_REQUESTED_QOS_INCOMPATIBLE, rmw_zenoh_cpp::ZENOH_EVENT_REQUESTED_QOS_INCOMPATIBLE},
{RMW_EVENT_OFFERED_QOS_INCOMPATIBLE, rmw_zenoh_cpp::ZENOH_EVENT_OFFERED_QOS_INCOMPATIBLE},
{RMW_EVENT_MESSAGE_LOST, rmw_zenoh_cpp::ZENOH_EVENT_MESSAGE_LOST},
{RMW_EVENT_SUBSCRIPTION_MATCHED, rmw_zenoh_cpp::ZENOH_EVENT_SUBSCRIPTION_MATCHED},
{RMW_EVENT_PUBLICATION_MATCHED, rmw_zenoh_cpp::ZENOH_EVENT_PUBLICATION_MATCHED},
{RMW_EVENT_SUBSCRIPTION_INCOMPATIBLE_TYPE,
rmw_zenoh_cpp::ZENOH_EVENT_SUBSCRIPTION_INCOMPATIBLE_TYPE},
{RMW_EVENT_PUBLISHER_INCOMPATIBLE_TYPE, rmw_zenoh_cpp::ZENOH_EVENT_PUBLISHER_INCOMPATIBLE_TYPE}
// TODO(clalancette): Implement remaining events
};
} // namespace
15 changes: 1 addition & 14 deletions rmw_zenoh_cpp/src/detail/graph_cache.cpp
Original file line number Diff line number Diff line change
@@ -33,8 +33,6 @@
#include "rmw/validate_namespace.h"
#include "rmw/validate_node_name.h"

#include "rosidl_runtime_c/type_hash.h"

#include "graph_cache.hpp"
#include "logging_macros.hpp"

@@ -1124,18 +1122,7 @@ rmw_ret_t GraphCache::get_entities_info_by_topic(
return ret;
}

rosidl_type_hash_t type_hash;
rcutils_ret_t rc_ret = rosidl_parse_type_hash_string(
topic_data->info_.type_hash_.c_str(),
&type_hash);
if (RCUTILS_RET_OK == rc_ret) {
ret = rmw_topic_endpoint_info_set_topic_type_hash(&ep, &type_hash);
if (RMW_RET_OK != ret) {
return ret;
}
}

memcpy(ep.endpoint_gid, entity->copy_gid().data(), RMW_GID_STORAGE_SIZE);
memcpy(ep.endpoint_gid, entity->copy_gid().data(), 16);

endpoints.push_back(ep);
}
6 changes: 2 additions & 4 deletions rmw_zenoh_cpp/src/detail/liveliness_utils.cpp
Original file line number Diff line number Diff line change
@@ -179,8 +179,6 @@ static const std::unordered_map<std::string, rmw_qos_liveliness_policy_e> str_to
{std::to_string(RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_TOPIC),
RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_TOPIC},
{std::to_string(RMW_QOS_POLICY_LIVELINESS_UNKNOWN), RMW_QOS_POLICY_LIVELINESS_UNKNOWN},
{std::to_string(RMW_QOS_POLICY_LIVELINESS_BEST_AVAILABLE),
RMW_QOS_POLICY_LIVELINESS_BEST_AVAILABLE}
};

std::vector<std::string> split_keyexpr(
@@ -631,7 +629,7 @@ std::string Entity::liveliness_keyexpr() const
}

///=============================================================================
std::array<uint8_t, RMW_GID_STORAGE_SIZE> Entity::copy_gid() const
std::array<uint8_t, 16> Entity::copy_gid() const
{
return gid_;
}
@@ -672,7 +670,7 @@ std::string demangle_name(const std::string & input)
} // namespace liveliness

///=============================================================================
size_t hash_gid(const std::array<uint8_t, RMW_GID_STORAGE_SIZE> gid)
size_t hash_gid(const std::array<uint8_t, 16> gid)
{
std::stringstream hash_str;
hash_str << std::hex;
6 changes: 3 additions & 3 deletions rmw_zenoh_cpp/src/detail/liveliness_utils.hpp
Original file line number Diff line number Diff line change
@@ -173,7 +173,7 @@ class Entity
// Two entities are equal if their keyexpr_hash are equal.
bool operator==(const Entity & other) const;

std::array<uint8_t, RMW_GID_STORAGE_SIZE> copy_gid() const;
std::array<uint8_t, 16> copy_gid() const;

private:
Entity(
@@ -192,7 +192,7 @@ class Entity
NodeInfo node_info_;
std::optional<TopicInfo> topic_info_;
std::string liveliness_keyexpr_;
std::array<uint8_t, RMW_GID_STORAGE_SIZE> gid_{};
std::array<uint8_t, 16> gid_{};
};

///=============================================================================
@@ -235,7 +235,7 @@ std::optional<rmw_qos_profile_t> keyexpr_to_qos(const std::string & keyexpr);
} // namespace liveliness

///=============================================================================
size_t hash_gid(const std::array<uint8_t, RMW_GID_STORAGE_SIZE> gid);
size_t hash_gid(const std::array<uint8_t, 16> gid);
} // namespace rmw_zenoh_cpp

///=============================================================================
26 changes: 6 additions & 20 deletions rmw_zenoh_cpp/src/detail/rmw_client_data.cpp
Original file line number Diff line number Diff line change
@@ -66,9 +66,6 @@ std::shared_ptr<ClientData> ClientData::make(
return nullptr;
}

rcutils_allocator_t * allocator = &node->context->options.allocator;

const rosidl_type_hash_t * type_hash = type_support->get_type_hash_func(type_support);
auto service_members = static_cast<const service_type_support_callbacks_t *>(type_support->data);
auto request_members = static_cast<const message_type_support_callbacks_t *>(
service_members->request_members_->data);
@@ -92,20 +89,9 @@ std::shared_ptr<ClientData> ClientData::make(
return nullptr;
}

// Convert the type hash to a string so that it can be included in the keyexpr.
char * type_hash_c_str = nullptr;
rcutils_ret_t stringify_ret = rosidl_stringify_type_hash(
type_hash,
*allocator,
&type_hash_c_str);
if (RCUTILS_RET_BAD_ALLOC == stringify_ret) {
// rosidl_stringify_type_hash already set the error
return nullptr;
}
auto free_type_hash_c_str = rcpputils::make_scope_exit(
[&allocator, &type_hash_c_str]() {
allocator->deallocate(type_hash_c_str, allocator->state);
});
// Humble doesn't support type hash, but we leave it in place as a constant so we don't have to
// change the graph and liveliness token code.
const char * type_hash_c_str = "TypeHashNotSupported";

std::size_t domain_id = node_info.domain_id_;
auto entity = liveliness::Entity::make(
@@ -203,7 +189,7 @@ bool ClientData::liveliness_is_valid() const
}

///=============================================================================
std::array<uint8_t, RMW_GID_STORAGE_SIZE> ClientData::copy_gid() const
std::array<uint8_t, 16> ClientData::copy_gid() const
{
return entity_->copy_gid();
}
@@ -307,7 +293,7 @@ rmw_ret_t ClientData::take_response(
memcpy(
request_header->request_id.writer_guid,
attachment.copy_gid().data(),
RMW_GID_STORAGE_SIZE);
16);
request_header->received_timestamp = latest_reply->get_received_timestamp();

*taken = true;
@@ -364,7 +350,7 @@ rmw_ret_t ClientData::send_request(

// Send request
zenoh::Session::GetOptions opts = zenoh::Session::GetOptions::create_default();
std::array<uint8_t, RMW_GID_STORAGE_SIZE> local_gid = entity_->copy_gid();
std::array<uint8_t, 16> local_gid = entity_->copy_gid();
opts.attachment = rmw_zenoh_cpp::create_map_and_set_sequence_num(*sequence_id, local_gid);
opts.target = Z_QUERY_TARGET_ALL_COMPLETE;
// The default timeout for a z_get query is 10 seconds and if a response is not received within
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
@@ -65,7 +65,7 @@ class ClientData final : public std::enable_shared_from_this<ClientData>
bool liveliness_is_valid() const;

// Copy the GID of this ClientData into an rmw_gid_t.
std::array<uint8_t, RMW_GID_STORAGE_SIZE> copy_gid() const;
std::array<uint8_t, 16> copy_gid() const;

// Add a new ZenohReply to the queue.
void add_new_reply(std::unique_ptr<rmw_zenoh_cpp::ZenohReply> reply);
23 changes: 4 additions & 19 deletions rmw_zenoh_cpp/src/detail/rmw_publisher_data.cpp
Original file line number Diff line number Diff line change
@@ -60,27 +60,12 @@ std::shared_ptr<PublisherData> PublisherData::make(
return nullptr;
}

rcutils_allocator_t * allocator = &node->context->options.allocator;

const rosidl_type_hash_t * type_hash = type_support->get_type_hash_func(type_support);
auto callbacks = static_cast<const message_type_support_callbacks_t *>(type_support->data);
auto message_type_support = std::make_unique<MessageTypeSupport>(callbacks);

// Convert the type hash to a string so that it can be included in
// the keyexpr.
char * type_hash_c_str = nullptr;
rcutils_ret_t stringify_ret = rosidl_stringify_type_hash(
type_hash,
*allocator,
&type_hash_c_str);
if (RCUTILS_RET_BAD_ALLOC == stringify_ret) {
// rosidl_stringify_type_hash already set the error
return nullptr;
}
auto always_free_type_hash_c_str = rcpputils::make_scope_exit(
[&allocator, &type_hash_c_str]() {
allocator->deallocate(type_hash_c_str, allocator->state);
});
// Humble doesn't support type hash, but we leave it in place as a constant so we don't have to
// change the graph and liveliness token code.
const char * type_hash_c_str = "TypeHashNotSupported";

std::size_t domain_id = node_info.domain_id_;
auto entity = liveliness::Entity::make(
@@ -328,7 +313,7 @@ liveliness::TopicInfo PublisherData::topic_info() const
return entity_->topic_info().value();
}

std::array<uint8_t, RMW_GID_STORAGE_SIZE> PublisherData::copy_gid() const
std::array<uint8_t, 16> PublisherData::copy_gid() const
{
std::lock_guard<std::mutex> lock(mutex_);
return entity_->copy_gid();
2 changes: 1 addition & 1 deletion rmw_zenoh_cpp/src/detail/rmw_publisher_data.hpp
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ class PublisherData final
liveliness::TopicInfo topic_info() const;

// Return a copy of the GID of this publisher.
std::array<uint8_t, RMW_GID_STORAGE_SIZE> copy_gid() const;
std::array<uint8_t, 16> copy_gid() const;

// Returns true if liveliness token is still valid.
bool liveliness_is_valid() const;
32 changes: 9 additions & 23 deletions rmw_zenoh_cpp/src/detail/rmw_service_data.cpp
Original file line number Diff line number Diff line change
@@ -62,9 +62,6 @@ std::shared_ptr<ServiceData> ServiceData::make(
return nullptr;
}

rcutils_allocator_t * allocator = &node->context->options.allocator;

const rosidl_type_hash_t * type_hash = type_support->get_type_hash_func(type_support);
auto service_members = static_cast<const service_type_support_callbacks_t *>(type_support->data);
auto request_members = static_cast<const message_type_support_callbacks_t *>(
service_members->request_members_->data);
@@ -88,20 +85,9 @@ std::shared_ptr<ServiceData> ServiceData::make(
return nullptr;
}

// Convert the type hash to a string so that it can be included in the keyexpr.
char * type_hash_c_str = nullptr;
rcutils_ret_t stringify_ret = rosidl_stringify_type_hash(
type_hash,
*allocator,
&type_hash_c_str);
if (RCUTILS_RET_BAD_ALLOC == stringify_ret) {
// rosidl_stringify_type_hash already set the error
return nullptr;
}
auto free_type_hash_c_str = rcpputils::make_scope_exit(
[&allocator, &type_hash_c_str]() {
allocator->deallocate(type_hash_c_str, allocator->state);
});
// Humble doesn't support type hash, but we leave it in place as a constant so we don't have to
// change the graph and liveliness token code.
const char * type_hash_c_str = "TypeHashNotSupported";

std::size_t domain_id = node_info.domain_id_;
auto entity = liveliness::Entity::make(
@@ -329,8 +315,8 @@ rmw_ret_t ServiceData::take_request(
return RMW_RET_ERROR;
}

std::array<uint8_t, RMW_GID_STORAGE_SIZE> writer_guid = attachment.copy_gid();
memcpy(request_header->request_id.writer_guid, writer_guid.data(), RMW_GID_STORAGE_SIZE);
std::array<uint8_t, 16> writer_guid = attachment.copy_gid();
memcpy(request_header->request_id.writer_guid, writer_guid.data(), 16);

request_header->source_timestamp = attachment.source_timestamp();
if (request_header->source_timestamp < 0) {
@@ -374,8 +360,8 @@ rmw_ret_t ServiceData::send_response(
return RMW_RET_OK;
}

std::array<uint8_t, RMW_GID_STORAGE_SIZE> writer_guid;
memcpy(writer_guid.data(), request_id->writer_guid, RMW_GID_STORAGE_SIZE);
std::array<uint8_t, 16> writer_guid;
memcpy(writer_guid.data(), request_id->writer_guid, 16);

// Create the queryable payload
const size_t hash = hash_gid(writer_guid);
@@ -433,8 +419,8 @@ rmw_ret_t ServiceData::send_response(

const zenoh::Query & loaned_query = query->get_query();
zenoh::Query::ReplyOptions options = zenoh::Query::ReplyOptions::create_default();
std::array<uint8_t, RMW_GID_STORAGE_SIZE> writer_gid;
memcpy(writer_gid.data(), request_id->writer_guid, RMW_GID_STORAGE_SIZE);
std::array<uint8_t, 16> writer_gid;
memcpy(writer_gid.data(), request_id->writer_guid, 16);
options.attachment = create_map_and_set_sequence_num(
request_id->sequence_number,
writer_gid);
24 changes: 5 additions & 19 deletions rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp
Original file line number Diff line number Diff line change
@@ -73,26 +73,12 @@ std::shared_ptr<SubscriptionData> SubscriptionData::make(
return nullptr;
}

rcutils_allocator_t * allocator = &node->context->options.allocator;

const rosidl_type_hash_t * type_hash = type_support->get_type_hash_func(type_support);
auto callbacks = static_cast<const message_type_support_callbacks_t *>(type_support->data);
auto message_type_support = std::make_unique<MessageTypeSupport>(callbacks);

// Convert the type hash to a string so that it can be included in the keyexpr.
char * type_hash_c_str = nullptr;
rcutils_ret_t stringify_ret = rosidl_stringify_type_hash(
type_hash,
*allocator,
&type_hash_c_str);
if (RCUTILS_RET_BAD_ALLOC == stringify_ret) {
// rosidl_stringify_type_hash already set the error
return nullptr;
}
auto free_type_hash_c_str = rcpputils::make_scope_exit(
[&allocator, &type_hash_c_str]() {
allocator->deallocate(type_hash_c_str, allocator->state);
});
// Humble doesn't support type hash, but we leave it in place as a constant so we don't have to
// change the graph and liveliness token code.
const char * type_hash_c_str = "TypeHashNotSupported";

// Everything above succeeded and is setup properly. Now declare a subscriber
// with Zenoh; after this, callbacks may come in at any time.
@@ -520,7 +506,7 @@ rmw_ret_t SubscriptionData::take_one_message(
memcpy(
message_info->publisher_gid.data,
msg_data->attachment.copy_gid().data(),
RMW_GID_STORAGE_SIZE);
16);
message_info->from_intra_process = false;
}
*taken = true;
@@ -577,7 +563,7 @@ rmw_ret_t SubscriptionData::take_serialized_message(
memcpy(
message_info->publisher_gid.data,
msg_data->attachment.copy_gid().data(),
RMW_GID_STORAGE_SIZE);
16);
message_info->from_intra_process = false;
}

2 changes: 1 addition & 1 deletion rmw_zenoh_cpp/src/detail/zenoh_utils.cpp
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ namespace rmw_zenoh_cpp
{
///=============================================================================
zenoh::Bytes create_map_and_set_sequence_num(
int64_t sequence_number, std::array<uint8_t, RMW_GID_STORAGE_SIZE> gid)
int64_t sequence_number, std::array<uint8_t, 16> gid)
{
auto now = std::chrono::system_clock::now().time_since_epoch();
auto now_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(now);
2 changes: 1 addition & 1 deletion rmw_zenoh_cpp/src/detail/zenoh_utils.hpp
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ namespace rmw_zenoh_cpp
{
///=============================================================================
zenoh::Bytes create_map_and_set_sequence_num(
int64_t sequence_number, std::array<uint8_t, RMW_GID_STORAGE_SIZE> gid);
int64_t sequence_number, std::array<uint8_t, 16> gid);

///=============================================================================
// A class to store the replies to service requests.
Loading

0 comments on commit cfc8b09

Please sign in to comment.