diff --git a/rmw_zenoh_cpp/src/detail/rmw_data_types.hpp b/rmw_zenoh_cpp/src/detail/rmw_data_types.hpp index e9bcfac9..8fe35f5d 100644 --- a/rmw_zenoh_cpp/src/detail/rmw_data_types.hpp +++ b/rmw_zenoh_cpp/src/detail/rmw_data_types.hpp @@ -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]; }; ///============================================================================== diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp index 85ca471b..29cca3af 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -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 dist( + std::numeric_limits::min(), std::numeric_limits::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 * @@ -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( @@ -1772,18 +1786,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 dist( - std::numeric_limits::min(), std::numeric_limits::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 * @@ -3529,9 +3531,14 @@ rmw_count_services( rmw_ret_t rmw_get_gid_for_publisher(const rmw_publisher_t * publisher, rmw_gid_t * gid) { - static_cast(publisher); - static_cast(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(publisher->data); + + gid->implementation_identifier = rmw_zenoh_identifier; + memcpy(gid->data, pub_data->pub_guid, RMW_GID_STORAGE_SIZE); + return RMW_RET_OK; }