Skip to content

Commit

Permalink
Change activate to check if there are discovered types for topic pref…
Browse files Browse the repository at this point in the history
…ix and adapt tests

Signed-off-by: Lucia Echevarria <[email protected]>
  • Loading branch information
LuciaEchevarria99 committed Oct 8, 2024
1 parent e899632 commit 22e8d05
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class DataStreamer : public TopicRateCalculator
FASTDDSSPY_PARTICIPANTS_DllAPI
bool activate(
const ddspipe::core::types::WildcardDdsFilterTopic& topic_to_activate,
const std::set<eprosima::ddspipe::core::types::DdsTopic>& topics,
const std::shared_ptr<CallbackType>& callback);

FASTDDSSPY_PARTICIPANTS_DllAPI
Expand All @@ -71,20 +72,20 @@ class DataStreamer : public TopicRateCalculator

FASTDDSSPY_PARTICIPANTS_DllAPI
bool is_topic_type_discovered(
const ddspipe::core::types::WildcardDdsFilterTopic& topic_to_activate) const noexcept;
const ddspipe::core::types::DdsTopic& topic_to_activate) const noexcept;

FASTDDSSPY_PARTICIPANTS_DllAPI
bool is_topic_type_discovered(
const ddspipe::core::types::DdsTopic& topic_to_activate) const noexcept;
bool is_any_topic_type_discovered(
const std::set<eprosima::ddspipe::core::types::DdsTopic>& topics) const noexcept;

protected:

bool is_topic_type_discovered_nts_(
const ddspipe::core::types::WildcardDdsFilterTopic& topic_to_activate) const noexcept;

bool is_topic_type_discovered_nts_(
const ddspipe::core::types::DdsTopic& topic_to_activate) const noexcept;

bool is_any_topic_type_discovered_nts_(
const std::set<eprosima::ddspipe::core::types::DdsTopic>& topics) const noexcept;

bool activated_ {false};

std::shared_ptr<CallbackType> callback_;
Expand Down
43 changes: 21 additions & 22 deletions fastddsspy_participants/src/cpp/model/DataStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ bool DataStreamer::activate_all(

bool DataStreamer::activate(
const ddspipe::core::types::WildcardDdsFilterTopic& topic_to_activate,
const std::set<eprosima::ddspipe::core::types::DdsTopic>& topics,
const std::shared_ptr<CallbackType>& callback)
{
if (!is_topic_type_discovered(topic_to_activate))
if (!is_any_topic_type_discovered(topics))
{
EPROSIMA_LOG_WARNING(FASTDDSSPY_DATASTREAMER,
"Type <" << topic_to_activate.type_name <<
Expand Down Expand Up @@ -157,40 +158,38 @@ void DataStreamer::add_data(
}

bool DataStreamer::is_topic_type_discovered(
const ddspipe::core::types::WildcardDdsFilterTopic& filter_topic) const noexcept
const ddspipe::core::types::DdsTopic& topic) const noexcept
{
std::shared_lock<std::shared_timed_mutex> _(mutex_);
return is_topic_type_discovered_nts_(filter_topic);
return is_topic_type_discovered_nts_(topic);
}

bool DataStreamer::is_topic_type_discovered_nts_(
const ddspipe::core::types::WildcardDdsFilterTopic& filter_topic) const noexcept
const ddspipe::core::types::DdsTopic& topic) const noexcept
{
ddspipe::core::types::DdsTopic topic;
for (const auto& it : topic_type_discovered_)
{
topic.m_topic_name = it.first;
topic.type_name = it.second;
if (filter_topic.matches(topic) == true)
{
return true;
}
}

return false;
return types_discovered_.find(topic.type_name) != types_discovered_.end();
}

bool DataStreamer::is_topic_type_discovered(
const ddspipe::core::types::DdsTopic& topic) const noexcept
bool DataStreamer::is_any_topic_type_discovered(
const std::set<eprosima::ddspipe::core::types::DdsTopic>& topics) const noexcept
{
std::shared_lock<std::shared_timed_mutex> _(mutex_);
return is_topic_type_discovered_nts_(topic);
return is_any_topic_type_discovered_nts_(topics);
}

bool DataStreamer::is_topic_type_discovered_nts_(
const ddspipe::core::types::DdsTopic& topic) const noexcept
bool DataStreamer::is_any_topic_type_discovered_nts_(
const std::set<eprosima::ddspipe::core::types::DdsTopic>& topics) const noexcept
{
return types_discovered_.find(topic.type_name) != types_discovered_.end();
for (const auto& topic : topics)
{
if (types_discovered_.find(topic.type_name) != types_discovered_.end())
{
// If there's at least one topic that matches the filter topic return true
return true;
}
}

return false;
}

} /* namespace participants */
Expand Down
Loading

0 comments on commit 22e8d05

Please sign in to comment.