diff --git a/rclpy/src/rclpy/client.cpp b/rclpy/src/rclpy/client.cpp index 8587f527d..d277dee71 100644 --- a/rclpy/src/rclpy/client.cpp +++ b/rclpy/src/rclpy/client.cpp @@ -155,7 +155,7 @@ Client::take_response(py::object pyresponse_type) void define_client(py::object module) { - py::class_(module, "Client") + py::class_>(module, "Client") .def(py::init()) .def_property_readonly( "pointer", [](const Client & client) { diff --git a/rclpy/src/rclpy/client.hpp b/rclpy/src/rclpy/client.hpp index f9f5a9f34..8c7621a8d 100644 --- a/rclpy/src/rclpy/client.hpp +++ b/rclpy/src/rclpy/client.hpp @@ -28,7 +28,7 @@ namespace py = pybind11; namespace rclpy { -class Client : public Destroyable +class Client : public Destroyable, public std::enable_shared_from_this { public: /// Create a client diff --git a/rclpy/src/rclpy/clock.cpp b/rclpy/src/rclpy/clock.cpp index bf91c84c7..f74947997 100644 --- a/rclpy/src/rclpy/clock.cpp +++ b/rclpy/src/rclpy/clock.cpp @@ -181,7 +181,7 @@ void Clock::remove_clock_callback(py::object pyjump_handle) void define_clock(py::object module) { - py::class_(module, "Clock") + py::class_>(module, "Clock") .def(py::init()) .def_property_readonly( "pointer", [](const Clock & clock) { diff --git a/rclpy/src/rclpy/clock.hpp b/rclpy/src/rclpy/clock.hpp index 06bd5076b..c55682dff 100644 --- a/rclpy/src/rclpy/clock.hpp +++ b/rclpy/src/rclpy/clock.hpp @@ -31,7 +31,7 @@ namespace py = pybind11; namespace rclpy { -class Clock : public Destroyable +class Clock : public Destroyable, public std::enable_shared_from_this { public: /// Create a clock @@ -105,12 +105,6 @@ class Clock : public Destroyable void remove_clock_callback(py::object pyjump_handle); - /// Get rcl_client_t pointer - std::shared_ptr get_shared_ptr() - { - return rcl_clock_; - } - /// Get rcl_client_t pointer rcl_clock_t * rcl_ptr() const { diff --git a/rclpy/src/rclpy/destroyable.cpp b/rclpy/src/rclpy/destroyable.cpp index fa6ced3a1..fc8fda849 100644 --- a/rclpy/src/rclpy/destroyable.cpp +++ b/rclpy/src/rclpy/destroyable.cpp @@ -62,7 +62,7 @@ Destroyable::destroy_when_not_in_use() void define_destroyable(py::object module) { - py::class_(module, "Destroyable") + py::class_>(module, "Destroyable") .def("__enter__", &Destroyable::enter) .def("__exit__", &Destroyable::exit) .def( diff --git a/rclpy/src/rclpy/publisher.cpp b/rclpy/src/rclpy/publisher.cpp index a8980f477..7623026c5 100644 --- a/rclpy/src/rclpy/publisher.cpp +++ b/rclpy/src/rclpy/publisher.cpp @@ -167,7 +167,7 @@ Publisher::publish_raw(std::string msg) void define_publisher(py::object module) { - py::class_(module, "Publisher") + py::class_>(module, "Publisher") .def(py::init()) .def_property_readonly( "pointer", [](const Publisher & publisher) { diff --git a/rclpy/src/rclpy/publisher.hpp b/rclpy/src/rclpy/publisher.hpp index 6e5be6da5..c7b35f789 100644 --- a/rclpy/src/rclpy/publisher.hpp +++ b/rclpy/src/rclpy/publisher.hpp @@ -30,7 +30,7 @@ namespace py = pybind11; namespace rclpy { -class Publisher : public Destroyable +class Publisher : public Destroyable, public std::enable_shared_from_this { public: /// Create a publisher diff --git a/rclpy/src/rclpy/qos_event.cpp b/rclpy/src/rclpy/qos_event.cpp index 5286dc5a7..d22d24e06 100644 --- a/rclpy/src/rclpy/qos_event.cpp +++ b/rclpy/src/rclpy/qos_event.cpp @@ -66,7 +66,7 @@ QoSEvent::QoSEvent( rclpy::Subscription & subscription, rcl_subscription_event_type_t event_type) : event_type_(event_type) { - grandparent_sub_handle_ = std::make_shared(subscription); + grandparent_sub_handle_ = subscription.shared_from_this(); // Create a subscription event rcl_event_ = create_zero_initialized_event(); @@ -89,7 +89,7 @@ QoSEvent::QoSEvent( rclpy::Publisher & publisher, rcl_publisher_event_type_t event_type) : event_type_(event_type) { - grandparent_pub_handle_ = std::make_shared(publisher); + grandparent_pub_handle_ = publisher.shared_from_this(); // Create a publisher event rcl_event_ = create_zero_initialized_event(); @@ -169,7 +169,7 @@ QoSEvent::take_event() void define_qos_event(py::module module) { - py::class_(module, "QoSEvent") + py::class_>(module, "QoSEvent") .def(py::init()) .def(py::init()) .def_property_readonly( diff --git a/rclpy/src/rclpy/qos_event.hpp b/rclpy/src/rclpy/qos_event.hpp index 8f537f7de..e41ffb927 100644 --- a/rclpy/src/rclpy/qos_event.hpp +++ b/rclpy/src/rclpy/qos_event.hpp @@ -31,7 +31,7 @@ namespace py = pybind11; namespace rclpy { -class QoSEvent : public Destroyable +class QoSEvent : public Destroyable, public std::enable_shared_from_this { public: /// Create a subscription event diff --git a/rclpy/src/rclpy/service.cpp b/rclpy/src/rclpy/service.cpp index 1002fbf73..c8cbf6efb 100644 --- a/rclpy/src/rclpy/service.cpp +++ b/rclpy/src/rclpy/service.cpp @@ -139,7 +139,7 @@ Service::service_take_request(py::object pyrequest_type) void define_service(py::object module) { - py::class_(module, "Service") + py::class_>(module, "Service") .def(py::init()) .def_property_readonly( "pointer", [](const Service & service) { diff --git a/rclpy/src/rclpy/service.hpp b/rclpy/src/rclpy/service.hpp index ec87880c7..5e300d684 100644 --- a/rclpy/src/rclpy/service.hpp +++ b/rclpy/src/rclpy/service.hpp @@ -33,7 +33,7 @@ namespace py = pybind11; namespace rclpy { -class Service : public Destroyable +class Service : public Destroyable, public std::enable_shared_from_this { public: /// Create a service server diff --git a/rclpy/src/rclpy/subscription.cpp b/rclpy/src/rclpy/subscription.cpp index 8efaac286..1be7a7884 100644 --- a/rclpy/src/rclpy/subscription.cpp +++ b/rclpy/src/rclpy/subscription.cpp @@ -177,7 +177,7 @@ Subscription::get_topic_name() void define_subscription(py::object module) { - py::class_(module, "Subscription") + py::class_>(module, "Subscription") .def(py::init()) .def_property_readonly( "pointer", [](const Subscription & subscription) { diff --git a/rclpy/src/rclpy/subscription.hpp b/rclpy/src/rclpy/subscription.hpp index 28aa651ae..89f56f000 100644 --- a/rclpy/src/rclpy/subscription.hpp +++ b/rclpy/src/rclpy/subscription.hpp @@ -30,7 +30,7 @@ namespace py = pybind11; namespace rclpy { -class Subscription : public Destroyable +class Subscription : public Destroyable, public std::enable_shared_from_this { public: /// Create a subscription diff --git a/rclpy/src/rclpy/timer.cpp b/rclpy/src/rclpy/timer.cpp index b4e192e57..997c3fb06 100644 --- a/rclpy/src/rclpy/timer.cpp +++ b/rclpy/src/rclpy/timer.cpp @@ -43,7 +43,7 @@ Timer::destroy() Timer::Timer( Clock & rclcy_clock, py::capsule pycontext, int64_t period_nsec) { - clock_handle_ = rclcy_clock.get_shared_ptr(); + clock_handle_ = rclcy_clock.shared_from_this(); auto context = static_cast( rclpy_handle_get_pointer_from_capsule(pycontext.ptr(), "rcl_context_t")); @@ -72,7 +72,7 @@ Timer::Timer( rcl_allocator_t allocator = rcl_get_default_allocator(); rcl_ret_t ret = rcl_timer_init( - rcl_timer_.get(), clock_handle_.get(), context, + rcl_timer_.get(), clock_handle_->rcl_ptr(), context, period_nsec, NULL, allocator); if (RCL_RET_OK != ret) { @@ -168,7 +168,7 @@ bool Timer::is_timer_canceled() void define_timer(py::object module) { - py::class_(module, "Timer") + py::class_>(module, "Timer") .def(py::init()) .def_property_readonly( "pointer", [](const Timer & timer) { diff --git a/rclpy/src/rclpy/timer.hpp b/rclpy/src/rclpy/timer.hpp index 57e5dde7e..786322804 100644 --- a/rclpy/src/rclpy/timer.hpp +++ b/rclpy/src/rclpy/timer.hpp @@ -30,7 +30,7 @@ namespace py = pybind11; namespace rclpy { -class Timer : public Destroyable +class Timer : public Destroyable, public std::enable_shared_from_this { public: /// Create a timer @@ -133,8 +133,7 @@ class Timer : public Destroyable void destroy() override; private: - // TODO(ahcorde) replace with std::shared_ptr when rclpy::Clock exists - std::shared_ptr clock_handle_; + std::shared_ptr clock_handle_; std::shared_ptr rcl_timer_; };