@@ -43,6 +43,8 @@ const TypeDescriptionService = require('./type_description_service.js');
4343const Entity = require ( './entity.js' ) ;
4444const { SubscriptionEventCallbacks } = require ( '../lib/event_handler.js' ) ;
4545const { PublisherEventCallbacks } = require ( '../lib/event_handler.js' ) ;
46+ const { validateFullTopicName } = require ( './validator.js' ) ;
47+ const node = require ( 'debug/src/node.js' ) ;
4648
4749// Parameter event publisher constants
4850const PARAMETER_EVENT_MSG_TYPE = 'rcl_interfaces/msg/ParameterEvent' ;
@@ -1072,27 +1074,55 @@ class Node extends rclnodejs.ShadowNode {
10721074 }
10731075
10741076 /**
1075- * Get a list of publishers on a given topic.
1076- * @param {string } topic - the topic name to get the publishers for.
1077- * @param {boolean } noDemangle - if `true`, `topic_name` needs to be a valid middleware topic name,
1078- * otherwise it should be a valid ROS topic name.
1077+ * Return a list of publishers on a given topic.
1078+ *
1079+ * The returned parameter is a list of TopicEndpointInfo objects, where each will contain
1080+ * the node name, node namespace, topic type, topic endpoint's GID, and its QoS profile.
1081+ *
1082+ * When the `no_mangle` parameter is `true`, the provided `topic` should be a valid
1083+ * topic name for the middleware (useful when combining ROS with native middleware (e.g. DDS)
1084+ * apps). When the `no_mangle` parameter is `False`, the provided `topic` should
1085+ * follow ROS topic name conventions.
1086+ *
1087+ * `topic` may be a relative, private, or fully qualified topic name.
1088+ * A relative or private topic will be expanded using this node's namespace and name.
1089+ * The queried `topic` is not remapped.
1090+ * @param {string } topic - The topic on which to find the publishers.
1091+ * @param {boolean } noDemangle - If `true`, `topic` needs to be a valid middleware topic
1092+ * name, otherwise it should be a valid ROS topic name. Defaults to `false`.
10791093 * @returns {Array } - list of publishers
10801094 */
10811095 getPublishersInfoByTopic ( topic , noDemangle ) {
1082- return rclnodejs . getPublishersInfoByTopic ( this . handle , topic , noDemangle ) ;
1096+ return rclnodejs . getPublishersInfoByTopic (
1097+ this . handle ,
1098+ this . _getValidatedTopic ( topic , noDemangle ) ,
1099+ noDemangle
1100+ ) ;
10831101 }
10841102
10851103 /**
1086- * Get a list of subscriptions on a given topic.
1087- * @param {string } topic - the topic name to get the subscriptions for.
1088- * @param {boolean } noDemangle - if `true`, `topic_name` needs to be a valid middleware topic name,
1089- * otherwise it should be a valid ROS topic name.
1104+ * Return a list of subscriptions on a given topic.
1105+ *
1106+ * The returned parameter is a list of TopicEndpointInfo objects, where each will contain
1107+ * the node name, node namespace, topic type, topic endpoint's GID, and its QoS profile.
1108+ *
1109+ * When the `no_mangle` parameter is `true`, the provided `topic` should be a valid
1110+ * topic name for the middleware (useful when combining ROS with native middleware (e.g. DDS)
1111+ * apps). When the `no_mangle` parameter is `False`, the provided `topic` should
1112+ * follow ROS topic name conventions.
1113+ *
1114+ * `topic` may be a relative, private, or fully qualified topic name.
1115+ * A relative or private topic will be expanded using this node's namespace and name.
1116+ * The queried `topic` is not remapped.
1117+ * @param {string } topic - The topic on which to find the subscriptions.
1118+ * @param {boolean } noDemangle - If `True`, `topic` needs to be a valid middleware topic
1119+ name, otherwise it should be a valid ROS topic name. Defaults to `False`.
10901120 * @returns {Array } - list of subscriptions
10911121 */
10921122 getSubscriptionsInfoByTopic ( topic , noDemangle ) {
10931123 return rclnodejs . getSubscriptionsInfoByTopic (
10941124 this . handle ,
1095- topic ,
1125+ this . _getValidatedTopic ( topic , noDemangle ) ,
10961126 noDemangle
10971127 ) ;
10981128 }
@@ -1864,6 +1894,19 @@ class Node extends rclnodejs.ShadowNode {
18641894 this . _actionServers . push ( actionServer ) ;
18651895 this . syncHandles ( ) ;
18661896 }
1897+
1898+ _getValidatedTopic ( topicName , noDemangle ) {
1899+ if ( noDemangle ) {
1900+ return topicName ;
1901+ }
1902+ const fqTopicName = rclnodejs . expandTopicName (
1903+ topicName ,
1904+ this . name ( ) ,
1905+ this . namespace ( )
1906+ ) ;
1907+ validateFullTopicName ( fqTopicName ) ;
1908+ return rclnodejs . remapTopicName ( this . handle , fqTopicName ) ;
1909+ }
18671910}
18681911
18691912/**
0 commit comments