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

Make the trigger of the DDS Pipe callbacks configurable #67

Merged
merged 12 commits into from
Nov 22, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ namespace eprosima {
namespace ddspipe {
namespace core {

enum DiscoveryTrigger
{
READER = 0, //! The discovery callbacks get triggered by the discovery of a reader.
WRITER = 1, //! The discovery callbacks get triggered by the discovery of a writer.
NONE = 2, //! The discovery callbacks don't get triggered by the discovery of readers or writers.
ANY = 3 //! The discovery callbacks get triggered by the discovery of either a reader or a writer.
};

/**
* Configuration structure encapsulating the configuration of a \c DdsPipe instance.
*/
Expand Down Expand Up @@ -108,6 +116,9 @@ struct DdsPipeConfiguration : public IConfiguration

//! Whether the DDS Pipe should be initialized enabled.
bool init_enabled = false;

//! The type of the entity whose discovery should trigger the discovery callbacks.
DiscoveryTrigger discovery_trigger = DiscoveryTrigger::READER;
};

} /* namespace core */
Expand Down
29 changes: 23 additions & 6 deletions ddspipe_core/src/cpp/core/DdsPipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,19 +350,36 @@ void DdsPipe::updated_endpoint_nts_(
bool DdsPipe::is_endpoint_relevant_(
const Endpoint& endpoint) noexcept
jepemi marked this conversation as resolved.
Show resolved Hide resolved
{
if (!endpoint.is_reader())
{
return false;
}
auto is_endpoint_type_relevant = [&](const Endpoint& entity)
{
switch (configuration_.discovery_trigger)
{
case DiscoveryTrigger::READER:
return entity.is_reader();
case DiscoveryTrigger::WRITER:
return entity.is_writer();
case DiscoveryTrigger::ANY:
return true;
case DiscoveryTrigger::NONE:
return false;
default:
return false;
}
};

auto is_endpoint_relevant = [endpoint](const Endpoint& entity)
auto is_endpoint_relevant = [endpoint, is_endpoint_type_relevant](const Endpoint& entity)
{
return entity.active &&
entity.is_reader() &&
is_endpoint_type_relevant(entity) &&
entity.topic == endpoint.topic &&
entity.discoverer_participant_id == endpoint.discoverer_participant_id;
};

if (!is_endpoint_type_relevant(endpoint))
{
return false;
}

const auto& relevant_endpoints = discovery_database_->get_endpoints(is_endpoint_relevant);

if (endpoint.active)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,6 @@ SchemaParticipant::SchemaParticipant(
, discovery_database_(discovery_database)
, schema_handler_(schema_handler)
{
// Simulate that there is a reader of type object to force this track creation
discovery_database_->add_endpoint(
rtps::CommonParticipant::simulate_endpoint(type_object_topic(), this->id())
);

// Force for every topic found to create track by creating simulated readers
// NOTE: this could change for: in DDS Pipe change that only readers create track
discovery_database_->add_endpoint_discovered_callback(
[this](Endpoint endpoint_discovered)
{
if (endpoint_discovered.is_writer() && endpoint_discovered.discoverer_participant_id != this->id())
{
discovery_database_->add_endpoint(
rtps::CommonParticipant::simulate_endpoint(endpoint_discovered.topic,
endpoint_discovered.discoverer_participant_id)
);
}
}
);
}

ParticipantId SchemaParticipant::id() const noexcept
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ constexpr const char* SPECS_QOS_TAG("qos"); //! Global Topic QoS
constexpr const char* NUMBER_THREADS_TAG("threads"); //! Number of threads to configure the thread pool
constexpr const char* WAIT_ALL_ACKED_TIMEOUT_TAG("wait-all-acked-timeout"); //! Wait for a maximum of *wait-all-acked-timeout* ms until all msgs sent by reliable writers are acknowledged by their matched readers
constexpr const char* REMOVE_UNUSED_ENTITIES_TAG("remove-unused-entities"); //! Dynamically create and delete entities and tracks.
constexpr const char* DISCOVERY_TRIGGER_TAG("discovery-trigger"); //! Dynamically trigger the discovery of entities.
juanlofer-eprosima marked this conversation as resolved.
Show resolved Hide resolved

// XML configuration tags
constexpr const char* XML_TAG("xml"); //! Tag to read xml configuration
Expand Down
Loading