Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align on Transport GID and Liveliness GUID #291

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion rmw_zenoh_cpp/src/detail/graph_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,26 @@ rmw_ret_t GraphCache::get_entities_info_by_topic(
}
}

// TODO(Yadunund): Set gid.
liveliness::ConstEntityPtr entity;
if (entity_type == EntityType::Publisher) {
entity = (*topic_data->pubs_.begin());
} else {
entity = (*topic_data->subs_.begin());
}

if (entity) {
uint8_t gid[RMW_GID_STORAGE_SIZE];
entity->get_gid(gid);
Comment on lines +1211 to +1220
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we iterate though all the Entity ptrs in the EnittySet?

const auto & entity_set = entity_type == EntityType::Publisher? topic_data->pubs_ : topic_data->subs_;
for (auto entity_it = entity_set.begin(); entity_it != entity_set.end(); ++entity_it) {
   uint8_t gid[RMW_GID_STORAGE_SIZE];
   entity->get_gid(gid);
    ret = rmw_topic_endpoint_info_set_gid(
        &endpoint_info,
        gid,
        RMW_GID_STORAGE_SIZE
     );
     if (RMW_RET_OK != ret) {
        return ret;
          }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we iterate over the list, then it will override the gid value (if there is more than one).


ret = rmw_topic_endpoint_info_set_gid(
&endpoint_info,
gid,
RMW_GID_STORAGE_SIZE
);
if (RMW_RET_OK != ret) {
return ret;
}
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions rmw_zenoh_cpp/src/detail/liveliness_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,16 @@ std::size_t Entity::guid() const
return this->guid_;
}

///=============================================================================
void Entity::get_gid(uint8_t gid[RMW_GID_STORAGE_SIZE]) const
{
std::vector<uint8_t> guid_bytes(sizeof(this->guid_));
memcpy(guid_bytes.data(), &this->guid_, sizeof(this->guid_));
for (size_t i = 0; i < guid_bytes.size(); ++i) {
gid[i] = guid_bytes[i];
}
}

///=============================================================================
EntityType Entity::type() const
{
Expand Down
6 changes: 6 additions & 0 deletions rmw_zenoh_cpp/src/detail/liveliness_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ class Entity
// This is named guid and not gid to remain distinct as it is not of type rmw_gid_t.
std::size_t guid() const;

// Generate the 16byte GID from the keyexpr guid
// The size of guid is std::size_t. It can vary depending on the platform and architecture.
// On most 32-bit systems, it is usually 32 bits, while on 64-bit systems,
// it is typically 64 bits. It fit in the RMW_GID_STORAGE_SIZE.
void get_gid(uint8_t gid[RMW_GID_STORAGE_SIZE]) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: To be consistent with naming of other getters.

Suggested change
void get_gid(uint8_t gid[RMW_GID_STORAGE_SIZE]) const;
void gid(uint8_t gid[RMW_GID_STORAGE_SIZE]) const;


/// Get the entity type.
EntityType type() const;

Expand Down