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

[core] split GetTopicNames into GetPublishedTopicNames and GetSubscribedTopicNames. #1969

Merged
merged 2 commits into from
Jan 30, 2025

Conversation

KerstinKeller
Copy link
Contributor

Please see if you like the naming.
To be more in line with the functions for service / client, the function was split into two separate functions.

@KerstinKeller KerstinKeller added the cherry-pick-to-NONE Don't cherry-pick these changes label Jan 29, 2025
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]

Suggested change
std::cout << "GetTopics : " << static_cast<double>(diff_time.count()) / runs << " ms" << " (" << num_entities << " entities)" << std::endl;
std::cout << "GetTopics : " << static_cast<double>(diff_time.count()) / runs << " ms" << " (" << num_entities << " entities)" << '\n';

Comment on lines 121 to 129
void GetSubscribedTopicNames(std::set<std::string>& topic_names_)
{
topic_names_.clear();
Copy link
Contributor

@DownerCase DownerCase Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why take these as ref if you're going to wipe the input anyway? Are you assuming the implementation will reuse the previously allocated memory?

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be more than fine if they just returned the set. I guess we do have a few other functions which take a reference and then return bool.
Personally I don't like the style too much (I'd prefer something like std::expected, or std::variant, but since the core still uses C++ 14 that's out of the question 😞

Anyways, I guess the biggest problem here is that we're not consistent. ECAL_API std::set<SServiceId> GetClientIDs(); here we return a set, but ECAL_API bool GetClientInfo(const SServiceId& id_, ServiceMethodInformationSetT& service_method_info_); returns bool and takes a ref, and then lastly the functions to just get a name return void.

@KerstinKeller KerstinKeller force-pushed the feature/registration-functions branch from 05b442a to adbc6ef Compare January 30, 2025 08:07
@KerstinKeller KerstinKeller force-pushed the feature/registration-functions branch from adbc6ef to 2e41b7f Compare January 30, 2025 12:11
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

const std::set<STopicId> pub_id_set = GetPublisherIDs();
// get publisher id sets and insert names into the topic_names set
std::set<STopicId> pub_id_set;
bool return_value = GetPublisherIDs(pub_id_set);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'return_value' of type 'bool' can be declared 'const' [misc-const-correctness]

Suggested change
bool return_value = GetPublisherIDs(pub_id_set);
bool const return_value = GetPublisherIDs(pub_id_set);


// get subscriber id sets and insert names into the topic_names set
std::set<STopicId> sub_id_set;
bool return_value = GetSubscriberIDs(sub_id_set);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'return_value' of type 'bool' can be declared 'const' [misc-const-correctness]

Suggested change
bool return_value = GetSubscriberIDs(sub_id_set);
bool const return_value = GetSubscriberIDs(sub_id_set);

{
server_method_names_.clear();

// get servers id set and insert names into the server_method_names_ set
const std::set<SServiceId> server_id_set = GetServerIDs();
std::set<SServiceId> server_id_set;
bool return_value = GetServerIDs(server_id_set);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'return_value' of type 'bool' can be declared 'const' [misc-const-correctness]

Suggested change
bool return_value = GetServerIDs(server_id_set);
bool const return_value = GetServerIDs(server_id_set);

{
client_method_names_.clear();

// get clients id set and insert names into the client_method_names set
const std::set<SServiceId> client_id_set = GetClientIDs();
std::set<SServiceId> client_id_set;
bool return_value = GetClientIDs(client_id_set);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'return_value' of type 'bool' can be declared 'const' [misc-const-correctness]

Suggested change
bool return_value = GetClientIDs(client_id_set);
bool const return_value = GetClientIDs(client_id_set);

@@ -41,6 +41,8 @@ TEST(core_cpp_registration_public, GetTopics)

std::set<eCAL::STopicId> topic_id_pub_set;
std::set<eCAL::STopicId> topic_id_sub_set;
bool get_publisher_ids_succeeded;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'get_publisher_ids_succeeded' is not initialized [cppcoreguidelines-init-variables]

Suggested change
bool get_publisher_ids_succeeded;
bool get_publisher_ids_succeeded = false;

@@ -41,6 +41,8 @@ TEST(core_cpp_registration_public, GetTopics)

std::set<eCAL::STopicId> topic_id_pub_set;
std::set<eCAL::STopicId> topic_id_sub_set;
bool get_publisher_ids_succeeded;
bool get_subscriber_ids_succeeded;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'get_subscriber_ids_succeeded' is not initialized [cppcoreguidelines-init-variables]

Suggested change
bool get_subscriber_ids_succeeded;
bool get_subscriber_ids_succeeded = false;

@hannemn hannemn merged commit 55da7f3 into master Jan 30, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-to-NONE Don't cherry-pick these changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants