-
Notifications
You must be signed in to change notification settings - Fork 288
Convert Guardcondition to use C++ classes #772
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,31 +17,73 @@ | |||||||||||
|
|
||||||||||||
| #include <pybind11/pybind11.h> | ||||||||||||
|
|
||||||||||||
| #include <rcl/error_handling.h> | ||||||||||||
| #include <rcl/guard_condition.h> | ||||||||||||
|
|
||||||||||||
| #include <memory> | ||||||||||||
|
|
||||||||||||
| #include "destroyable.hpp" | ||||||||||||
| #include "rclpy_common/exceptions.hpp" | ||||||||||||
| #include "rclpy_common/handle.h" | ||||||||||||
| #include "utils.hpp" | ||||||||||||
|
|
||||||||||||
| namespace py = pybind11; | ||||||||||||
|
|
||||||||||||
| namespace rclpy | ||||||||||||
| { | ||||||||||||
| /// Create a general purpose guard condition | ||||||||||||
| /** | ||||||||||||
| * A successful call will return a Capsule with the pointer of the created | ||||||||||||
| * rcl_guard_condition_t * structure | ||||||||||||
| * | ||||||||||||
| * Raises RuntimeError if initializing the guard condition fails | ||||||||||||
| * | ||||||||||||
| * \return a guard condition capsule | ||||||||||||
| */ | ||||||||||||
| py::capsule | ||||||||||||
| guard_condition_create(py::capsule pycontext); | ||||||||||||
|
|
||||||||||||
| /// Trigger a general purpose guard condition | ||||||||||||
| /** | ||||||||||||
| * Raises ValueError if pygc is not a guard condition capsule | ||||||||||||
| * Raises RCLError if the guard condition could not be triggered | ||||||||||||
| * | ||||||||||||
| * \param[in] pygc Capsule pointing to guard condtition | ||||||||||||
| */ | ||||||||||||
| void | ||||||||||||
| guard_condition_trigger(py::capsule pygc); | ||||||||||||
| class GuardCondition : public Destroyable, public std::enable_shared_from_this<GuardCondition> | ||||||||||||
| { | ||||||||||||
| public: | ||||||||||||
| /** | ||||||||||||
| * Raises RuntimeError if initializing the guard condition fails | ||||||||||||
| */ | ||||||||||||
| explicit GuardCondition(py::capsule pycontext); | ||||||||||||
|
|
||||||||||||
| /// Trigger a general purpose guard condition | ||||||||||||
| /** | ||||||||||||
| * Raises ValueError if pygc is not a guard condition capsule | ||||||||||||
| * Raises RCLError if the guard condition could not be triggered | ||||||||||||
| */ | ||||||||||||
| void | ||||||||||||
| trigger_guard_condition(); | ||||||||||||
|
|
||||||||||||
| /// Get rcl_client_t pointer | ||||||||||||
| rcl_guard_condition_t * rcl_ptr() const | ||||||||||||
| { | ||||||||||||
| return rcl_guard_condition_.get(); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /// Handle destructor for guard condition | ||||||||||||
| static void | ||||||||||||
| _rclpy_destroy_guard_condition(void * p) | ||||||||||||
| { | ||||||||||||
| (void)p; | ||||||||||||
| // Empty destructor, the class should take care of the lifecycle. | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ahcorde what ensures this object won't get trashed before the capsule does?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Python class Lines 38 to 42 in 7dff0ee
or should we include some kind of logic ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. This is arguably a (temporary?) implementation detail. No need to change it. |
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // TODO(ahcorde): Remove the pycapsule method when #728 is in | ||||||||||||
| /// Return a pycapsule object to be able to handle the signal in C. | ||||||||||||
| py::capsule | ||||||||||||
| pycapsule() const | ||||||||||||
| { | ||||||||||||
| PyObject * capsule = rclpy_create_handle_capsule( | ||||||||||||
| rcl_guard_condition_.get(), "rcl_guard_condition_t", _rclpy_destroy_guard_condition); | ||||||||||||
| if (!capsule) { | ||||||||||||
| throw py::error_already_set(); | ||||||||||||
| } | ||||||||||||
| return py::reinterpret_steal<py::capsule>(capsule); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /// Force an early destruction of this object | ||||||||||||
| void destroy() override; | ||||||||||||
|
|
||||||||||||
| private: | ||||||||||||
| std::shared_ptr<rcl_guard_condition_t> rcl_guard_condition_; | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| /// Define a pybind11 wrapper for an rclpy::Service | ||||||||||||
| void define_guard_condition(py::object module); | ||||||||||||
| } // namespace rclpy | ||||||||||||
|
|
||||||||||||
| #endif // RCLPY__GUARD_CONDITION_HPP_ | ||||||||||||
Uh oh!
There was an error while loading. Please reload this page.