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] redesign subscriber api #1863

Merged
merged 14 commits into from
Dec 17, 2024
Merged

Conversation

rex-schilasky
Copy link
Contributor

@rex-schilasky rex-schilasky commented Dec 16, 2024

Description

Changes Summary:

  1. Namespace Updates:

    • The legacy eCAL::CSubscriber API has been moved to the eCAL::v5 namespace for compatibility with existing systems using eCAL version 5.
    • Introduced a new, modern eCAL::CSubscriber API under the eCAL::v6 namespace (default inline namespace).
  2. API Modernization:

    • Initialization:
      • Removed Create and Destroy methods in v6. Subscribers are now fully initialized via constructors and cleaned up automatically via destructors.
    • Callback Registration:
      • Event callbacks (AddEventCallback, RemEventCallback) are now passed as optional parameters during object construction, simplifying event handling.
      • Receive callbacks renamed AddReceiveCallback to SetReceiveCallback, RemReceiveCallback to RemoveReceiveCallback
      • SetReceiveCallback and RemoveReceiveCallback methods remain part of the API for flexibility in managing message reception callbacks.
    • Removed Legacy Methods:
      • Methods such as SetAttribute, ClearAttribute, and SetID were removed as they were experimental or rarely used.
    • Streamlined Methods:
      • The ReceiveBuffer method in v5 was replaced with SetReceiveCallback to encourage a more event-driven approach to data reception in v6.
  3. Code Refactoring:

    • Internally uses std::shared_ptr<CSubscriberImpl> for robust resource management and memory safety.
    • Constructors support optional SDataTypeInformation for specifying topic metadata and a SubEventIDCallbackT for event-driven designs.
  4. Improved Usability:

    • Constructors now provide better defaults and more configuration options, making the API easier to use in a wide range of scenarios.
    • Cleaner separation of concerns and removal of outdated features.

Impact:

  • Maintains backward compatibility with eCAL::v5::CSubscriber while offering a modern, streamlined API for new applications.
  • Improves code readability, usability, and performance for developers integrating eCAL.

@rex-schilasky rex-schilasky added the cherry-pick-to-NONE Don't cherry-pick these changes label Dec 16, 2024
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

There were too many comments to post at once. Showing the first 20 out of 125. Check the log or trigger a new build to see more.

app/rec/rec_client_core/src/ecal_rec_impl.cpp Show resolved Hide resolved
app/rec/rec_client_core/src/ecal_rec_impl.cpp Show resolved Hide resolved
app/rec/rec_client_core/src/ecal_rec_impl.cpp Show resolved Hide resolved
app/rec/rec_client_core/src/ecal_rec_impl.cpp Show resolved Hide resolved
ecal/core/include/ecal/ecal_subscriber_v5.h Show resolved Hide resolved
ecal/core/include/ecal/ecal_subscriber_v5.h Show resolved Hide resolved
ecal/core/include/ecal/ecal_subscriber_v5.h Show resolved Hide resolved
ecal/core/include/ecal/msg/dynamic.h Show resolved Hide resolved
ecal/core/include/ecal/msg/dynamic.h Outdated Show resolved Hide resolved
CPublisherImpl event handling renamings
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

There were too many comments to post at once. Showing the first 20 out of 109. Check the log or trigger a new build to see more.

ecal/core/include/ecal/msg/dynamic.h Outdated Show resolved Hide resolved
ecal/core/include/ecal/msg/dynamic.h Show resolved Hide resolved
ecal/core/include/ecal/msg/dynamic.h Show resolved Hide resolved
ecal/core/include/ecal/msg/dynamic.h Show resolved Hide resolved
ecal/core/include/ecal/msg/subscriber.h Show resolved Hide resolved
ecal/core/src/pubsub/ecal_publisher_impl.h Show resolved Hide resolved
ecal/core/src/pubsub/ecal_subgate.cpp Show resolved Hide resolved
ecal/core/src/pubsub/ecal_subgate.cpp Show resolved Hide resolved
ecal/core/src/pubsub/ecal_subgate.h Show resolved Hide resolved
ecal/core/src/pubsub/ecal_subscriber.cpp Show resolved Hide resolved
RemXY -> RemoveXY
Logging corrected
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

There were too many comments to post at once. Showing the first 20 out of 105. Check the log or trigger a new build to see more.

app/rec/rec_client_core/src/ecal_rec_impl.cpp Show resolved Hide resolved
app/rec/rec_client_core/src/ecal_rec_impl.cpp Show resolved Hide resolved
app/rec/rec_client_core/src/ecal_rec_impl.cpp Show resolved Hide resolved
ecal/core/src/pubsub/ecal_publisher_impl.cpp Show resolved Hide resolved
ecal/core/src/pubsub/ecal_subscriber.cpp Show resolved Hide resolved
}

bool CSubscriber::Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_)
CSubscriber::CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const SubEventIDCallbackT event_callback_, const Subscriber::Configuration& config_) :
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: the const qualified parameter 'event_callback_' is copied for each invocation; consider making it a reference [performance-unnecessary-value-param]

ecal/core/include/ecal/ecal_subscriber.h:69:

-         CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const SubEventIDCallbackT event_callback_, const Subscriber::Configuration& config_ = GetSubscriberConfiguration());
+         CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const SubEventIDCallbackT& event_callback_, const Subscriber::Configuration& config_ = GetSubscriberConfiguration());
Suggested change
CSubscriber::CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const SubEventIDCallbackT event_callback_, const Subscriber::Configuration& config_) :
CSubscriber::CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const SubEventIDCallbackT& event_callback_, const Subscriber::Configuration& config_) :

Copy link
Contributor

Choose a reason for hiding this comment

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

Rex: did you want to turn off this warning? doesn't it make sense in this case? Why not a reference?

ecal/core/src/pubsub/ecal_subscriber.cpp Show resolved Hide resolved
ecal/core/src/pubsub/ecal_subscriber.cpp Show resolved Hide resolved
ecal/core/src/pubsub/ecal_subscriber.cpp Show resolved Hide resolved
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

There were too many comments to post at once. Showing the first 20 out of 89. Check the log or trigger a new build to see more.

ecal/core/include/ecal/ecal_subscriber.h Show resolved Hide resolved
}

bool CSubscriber::Create(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const Subscriber::Configuration& config_)
CSubscriber::CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const SubEventIDCallbackT event_callback_, const Subscriber::Configuration& config_) :
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: the const qualified parameter 'event_callback_' is copied for each invocation; consider making it a reference [performance-unnecessary-value-param]

ecal/core/include/ecal/ecal_subscriber.h:67:

-         CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const SubEventIDCallbackT event_callback_, const Subscriber::Configuration& config_ = GetSubscriberConfiguration());
+         CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const SubEventIDCallbackT& event_callback_, const Subscriber::Configuration& config_ = GetSubscriberConfiguration());
Suggested change
CSubscriber::CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const SubEventIDCallbackT event_callback_, const Subscriber::Configuration& config_) :
CSubscriber::CSubscriber(const std::string& topic_name_, const SDataTypeInformation& data_type_info_, const SubEventIDCallbackT& event_callback_, const Subscriber::Configuration& config_) :

ecal/core/src/service/ecal_service_server.cpp Show resolved Hide resolved
ecal/core/src/service/ecal_service_server.cpp Show resolved Hide resolved
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

There were too many comments to post at once. Showing the first 20 out of 30. Check the log or trigger a new build to see more.


int content(static_cast<int>(static_cast<unsigned char*>(data_->buf)[0]));
int content(static_cast<int>(static_cast<unsigned char*>(data_.buf)[0]));
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 'content' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int content(static_cast<int>(static_cast<unsigned char*>(data_.buf)[0]));
int const content(static_cast<int>(static_cast<unsigned char*>(data_.buf)[0]));

std::cout << " Id : " << data_->id << std::endl;
std::cout << " Time : " << data_->time << std::endl;
std::cout << " Clock : " << data_->clock << std::endl;
std::cout << " Size : " << data_.size << 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 << " Size : " << data_.size << std::endl;
std::cout << " Size : " << data_.size << '\n';

std::cout << " Time : " << data_->time << std::endl;
std::cout << " Clock : " << data_->clock << std::endl;
std::cout << " Size : " << data_.size << std::endl;
std::cout << " Id : " << data_.id << 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 << " Id : " << data_.id << std::endl;
std::cout << " Id : " << data_.id << '\n';

std::cout << " Clock : " << data_->clock << std::endl;
std::cout << " Size : " << data_.size << std::endl;
std::cout << " Id : " << data_.id << std::endl;
std::cout << " Time : " << data_.time << 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 << " Time : " << data_.time << std::endl;
std::cout << " Time : " << data_.time << '\n';

std::cout << " Size : " << data_.size << std::endl;
std::cout << " Id : " << data_.id << std::endl;
std::cout << " Time : " << data_.time << std::endl;
std::cout << " Clock : " << data_.clock << 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 << " Clock : " << data_.clock << std::endl;
std::cout << " Clock : " << data_.clock << '\n';

eCAL::Initialize(config, "callback_topic_id");
}

void TearDown() override
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: method 'TearDown' can be made static [readability-convert-member-functions-to-static]

Suggested change
void TearDown() override
static void TearDown() override

}
};

TEST_P(TestFixture, OnePubSub)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_P(TestFixture, OnePubSub)
TEST_P(TestFixture /*unused*/, OnePubSub /*unused*/)

}
};

TEST_P(TestFixture, OnePubSub)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: the parameter #1 is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

Suggested change
TEST_P(TestFixture, OnePubSub)
TEST_P(const TestFixture&, OnePubSub)

EXPECT_EQ(callback_datatype_info, datatype_info);
}

TEST_P(TestFixture, MultiplePubSub)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST_P(TestFixture, MultiplePubSub)
TEST_P(TestFixture /*unused*/, MultiplePubSub /*unused*/)

EXPECT_EQ(callback_datatype_info, datatype_info);
}

TEST_P(TestFixture, MultiplePubSub)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: the parameter #1 is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

Suggested change
TEST_P(TestFixture, MultiplePubSub)
TEST_P(const TestFixture&, MultiplePubSub)

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

@@ -68,25 +68,25 @@ namespace eCAL


template <typename T, typename DynamicDeserializer>
class CDynamicMessageSubscriber final : public CSubscriber
class CDynamicMessageSubscriber final : public v5::CSubscriber
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: constructor does not initialize these fields: m_cb_callback, m_error_callback [cppcoreguidelines-pro-type-member-init]

ecal/core/include/ecal/msg/dynamic.h:258:

-     MsgReceiveCallbackT  m_cb_callback;
+     MsgReceiveCallbackT  m_cb_callback{};

ecal/core/include/ecal/msg/dynamic.h:260:

-     ErrorCallbackT       m_error_callback;
+     ErrorCallbackT       m_error_callback{};

#include <string>
#include <thread>

#include <gtest/gtest.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: 'gtest/gtest.h' file not found [clang-diagnostic-error]

#include <gtest/gtest.h>
         ^


#include <gtest/gtest.h>

TEST(core_cpp_pubsub_v5, TestSubscriberIsPublishedTiming)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST(core_cpp_pubsub_v5, TestSubscriberIsPublishedTiming)
TEST(core_cpp_pubsub_v5 /*unused*/, TestSubscriberIsPublishedTiming /*unused*/)

eCAL::Finalize();
}

TEST(core_cpp_pubsub_v5, TestPublisherIsSubscribedTiming)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST(core_cpp_pubsub_v5, TestPublisherIsSubscribedTiming)
TEST(core_cpp_pubsub_v5 /*unused*/, TestPublisherIsSubscribedTiming /*unused*/)

eCAL::Finalize();
}

TEST(core_cpp_pubsub_v5, TestChainedPublisherSubscriberCallback)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: all parameters should be named in a function [readability-named-parameter]

Suggested change
TEST(core_cpp_pubsub_v5, TestChainedPublisherSubscriberCallback)
TEST(core_cpp_pubsub_v5 /*unused*/, TestChainedPublisherSubscriberCallback /*unused*/)

@@ -384,7 +385,7 @@
topic_info.encoding = topic_enc_;
topic_info.descriptor = std::string(topic_desc_, static_cast<size_t>(topic_desc_length_));

auto* sub = new eCAL::CSubscriber;
auto* sub = new eCAL::v5::CSubscriber;
if (!sub->Create(topic_name_, topic_info))
{
delete sub;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: deleting a pointer through a type that is not marked 'gsl::owner<>'; consider using a smart pointer instead [cppcoreguidelines-owning-memory]

    delete sub;
    ^
Additional context

lang/python/core/src/ecal_clang.cpp:387: variable declared here

  auto* sub = new eCAL::v5::CSubscriber;
  ^

@@ -398,7 +399,7 @@
/****************************************/
bool sub_destroy(ECAL_HANDLE handle_)
{
auto* sub = static_cast<eCAL::CSubscriber*>(handle_);
auto* sub = static_cast<eCAL::v5::CSubscriber*>(handle_);
if(sub != nullptr)
{
delete sub;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: deleting a pointer through a type that is not marked 'gsl::owner<>'; consider using a smart pointer instead [cppcoreguidelines-owning-memory]

    delete sub;
    ^
Additional context

lang/python/core/src/ecal_clang.cpp:401: variable declared here

  auto* sub = static_cast<eCAL::v5::CSubscriber*>(handle_);
  ^

@@ -422,7 +423,7 @@ PyObject* sub_set_callback(PyObject* /*self*/, PyObject* args)
if (!PyArg_ParseTuple(args, "nO", &topic_handle, &cb_func))
return nullptr;

eCAL::CSubscriber* sub = (eCAL::CSubscriber*)topic_handle;
eCAL::v5::CSubscriber* sub = (eCAL::v5::CSubscriber*)topic_handle;
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 C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]

  eCAL::v5::CSubscriber* sub = (eCAL::v5::CSubscriber*)topic_handle;
                               ^

@@ -475,7 +476,7 @@
if (!PyArg_ParseTuple(args, "nO", &topic_handle, &cb_func))
return nullptr;

eCAL::CSubscriber* sub = (eCAL::CSubscriber*)topic_handle;
eCAL::v5::CSubscriber* sub = (eCAL::v5::CSubscriber*)topic_handle;
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 C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]

  eCAL::v5::CSubscriber* sub = (eCAL::v5::CSubscriber*)topic_handle;
                               ^

{
std::string topicName = topic_name_;
std::string topicName = topic_id_.topic_name;
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 'topicName' of type 'std::string' (aka 'basic_string') can be declared 'const' [misc-const-correctness]

Suggested change
std::string topicName = topic_id_.topic_name;
std::string const topicName = topic_id_.topic_name;

@rex-schilasky rex-schilasky merged commit 7a1d931 into master Dec 17, 2024
20 checks passed
@rex-schilasky rex-schilasky deleted the feature/redesign-subscriber-api branch December 17, 2024 15:10
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.

2 participants