Skip to content

Add publisher/subscription_event_type_is_supported#1520

Merged
minggangw merged 2 commits into
RobotWebTools:developfrom
minggangw:fix-1519
May 26, 2026
Merged

Add publisher/subscription_event_type_is_supported#1520
minggangw merged 2 commits into
RobotWebTools:developfrom
minggangw:fix-1519

Conversation

@minggangw
Copy link
Copy Markdown
Member

@minggangw minggangw commented May 26, 2026

Port rclpy PR ros2/rclpy#1647 (commit cfac914) to expose rcl_publisher_event_type_is_supported() and rcl_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.

  • Native binding (src/rcl_event_handle_bindings.cpp): N-API wrappers exported as isPublisherEventTypeSupported / isSubscriptionEventTypeSupported, both gated by #if ROS_VERSION >= 5000.
  • JS wrapper (lib/event_handler.js): public isPublisherEventTypeSupported(eventType) / isSubscriptionEventTypeSupported(eventType). Availability guard keys off typeof rclnodejs.<fn> !== 'function' (mirrors the C++ build gate, matches the existing pattern in lib/action/client.js) and throws OperationError on pre-rolling. Argument validation uses TypeValidationError / RangeValidationError for consistency with lib/time.js, lib/logging.js, lib/message_serialization.js.
  • Tests (test/test-event-handle.js): two suites gated on native-symbol presence — asserts the unavailable-throw path, boolean returns for every enum value, MATCHED reported supported, and the right validation-error class/message for invalid inputs.

Fix: #1519

Copilot AI review requested due to automatic review settings May 26, 2026 02:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_supported and rcl_subscription_event_type_is_supported (ROS 2 Rolling+ only).
  • Add JS wrapper functions isPublisherEventTypeSupported / isSubscriptionEventTypeSupported with 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 thread lib/event_handler.js
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 thread lib/event_handler.js
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);
}
@coveralls
Copy link
Copy Markdown

coveralls commented May 26, 2026

Coverage Status

coverage: 85.47% (-0.004%) from 85.474% — minggangw:fix-1519 into RobotWebTools:develop

@minggangw minggangw merged commit b527ca3 into RobotWebTools:develop May 26, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add publisher/subscription_event_type_is_supported()

3 participants