def test_call_publisher_rclpy_event_apis(self): # Go through the exposed apis and ensure that things don't explode when called # Make no assumptions about being able to actually receive the events publisher = self.node.create_publisher(EmptyMsg, 'test_topic', 10) wait_set = _rclpy.rclpy_get_zero_initialized_wait_set() _rclpy.rclpy_wait_set_init(wait_set, 0, 0, 0, 0, 0, 2, self.context.handle) deadline_event_handle = self._create_event_handle( publisher, QoSPublisherEventType.RCL_PUBLISHER_OFFERED_DEADLINE_MISSED) with deadline_event_handle as capsule: deadline_event_index = _rclpy.rclpy_wait_set_add_entity( 'event', wait_set, capsule) self.assertIsNotNone(deadline_event_index) liveliness_event_handle = self._create_event_handle( publisher, QoSPublisherEventType.RCL_PUBLISHER_LIVELINESS_LOST) with liveliness_event_handle as capsule: liveliness_event_index = _rclpy.rclpy_wait_set_add_entity( 'event', wait_set, capsule) self.assertIsNotNone(liveliness_event_index) # We live in our own namespace and have created no other participants, so # there can't be any of these events. _rclpy.rclpy_wait(wait_set, 0) self.assertFalse( _rclpy.rclpy_wait_set_is_ready('event', wait_set, deadline_event_index)) self.assertFalse( _rclpy.rclpy_wait_set_is_ready('event', wait_set, liveliness_event_index)) # Calling take data even though not ready should provide me an empty initialized message # Tests data conversion utilities in C side try: with deadline_event_handle as event_capsule, publisher.handle as publisher_capsule: event_data = _rclpy.rclpy_take_event( event_capsule, publisher_capsule, QoSPublisherEventType. RCL_PUBLISHER_OFFERED_DEADLINE_MISSED) self.assertIsInstance(event_data, QoSOfferedDeadlineMissedInfo) self.assertEqual(event_data.total_count, 0) self.assertEqual(event_data.total_count_change, 0) except NotImplementedError: pass try: with liveliness_event_handle as event_capsule, publisher.handle as publisher_capsule: event_data = _rclpy.rclpy_take_event( event_capsule, publisher_capsule, QoSPublisherEventType.RCL_PUBLISHER_LIVELINESS_LOST) self.assertIsInstance(event_data, QoSLivelinessLostInfo) self.assertEqual(event_data.total_count, 0) self.assertEqual(event_data.total_count_change, 0) except NotImplementedError: pass self.node.destroy_publisher(publisher)
def test_call_subscription_rclpy_event_apis(self): # Go through the exposed apis and ensure that things don't explode when called # Make no assumptions about being able to actually receive the events subscription = self.node.create_subscription(EmptyMsg, 'test_topic', Mock(), 10) wait_set = _rclpy.rclpy_get_zero_initialized_wait_set() with self.context.handle as context_handle: _rclpy.rclpy_wait_set_init(wait_set, 0, 0, 0, 0, 0, 2, context_handle) deadline_event_handle = self._create_event_handle( subscription, QoSSubscriptionEventType.RCL_SUBSCRIPTION_REQUESTED_DEADLINE_MISSED) with deadline_event_handle as capsule: deadline_event_index = _rclpy.rclpy_wait_set_add_entity('event', wait_set, capsule) self.assertIsNotNone(deadline_event_index) liveliness_event_handle = self._create_event_handle( subscription, QoSSubscriptionEventType.RCL_SUBSCRIPTION_LIVELINESS_CHANGED) with liveliness_event_handle as capsule: liveliness_event_index = _rclpy.rclpy_wait_set_add_entity('event', wait_set, capsule) self.assertIsNotNone(liveliness_event_index) # We live in our own namespace and have created no other participants, so # there can't be any of these events. _rclpy.rclpy_wait(wait_set, 0) self.assertFalse(_rclpy.rclpy_wait_set_is_ready('event', wait_set, deadline_event_index)) self.assertFalse(_rclpy.rclpy_wait_set_is_ready('event', wait_set, liveliness_event_index)) # Calling take data even though not ready should provide me an empty initialized message # Tests data conversion utilities in C side try: with deadline_event_handle as event_capsule, subscription.handle as parent_capsule: event_data = _rclpy.rclpy_take_event( event_capsule, parent_capsule, QoSSubscriptionEventType.RCL_SUBSCRIPTION_REQUESTED_DEADLINE_MISSED) self.assertIsInstance(event_data, QoSRequestedDeadlineMissedInfo) self.assertEqual(event_data.total_count, 0) self.assertEqual(event_data.total_count_change, 0) except NotImplementedError: pass try: with liveliness_event_handle as event_capsule, subscription.handle as parent_capsule: event_data = _rclpy.rclpy_take_event( event_capsule, parent_capsule, QoSSubscriptionEventType.RCL_SUBSCRIPTION_LIVELINESS_CHANGED) self.assertIsInstance(event_data, QoSLivelinessChangedInfo) self.assertEqual(event_data.alive_count, 0) self.assertEqual(event_data.alive_count_change, 0) self.assertEqual(event_data.not_alive_count, 0) self.assertEqual(event_data.not_alive_count_change, 0) except NotImplementedError: pass self.node.destroy_subscription(subscription)
def take_data(self): """Take stuff from lower level so the wait set doesn't immediately wake again.""" if self._ready_to_take_data: self._ready_to_take_data = False with self._parent_handle as parent_capsule, self._event_handle as event_capsule: return _rclpy.rclpy_take_event(event_capsule, parent_capsule, self.event_type) return None