1818#include < algorithm>
1919#include < array>
2020#include < chrono>
21+ #include < cstddef>
22+ #include < cstdint>
2123#include < map>
2224#include < string>
2325#include < tuple>
@@ -40,7 +42,9 @@ enum class EndpointType
4042{
4143 Invalid = RMW_ENDPOINT_INVALID,
4244 Publisher = RMW_ENDPOINT_PUBLISHER,
43- Subscription = RMW_ENDPOINT_SUBSCRIPTION
45+ Subscription = RMW_ENDPOINT_SUBSCRIPTION,
46+ Client = RMW_ENDPOINT_CLIENT,
47+ Server = RMW_ENDPOINT_SERVER
4448};
4549
4650/* *
@@ -143,6 +147,125 @@ class TopicEndpointInfo
143147 rosidl_type_hash_t topic_type_hash_;
144148};
145149
150+ /* *
151+ * Struct that contains service endpoint information like the associated node name, node namespace,
152+ * service type, endpoint type, endpoint count, endpoint GIDs, and its QoS profiles.
153+ */
154+ class ServiceEndpointInfo
155+ {
156+ public:
157+ // / Construct a ServiceEndpointInfo from a rcl_service_endpoint_info_t.
158+ RCLCPP_PUBLIC
159+ explicit ServiceEndpointInfo (const rcl_service_endpoint_info_t & info)
160+ : node_name_(info.node_name),
161+ node_namespace_(info.node_namespace),
162+ service_type_(info.service_type),
163+ endpoint_type_(static_cast <rclcpp::EndpointType>(info.endpoint_type)),
164+ service_type_hash_(info.service_type_hash),
165+ endpoint_count_(info.endpoint_count)
166+ {
167+ for (size_t i = 0 ; i < endpoint_count_; i++) {
168+ std::array<uint8_t , RMW_GID_STORAGE_SIZE> gid;
169+ std::copy (info.endpoint_gids [i], info.endpoint_gids [i] + RMW_GID_STORAGE_SIZE, gid.begin ());
170+ endpoint_gids_.push_back (gid);
171+
172+ rclcpp::QoS qos (
173+ {info.qos_profiles [i].history , info.qos_profiles [i].depth }, info.qos_profiles [i]);
174+ qos_profiles_.push_back (qos);
175+ }
176+ }
177+
178+ // / Get a mutable reference to the node name.
179+ RCLCPP_PUBLIC
180+ std::string &
181+ node_name ();
182+
183+ // / Get a const reference to the node name.
184+ RCLCPP_PUBLIC
185+ const std::string &
186+ node_name () const ;
187+
188+ // / Get a mutable reference to the node namespace.
189+ RCLCPP_PUBLIC
190+ std::string &
191+ node_namespace ();
192+
193+ // / Get a const reference to the node namespace.
194+ RCLCPP_PUBLIC
195+ const std::string &
196+ node_namespace () const ;
197+
198+ // / Get a mutable reference to the service type string.
199+ RCLCPP_PUBLIC
200+ std::string &
201+ service_type ();
202+
203+ // / Get a const reference to the service type string.
204+ RCLCPP_PUBLIC
205+ const std::string &
206+ service_type () const ;
207+
208+ // / Get a mutable reference to the service endpoint type.
209+ RCLCPP_PUBLIC
210+ rclcpp::EndpointType &
211+ endpoint_type ();
212+
213+ // / Get a const reference to the service endpoint type.
214+ RCLCPP_PUBLIC
215+ const rclcpp::EndpointType &
216+ endpoint_type () const ;
217+
218+ // / Get a mutable reference to the endpoint count.
219+ RCLCPP_PUBLIC
220+ size_t &
221+ endpoint_count ();
222+
223+ // / Get a const reference to the endpoint count.
224+ RCLCPP_PUBLIC
225+ const size_t &
226+ endpoint_count () const ;
227+
228+ // / Get a mutable reference to the GID of the service endpoint.
229+ RCLCPP_PUBLIC
230+ std::vector<std::array<uint8_t , RMW_GID_STORAGE_SIZE>> &
231+ endpoint_gids ();
232+
233+ // / Get a const reference to the GID of the service endpoint.
234+ RCLCPP_PUBLIC
235+ const std::vector<std::array<uint8_t , RMW_GID_STORAGE_SIZE>> &
236+ endpoint_gids () const ;
237+
238+ // / Get a mutable reference to the QoS profile of the service endpoint.
239+ RCLCPP_PUBLIC
240+ std::vector<rclcpp::QoS> &
241+ qos_profiles ();
242+
243+ // / Get a const reference to the QoS profile of the service endpoint.
244+ RCLCPP_PUBLIC
245+ const std::vector<rclcpp::QoS> &
246+ qos_profiles () const ;
247+
248+ // / Get a mutable reference to the type hash of the service endpoint.
249+ RCLCPP_PUBLIC
250+ rosidl_type_hash_t &
251+ service_type_hash ();
252+
253+ // / Get a const reference to the type hash of the service endpoint.
254+ RCLCPP_PUBLIC
255+ const rosidl_type_hash_t &
256+ service_type_hash () const ;
257+
258+ private:
259+ std::string node_name_;
260+ std::string node_namespace_;
261+ std::string service_type_;
262+ rclcpp::EndpointType endpoint_type_;
263+ std::vector<std::array<uint8_t , RMW_GID_STORAGE_SIZE>> endpoint_gids_;
264+ std::vector<rclcpp::QoS> qos_profiles_;
265+ rosidl_type_hash_t service_type_hash_;
266+ size_t endpoint_count_;
267+ };
268+
146269namespace node_interfaces
147270{
148271
@@ -408,6 +531,30 @@ class NodeGraphInterface
408531 virtual
409532 std::vector<rclcpp::TopicEndpointInfo>
410533 get_subscriptions_info_by_topic (const std::string & topic_name, bool no_mangle = false ) const = 0 ;
534+
535+ // / Return the service endpoint information about clients on a given service.
536+ /* *
537+ * \param[in] service_name the actual service name used; it will not be automatically remapped.
538+ * \param[in] no_mangle if `true`, `service_name` needs to be a valid middleware service name,
539+ * otherwise it should be a valid ROS service name.
540+ * \sa rclcpp::Node::get_clients_info_by_service
541+ */
542+ RCLCPP_PUBLIC
543+ virtual
544+ std::vector<rclcpp::ServiceEndpointInfo>
545+ get_clients_info_by_service (const std::string & service_name, bool no_mangle = false ) const = 0 ;
546+
547+ // / Return the service endpoint information about servers on a given service.
548+ /* *
549+ * \param[in] service_name the actual service name used; it will not be automatically remapped.
550+ * \param[in] no_mangle if `true`, `service_name` needs to be a valid middleware service name,
551+ * otherwise it should be a valid ROS service name.
552+ * \sa rclcpp::Node::get_servers_info_by_service
553+ */
554+ RCLCPP_PUBLIC
555+ virtual
556+ std::vector<rclcpp::ServiceEndpointInfo>
557+ get_servers_info_by_service (const std::string & service_name, bool no_mangle = false ) const = 0 ;
411558};
412559
413560} // namespace node_interfaces
0 commit comments