@@ -43,6 +43,7 @@ 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' ) ;
4647
4748// Parameter event publisher constants
4849const PARAMETER_EVENT_MSG_TYPE = 'rcl_interfaces/msg/ParameterEvent' ;
@@ -1072,27 +1073,57 @@ class Node extends rclnodejs.ShadowNode {
10721073 }
10731074
10741075 /**
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.
1076+ * Return a list of publishers on a given topic.
1077+ *
1078+ * The returned parameter is a list of TopicEndpointInfo objects, where each will contain
1079+ * the node name, node namespace, topic type, topic endpoint's GID, and its QoS profile.
1080+ *
1081+ * When the `no_mangle` parameter is `true`, the provided `topic` should be a valid
1082+ * topic name for the middleware (useful when combining ROS with native middleware (e.g. DDS)
1083+ * apps). When the `no_mangle` parameter is `false`, the provided `topic` should
1084+ * follow ROS topic name conventions.
1085+ *
1086+ * `topic` may be a relative, private, or fully qualified topic name.
1087+ * A relative or private topic will be expanded using this node's namespace and name.
1088+ * The queried `topic` is not remapped.
1089+ *
1090+ * @param {string } topic - The topic on which to find the publishers.
1091+ * @param {boolean } [noDemangle=false] - 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 */
1081- getPublishersInfoByTopic ( topic , noDemangle ) {
1082- return rclnodejs . getPublishersInfoByTopic ( this . handle , topic , noDemangle ) ;
1095+ getPublishersInfoByTopic ( topic , noDemangle = false ) {
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+ *
1118+ * @param {string } topic - The topic on which to find the subscriptions.
1119+ * @param {boolean } [noDemangle=false] - If `true`, `topic` needs to be a valid middleware topic
1120+ name, otherwise it should be a valid ROS topic name. Defaults to `false`.
10901121 * @returns {Array } - list of subscriptions
10911122 */
1092- getSubscriptionsInfoByTopic ( topic , noDemangle ) {
1123+ getSubscriptionsInfoByTopic ( topic , noDemangle = false ) {
10931124 return rclnodejs . getSubscriptionsInfoByTopic (
10941125 this . handle ,
1095- topic ,
1126+ this . _getValidatedTopic ( topic , noDemangle ) ,
10961127 noDemangle
10971128 ) ;
10981129 }
@@ -1428,7 +1459,7 @@ class Node extends rclnodejs.ShadowNode {
14281459 * Determine if a parameter descriptor exists.
14291460 *
14301461 * @param {string } name - The name of a descriptor to for.
1431- * @return {boolean } - True if a descriptor has been declared; otherwise false.
1462+ * @return {boolean } - true if a descriptor has been declared; otherwise false.
14321463 */
14331464 hasParameterDescriptor ( name ) {
14341465 return ! ! this . getParameterDescriptor ( name ) ;
@@ -1864,6 +1895,19 @@ class Node extends rclnodejs.ShadowNode {
18641895 this . _actionServers . push ( actionServer ) ;
18651896 this . syncHandles ( ) ;
18661897 }
1898+
1899+ _getValidatedTopic ( topicName , noDemangle ) {
1900+ if ( noDemangle ) {
1901+ return topicName ;
1902+ }
1903+ const fqTopicName = rclnodejs . expandTopicName (
1904+ topicName ,
1905+ this . name ( ) ,
1906+ this . namespace ( )
1907+ ) ;
1908+ validateFullTopicName ( fqTopicName ) ;
1909+ return rclnodejs . remapTopicName ( this . handle , fqTopicName ) ;
1910+ }
18671911}
18681912
18691913/**
0 commit comments