diff --git a/rmw_connext_shared_cpp/src/node_names.cpp b/rmw_connext_shared_cpp/src/node_names.cpp index c91ffc90..a666df6d 100644 --- a/rmw_connext_shared_cpp/src/node_names.cpp +++ b/rmw_connext_shared_cpp/src/node_names.cpp @@ -17,6 +17,7 @@ #include "rmw/convert_rcutils_ret_to_rmw_ret.h" #include "rmw/error_handling.h" +#include "rmw/impl/cpp/key_value.hpp" #include "rmw/sanity_checks.h" #include "rmw_connext_shared_cpp/ndds_include.hpp" @@ -67,15 +68,28 @@ get_node_names( return RMW_RET_BAD_ALLOC; } - for (auto i = 1; i < length; ++i) { DDS::ParticipantBuiltinTopicData pbtd; auto dds_ret = participant->get_discovered_participant_data(pbtd, handles[i - 1]); - const char * name = pbtd.participant_name.name; - if (!name || dds_ret != DDS_RETCODE_OK) { - name = "(no name)"; + std::string name; + if (dds_ret == DDS_RETCODE_OK) { + auto data = static_cast(pbtd.user_data.value.get_contiguous_buffer()); + std::vector kv(data, data + pbtd.user_data.value.length()); + auto map = rmw::impl::cpp::parse_key_value(kv); + auto found = map.find("name"); + if (found != map.end()) { + name = std::string(found->second.begin(), found->second.end()); + } + if (name.empty()) { + name = pbtd.participant_name.name; + } + } + if (name.empty()) { + // ignore discovered participants without a name + node_names->data[i] = nullptr; + continue; } - node_names->data[i] = rcutils_strdup(name, allocator); + node_names->data[i] = rcutils_strdup(name.c_str(), allocator); if (!node_names->data[i]) { RMW_SET_ERROR_MSG("could not allocate memory for node name") rcutils_ret = rcutils_string_array_fini(node_names);