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

[21817] Add EntityId getters and delete Endpoint kind prefixes #254

Merged
merged 6 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
22 changes: 22 additions & 0 deletions include/fastdds_statistics_backend/StatisticsBackend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,28 @@ class StatisticsBackend
static std::string get_type_idl(
EntityId entity_id);

/**
* @brief Returns the id of the topic associated to an endpoint.
*
* @param endpoint_id The ID of a given endpoint.
*
* @return EntityId of the topic on which the endpoint publishes/receives messages.
*/
FASTDDS_STATISTICS_BACKEND_DllAPI
static EntityId get_endpoint_topic_id(
EntityId endpoint_id);

/**
* @brief Returns the id of the domain to which a given entity (Domain, DomainParticipant, Topic, endpoints) belongs.
*
* @param entity_id The ID of a given entity.
*
* @return EntityId of the domain.
*/
FASTDDS_STATISTICS_BACKEND_DllAPI
static EntityId get_domain_id(
EntityId entity_id);

/**
* @brief Provides access to the data measured during the monitoring.
*
Expand Down
12 changes: 12 additions & 0 deletions src/cpp/StatisticsBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,18 @@ std::string StatisticsBackend::get_type_idl(
return StatisticsBackendData::get_instance()->database_->get_type_idl(topic_info[DATA_TYPE_TAG]);
}

EntityId StatisticsBackend::get_endpoint_topic_id(
EntityId endpoint_id)
{
return StatisticsBackendData::get_instance()->database_->get_endpoint_topic_id(endpoint_id);
}

EntityId StatisticsBackend::get_domain_id(
EntityId entity_id)
{
return StatisticsBackendData::get_instance()->database_->get_domain_id(entity_id);
}

std::vector<StatisticsData> StatisticsBackend::get_data(
DataKind data_type,
const std::vector<EntityId>& entity_ids_source,
Expand Down
48 changes: 48 additions & 0 deletions src/cpp/database/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5343,6 +5343,54 @@ Info Database::get_info(
return info;
}

EntityId Database::get_endpoint_topic_id(
const EntityId& endpoint_id)
{
std::shared_lock<std::shared_timed_mutex> lock(mutex_);
std::shared_ptr<const Entity> endpoint = get_entity_nts(endpoint_id);

// Check if the entity is a valid endpoint
if (endpoint->kind != EntityKind::DATAWRITER && endpoint->kind != EntityKind::DATAREADER)
{
throw BadParameter("Error: Entity is not a valid endpoint");
}

return std::dynamic_pointer_cast<const DDSEndpoint>(endpoint)->topic->id;
}

EntityId Database::get_domain_id(
const EntityId& entity_id)
{
std::shared_lock<std::shared_timed_mutex> lock(mutex_);
std::shared_ptr<const Entity> entity = get_entity_nts(entity_id);

switch (entity->kind)
{
case EntityKind::DOMAIN:
{
return entity_id;
}
case EntityKind::PARTICIPANT:
{
return std::dynamic_pointer_cast<const DomainParticipant>(entity)->domain->id;
}
case EntityKind::TOPIC:
{
return std::dynamic_pointer_cast<const Topic>(entity)->domain->id;
}
case EntityKind::DATAWRITER:
case EntityKind::DATAREADER:
{
return std::dynamic_pointer_cast<const DDSEndpoint>(entity)->participant->domain->id;
}
default:
{
return EntityId::invalid();
}
}

}

void Database::check_entity_kinds(
EntityKind kind,
const std::vector<EntityId>& entity_ids,
Expand Down
20 changes: 20 additions & 0 deletions src/cpp/database/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,26 @@ class Database
Info get_info(
const EntityId& entity_id);

/**
* @brief Returns the id of the topic associated to an endpoint.
*
* @param endpoint_id The ID of a given endpoint.
*
* @return EntityId of the topic on which the endpoint publishes/receives messages.
*/
EntityId get_endpoint_topic_id(
const EntityId& endpoint_id);

/**
* @brief Returns the id of the domain associated to a given entity (Domain, Participant, topic and endpoint).
*
* @param entity_id The ID of an entity.
*
* @return EntityId of the domain which the entity belongs.
*/
EntityId get_domain_id(
const EntityId& entity_id);

/**
* @brief Check if the entities passed correspond to the specified entity kind.
*
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/database/database_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,11 @@ EntityId DatabaseEntityQueue::process_endpoint_discovery(

if (info.kind() == EntityKind::DATAREADER)
depink5 marked this conversation as resolved.
Show resolved Hide resolved
{
name << "DataReader_" << info.topic_name << "_" << info.guid.entityId;
name << info.topic_name << "_" << info.guid.entityId;
}
else
{
name << "DataWriter_" << info.topic_name << "_" << info.guid.entityId;
name << info.topic_name << "_" << info.guid.entityId;
}

// Endpoint AppId and metadata
Expand Down
8 changes: 4 additions & 4 deletions test/unittest/DatabaseQueue/DatabaseQueueTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ TEST_F(database_queue_tests, push_datawriter)
std::chrono::system_clock::time_point timestamp = std::chrono::system_clock::now();

// Create the writer info
std::string datawriter_name = "DataWriter_topic_name_0.0.0.1"; //< Name constructed from the topic and entity_id
std::string datawriter_name = "topic_name_0.0.0.1"; //< Name constructed from the topic and entity_id
Qos datawriter_qos;
std::string datawriter_guid_str = "01.02.03.04.05.06.07.08.09.0a.0b.0c|0.0.0.1";
std::string topic_name = "topic_name";
Expand Down Expand Up @@ -1594,7 +1594,7 @@ TEST_F(database_queue_tests, push_datawriter_topic_does_not_exist)
std::chrono::system_clock::time_point timestamp = std::chrono::system_clock::now();

// Create the writer info
std::string datawriter_name = "DataWriter_topic_name_0.0.0.1"; //< Name constructed from the topic and entity_id
std::string datawriter_name = "topic_name_0.0.0.1"; //< Name constructed from the topic and entity_id
Qos datawriter_qos;
std::string datawriter_guid_str = "01.02.03.04.05.06.07.08.09.0a.0b.0c|0.0.0.1";
std::string topic_name = "topic_name";
Expand Down Expand Up @@ -1720,7 +1720,7 @@ TEST_F(database_queue_tests, push_datareader)
std::chrono::system_clock::time_point timestamp = std::chrono::system_clock::now();

// Create the reader info
std::string datareader_name = "DataReader_topic_name_0.0.0.2"; //< Name constructed from the topic and entity_id
std::string datareader_name = "topic_name_0.0.0.2"; //< Name constructed from the topic and entity_id
Qos datareader_qos;
std::string datareader_guid_str = "01.02.03.04.05.06.07.08.09.0a.0b.0c|0.0.0.2";
std::string topic_name = "topic_name";
Expand Down Expand Up @@ -1958,7 +1958,7 @@ TEST_F(database_queue_tests, push_datareader_topic_does_not_exist)
std::chrono::system_clock::time_point timestamp = std::chrono::system_clock::now();

// Create the reader info
std::string datareader_name = "DataReader_topic_name_0.0.0.2"; //< Name constructed from the topic and entity_id
std::string datareader_name = "topic_name_0.0.0.2"; //< Name constructed from the topic and entity_id
Qos datareader_qos;
std::string datareader_guid_str = "01.02.03.04.05.06.07.08.09.0a.0b.0c|0.0.0.2";
std::string topic_name = "topic_name";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ class statistics_participant_listener_tests : public ::testing::Test
metatraffic_topic_ = std::make_shared<Topic>(metatraffic_topic_name_, metatraffic_type_name_, domain_);

// Metatraffic Endpoint entity
metatraffic_endpoint_name_ = "DataWriter_" + metatraffic_prefix + "TOPIC_0.0.1.c1";
metatraffic_endpoint_name_ = metatraffic_prefix + "TOPIC_0.0.1.c1";
metatraffic_qos_ = {{"description", "This is a virtual placeholder endpoint with no real counterpart"}};
metatraffic_endpoint_ = std::make_shared<DataWriter>(metatraffic_endpoint_name_, metatraffic_qos_,
participant_guid_str_, participant_, metatraffic_topic_);
Expand Down Expand Up @@ -552,7 +552,7 @@ TEST_F(statistics_participant_listener_tests, new_participant_discovered)
const std::pair<AppId, std::string> app_data)
{
EXPECT_EQ(endpoint_guid, participant_guid_str_);
EXPECT_EQ(name, "DataWriter_" + metatraffic_prefix + "TOPIC_0.0.1.c1");
EXPECT_EQ(name, metatraffic_prefix + "TOPIC_0.0.1.c1");
EXPECT_EQ(alias, "_metatraffic_");
EXPECT_EQ(qos, metatraffic_qos_);
EXPECT_EQ(is_virtual_metatraffic, true);
Expand Down Expand Up @@ -749,7 +749,7 @@ TEST_F(statistics_participant_listener_tests, new_participant_discovered_not_fir
const std::pair<AppId, std::string> app_data)
{
EXPECT_EQ(endpoint_guid, participant_2_guid_str);
EXPECT_EQ(name, "DataWriter_" + metatraffic_prefix + "TOPIC_0.0.1.c1");
EXPECT_EQ(name, metatraffic_prefix + "TOPIC_0.0.1.c1");
EXPECT_EQ(alias, "_metatraffic_");
EXPECT_EQ(qos, metatraffic_qos_);
EXPECT_EQ(is_virtual_metatraffic, true);
Expand Down Expand Up @@ -963,7 +963,7 @@ TEST_F(statistics_participant_listener_tests, new_participant_discovered_empty_n
const std::pair<AppId, std::string> app_data)
{
EXPECT_EQ(endpoint_guid, participant_guid_str_);
EXPECT_EQ(name, "DataWriter_" + metatraffic_prefix + "TOPIC_0.0.1.c1");
EXPECT_EQ(name, metatraffic_prefix + "TOPIC_0.0.1.c1");
EXPECT_EQ(alias, "_metatraffic_");
EXPECT_EQ(qos, metatraffic_qos_);
EXPECT_EQ(is_virtual_metatraffic, true);
Expand Down Expand Up @@ -1201,7 +1201,7 @@ TEST_F(statistics_participant_listener_tests, new_participant_discovered_empty_n
const std::pair<AppId, std::string> app_data)
{
EXPECT_EQ(endpoint_guid, participant_guid_str_);
EXPECT_EQ(name, "DataWriter_" + metatraffic_prefix + "TOPIC_0.0.1.c1");
EXPECT_EQ(name, metatraffic_prefix + "TOPIC_0.0.1.c1");
EXPECT_EQ(alias, "_metatraffic_");
EXPECT_EQ(qos, metatraffic_qos_);
EXPECT_EQ(is_virtual_metatraffic, true);
Expand Down Expand Up @@ -1427,7 +1427,7 @@ TEST_F(statistics_participant_listener_tests, new_participant_discovered_empty_n
const std::pair<AppId, std::string> app_data)
{
EXPECT_EQ(endpoint_guid, participant_guid_str_);
EXPECT_EQ(name, "DataWriter_" + metatraffic_prefix + "TOPIC_0.0.1.c1");
EXPECT_EQ(name, metatraffic_prefix + "TOPIC_0.0.1.c1");
EXPECT_EQ(alias, "_metatraffic_");
EXPECT_EQ(qos, metatraffic_qos_);
EXPECT_EQ(is_virtual_metatraffic, true);
Expand Down Expand Up @@ -1658,7 +1658,7 @@ TEST_F(statistics_participant_listener_tests, new_participant_discovered_empty_n
const std::pair<AppId, std::string> app_data)
{
EXPECT_EQ(endpoint_guid, participant_guid_str_);
EXPECT_EQ(name, "DataWriter_" + metatraffic_prefix + "TOPIC_0.0.1.c1");
EXPECT_EQ(name, metatraffic_prefix + "TOPIC_0.0.1.c1");
EXPECT_EQ(alias, "_metatraffic_");
EXPECT_EQ(qos, metatraffic_qos_);
EXPECT_EQ(is_virtual_metatraffic, true);
Expand Down Expand Up @@ -1855,7 +1855,7 @@ TEST_F(statistics_participant_listener_tests, new_participant_discovered_empty_n
const std::pair<AppId, std::string> app_data)
{
EXPECT_EQ(endpoint_guid, participant_guid_str_);
EXPECT_EQ(name, "DataWriter_" + metatraffic_prefix + "TOPIC_0.0.1.c1");
EXPECT_EQ(name, metatraffic_prefix + "TOPIC_0.0.1.c1");
EXPECT_EQ(alias, "_metatraffic_");
EXPECT_EQ(qos, metatraffic_qos_);
EXPECT_EQ(is_virtual_metatraffic, true);
Expand Down Expand Up @@ -2085,7 +2085,7 @@ TEST_F(statistics_participant_listener_tests, new_participant_discovered_empty_n
const std::pair<AppId, std::string> app_data)
{
EXPECT_EQ(endpoint_guid, participant_guid_str_);
EXPECT_EQ(name, "DataWriter_" + metatraffic_prefix + "TOPIC_0.0.1.c1");
EXPECT_EQ(name, metatraffic_prefix + "TOPIC_0.0.1.c1");
EXPECT_EQ(alias, "_metatraffic_");
EXPECT_EQ(qos, metatraffic_qos_);
EXPECT_EQ(is_virtual_metatraffic, true);
Expand Down Expand Up @@ -2420,7 +2420,7 @@ TEST_F(statistics_participant_listener_tests, new_reader_discovered)
const std::pair<AppId, std::string> app_data)
{
EXPECT_EQ(endpoint_guid, reader_guid_str_);
EXPECT_EQ(name, std::string("DataReader_") + topic_->name + "_" + reader_entity_id_str_);
EXPECT_EQ(name, topic_->name + "_" + reader_entity_id_str_);
EXPECT_EQ(alias, "");
EXPECT_EQ(qos, reader_proxy_data_to_backend_qos(data));
EXPECT_EQ(is_virtual_metatraffic, false);
Expand Down Expand Up @@ -2593,7 +2593,7 @@ TEST_F(statistics_participant_listener_tests, new_reader_no_topic)
const std::pair<AppId, std::string> app_data)
{
EXPECT_EQ(endpoint_guid, reader_guid_str_);
EXPECT_EQ(name, std::string("DataReader_") + topic_->name + "_" + reader_entity_id_str_);
EXPECT_EQ(name, topic_->name + "_" + reader_entity_id_str_);
EXPECT_EQ(alias, "");
EXPECT_EQ(qos, reader_proxy_data_to_backend_qos(data));
EXPECT_EQ(is_virtual_metatraffic, false);
Expand Down Expand Up @@ -2728,7 +2728,7 @@ TEST_F(statistics_participant_listener_tests, new_reader_several_topics)
const std::pair<AppId, std::string> app_data)
{
EXPECT_EQ(endpoint_guid, reader_guid_str_);
EXPECT_EQ(name, std::string("DataReader_") + topic_->name + "_" + reader_entity_id_str_);
EXPECT_EQ(name, topic_->name + "_" + reader_entity_id_str_);
EXPECT_EQ(alias, "");
EXPECT_EQ(qos, reader_proxy_data_to_backend_qos(data));
EXPECT_EQ(is_virtual_metatraffic, false);
Expand Down Expand Up @@ -2873,7 +2873,7 @@ TEST_F(statistics_participant_listener_tests, new_reader_several_locators)
const std::pair<AppId, std::string> app_data)
{
EXPECT_EQ(endpoint_guid, reader_guid_str_);
EXPECT_EQ(name, std::string("DataReader_") + topic_->name + "_" + reader_entity_id_str_);
EXPECT_EQ(name, topic_->name + "_" + reader_entity_id_str_);
EXPECT_EQ(alias, "");
EXPECT_EQ(qos, reader_proxy_data_to_backend_qos(data));
EXPECT_EQ(is_virtual_metatraffic, false);
Expand Down Expand Up @@ -3025,7 +3025,7 @@ TEST_F(statistics_participant_listener_tests, new_reader_several_locators_no_hos
const std::pair<AppId, std::string> app_data)
{
EXPECT_EQ(endpoint_guid, reader_guid_str_);
EXPECT_EQ(name, std::string("DataReader_") + topic_->name + "_" + reader_entity_id_str_);
EXPECT_EQ(name, topic_->name + "_" + reader_entity_id_str_);
EXPECT_EQ(alias, "");
EXPECT_EQ(qos, reader_proxy_data_to_backend_qos(data));
EXPECT_EQ(is_virtual_metatraffic, false);
Expand Down Expand Up @@ -3380,7 +3380,7 @@ TEST_F(statistics_participant_listener_tests, new_writer_discovered)
const std::pair<AppId, std::string> app_data)
{
EXPECT_EQ(endpoint_guid, writer_guid_str_);
EXPECT_EQ(name, std::string("DataWriter_") + topic_->name + "_" + writer_entity_id_str_);
EXPECT_EQ(name, topic_->name + "_" + writer_entity_id_str_);
EXPECT_EQ(alias, "");
EXPECT_EQ(qos, writer_proxy_data_to_backend_qos(data));
EXPECT_EQ(is_virtual_metatraffic, false);
Expand Down Expand Up @@ -3553,7 +3553,7 @@ TEST_F(statistics_participant_listener_tests, new_writer_no_topic)
const std::pair<AppId, std::string> app_data)
{
EXPECT_EQ(endpoint_guid, writer_guid_str_);
EXPECT_EQ(name, std::string("DataWriter_") + topic_->name + "_" + writer_entity_id_str_);
EXPECT_EQ(name, topic_->name + "_" + writer_entity_id_str_);
EXPECT_EQ(alias, "");
EXPECT_EQ(qos, writer_proxy_data_to_backend_qos(data));
EXPECT_EQ(is_virtual_metatraffic, false);
Expand Down Expand Up @@ -3705,7 +3705,7 @@ TEST_F(statistics_participant_listener_tests, new_writer_several_locators)
const std::pair<AppId, std::string> app_data)
{
EXPECT_EQ(endpoint_guid, writer_guid_str_);
EXPECT_EQ(name, std::string("DataWriter_") + topic_->name + "_" + writer_entity_id_str_);
EXPECT_EQ(name, topic_->name + "_" + writer_entity_id_str_);
EXPECT_EQ(alias, "");
EXPECT_EQ(qos, writer_proxy_data_to_backend_qos(data));
EXPECT_EQ(is_virtual_metatraffic, false);
Expand Down Expand Up @@ -3851,7 +3851,7 @@ TEST_F(statistics_participant_listener_tests, new_writer_several_locators_no_hos
const std::pair<AppId, std::string> app_data)
{
EXPECT_EQ(endpoint_guid, writer_guid_str_);
EXPECT_EQ(name, std::string("DataWriter_") + topic_->name + "_" + writer_entity_id_str_);
EXPECT_EQ(name, topic_->name + "_" + writer_entity_id_str_);
EXPECT_EQ(alias, "");
EXPECT_EQ(qos, writer_proxy_data_to_backend_qos(data));
EXPECT_EQ(is_virtual_metatraffic, false);
Expand Down
Loading