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

Feature/nanobind submodule #1556

Open
wants to merge 13 commits into
base: feature/nanobind-submodule
Choose a base branch
from

Conversation

KerstinKeller
Copy link
Contributor

Description

Related issues

Cherry-pick to

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

ecal/core/include/ecal/ecal_nb_subscriber.h Outdated Show resolved Hide resolved
{
std::string Rec_Data = "No Reception";
long long rcv_time = 12345;
auto success = eCAL::CSubscriber::ReceiveBuffer(Rec_Data, &rcv_time, 500);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: Value stored to 'success' during its initialization is never read [clang-analyzer-deadcode.DeadStores]

            auto success = eCAL::CSubscriber::ReceiveBuffer(Rec_Data, &rcv_time, 500);
                 ^
Additional context

ecal/core/include/ecal/ecal_nb_subscriber.h:17: Value stored to 'success' during its initialization is never read

            auto success = eCAL::CSubscriber::ReceiveBuffer(Rec_Data, &rcv_time, 500);
                 ^

@@ -1,5 +1,164 @@
#include <nanobind/nanobind.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: 'nanobind/nanobind.h' file not found [clang-diagnostic-error]

#include <nanobind/nanobind.h>
         ^

lang/python/nanobind_core/main.cpp Outdated Show resolved Hide resolved
Copy link
Contributor Author

@KerstinKeller KerstinKeller left a comment

Choose a reason for hiding this comment

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

I made some remarks.

.def("get_datatype_information", &eCAL::CSubscriber::GetDataTypeInformation)
.def("dump", &eCAL::CSubscriber::Dump);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need only one class "Subscriber" which wraps the CNBSubscriber class, but then it wraps all methods.

ecal/core/include/ecal/ecal_nb_subscriber.h Outdated Show resolved Hide resolved
m.def("get_version", [](int* nb_major, int* nb_minor, int* nb_patch)
{ return eCAL::GetVersion(nb_major, nb_minor, nb_patch); });
// m.def("initialize", [](int nb_argc_, char *nb_argv_, const char* nb_unit_name_, unsigned int nb_components_)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this function should return return all three values instead of taking them as a pointer.
in python [major, minor, patch] = get_version().
so you can use nb::tuple to return a tuple.

https://nanobind.readthedocs.io/en/latest/api_core.html#_CPPv4N8nanobind5tupleE

m.def("get_version_string", []() { return eCAL::GetVersionString(); });
m.def("get_version_date", []() { return eCAL::GetVersionDateString(); });
m.def("set_unitname", [](const char* nb_unit_name) { return eCAL::SetUnitName(nb_unit_name); });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

you need here to take a std::string I think. you can then do return eCAL::SetUnitName(nb_unit_name.c_str())


m.def("get_topics", [](std::unordered_map<std::string, eCAL::SDataTypeInformation>& nb_topic_info_map_)
{ return eCAL::Util::GetTopics(nb_topic_info_map_); });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

with this function you probably need to return a map.

{ return eCAL::Util::GetTopicNames(nb_topic_names_); });
m.def("get_topic_datatype_info", [](const std::string& nb_topic_name_, eCAL::SDataTypeInformation& nb_topic_info_)
{ return eCAL::Util::GetTopicDataTypeInformation(nb_topic_name_, nb_topic_info_); });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this function also: take a std::string, return [bool, SDatatypeInformation]

Copy link
Contributor Author

@KerstinKeller KerstinKeller left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, I left some comments.

#include <wrappers/datatypeinfo.h>
#include <wrappers/publisher.h>
#include <wrappers/server.h>
#include <wrappers/subscriber.h>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

#include only modules/...


//void AddSubscriberClassToModule(const nanobind::module_& module) {};

NB_MODULE(nanobind_core, m) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be in modules/datatypeinfo.h

.def_rw("descriptor", &eCAL::CNBDataTypeInformation::descriptor);

// Struct eCAL::SServiceResponse
nanobind::class_<eCAL::SServiceResponse>(m, "ServiceResponse")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

move to file... /server.h


namespace eCAL
{
CNBSrvClient::CNBSrvClient() : CServiceClient() { }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

CNBSrvCLient -> CNBServiceClient

{
public:
std::string name;
std::string encoding;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe: nanobind:string???

CNBPublisher::CNBPublisher(const std::string& topic_name, const CNBDataTypeInformation& datainfo) : CPublisher(topic_name, convert(datainfo)) { }

bool CNBPublisher::WrapAddPubEventCB(eCAL_Publisher_Event event, nanobind::callable callback_)
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Think about naming


namespace eCAL
{
CNBSrvServer::CNBSrvServer() : CServiceServer() { }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

CNBSrvServer -> CNBServiceServer

#include <string>
#include <cstddef>
#include <ecal/ecal_types.h>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in this file, probably the only include you need is #include <nanobind/nanobind.h> (for nanobind::module).
If then it doesn't compile, move the includes to module_subscriber.cpp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants