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 all 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
4 changes: 3 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ def configure_doxyfile(

suppress_warnings = [
'cpp.duplicate_declaration',
'cpp.parse_function_declaration'
'cpp.parse_function_declaration',
'config.cache'

]

# If true, `todo` and `todoList` produce output, else they produce nothing.
Expand Down
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
16 changes: 4 additions & 12 deletions src/cpp/database/database_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ EntityId DatabaseEntityQueue::process_datareader(
if (participant_id.first != info.domain_id)
{
throw BadParameter("Participant " + to_string(participant_guid)
+ " found in the database but it is not in the current domain");
+ " found in the database but it is not in the current domain");
}
}
catch (const Exception&)
Expand Down Expand Up @@ -265,7 +265,7 @@ EntityId DatabaseEntityQueue::process_datawriter(
if (participant_id.first != info.domain_id)
{
throw BadParameter("Participant " + to_string(participant_guid)
+ " found in the database but it is not in the current domain");
+ " found in the database but it is not in the current domain");
}
}
catch (const Exception&)
Expand Down Expand Up @@ -328,7 +328,7 @@ EntityId DatabaseEntityQueue::process_endpoint_discovery(
if (participant_id.first != info.domain_id)
{
throw BadParameter("Participant " + to_string(participant_guid)
+ " found in the database but it is not in the current domain");
+ " found in the database but it is not in the current domain");
}
}
catch (const Exception&)
Expand Down Expand Up @@ -377,15 +377,7 @@ EntityId DatabaseEntityQueue::process_endpoint_discovery(
// Create the endpoint
EntityId endpoint_id;
std::stringstream name;

if (info.kind() == EntityKind::DATAREADER)
{
name << "DataReader_" << 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
// TODO: get app data from info (parameters), not from participant
Expand Down
13 changes: 5 additions & 8 deletions test/dds/communication/Communication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ class Communication
eProsima_user_DllExport Communication(
const Communication& x)
{
m_index = x.m_index;
m_index = x.m_index;

m_message = x.m_message;
m_message = x.m_message;

}

Expand All @@ -105,9 +105,9 @@ class Communication
const Communication& x)
{

m_index = x.m_index;
m_index = x.m_index;

m_message = x.m_message;
m_message = x.m_message;

return *this;
}
Expand All @@ -133,7 +133,7 @@ class Communication
const Communication& x) const
{
return (m_index == x.m_index &&
m_message == x.m_message);
m_message == x.m_message);
}

/*!
Expand Down Expand Up @@ -174,7 +174,6 @@ class Communication
return m_index;
}


/*!
* @brief This function copies the value in member message
* @param _message New value to be copied in member message
Expand Down Expand Up @@ -213,8 +212,6 @@ class Communication
return m_message;
}



private:

uint32_t m_index{0};
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
Loading
Loading