Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rclpy/src/rclpy/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Client::take_response(py::object pyresponse_type)
void
define_client(py::object module)
{
py::class_<Client, Destroyable>(module, "Client")
py::class_<Client, Destroyable, std::shared_ptr<Client>>(module, "Client")
.def(py::init<py::capsule, py::object, const char *, py::object>())
.def_property_readonly(
"pointer", [](const Client & client) {
Expand Down
2 changes: 1 addition & 1 deletion rclpy/src/rclpy/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace py = pybind11;

namespace rclpy
{
class Client : public Destroyable
class Client : public Destroyable, public std::enable_shared_from_this<Client>
{
public:
/// Create a client
Expand Down
2 changes: 1 addition & 1 deletion rclpy/src/rclpy/clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void Clock::remove_clock_callback(py::object pyjump_handle)

void define_clock(py::object module)
{
py::class_<Clock, Destroyable>(module, "Clock")
py::class_<Clock, Destroyable, std::shared_ptr<Clock>>(module, "Clock")
.def(py::init<rcl_clock_type_t>())
.def_property_readonly(
"pointer", [](const Clock & clock) {
Expand Down
8 changes: 1 addition & 7 deletions rclpy/src/rclpy/clock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace py = pybind11;

namespace rclpy
{
class Clock : public Destroyable
class Clock : public Destroyable, public std::enable_shared_from_this<Clock>
{
public:
/// Create a clock
Expand Down Expand Up @@ -105,12 +105,6 @@ class Clock : public Destroyable
void
remove_clock_callback(py::object pyjump_handle);

/// Get rcl_client_t pointer
std::shared_ptr<rcl_clock_t> get_shared_ptr()
{
return rcl_clock_;
}

/// Get rcl_client_t pointer
rcl_clock_t * rcl_ptr() const
{
Expand Down
2 changes: 1 addition & 1 deletion rclpy/src/rclpy/destroyable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Destroyable::destroy_when_not_in_use()
void
define_destroyable(py::object module)
{
py::class_<Destroyable>(module, "Destroyable")
py::class_<Destroyable, std::shared_ptr<Destroyable>>(module, "Destroyable")
.def("__enter__", &Destroyable::enter)
.def("__exit__", &Destroyable::exit)
.def(
Expand Down
2 changes: 1 addition & 1 deletion rclpy/src/rclpy/publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Publisher::publish_raw(std::string msg)
void
define_publisher(py::object module)
{
py::class_<Publisher, Destroyable>(module, "Publisher")
py::class_<Publisher, Destroyable, std::shared_ptr<Publisher>>(module, "Publisher")
.def(py::init<py::capsule, py::object, std::string, py::object>())
.def_property_readonly(
"pointer", [](const Publisher & publisher) {
Expand Down
2 changes: 1 addition & 1 deletion rclpy/src/rclpy/publisher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace py = pybind11;

namespace rclpy
{
class Publisher : public Destroyable
class Publisher : public Destroyable, public std::enable_shared_from_this<Publisher>
{
public:
/// Create a publisher
Expand Down
6 changes: 3 additions & 3 deletions rclpy/src/rclpy/qos_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<rclpy::Subscription>(subscription);
grandparent_sub_handle_ = subscription.shared_from_this();

// Create a subscription event
rcl_event_ = create_zero_initialized_event();
Expand All @@ -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<rclpy::Publisher>(publisher);
grandparent_pub_handle_ = publisher.shared_from_this();

// Create a publisher event
rcl_event_ = create_zero_initialized_event();
Expand Down Expand Up @@ -169,7 +169,7 @@ QoSEvent::take_event()
void
define_qos_event(py::module module)
{
py::class_<QoSEvent, Destroyable>(module, "QoSEvent")
py::class_<QoSEvent, Destroyable, std::shared_ptr<QoSEvent>>(module, "QoSEvent")
.def(py::init<rclpy::Subscription &, rcl_subscription_event_type_t>())
.def(py::init<rclpy::Publisher &, rcl_publisher_event_type_t>())
.def_property_readonly(
Expand Down
2 changes: 1 addition & 1 deletion rclpy/src/rclpy/qos_event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace py = pybind11;

namespace rclpy
{
class QoSEvent : public Destroyable
class QoSEvent : public Destroyable, public std::enable_shared_from_this<QoSEvent>
{
public:
/// Create a subscription event
Expand Down
2 changes: 1 addition & 1 deletion rclpy/src/rclpy/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Service::service_take_request(py::object pyrequest_type)
void
define_service(py::object module)
{
py::class_<Service, Destroyable>(module, "Service")
py::class_<Service, Destroyable, std::shared_ptr<Service>>(module, "Service")
.def(py::init<py::capsule, py::object, std::string, py::object>())
.def_property_readonly(
"pointer", [](const Service & service) {
Expand Down
2 changes: 1 addition & 1 deletion rclpy/src/rclpy/service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace py = pybind11;
namespace rclpy
{

class Service : public Destroyable
class Service : public Destroyable, public std::enable_shared_from_this<Service>
{
public:
/// Create a service server
Expand Down
2 changes: 1 addition & 1 deletion rclpy/src/rclpy/subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Subscription::get_topic_name()
void
define_subscription(py::object module)
{
py::class_<Subscription, Destroyable>(module, "Subscription")
py::class_<Subscription, Destroyable, std::shared_ptr<Subscription>>(module, "Subscription")
.def(py::init<py::capsule, py::object, std::string, py::object>())
.def_property_readonly(
"pointer", [](const Subscription & subscription) {
Expand Down
2 changes: 1 addition & 1 deletion rclpy/src/rclpy/subscription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace py = pybind11;

namespace rclpy
{
class Subscription : public Destroyable
class Subscription : public Destroyable, public std::enable_shared_from_this<Subscription>
{
public:
/// Create a subscription
Expand Down
6 changes: 3 additions & 3 deletions rclpy/src/rclpy/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<rcl_context_t *>(
rclpy_handle_get_pointer_from_capsule(pycontext.ptr(), "rcl_context_t"));
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -168,7 +168,7 @@ bool Timer::is_timer_canceled()
void
define_timer(py::object module)
{
py::class_<Timer, Destroyable>(module, "Timer")
py::class_<Timer, Destroyable, std::shared_ptr<Timer>>(module, "Timer")
.def(py::init<Clock &, py::capsule, int64_t>())
.def_property_readonly(
"pointer", [](const Timer & timer) {
Expand Down
5 changes: 2 additions & 3 deletions rclpy/src/rclpy/timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace py = pybind11;
namespace rclpy
{

class Timer : public Destroyable
class Timer : public Destroyable, public std::enable_shared_from_this<Timer>
{
public:
/// Create a timer
Expand Down Expand Up @@ -133,8 +133,7 @@ class Timer : public Destroyable
void destroy() override;

private:
// TODO(ahcorde) replace with std::shared_ptr<rcl_clock_t> when rclpy::Clock exists
std::shared_ptr<rcl_clock_t> clock_handle_;
std::shared_ptr<Clock> clock_handle_;
std::shared_ptr<rcl_timer_t> rcl_timer_;
};

Expand Down