-
Notifications
You must be signed in to change notification settings - Fork 84
Add ParameterEventHandler node filtering support #1474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const { TypeValidationError, OperationError } = require('./errors'); | ||||||||||||||||||||||||
| const { normalizeNodeName } = require('./utils'); | ||||||||||||||||||||||||
| const validator = require('./validator'); | ||||||||||||||||||||||||
| const debug = require('debug')('rclnodejs:parameter_event_handler'); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const PARAMETER_EVENT_MSG_TYPE = 'rcl_interfaces/msg/ParameterEvent'; | ||||||||||||||||||||||||
|
|
@@ -210,6 +211,64 @@ class ParameterEventHandler { | |||||||||||||||||||||||
| return handle; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * Configure which node parameter events will be received. | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * If nodeNames is omitted or empty, the current node filter is cleared. | ||||||||||||||||||||||||
| * When a filter is active, parameter and event callbacks only receive | ||||||||||||||||||||||||
| * events from the specified nodes. | ||||||||||||||||||||||||
| * | ||||||||||||||||||||||||
| * @param {string[]} [nodeNames] - Node names to filter parameter events from. | ||||||||||||||||||||||||
| * Relative names are resolved against the handler node namespace. | ||||||||||||||||||||||||
| * @returns {boolean} True if the filter is active or was successfully cleared. | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
| configureNodesFilter(nodeNames) { | ||||||||||||||||||||||||
| this.#checkNotDestroyed(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (nodeNames === undefined || nodeNames === null) { | ||||||||||||||||||||||||
| this.#subscription.clearContentFilter(); | ||||||||||||||||||||||||
| return !this.#subscription.hasContentFilter(); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (!Array.isArray(nodeNames)) { | ||||||||||||||||||||||||
| throw new TypeValidationError('nodeNames', nodeNames, 'string[]', { | ||||||||||||||||||||||||
| entityType: 'parameter event handler', | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (nodeNames.length === 0) { | ||||||||||||||||||||||||
| this.#subscription.clearContentFilter(); | ||||||||||||||||||||||||
| return !this.#subscription.hasContentFilter(); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const resolvedNodeNames = nodeNames.map((nodeName, index) => { | ||||||||||||||||||||||||
| if (typeof nodeName !== 'string' || nodeName.trim() === '') { | ||||||||||||||||||||||||
| throw new TypeValidationError( | ||||||||||||||||||||||||
| `nodeNames[${index}]`, | ||||||||||||||||||||||||
| nodeName, | ||||||||||||||||||||||||
| 'non-empty string', | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| entityType: 'parameter event handler', | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const resolvedNodeName = this.#resolvePath(nodeName.trim()); | ||||||||||||||||||||||||
| this.#validateFullyQualifiedNodePath(resolvedNodeName); | ||||||||||||||||||||||||
| return resolvedNodeName; | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const contentFilter = { | ||||||||||||||||||||||||
| expression: resolvedNodeNames | ||||||||||||||||||||||||
| .map((_, index) => `node = %${index}`) | ||||||||||||||||||||||||
| .join(' OR '), | ||||||||||||||||||||||||
| parameters: resolvedNodeNames.map((nodeName) => `'${nodeName}'`), | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
|
Comment on lines
+244
to
+266
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
| if ( | |
| typeof this.#subscription.isContentFilterSupported === 'function' && | |
| !this.#subscription.isContentFilterSupported() | |
| ) { | |
| throw new OperationError( | |
| 'Node filtering requires content-filtered topic support, which is not available in the current ROS distro/RMW implementation', | |
| { entityType: 'parameter event handler' } | |
| ); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#validateFullyQualifiedNodePath()strips trailing slashes only for validation, butresolvedNodeNameis used unchanged in the filter parameters. Inputs like/ns/node/can pass validation yet generate a filter that won’t matchParameterEvent.node(published without trailing slashes), causing missed events. NormalizeresolvedNodeName(strip trailing/except for/, and ideally collapse repeated/) before building the filter.