Skip to content

Commit

Permalink
[core] split GetTopicNames into GetPublishedTopicNames and `GetSu…
Browse files Browse the repository at this point in the history
…bscribedTopicNames`.
  • Loading branch information
KerstinKeller committed Jan 29, 2025
1 parent d453403 commit 05b442a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 36 deletions.
15 changes: 13 additions & 2 deletions ecal/core/include/ecal/registration.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,24 @@ namespace eCAL
ECAL_API bool GetClientInfo(const SServiceId& id_, ServiceMethodInformationSetT& service_method_info_);

/**
* @brief Get all topic names.
* @brief Get all names of topics that are being published.
* This is a convenience function.
* It calls GetPublisherIDs() and filters by name
*
* @param topic_names_ Set to store the topic names.
**/
ECAL_API void GetTopicNames(std::set<std::string>& topic_names_);
ECAL_API void GetPublishedTopicNames(std::set<std::string>& topic_names_);

/**
* @brief Get all names of topics that are being subscribed
* This is a convenience function.
* It calls GetSubscriberIDs() and filters by name
*
* @param topic_names_ Set to store the topic names.
**/
ECAL_API void GetSubscribedTopicNames(std::set<std::string>& topic_names_);

/**
* @brief Get the pairs of service name / method name of all eCAL Servers.
*
* @param service_method_names_ Set to store the service/method names (Set { (ServiceName, MethodName) }).
Expand Down
11 changes: 9 additions & 2 deletions ecal/core/src/registration/ecal_registration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,23 @@ namespace eCAL
return g_descgate()->GetClientInfo(id_, service_info_);
}

void GetTopicNames(std::set<std::string>& topic_names_)
void GetPublishedTopicNames(std::set<std::string>& topic_names_)
{
topic_names_.clear();

// get publisher & subscriber id sets and insert names into the topic_names set
// get publisher id sets and insert names into the topic_names set
const std::set<STopicId> pub_id_set = GetPublisherIDs();
for (const auto& pub_id : pub_id_set)
{
topic_names_.insert(pub_id.topic_name);
}
}

void GetSubscribedTopicNames(std::set<std::string>& topic_names_)
{
topic_names_.clear();

// get subscriber id sets and insert names into the topic_names set
const std::set<STopicId> sub_id_set = GetSubscriberIDs();
for (const auto& sub_id : sub_id_set)
{
Expand Down
4 changes: 3 additions & 1 deletion ecal/core/src/util/frequency_calculator.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2024 Continental Corporation
* Copyright (C) 2016 - 2025 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -141,6 +141,8 @@ namespace eCAL
return 0.0;
}

// We haven't received any ticks, yet we don't want to reset the calculation.
// Hence we return the frequency that the calculator returned.
return frequency;
}

Expand Down
12 changes: 5 additions & 7 deletions ecal/samples/cpp/benchmarks/latency_rec/src/latency_rec.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2024 Continental Corporation
* Copyright (C) 2016 - 2025 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -58,9 +58,6 @@ void on_receive(const struct eCAL::SReceiveCallbackData& data_, SCallbackPar* pa
// single test run
void do_run(int delay_, std::string& log_file_)
{
// initialize eCAL API
eCAL::Initialize("latency_rec");

// subscriber
eCAL::CSubscriber sub("ping");

Expand Down Expand Up @@ -90,9 +87,6 @@ void do_run(int delay_, std::string& log_file_)

// log all latencies into file
log2file(cb_par.latency_array, cb_par.rec_size, log_file_);

// finalize eCAL API
eCAL::Finalize();
}

int main(int argc, char** argv)
Expand All @@ -107,11 +101,15 @@ int main(int argc, char** argv)
cmd.add(log_file);
cmd.parse(argc, argv);

// initialize eCAL API
eCAL::Initialize("latency_rec");
// run tests
while(eCAL::Ok())
{
do_run(delay.getValue(), log_file.getValue());
}
// finalize eCAL API
eCAL::Finalize();
}
catch (TCLAP::ArgException& e) // catch any exceptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,9 @@ int main()
topic_id_sub_set = eCAL::Registration::GetSubscriberIDs();
}

auto num_topics = topic_id_pub_set.size() + topic_id_sub_set.size();
auto num_entities = topic_id_pub_set.size() + topic_id_sub_set.size();
auto diff_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start_time);
std::cout << "GetTopics : " << static_cast<double>(diff_time.count()) / runs << " ms" << " (" << num_topics << " topics)" << std::endl;
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));

// GetTopicNames
{
std::set<std::string> topic_names;

start_time = std::chrono::steady_clock::now();
for (run = 0; run < runs; ++run)
{
eCAL::Registration::GetTopicNames(topic_names);
}

auto num_topics = topic_names.size();
auto diff_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start_time);
std::cout << "GetTopicsNames : " << static_cast<double>(diff_time.count()) / runs << " ms" << " (" << num_topics << " topics)" << std::endl;
std::cout << std::endl;
std::cout << "GetTopics : " << static_cast<double>(diff_time.count()) / runs << " ms" << " (" << num_entities << " entities)" << std::endl;
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,12 @@ TEST(core_cpp_registration_public, GetTopicsParallel)
size_t number_publishers_seen = 0;
size_t max_number_publishers_seen = 0;

std::set<std::string> tmp_topic_names;
std::set<eCAL::STopicId> tmp_topic_ids;
std::set<eCAL::STopicId> tmp_publisher_ids;

do {
eCAL::Registration::GetTopicNames(tmp_topic_names);
tmp_topic_ids = eCAL::Registration::GetPublisherIDs();
tmp_publisher_ids = eCAL::Registration::GetPublisherIDs();

number_publishers_seen = tmp_topic_names.size();
number_publishers_seen = tmp_publisher_ids.size();
max_number_publishers_seen = std::max(max_number_publishers_seen, number_publishers_seen);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
} while (!testing_completed);
Expand Down

0 comments on commit 05b442a

Please sign in to comment.