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

Implement rmw_get_gid_for_publisher properly. #116

Merged
merged 1 commit into from
Mar 1, 2024
Merged
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
2 changes: 2 additions & 0 deletions rmw_zenoh_cpp/src/detail/rmw_data_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ struct rmw_publisher_data_t

// Context for memory allocation for messages.
rmw_context_t * context;

uint8_t pub_guid[RMW_GID_STORAGE_SIZE];
};

///==============================================================================
Expand Down
37 changes: 22 additions & 15 deletions rmw_zenoh_cpp/src/rmw_zenoh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,18 @@ rmw_fini_publisher_allocation(
return RMW_RET_UNSUPPORTED;
}

static void generate_random_guid(uint8_t guid[RMW_GID_STORAGE_SIZE])
{
std::random_device dev;
std::mt19937 rng(dev());
std::uniform_int_distribution<std::mt19937::result_type> dist(
std::numeric_limits<unsigned char>::min(), std::numeric_limits<unsigned char>::max());

for (size_t i = 0; i < RMW_GID_STORAGE_SIZE; ++i) {
guid[i] = dist(rng);
}
}

//==============================================================================
/// Create a publisher and return a handle to that publisher.
rmw_publisher_t *
Expand Down Expand Up @@ -497,6 +509,8 @@ rmw_create_publisher(
publisher_data->~rmw_publisher_data_t(), rmw_publisher_data_t);
});

generate_random_guid(publisher_data->pub_guid);

// Adapt any 'best available' QoS options
publisher_data->adapted_qos_profile = *qos_profile;
rmw_ret_t ret = rmw_dds_common::qos_profile_get_best_available_for_topic_publisher(
Expand Down Expand Up @@ -1774,18 +1788,6 @@ rmw_return_loaned_message_from_subscription(
return RMW_RET_UNSUPPORTED;
}

static void generate_random_guid(uint8_t guid[RMW_GID_STORAGE_SIZE])
{
std::random_device dev;
std::mt19937 rng(dev());
std::uniform_int_distribution<std::mt19937::result_type> dist(
std::numeric_limits<unsigned char>::min(), std::numeric_limits<unsigned char>::max());

for (size_t i = 0; i < RMW_GID_STORAGE_SIZE; ++i) {
guid[i] = dist(rng);
}
}

//==============================================================================
/// Create a service client that can send requests to and receive replies from a service server.
rmw_client_t *
Expand Down Expand Up @@ -3531,9 +3533,14 @@ rmw_count_services(
rmw_ret_t
rmw_get_gid_for_publisher(const rmw_publisher_t * publisher, rmw_gid_t * gid)
{
static_cast<void>(publisher);
static_cast<void>(gid);
// TODO(clalancette): Implement me
RMW_CHECK_ARGUMENT_FOR_NULL(publisher, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_ARGUMENT_FOR_NULL(gid, RMW_RET_INVALID_ARGUMENT);

rmw_publisher_data_t * pub_data = static_cast<rmw_publisher_data_t *>(publisher->data);

gid->implementation_identifier = rmw_zenoh_identifier;
memcpy(gid->data, pub_data->pub_guid, RMW_GID_STORAGE_SIZE);

return RMW_RET_OK;
}

Expand Down
Loading