Skip to content

Commit

Permalink
Apply suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: tempate <danieldiaz@eprosima.com>
  • Loading branch information
Tempate committed Jul 15, 2024
1 parent c87ab7b commit 1cf2453
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include <ddspipe_core/communication/Bridge.hpp>
#include <ddspipe_core/communication/dds/Track.hpp>
#include <ddspipe_core/configuration/DdsPipeConfiguration.hpp>
#include <ddspipe_core/configuration/RoutesConfiguration.hpp>
#include <ddspipe_core/types/dds/Endpoint.hpp>
#include <ddspipe_core/types/topic/dds/DistributedTopic.hpp>
Expand Down Expand Up @@ -52,7 +51,10 @@ class DdsBridge : public Bridge
* @param participant_database: Collection of Participants to manage communication
* @param payload_pool: Payload Pool that handles the reservation/release of payloads throughout the DDS Router
* @param thread_pool: Shared pool of threads in charge of data transmission.
* @param enable: Whether the Bridge should be initialized as enabled
* @param routes_config: Configuration of the routes of the Bridge
* @param remove_unused_entities: Whether the Bridge should remove unused entities
* @param manual_topics: Topics that explicitally set a QoS attribute for this participant
* @param endpoint_kind: Kind of the endpoint that discovered the topic
*
* @throw InitializationException in case \c IWriters or \c IReaders creation fails.
*/
Expand Down Expand Up @@ -200,6 +202,8 @@ class DdsBridge : public Bridge
* @brief Impose the Topic QoS that have been pre-configured for a participant.
*
* First, it imposes the Topic QoS configured at \c manual_topics and then the ones configured at \c participants.
*
* @param participant: The participant to impose the QoS on.
*/
utils::Heritable<types::DistributedTopic> create_topic_for_participant_nts_(
const std::shared_ptr<IParticipant>& participant) noexcept;
Expand Down
7 changes: 5 additions & 2 deletions ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ class DdsPipe
* @note This is the only method that adds topics to \c current_topics_
*
* @param [in] topic : topic discovered
* @param [in] endpoint_kind : kind of the endpoint
*/
void discovered_topic_nts_(
const utils::Heritable<types::DistributedTopic>& topic,
Expand Down Expand Up @@ -303,11 +304,12 @@ class DdsPipe
* It is created enabled if the DdsPipe is enabled.
*
* @param [in] topic : new topic
* @param [in] enabled : whether to enable the bridge on creation or not
*/
void create_new_bridge_nts_(
const utils::Heritable<types::DistributedTopic>& topic,
bool enabled = false,
const types::EndpointKind& endpoint_kind = types::EndpointKind::reader) noexcept;
const types::EndpointKind endpoint_kind = types::EndpointKind::reader,
bool enabled = false) noexcept;

/**
* @brief Create a new \c RpcBridge object
Expand All @@ -325,6 +327,7 @@ class DdsPipe
* If the topic did not exist before, the Bridge is created.
*
* @param [in] topic : Topic to be enabled
* @param [in] endpoint_kind : Kind of endpoint who discovered the topic
*/
void activate_topic_nts_(
const utils::Heritable<types::DistributedTopic>& topic,
Expand Down
39 changes: 24 additions & 15 deletions ddspipe_core/src/cpp/communication/dds/DdsBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,17 @@ void DdsBridge::create_endpoint(
{
std::lock_guard<std::mutex> lock(mutex_);

if (discovered_endpoint_kind == EndpointKind::reader)
switch (discovered_endpoint_kind)
{
create_writer_and_its_tracks_nts_(participant_id);
}
else
{
create_reader_and_its_track_nts_(participant_id);
case EndpointKind::reader:
create_writer_and_its_tracks_nts_(participant_id);
break;
case EndpointKind::writer:
create_reader_and_its_track_nts_(participant_id);
break;
default:
logError(DDSPIPE_DDSBRIDGE, "Invalid kind " << discovered_endpoint_kind << " to create an endpoint.");
break;
}
}

Expand All @@ -126,13 +130,17 @@ void DdsBridge::remove_endpoint(
{
std::lock_guard<std::mutex> lock(mutex_);

if (removed_endpoint_kind == EndpointKind::reader)
{
remove_writer_and_its_tracks_nts_(participant_id);
}
else
switch (removed_endpoint_kind)
{
remove_reader_and_its_track_nts_(participant_id);
case EndpointKind::reader:
remove_writer_and_its_tracks_nts_(participant_id);
break;
case EndpointKind::writer:
remove_reader_and_its_track_nts_(participant_id);
break;
default:
logError(DDSPIPE_DDSBRIDGE, "Invalid kind " << removed_endpoint_kind << " to remove an endpoint.");
break;
}
}

Expand Down Expand Up @@ -196,15 +204,16 @@ void DdsBridge::remove_writer_and_its_tracks_nts_(
assert(participant_id != DEFAULT_PARTICIPANT_ID);

// Remove the writer from the tracks and remove the tracks without writers
for (const auto& track_it : tracks_)
for (auto it = tracks_.cbegin(), next_it = it; it != tracks_.cend(); it = next_it)
{
auto& track = track_it.second;
++next_it;
const auto& track = it->second;

track->remove_writer(participant_id);

if (!track->has_writers())
{
tracks_.erase(track_it.first);
tracks_.erase(it);
}
}

Expand Down
12 changes: 6 additions & 6 deletions ddspipe_core/src/cpp/core/DdsPipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,13 @@ bool DdsPipe::is_endpoint_relevant_(

if (endpoint.active)
{
// An active reader is relevant when it is the only active reader in a topic
// An active endpoint is relevant when it is the only active endpoint in a topic
// with a discoverer participant id.
return relevant_endpoints.size() == 1 && relevant_endpoints.count(endpoint.guid);
}
else
{
// An inactive reader is relevant when there aren't any active readers in a topic
// An inactive endpoint is relevant when there aren't any active endpoints in a topic
// with a discoverer participant id.
return relevant_endpoints.size() == 0;
}
Expand All @@ -408,7 +408,7 @@ void DdsPipe::init_bridges_nts_(
for (const auto& topic : builtin_topics)
{
discovered_topic_nts_(topic);
create_new_bridge_nts_(topic, false);
create_new_bridge_nts_(topic, EndpointKind::reader, false);
}
}

Expand Down Expand Up @@ -486,8 +486,8 @@ void DdsPipe::removed_service_nts_(

void DdsPipe::create_new_bridge_nts_(
const utils::Heritable<DistributedTopic>& topic,
bool enabled, /*= false*/
const EndpointKind& endpoint_kind /*= EndpointKind::reader*/) noexcept
const EndpointKind endpoint_kind /*= EndpointKind::reader*/,
bool enabled /*= false*/) noexcept
{
logInfo(DDSPIPE, "Creating Bridge for topic: " << topic << ".");

Expand Down Expand Up @@ -545,7 +545,7 @@ void DdsPipe::activate_topic_nts_(
if (it_bridge == bridges_.end())
{
// The Bridge did not exist
create_new_bridge_nts_(topic, true, endpoint_kind);
create_new_bridge_nts_(topic, endpoint_kind, true);
}
else
{
Expand Down

0 comments on commit 1cf2453

Please sign in to comment.