Skip to content

Commit

Permalink
Fix lint, start adding unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Emerson Knapp <[email protected]>
  • Loading branch information
Emerson Knapp committed Apr 18, 2019
1 parent 8f1b6aa commit fdb9a6f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 22 deletions.
5 changes: 0 additions & 5 deletions rclpy/rclpy/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import List
from typing import TypeVar

from rclpy.callback_groups import CallbackGroup
from rclpy.impl.implementation_singleton import rclpy_implementation as _rclpy
from rclpy.qos import QoSProfile
from rclpy.qos_event import PublisherEventCallbacks
from rclpy.qos_event import QoSEventHandler
from rclpy.qos_event import QoSPublisherEventType

MsgType = TypeVar('MsgType')

Expand Down Expand Up @@ -60,8 +57,6 @@ def __init__(
self.node_handle = node_handle
self.callback_group = callback_group

self.event_callbacks = event_callbacks
self.event_handlers: List[QoSEventHandler] = []
self.event_callbacks = event_callbacks
self.event_handlers = event_callbacks.create_event_handlers(
callback_group, publisher_handle)
Expand Down
3 changes: 0 additions & 3 deletions rclpy/rclpy/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@
# limitations under the License.

from typing import Callable
from typing import List
from typing import TypeVar

from rclpy.callback_groups import CallbackGroup
from rclpy.qos import QoSProfile
from rclpy.qos_event import QoSEventHandler
from rclpy.qos_event import QoSSubscriptionEventType
from rclpy.qos_event import SubscriptionEventCallbacks


Expand Down
1 change: 0 additions & 1 deletion rclpy/src/rclpy/_rclpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -3606,7 +3606,6 @@ rclpy_convert_from_py_qos_policy(PyObject * Py_UNUSED(self), PyObject * args)
qos_profile->depth = pyqos_depth;
qos_profile->reliability = pyqos_reliability;
qos_profile->durability = pyqos_durability;
qos_profile->deadline = (rmw_time_t){0, 500 * 1000LL * 1000LL};
qos_profile->avoid_ros_namespace_conventions = avoid_ros_namespace_conventions;
PyObject * pyqos_profile = PyCapsule_New(qos_profile, "rmw_qos_profile_t", NULL);
return pyqos_profile;
Expand Down
28 changes: 16 additions & 12 deletions rclpy/src/rclpy/_rclpy_qos_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <rcl/event.h>

typedef union _qos_event_callback_data {
// Subscription events
rmw_requested_deadline_missed_status_t requested_deadline_missed;
Expand All @@ -21,9 +23,11 @@ typedef union _qos_event_callback_data {
rmw_liveliness_lost_status_t liveliness_lost;
} _qos_event_callback_data_t;

typedef PyObject * (*_qos_event_data_filler_function)(_qos_event_callback_data_t *);
typedef PyObject * (* _qos_event_data_filler_function)(_qos_event_callback_data_t *);

bool _check_rcl_return(rcl_ret_t ret, const char * error_msg) {
bool
_check_rcl_return(rcl_ret_t ret, const char * error_msg)
{
if (ret != RCL_RET_OK) {
PyErr_Format(PyExc_RuntimeError,
"%s: %s", error_msg, rcl_get_error_string().str);
Expand Down Expand Up @@ -177,7 +181,7 @@ _liveliness_lost_to_py_object(_qos_event_callback_data_t * data)


_qos_event_data_filler_function
_get_qos_event_data_filler_function_for(PyObject * pyparent, unsigned long event_type)
_get_qos_event_data_filler_function_for(PyObject * pyparent, uint32_t event_type)
{
if (_is_pycapsule_rcl_subscription(pyparent)) {
switch (event_type) {
Expand All @@ -203,7 +207,6 @@ _get_qos_event_data_filler_function_for(PyObject * pyparent, unsigned long event
PyErr_Format(PyExc_TypeError,
"Parent handle was not a valid Publisher or Subscription.");
}

return NULL;
}

Expand All @@ -226,9 +229,13 @@ rclpy_create_event(PyObject * Py_UNUSED(self), PyObject * args)
{
unsigned PY_LONG_LONG pyevent_type;
PyObject * pyparent = NULL;

rcl_ret_t ret;
rcl_subscription_t * subscription = NULL;
rcl_publisher_t * publisher = NULL;
rcl_ret_t ret;
rcl_event_t * event = NULL;

PyObject * pyevent = NULL;

if (!PyArg_ParseTuple(args, "KO", &pyevent_type, &pyparent)) {
return NULL;
Expand All @@ -243,7 +250,7 @@ rclpy_create_event(PyObject * Py_UNUSED(self), PyObject * args)
return NULL;
}

rcl_event_t * event = _new_zero_initialized_rcl_event();
event = _new_zero_initialized_rcl_event();
if (!event) {
return NULL;
}
Expand All @@ -253,15 +260,14 @@ rclpy_create_event(PyObject * Py_UNUSED(self), PyObject * args)
} else {
ret = rcl_publisher_event_init(event, publisher, pyevent_type);
}

if (!_check_rcl_return(ret, "Failed to initialize event")) {
PyMem_Free(event);
return NULL;
}

PyObject * pyevent = PyCapsule_New(event, "rcl_event_t", _destroy_event_capsule);
pyevent = PyCapsule_New(event, "rcl_event_t", _destroy_event_capsule);
if (!pyevent) {
rcl_ret_t ret = rcl_event_fini(event);
ret = rcl_event_fini(event);
PyMem_Free(event);
_check_rcl_return(ret, "Failed to fini 'rcl_event_t'");
return NULL;
Expand Down Expand Up @@ -295,10 +301,9 @@ rclpy_take_event(PyObject * Py_UNUSED(self), PyObject * args)

// Type conversion
rcl_ret_t ret;
_qos_event_callback_data_t event_data;

rcl_event_t * event = NULL;
PyObject * pyqos_event = NULL;
_qos_event_callback_data_t event_data;
_qos_event_data_filler_function event_filler = NULL;

if (!PyArg_ParseTuple(args, "OOK", &pyevent, &pyparent, &pyevent_type)) {
Expand All @@ -323,7 +328,6 @@ rclpy_take_event(PyObject * Py_UNUSED(self), PyObject * args)

pyqos_event = event_filler(&event_data);
if (!pyqos_event) {
PyErr_Format(PyExc_RuntimeError, "Unable to convert callback payload into a Python type.");
return NULL;
}
return pyqos_event;
Expand Down
1 change: 0 additions & 1 deletion rclpy/src/rclpy_common/include/rclpy_common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include <Python.h>

#include <rcl/event.h>
#include <rcl/graph.h> // rcl_names_and_types_t
#include <rmw/types.h>

Expand Down
1 change: 1 addition & 0 deletions rclpy/test/test_qos_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit fdb9a6f

Please sign in to comment.