Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
get participant name from user data first
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-thomas committed Jan 31, 2018
1 parent 8be510a commit e523a82
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions rmw_connext_shared_cpp/src/node_names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <string>
#include <vector>

#include "rcutils/logging_macros.h"
#include "rcutils/strdup.h"

#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"
Expand Down Expand Up @@ -67,15 +71,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_RETCODE_OK == dds_ret) {
auto data = static_cast<unsigned char *>(pbtd.user_data.value.get_contiguous_buffer());
std::vector<uint8_t> 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);
Expand Down

0 comments on commit e523a82

Please sign in to comment.