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

Use consolidated rcl_wait_set_clear() #230

Merged
merged 2 commits into from
Aug 27, 2018
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/rclpy/executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ def _wait_for_ready_callbacks(self, timeout_sec=None, nodes=None):
'service': (services, 'service_handle'),
'timer': (timers, 'timer_handle'),
}
_rclpy.rclpy_wait_set_clear_entities(wait_set)
for entity, (handles, handle_name) in entities.items():
_rclpy.rclpy_wait_set_clear_entities(entity, wait_set)
for h in handles:
_rclpy.rclpy_wait_set_add_entity(
entity, wait_set, h.__getattribute__(handle_name)
Expand Down
28 changes: 5 additions & 23 deletions rclpy/src/rclpy/_rclpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -2191,48 +2191,30 @@ rclpy_wait_set_init(PyObject * Py_UNUSED(self), PyObject * args)
Py_RETURN_NONE;
}

/// Clear all the pointers of a given wait set field
/// Clear all the pointers in the wait set
/**
* Raises RuntimeError if the entity type is unknown or any rcl error occurs
* Raises RuntimeError if any rcl error occurs
*
* \param[in] entity_type string defining the entity ["subscription, client, service"]
* \param[in] pywait_set Capsule pointing to the wait set structure
* \return NULL
*/
static PyObject *
rclpy_wait_set_clear_entities(PyObject * Py_UNUSED(self), PyObject * args)
{
const char * entity_type;
PyObject * pywait_set;

if (!PyArg_ParseTuple(args, "zO", &entity_type, &pywait_set)) {
if (!PyArg_ParseTuple(args, "O", &pywait_set)) {
return NULL;
}

rcl_wait_set_t * wait_set = (rcl_wait_set_t *)PyCapsule_GetPointer(pywait_set, "rcl_wait_set_t");
if (!wait_set) {
return NULL;
}
rcl_ret_t ret;
if (0 == strcmp(entity_type, "subscription")) {
ret = rcl_wait_set_clear_subscriptions(wait_set);
} else if (0 == strcmp(entity_type, "client")) {
ret = rcl_wait_set_clear_clients(wait_set);
} else if (0 == strcmp(entity_type, "service")) {
ret = rcl_wait_set_clear_services(wait_set);
} else if (0 == strcmp(entity_type, "timer")) {
ret = rcl_wait_set_clear_timers(wait_set);
} else if (0 == strcmp(entity_type, "guard_condition")) {
ret = rcl_wait_set_clear_guard_conditions(wait_set);
} else {
ret = RCL_RET_ERROR; // to avoid a linter warning
PyErr_Format(PyExc_RuntimeError,
"'%s' is not a known entity", entity_type);
return NULL;
}
rcl_ret_t ret = rcl_wait_set_clear(wait_set);
if (ret != RCL_RET_OK) {
PyErr_Format(PyExc_RuntimeError,
"Failed to clear '%s' from wait set: %s", entity_type, rcl_get_error_string_safe());
"Failed to clear wait set: %s", rcl_get_error_string_safe());
rcl_reset_error();
return NULL;
}
Expand Down