Skip to content

Commit

Permalink
Resolve merge conflicts after gid merge
Browse files Browse the repository at this point in the history
Signed-off-by: Yadunund <[email protected]>
  • Loading branch information
Yadunund committed Mar 1, 2024
2 parents e4e60b0 + 191a56b commit bfd409c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
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 @@ -109,6 +109,8 @@ class rmw_publisher_data_t
// Context for memory allocation for messages.
rmw_context_t * context;

uint8_t pub_guid[RMW_GID_STORAGE_SIZE];

EventsManager events_mgr;
};

Expand Down
49 changes: 31 additions & 18 deletions rmw_zenoh_cpp/src/rmw_zenoh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,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 @@ -507,6 +519,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 @@ -1789,18 +1803,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 @@ -3616,9 +3618,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 All @@ -3627,9 +3634,15 @@ rmw_get_gid_for_publisher(const rmw_publisher_t * publisher, rmw_gid_t * gid)
rmw_ret_t
rmw_get_gid_for_client(const rmw_client_t * client, rmw_gid_t * gid)
{
static_cast<void>(client);
static_cast<void>(gid);
return RMW_RET_UNSUPPORTED;
RMW_CHECK_ARGUMENT_FOR_NULL(client, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_ARGUMENT_FOR_NULL(gid, RMW_RET_INVALID_ARGUMENT);

rmw_client_data_t * client_data = static_cast<rmw_client_data_t *>(client->data);

gid->implementation_identifier = rmw_zenoh_identifier;
memcpy(gid->data, client_data->client_guid, RMW_GID_STORAGE_SIZE);

return RMW_RET_OK;
}

//==============================================================================
Expand Down

0 comments on commit bfd409c

Please sign in to comment.