@@ -22,6 +22,7 @@ extern "C"
2222
2323#include <rmw/names_and_types.h>
2424#include <rmw/get_topic_names_and_types.h>
25+ #include <rmw/topic_endpoint_info_array.h>
2526
2627#include "rcutils/types.h"
2728
@@ -420,8 +421,8 @@ rcl_names_and_types_fini(rcl_names_and_types_t * names_and_types);
420421 *
421422 * \param[in] node the handle to the node being used to query the ROS graph
422423 * \param[in] allocator used to control allocation and deallocation of names
423- * \param[out] node_names struct storing discovered node names.
424- * \param[out] node_namesspaces struct storing discovered node namespaces.
424+ * \param[out] node_names struct storing discovered node names
425+ * \param[out] node_namesspaces struct storing discovered node namespaces
425426 * \return `RCL_RET_OK` if the query was successful, or
426427 * \return `RCL_RET_ERROR` if an unspecified error occurs.
427428 */
@@ -524,6 +525,126 @@ rcl_count_subscribers(
524525 const char * topic_name ,
525526 size_t * count );
526527
528+ /// Return a list of all publishers to a topic.
529+ /**
530+ * The `node` parameter must point to a valid node.
531+ *
532+ * The `topic_name` parameter must not be `NULL`.
533+ *
534+ * When the `no_mangle` parameter is `true`, the provided `topic_name` should be a valid topic name
535+ * for the middleware (useful when combining ROS with native middleware (e.g. DDS) apps).
536+ * When the `no_mangle` parameter is `false`, the provided `topic_name` should follow
537+ * ROS topic name conventions.
538+ * In either case, the topic name should always be fully qualified.
539+ *
540+ * Each element in the `publishers_info` array will contain the node name, node namespace,
541+ * topic type, gid and the qos profile of the publisher.
542+ * It is the responsibility of the caller to ensure that `publishers_info` parameter points
543+ * to a valid struct of type rmw_topic_endpoint_info_array_t.
544+ * The `count` field inside the struct must be set to 0 and the `info_array` field inside
545+ * the struct must be set to null.
546+ * \see rmw_get_zero_initialized_topic_endpoint_info_array
547+ *
548+ * The `allocator` will be used to allocate memory to the `info_array` member
549+ * inside of `publishers_info`.
550+ * Moreover, every const char * member inside of
551+ * rmw_topic_endpoint_info_t will be assigned a copied value on allocated memory.
552+ * \see rmw_topic_endpoint_info_set_node_name and the likes.
553+ * However, it is the responsibility of the caller to
554+ * reclaim any allocated resources to `publishers_info` to avoid leaking memory.
555+ * \see rmw_topic_endpoint_info_array_fini
556+ *
557+ * <hr>
558+ * Attribute | Adherence
559+ * ------------------ | -------------
560+ * Allocates Memory | Yes
561+ * Thread-Safe | No
562+ * Uses Atomics | No
563+ * Lock-Free | Maybe [1]
564+ * <i>[1] implementation may need to protect the data structure with a lock</i>
565+ *
566+ * \param[in] node the handle to the node being used to query the ROS graph
567+ * \param[in] allocator allocator to be used when allocating space for
568+ * the array inside publishers_info
569+ * \param[in] topic_name the name of the topic in question
570+ * \param[in] no_mangle if true, the topic_name will be expanded to its fully qualified name
571+ * \param[out] publishers_info a struct representing a list of publisher information
572+ * \return `RCL_RET_OK` if the query was successful, or
573+ * \return `RCL_RET_NODE_INVALID` if the node is invalid, or
574+ * \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or
575+ * \return `RCL_RET_BAD_ALLOC` if memory allocation fails, or
576+ * \return `RCL_RET_ERROR` if an unspecified error occurs.
577+ */
578+ RCL_PUBLIC
579+ RCL_WARN_UNUSED
580+ rcl_ret_t
581+ rcl_get_publishers_info_by_topic (
582+ const rcl_node_t * node ,
583+ rcutils_allocator_t * allocator ,
584+ const char * topic_name ,
585+ bool no_mangle ,
586+ rmw_topic_endpoint_info_array_t * publishers_info );
587+
588+ /// Return a list of all subscriptions to a topic.
589+ /**
590+ * The `node` parameter must point to a valid node.
591+ *
592+ * The `topic_name` parameter must not be `NULL`.
593+ *
594+ * When the `no_mangle` parameter is `true`, the provided `topic_name` should be a valid topic name
595+ * for the middleware (useful when combining ROS with native middleware (e.g. DDS) apps).
596+ * When the `no_mangle` parameter is `false`, the provided `topic_name` should follow
597+ * ROS topic name conventions.
598+ * In either case, the topic name should always be fully qualified.
599+ *
600+ * Each element in the `subscriptions_info` array will contain the node name, node namespace,
601+ * topic type, gid and the qos profile of the subscription.
602+ * It is the responsibility of the caller to ensure that `subscriptions_info` parameter points
603+ * to a valid struct of type rmw_topic_endpoint_info_array_t.
604+ * The `count` field inside the struct must be set to 0 and the `info_array` field inside
605+ * the struct must be set to null.
606+ * \see rmw_get_zero_initialized_topic_endpoint_info_array
607+ *
608+ * The `allocator` will be used to allocate memory to the `info_array` member
609+ * inside of `subscriptions_info`.
610+ * Moreover, every const char * member inside of
611+ * rmw_topic_endpoint_info_t will be assigned a copied value on allocated memory.
612+ * \see rmw_topic_endpoint_info_set_node_name and the likes.
613+ * However, it is the responsibility of the caller to
614+ * reclaim any allocated resources to `subscriptions_info` to avoid leaking memory.
615+ * \see rmw_topic_endpoint_info_array_fini
616+ *
617+ * <hr>
618+ * Attribute | Adherence
619+ * ------------------ | -------------
620+ * Allocates Memory | Yes
621+ * Thread-Safe | No
622+ * Uses Atomics | No
623+ * Lock-Free | Maybe [1]
624+ * <i>[1] implementation may need to protect the data structure with a lock</i>
625+ *
626+ * \param[in] node the handle to the node being used to query the ROS graph
627+ * \param[in] allocator allocator to be used when allocating space for
628+ * the array inside publishers_info
629+ * \param[in] topic_name the name of the topic in question
630+ * \param[in] no_mangle if true, the topic_name will be expanded to its fully qualified name
631+ * \param[out] subscriptions_info a struct representing a list of subscriptions information
632+ * \return `RCL_RET_OK` if the query was successful, or
633+ * \return `RCL_RET_NODE_INVALID` if the node is invalid, or
634+ * \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or
635+ * \return `RCL_RET_BAD_ALLOC` if memory allocation fails, or
636+ * \return `RCL_RET_ERROR` if an unspecified error occurs.
637+ */
638+ RCL_PUBLIC
639+ RCL_WARN_UNUSED
640+ rcl_ret_t
641+ rcl_get_subscriptions_info_by_topic (
642+ const rcl_node_t * node ,
643+ rcutils_allocator_t * allocator ,
644+ const char * topic_name ,
645+ bool no_mangle ,
646+ rmw_topic_endpoint_info_array_t * subscriptions_info );
647+
527648/// Check if a service server is available for the given service client.
528649/**
529650 * This function will return true for `is_available` if there is a service server
0 commit comments