@@ -55,6 +55,85 @@ const SubscriptionEventType = {
5555 SUBSCRIPTION_MATCHED : 5 ,
5656} ;
5757
58+ /**
59+ * Check if a publisher event type is supported by the active RMW implementation.
60+ *
61+ * Only available in ROS 2 Rolling and later, where the underlying rcl API
62+ * (`rcl_publisher_event_type_is_supported`) is provided.
63+ *
64+ * @param {number } eventType - A {@link PublisherEventType} value.
65+ * @return {boolean } True if the event type is supported by the active RMW
66+ * implementation, false otherwise.
67+ * @throws {OperationError } if invoked on a ROS distro older than Rolling, or
68+ * if eventType is not a valid {@link PublisherEventType} value.
69+ */
70+ function isPublisherEventTypeSupported ( eventType ) {
71+ if ( typeof rclnodejs . isPublisherEventTypeSupported !== 'function' ) {
72+ throw new OperationError (
73+ 'isPublisherEventTypeSupported is only available in ROS 2 Rolling and later' ,
74+ {
75+ code : 'UNSUPPORTED_ROS_VERSION' ,
76+ entityType : 'publisher event type' ,
77+ details : {
78+ requiredVersion : 'rolling' ,
79+ currentVersion : DistroUtils . getDistroId ( ) ,
80+ } ,
81+ }
82+ ) ;
83+ }
84+ if (
85+ typeof eventType !== 'number' ||
86+ ! Object . values ( PublisherEventType ) . includes ( eventType )
87+ ) {
88+ throw new OperationError ( `Invalid PublisherEventType value: ${ eventType } ` , {
89+ code : 'INVALID_ARGUMENT' ,
90+ entityType : 'publisher event type' ,
91+ } ) ;
92+ }
93+ return rclnodejs . isPublisherEventTypeSupported ( eventType ) ;
94+ }
95+
96+ /**
97+ * Check if a subscription event type is supported by the active RMW implementation.
98+ *
99+ * Only available in ROS 2 Rolling and later, where the underlying rcl API
100+ * (`rcl_subscription_event_type_is_supported`) is provided.
101+ *
102+ * @param {number } eventType - A {@link SubscriptionEventType} value.
103+ * @return {boolean } True if the event type is supported by the active RMW
104+ * implementation, false otherwise.
105+ * @throws {OperationError } if invoked on a ROS distro older than Rolling, or
106+ * if eventType is not a valid {@link SubscriptionEventType} value.
107+ */
108+ function isSubscriptionEventTypeSupported ( eventType ) {
109+ if ( typeof rclnodejs . isSubscriptionEventTypeSupported !== 'function' ) {
110+ throw new OperationError (
111+ 'isSubscriptionEventTypeSupported is only available in ROS 2 Rolling and later' ,
112+ {
113+ code : 'UNSUPPORTED_ROS_VERSION' ,
114+ entityType : 'subscription event type' ,
115+ details : {
116+ requiredVersion : 'rolling' ,
117+ currentVersion : DistroUtils . getDistroId ( ) ,
118+ } ,
119+ }
120+ ) ;
121+ }
122+ if (
123+ typeof eventType !== 'number' ||
124+ ! Object . values ( SubscriptionEventType ) . includes ( eventType )
125+ ) {
126+ throw new OperationError (
127+ `Invalid SubscriptionEventType value: ${ eventType } ` ,
128+ {
129+ code : 'INVALID_ARGUMENT' ,
130+ entityType : 'subscription event type' ,
131+ }
132+ ) ;
133+ }
134+ return rclnodejs . isSubscriptionEventTypeSupported ( eventType ) ;
135+ }
136+
58137class EventHandler extends Entity {
59138 constructor ( handle , callback , eventType , eventTypeName ) {
60139 super ( handle , null , null ) ;
@@ -488,4 +567,6 @@ module.exports = {
488567 PublisherEventType,
489568 SubscriptionEventCallbacks,
490569 SubscriptionEventType,
570+ isPublisherEventTypeSupported,
571+ isSubscriptionEventTypeSupported,
491572} ;
0 commit comments