Skip to content

Commit 21d46eb

Browse files
ihasdapieclalancette
authored andcommitted
configure service introspection via node options & parameters
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
1 parent be8c5d0 commit 21d46eb

26 files changed

Lines changed: 988 additions & 57 deletions

rclcpp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ set(${PROJECT_NAME}_SRCS
7878
src/rclcpp/node_interfaces/node_logging.cpp
7979
src/rclcpp/node_interfaces/node_parameters.cpp
8080
src/rclcpp/node_interfaces/node_services.cpp
81+
src/rclcpp/node_interfaces/node_service_introspection.cpp
8182
src/rclcpp/node_interfaces/node_time_source.cpp
8283
src/rclcpp/node_interfaces/node_timers.cpp
8384
src/rclcpp/node_interfaces/node_topics.cpp

rclcpp/include/rclcpp/client.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
#define RCLCPP__CLIENT_HPP_
1717

1818
#include <atomic>
19+
#include <functional>
1920
#include <future>
20-
#include <unordered_map>
2121
#include <memory>
2222
#include <mutex>
2323
#include <optional> // NOLINT, cpplint doesn't think this is a cpp std header
2424
#include <sstream>
2525
#include <string>
2626
#include <tuple>
27+
#include <unordered_map>
2728
#include <utility>
2829
#include <variant> // NOLINT
2930
#include <vector>

rclcpp/include/rclcpp/create_client.hpp

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <string>
2020

2121
#include "rclcpp/node_interfaces/node_base_interface.hpp"
22+
#include "rclcpp/node_interfaces/node_clock_interface.hpp"
2223
#include "rclcpp/node_interfaces/node_services_interface.hpp"
2324
#include "rclcpp/qos.hpp"
2425
#include "rmw/rmw.h"
@@ -44,15 +45,15 @@ create_client(
4445
std::shared_ptr<node_interfaces::NodeBaseInterface> node_base,
4546
std::shared_ptr<node_interfaces::NodeGraphInterface> node_graph,
4647
std::shared_ptr<node_interfaces::NodeServicesInterface> node_services,
48+
std::shared_ptr<node_interfaces::NodeClockInterface> node_clock,
4749
const std::string & service_name,
48-
const rclcpp::QoS & qos = rclcpp::ServicesQoS(),
49-
rclcpp::CallbackGroup::SharedPtr group = nullptr)
50+
const rclcpp::QoS & qos,
51+
rclcpp::CallbackGroup::SharedPtr group,
52+
bool enable_service_introspection)
5053
{
5154
return create_client<ServiceT>(
52-
node_base, node_graph, node_services,
53-
service_name,
54-
qos.get_rmw_qos_profile(),
55-
group);
55+
node_base, node_graph, node_services, node_clock, service_name,
56+
qos.get_rmw_qos_profile(), group, enable_service_introspection);
5657
}
5758

5859
/// Create a service client with a given type.
@@ -63,12 +64,39 @@ create_client(
6364
std::shared_ptr<node_interfaces::NodeBaseInterface> node_base,
6465
std::shared_ptr<node_interfaces::NodeGraphInterface> node_graph,
6566
std::shared_ptr<node_interfaces::NodeServicesInterface> node_services,
67+
std::shared_ptr<node_interfaces::NodeClockInterface> node_clock,
68+
const std::string & service_name,
69+
const rmw_qos_profile_t & qos_profile,
70+
rclcpp::CallbackGroup::SharedPtr group,
71+
bool enable_service_introspection)
72+
{
73+
return create_client<ServiceT>(
74+
node_base, node_graph, node_services, node_clock, service_name, qos_profile,
75+
rcl_publisher_get_default_options().qos, group, enable_service_introspection);
76+
}
77+
78+
/// Create a service client with a given type and qos profiles
79+
/// \internal
80+
template<typename ServiceT>
81+
typename rclcpp::Client<ServiceT>::SharedPtr
82+
create_client(
83+
std::shared_ptr<node_interfaces::NodeBaseInterface> node_base,
84+
std::shared_ptr<node_interfaces::NodeGraphInterface> node_graph,
85+
std::shared_ptr<node_interfaces::NodeServicesInterface> node_services,
86+
std::shared_ptr<node_interfaces::NodeClockInterface> node_clock,
6687
const std::string & service_name,
6788
const rmw_qos_profile_t & qos_profile,
68-
rclcpp::CallbackGroup::SharedPtr group)
89+
const rmw_qos_profile_t & service_event_publisher_qos_profile,
90+
rclcpp::CallbackGroup::SharedPtr group,
91+
bool enable_service_introspection)
6992
{
7093
rcl_client_options_t options = rcl_client_get_default_options();
7194
options.qos = qos_profile;
95+
if (enable_service_introspection) {
96+
options.enable_service_introspection = enable_service_introspection;
97+
options.clock = node_clock->get_clock()->get_clock_handle();
98+
options.event_publisher_options.qos = service_event_publisher_qos_profile;
99+
}
72100

73101
auto cli = rclcpp::Client<ServiceT>::make_shared(
74102
node_base.get(),

rclcpp/include/rclcpp/create_service.hpp

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <utility>
2121

2222
#include "rclcpp/node_interfaces/node_base_interface.hpp"
23+
#include "rclcpp/node_interfaces/node_clock_interface.hpp"
2324
#include "rclcpp/node_interfaces/node_services_interface.hpp"
2425
#include "rclcpp/visibility_control.hpp"
2526
#include "rmw/rmw.h"
@@ -43,33 +44,65 @@ typename rclcpp::Service<ServiceT>::SharedPtr
4344
create_service(
4445
std::shared_ptr<node_interfaces::NodeBaseInterface> node_base,
4546
std::shared_ptr<node_interfaces::NodeServicesInterface> node_services,
47+
std::shared_ptr<node_interfaces::NodeClockInterface> node_clock,
4648
const std::string & service_name,
4749
CallbackT && callback,
4850
const rclcpp::QoS & qos,
49-
rclcpp::CallbackGroup::SharedPtr group)
51+
rclcpp::CallbackGroup::SharedPtr group,
52+
bool enable_service_introspection)
5053
{
5154
return create_service<ServiceT, CallbackT>(
52-
node_base, node_services, service_name,
53-
std::forward<CallbackT>(callback), qos.get_rmw_qos_profile(), group);
55+
node_base, node_services, node_clock, service_name, std::forward<CallbackT>(callback),
56+
qos.get_rmw_qos_profile(), group, enable_service_introspection);
5457
}
5558

56-
/// Create a service with a given type.
59+
60+
/// Create a service with a given type
61+
/// \internal
62+
template<typename ServiceT, typename CallbackT>
63+
typename rclcpp::Service<ServiceT>::SharedPtr
64+
create_service(
65+
std::shared_ptr<node_interfaces::NodeBaseInterface> node_base,
66+
std::shared_ptr<node_interfaces::NodeServicesInterface> node_services,
67+
std::shared_ptr<node_interfaces::NodeClockInterface> node_clock,
68+
const std::string & service_name,
69+
CallbackT && callback,
70+
const rmw_qos_profile_t & qos_profile,
71+
rclcpp::CallbackGroup::SharedPtr group,
72+
bool enable_service_introspection
73+
)
74+
{
75+
return create_service<ServiceT, CallbackT>(
76+
node_base, node_services, node_clock, service_name, std::forward<CallbackT>(callback),
77+
qos_profile, rcl_publisher_get_default_options().qos, group, enable_service_introspection);
78+
}
79+
80+
/// Create a service with a given type and qos profiles
5781
/// \internal
5882
template<typename ServiceT, typename CallbackT>
5983
typename rclcpp::Service<ServiceT>::SharedPtr
6084
create_service(
6185
std::shared_ptr<node_interfaces::NodeBaseInterface> node_base,
6286
std::shared_ptr<node_interfaces::NodeServicesInterface> node_services,
87+
std::shared_ptr<node_interfaces::NodeClockInterface> node_clock,
6388
const std::string & service_name,
6489
CallbackT && callback,
6590
const rmw_qos_profile_t & qos_profile,
66-
rclcpp::CallbackGroup::SharedPtr group)
91+
const rmw_qos_profile_t & service_event_publisher_qos_profile,
92+
rclcpp::CallbackGroup::SharedPtr group,
93+
bool enable_service_introspection
94+
)
6795
{
6896
rclcpp::AnyServiceCallback<ServiceT> any_service_callback;
6997
any_service_callback.set(std::forward<CallbackT>(callback));
7098

7199
rcl_service_options_t service_options = rcl_service_get_default_options();
72100
service_options.qos = qos_profile;
101+
if (enable_service_introspection) {
102+
service_options.enable_service_introspection = enable_service_introspection;
103+
service_options.clock = node_clock->get_clock()->get_clock_handle();
104+
service_options.event_publisher_options.qos = service_event_publisher_qos_profile;
105+
}
73106

74107
auto serv = Service<ServiceT>::make_shared(
75108
node_base->get_shared_rcl_node_handle(),

rclcpp/include/rclcpp/node.hpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "rclcpp/node_interfaces/node_logging_interface.hpp"
5454
#include "rclcpp/node_interfaces/node_parameters_interface.hpp"
5555
#include "rclcpp/node_interfaces/node_services_interface.hpp"
56+
#include "rclcpp/node_interfaces/node_service_introspection_interface.hpp"
5657
#include "rclcpp/node_interfaces/node_time_source_interface.hpp"
5758
#include "rclcpp/node_interfaces/node_timers_interface.hpp"
5859
#include "rclcpp/node_interfaces/node_topics_interface.hpp"
@@ -283,6 +284,22 @@ class Node : public std::enable_shared_from_this<Node>
283284
const rclcpp::QoS & qos = rclcpp::ServicesQoS(),
284285
rclcpp::CallbackGroup::SharedPtr group = nullptr);
285286

287+
/// Create and return a Client.
288+
/**
289+
* \param[in] service_name The name on which the service is accessible.
290+
* \param[in] qos Quality of service profile for client.
291+
* \param[in] service_event_publisher_qos QOS profile for the service event publisher.
292+
* \param[in] group Callback group to handle the reply to service calls.
293+
* \return Shared pointer to the created client.
294+
*/
295+
template<typename ServiceT>
296+
typename Client<ServiceT>::SharedPtr
297+
create_client(
298+
const std::string & service_name,
299+
const rclcpp::QoS & qos,
300+
const rclcpp::QoS & service_event_publisher_qos,
301+
rclcpp::CallbackGroup::SharedPtr group);
302+
286303
/// Create and return a Service.
287304
/**
288305
* \param[in] service_name The topic to service on.
@@ -317,6 +334,25 @@ class Node : public std::enable_shared_from_this<Node>
317334
const rclcpp::QoS & qos = rclcpp::ServicesQoS(),
318335
rclcpp::CallbackGroup::SharedPtr group = nullptr);
319336

337+
338+
/// Create and return a Service.
339+
/**
340+
* \param[in] service_name The topic to service on.
341+
* \param[in] callback User-defined callback function.
342+
* \param[in] qos Quality of service profile for the service.
343+
* \param[in] service_event_publisher_qos QOS profile for the service event publisher.
344+
* \param[in] group Callback group to call the service.
345+
* \return Shared pointer to the created service.
346+
*/
347+
template<typename ServiceT, typename CallbackT>
348+
typename rclcpp::Service<ServiceT>::SharedPtr
349+
create_service(
350+
const std::string & service_name,
351+
CallbackT && callback,
352+
const rclcpp::QoS & qos,
353+
const rclcpp::QoS & service_event_publisher_qos,
354+
rclcpp::CallbackGroup::SharedPtr group);
355+
320356
/// Create and return a GenericPublisher.
321357
/**
322358
* The returned pointer will never be empty, but this function can throw various exceptions, for
@@ -1439,6 +1475,11 @@ class Node : public std::enable_shared_from_this<Node>
14391475
rclcpp::node_interfaces::NodeServicesInterface::SharedPtr
14401476
get_node_services_interface();
14411477

1478+
/// Return the Node's internal NodeServicesInterface implementation.
1479+
RCLCPP_PUBLIC
1480+
rclcpp::node_interfaces::NodeServiceIntrospectionInterface::SharedPtr
1481+
get_node_service_introspection_interface();
1482+
14421483
/// Return the Node's internal NodeWaitablesInterface implementation.
14431484
RCLCPP_PUBLIC
14441485
rclcpp::node_interfaces::NodeWaitablesInterface::SharedPtr
@@ -1587,6 +1628,7 @@ class Node : public std::enable_shared_from_this<Node>
15871628
rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_parameters_;
15881629
rclcpp::node_interfaces::NodeTimeSourceInterface::SharedPtr node_time_source_;
15891630
rclcpp::node_interfaces::NodeWaitablesInterface::SharedPtr node_waitables_;
1631+
rclcpp::node_interfaces::NodeServiceIntrospectionInterface::SharedPtr node_service_introspection_;
15901632

15911633
const rclcpp::NodeOptions node_options_;
15921634
const std::string sub_namespace_;

rclcpp/include/rclcpp/node_impl.hpp

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,41 @@ Node::create_client(
143143
const rclcpp::QoS & qos,
144144
rclcpp::CallbackGroup::SharedPtr group)
145145
{
146-
return rclcpp::create_client<ServiceT>(
146+
typename Client<ServiceT>::SharedPtr cli = rclcpp::create_client<ServiceT>(
147147
node_base_,
148148
node_graph_,
149149
node_services_,
150+
node_clock_,
150151
extend_name_with_sub_namespace(service_name, this->get_sub_namespace()),
151152
qos,
152-
group);
153+
group,
154+
node_options_.enable_service_introspection());
155+
156+
node_service_introspection_->register_client(cli);
157+
return cli;
158+
}
159+
160+
template<typename ServiceT>
161+
typename Client<ServiceT>::SharedPtr
162+
Node::create_client(
163+
const std::string & service_name,
164+
const rclcpp::QoS & qos,
165+
const rclcpp::QoS & service_event_publisher_qos,
166+
rclcpp::CallbackGroup::SharedPtr group)
167+
{
168+
typename Client<ServiceT>::SharedPtr cli = rclcpp::create_client<ServiceT>(
169+
node_base_,
170+
node_graph_,
171+
node_services_,
172+
node_clock_,
173+
extend_name_with_sub_namespace(service_name, this->get_sub_namespace()),
174+
qos.get_rmw_qos_profile(),
175+
service_event_publisher_qos.get_rmw_qos_profile(),
176+
group,
177+
node_options_.enable_service_introspection());
178+
179+
node_service_introspection_->register_client(cli);
180+
return cli;
153181
}
154182

155183
template<typename ServiceT>
@@ -159,13 +187,18 @@ Node::create_client(
159187
const rmw_qos_profile_t & qos_profile,
160188
rclcpp::CallbackGroup::SharedPtr group)
161189
{
162-
return rclcpp::create_client<ServiceT>(
190+
typename Client<ServiceT>::SharedPtr cli = rclcpp::create_client<ServiceT>(
163191
node_base_,
164192
node_graph_,
165193
node_services_,
194+
node_clock_,
166195
extend_name_with_sub_namespace(service_name, this->get_sub_namespace()),
167196
qos_profile,
168-
group);
197+
group,
198+
node_options_.enable_service_introspection());
199+
200+
node_service_introspection_->register_client(cli);
201+
return cli;
169202
}
170203

171204
template<typename ServiceT, typename CallbackT>
@@ -176,13 +209,42 @@ Node::create_service(
176209
const rclcpp::QoS & qos,
177210
rclcpp::CallbackGroup::SharedPtr group)
178211
{
179-
return rclcpp::create_service<ServiceT, CallbackT>(
212+
typename rclcpp::Service<ServiceT>::SharedPtr serv = rclcpp::create_service<ServiceT, CallbackT>(
180213
node_base_,
181214
node_services_,
215+
node_clock_,
182216
extend_name_with_sub_namespace(service_name, this->get_sub_namespace()),
183217
std::forward<CallbackT>(callback),
184218
qos,
185-
group);
219+
group,
220+
node_options_.enable_service_introspection());
221+
222+
node_service_introspection_->register_service(serv);
223+
return serv;
224+
}
225+
226+
template<typename ServiceT, typename CallbackT>
227+
typename rclcpp::Service<ServiceT>::SharedPtr
228+
Node::create_service(
229+
const std::string & service_name,
230+
CallbackT && callback,
231+
const rclcpp::QoS & qos,
232+
const rclcpp::QoS & service_event_publisher_qos,
233+
rclcpp::CallbackGroup::SharedPtr group)
234+
{
235+
typename rclcpp::Service<ServiceT>::SharedPtr serv = rclcpp::create_service<ServiceT, CallbackT>(
236+
node_base_,
237+
node_services_,
238+
node_clock_,
239+
extend_name_with_sub_namespace(service_name, this->get_sub_namespace()),
240+
std::forward<CallbackT>(callback),
241+
qos.get_rmw_qos_profile(),
242+
service_event_publisher_qos.get_rmw_qos_profile(),
243+
group,
244+
node_options_.enable_service_introspection());
245+
246+
node_service_introspection_->register_service(serv);
247+
return serv;
186248
}
187249

188250
template<typename ServiceT, typename CallbackT>
@@ -193,13 +255,19 @@ Node::create_service(
193255
const rmw_qos_profile_t & qos_profile,
194256
rclcpp::CallbackGroup::SharedPtr group)
195257
{
196-
return rclcpp::create_service<ServiceT, CallbackT>(
258+
typename rclcpp::Service<ServiceT>::SharedPtr serv = rclcpp::create_service<ServiceT, CallbackT>(
197259
node_base_,
198260
node_services_,
261+
node_clock_,
199262
extend_name_with_sub_namespace(service_name, this->get_sub_namespace()),
200263
std::forward<CallbackT>(callback),
201264
qos_profile,
202-
group);
265+
group,
266+
node_options_.enable_service_introspection()
267+
);
268+
269+
node_service_introspection_->register_service(serv);
270+
return serv;
203271
}
204272

205273
template<typename AllocatorT>

rclcpp/include/rclcpp/node_interfaces/node_parameters.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ class NodeParameters : public NodeParametersInterface
108108
const rclcpp::QoS & parameter_event_qos,
109109
const rclcpp::PublisherOptionsBase & parameter_event_publisher_options,
110110
bool allow_undeclared_parameters,
111-
bool automatically_declare_parameters_from_overrides);
111+
bool automatically_declare_parameters_from_overrides,
112+
bool enable_service_introspection_for_parameter_service);
112113

113114
RCLCPP_PUBLIC
114115
virtual

0 commit comments

Comments
 (0)