Add publisher/subscription_event_type_is_supported#1520
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces new APIs to query whether specific publisher/subscription event types are supported by the active RMW implementation, exposing ROS 2 Rolling+ rcl_*_event_type_is_supported functionality through the native addon and a JS wrapper, with accompanying tests.
Changes:
- Add native N-API bindings for
rcl_publisher_event_type_is_supportedandrcl_subscription_event_type_is_supported(ROS 2 Rolling+ only). - Add JS wrapper functions
isPublisherEventTypeSupported/isSubscriptionEventTypeSupportedwith argument validation and Rolling+ gating. - Add tests covering behavior both when the native binding is present and when it is unavailable.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
test/test-event-handle.js |
Adds unit tests for the new “event type supported” APIs in both binding-available/unavailable scenarios. |
src/rcl_event_handle_bindings.cpp |
Exposes Rolling+ native functions to check event type support from the underlying rcl API. |
lib/event_handler.js |
Adds public JS helpers for checking event type support and exports them from the event handler module. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+70
to
+93
| function isPublisherEventTypeSupported(eventType) { | ||
| if (typeof rclnodejs.isPublisherEventTypeSupported !== 'function') { | ||
| throw new OperationError( | ||
| 'isPublisherEventTypeSupported is only available in ROS 2 Rolling and later', | ||
| { | ||
| code: 'UNSUPPORTED_ROS_VERSION', | ||
| entityType: 'publisher event type', | ||
| details: { | ||
| requiredVersion: 'rolling', | ||
| currentVersion: DistroUtils.getDistroId(), | ||
| }, | ||
| } | ||
| ); | ||
| } | ||
| if ( | ||
| typeof eventType !== 'number' || | ||
| !Object.values(PublisherEventType).includes(eventType) | ||
| ) { | ||
| throw new OperationError(`Invalid PublisherEventType value: ${eventType}`, { | ||
| code: 'INVALID_ARGUMENT', | ||
| entityType: 'publisher event type', | ||
| }); | ||
| } | ||
| return rclnodejs.isPublisherEventTypeSupported(eventType); |
Comment on lines
+108
to
+135
| function isSubscriptionEventTypeSupported(eventType) { | ||
| if (typeof rclnodejs.isSubscriptionEventTypeSupported !== 'function') { | ||
| throw new OperationError( | ||
| 'isSubscriptionEventTypeSupported is only available in ROS 2 Rolling and later', | ||
| { | ||
| code: 'UNSUPPORTED_ROS_VERSION', | ||
| entityType: 'subscription event type', | ||
| details: { | ||
| requiredVersion: 'rolling', | ||
| currentVersion: DistroUtils.getDistroId(), | ||
| }, | ||
| } | ||
| ); | ||
| } | ||
| if ( | ||
| typeof eventType !== 'number' || | ||
| !Object.values(SubscriptionEventType).includes(eventType) | ||
| ) { | ||
| throw new OperationError( | ||
| `Invalid SubscriptionEventType value: ${eventType}`, | ||
| { | ||
| code: 'INVALID_ARGUMENT', | ||
| entityType: 'subscription event type', | ||
| } | ||
| ); | ||
| } | ||
| return rclnodejs.isSubscriptionEventTypeSupported(eventType); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Port rclpy PR ros2/rclpy#1647 (commit cfac914) to expose
rcl_publisher_event_type_is_supported()andrcl_subscription_event_type_is_supported(), so user code can query the active RMW implementation about which QoS events it delivers before wiring up a handler.The underlying rcl APIs (ros2/rcl#1317) ship in ROS 2 Rolling only.
src/rcl_event_handle_bindings.cpp): N-API wrappers exported asisPublisherEventTypeSupported/isSubscriptionEventTypeSupported, both gated by#if ROS_VERSION >= 5000.lib/event_handler.js): publicisPublisherEventTypeSupported(eventType)/isSubscriptionEventTypeSupported(eventType). Availability guard keys offtypeof rclnodejs.<fn> !== 'function'(mirrors the C++ build gate, matches the existing pattern inlib/action/client.js) and throwsOperationErroron pre-rolling. Argument validation usesTypeValidationError/RangeValidationErrorfor consistency withlib/time.js,lib/logging.js,lib/message_serialization.js.test/test-event-handle.js): two suites gated on native-symbol presence — asserts the unavailable-throw path, boolean returns for every enum value,MATCHEDreported supported, and the right validation-error class/message for invalid inputs.Fix: #1519