Skip to content

Commit b95eccb

Browse files
leeminju531fujitatomoya
authored andcommitted
update service info verbose option
Signed-off-by: Minju, Lee <[email protected]>
1 parent 58f3245 commit b95eccb

File tree

4 files changed

+85
-9
lines changed

4 files changed

+85
-9
lines changed

ros2cli/ros2cli/daemon/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ def serve(server: LocalXMLRPCServer, *, timeout: int = 2 * 60 * 60):
9191
node.get_subscriber_names_and_types_by_node,
9292
node.get_subscriptions_info_by_topic,
9393
node.get_service_names_and_types_by_node,
94+
node.get_servers_info_by_service,
95+
node.get_clients_info_by_service,
9496
node.get_client_names_and_types_by_node,
9597
bind(rclpy.action.get_action_server_names_and_types_by_node, node),
9698
bind(rclpy.action.get_action_client_names_and_types_by_node, node),

ros2cli/ros2cli/xmlrpc/marshal/rclpy.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
from xmlrpc.client import Unmarshaller
1818

1919
import rclpy.duration
20+
import rclpy.endpoint_info
2021
import rclpy.qos
21-
import rclpy.topic_endpoint_info
2222
import rclpy.type_hash
2323

2424
from .generic import dump_any_enum
@@ -66,16 +66,22 @@ def dump_duration(marshaller, value, write):
6666
Marshaller.dispatch[enum_type] = dump_any_enum
6767

6868

69-
Unmarshaller.dispatch[fullname(rclpy.topic_endpoint_info.TopicEndpointInfo)] = \
70-
functools.partial(end_any_with_slots, type_=rclpy.topic_endpoint_info.TopicEndpointInfo)
69+
Unmarshaller.dispatch[fullname(rclpy.endpoint_info.TopicEndpointInfo)] = \
70+
functools.partial(end_any_with_slots, type_=rclpy.endpoint_info.TopicEndpointInfo)
7171

72-
Marshaller.dispatch[rclpy.topic_endpoint_info.TopicEndpointInfo] = \
72+
Marshaller.dispatch[rclpy.endpoint_info.TopicEndpointInfo] = \
7373
functools.partial(dump_any_with_slots, transform=lambda slot: slot.lstrip('_'))
7474

75-
Unmarshaller.dispatch[fullname(rclpy.topic_endpoint_info.TopicEndpointTypeEnum)] = \
76-
functools.partial(end_any_enum, enum_=rclpy.topic_endpoint_info.TopicEndpointTypeEnum)
75+
Unmarshaller.dispatch[fullname(rclpy.endpoint_info.ServiceEndpointInfo)] = \
76+
functools.partial(end_any_with_slots, type_=rclpy.endpoint_info.ServiceEndpointInfo)
7777

78-
Marshaller.dispatch[rclpy.topic_endpoint_info.TopicEndpointTypeEnum] = dump_any_enum
78+
Marshaller.dispatch[rclpy.endpoint_info.ServiceEndpointInfo] = \
79+
functools.partial(dump_any_with_slots, transform=lambda slot: slot.lstrip('_'))
80+
81+
Unmarshaller.dispatch[fullname(rclpy.endpoint_info.EndpointTypeEnum)] = \
82+
functools.partial(end_any_enum, enum_=rclpy.endpoint_info.EndpointTypeEnum)
83+
84+
Marshaller.dispatch[rclpy.endpoint_info.EndpointTypeEnum] = dump_any_enum
7985

8086

8187
def end_type_hash(unmarshaller, data):

ros2cli/test/test_ros2cli_daemon.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import rclpy
2020
import rclpy.action
21+
from rclpy.endpoint_info import EndpointTypeEnum
2122

2223
from ros2cli.node.daemon import DaemonNode
2324
from ros2cli.node.daemon import is_daemon_running
@@ -45,6 +46,8 @@
4546
history=rclpy.qos.HistoryPolicy.KEEP_LAST,
4647
depth=8
4748
)
49+
TEST_SERVICE_CLIENT_QOS = TEST_TOPIC_PUBLISHER_QOS
50+
TEST_SERVICE_SERVER_QOS = TEST_TOPIC_SUBSCRIPTION_QOS
4851
TEST_SERVICE_NAME = '/test/service'
4952
TEST_SERVICE_TYPE = 'test_msgs/srv/Empty'
5053
TEST_ACTION_NAME = '/test/action'
@@ -73,12 +76,14 @@ def local_node():
7376
service = node.create_service(
7477
srv_type=test_msgs.srv.Empty,
7578
srv_name=TEST_SERVICE_NAME,
76-
callback=(lambda req, res: res)
79+
callback=(lambda req, res: res),
80+
qos_profile=TEST_SERVICE_SERVER_QOS
7781
)
7882
service # to avoid "assigned by never used" warning
7983
client = node.create_client(
8084
srv_type=test_msgs.srv.Empty,
81-
srv_name=TEST_SERVICE_NAME
85+
srv_name=TEST_SERVICE_NAME,
86+
qos_profile=TEST_SERVICE_CLIENT_QOS
8287
)
8388
client # to avoid "assigned by never used" warning
8489

@@ -235,6 +240,42 @@ def test_get_subscriptions_info_by_topic(daemon_node):
235240
TEST_TOPIC_SUBSCRIPTION_QOS.depth
236241

237242

243+
def test_get_clients_info_by_service(daemon_node):
244+
clients_info = daemon_node.get_clients_info_by_service(TEST_SERVICE_NAME)
245+
assert len(clients_info) == 1
246+
test_client_info = clients_info[0]
247+
assert test_client_info.node_name == TEST_NODE_NAME
248+
assert test_client_info.node_namespace == TEST_NODE_NAMESPACE
249+
assert test_client_info.service_type == TEST_SERVICE_TYPE
250+
assert test_client_info.endpoint_type == EndpointTypeEnum.CLIENT
251+
assert (test_client_info.endpoint_count == 1 or test_client_info.endpoint_count == 2)
252+
assert len(test_client_info.qos_profiles) == test_client_info.endpoint_count
253+
assert len(test_client_info.endpoint_gids) == test_client_info.endpoint_count
254+
for i in range(test_client_info.endpoint_count):
255+
assert test_client_info.qos_profiles[i].durability == \
256+
TEST_SERVICE_CLIENT_QOS.durability
257+
assert test_client_info.qos_profiles[i].reliability == \
258+
TEST_SERVICE_CLIENT_QOS.reliability
259+
260+
261+
def test_get_servers_info_by_service(daemon_node):
262+
servers_info = daemon_node.get_servers_info_by_service(TEST_SERVICE_NAME)
263+
assert len(servers_info) == 1
264+
test_server_info = servers_info[0]
265+
assert test_server_info.node_name == TEST_NODE_NAME
266+
assert test_server_info.node_namespace == TEST_NODE_NAMESPACE
267+
assert test_server_info.service_type == TEST_SERVICE_TYPE
268+
assert test_server_info.endpoint_type == EndpointTypeEnum.SERVER
269+
assert (test_server_info.endpoint_count == 1 or test_server_info.endpoint_count == 2)
270+
assert len(test_server_info.qos_profiles) == test_server_info.endpoint_count
271+
assert len(test_server_info.endpoint_gids) == test_server_info.endpoint_count
272+
for i in range(test_server_info.endpoint_count):
273+
assert test_server_info.qos_profiles[i].durability == \
274+
TEST_SERVICE_SERVER_QOS.durability
275+
assert test_server_info.qos_profiles[i].reliability == \
276+
TEST_SERVICE_SERVER_QOS.reliability
277+
278+
238279
def test_count_publishers(daemon_node):
239280
assert 1 == daemon_node.count_publishers(TEST_TOPIC_NAME)
240281

ros2service/ros2service/verb/info.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright 2022 CLOBOT Co., Ltd.
2+
# Copyright 2025 Minju Lee (이민주). All rights reserved.
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");
45
# you may not use this file except in compliance with the License.
@@ -27,6 +28,13 @@ def add_arguments(self, parser, cli_name):
2728
arg = parser.add_argument(
2829
'service_name',
2930
help="Name of the ROS service to get info (e.g. '/add_two_ints')")
31+
parser.add_argument(
32+
'--verbose',
33+
'-v',
34+
action='store_true',
35+
help='Prints detailed information like the node name, node namespace, service type, '
36+
'service type hash, GUIDs, and QoS Profiless of the clients and servers to '
37+
'this service')
3038
arg.completer = ServiceNameCompleter(
3139
include_hidden_services_key='include_hidden_services')
3240

@@ -44,11 +52,30 @@ def main(self, *, args):
4452
else:
4553
return "Unknown service '%s'" % service_name
4654

55+
line_end = '\n'
56+
if args.verbose:
57+
line_end = '\n\n'
58+
4759
type_str = service_types[0] if len(service_types) == 1 else service_types
4860
print('Type: %s' % type_str, end='\n')
4961

5062
print('Clients count: %d' %
5163
node.count_clients(service_name), end='\n')
5264

65+
if args.verbose:
66+
try:
67+
for info in node.get_clients_info_by_service(service_name):
68+
print(info, end=line_end)
69+
70+
except NotImplementedError as e:
71+
return str(e)
72+
5373
print('Services count: %d' %
5474
node.count_services(service_name), end='\n')
75+
if args.verbose:
76+
try:
77+
for info in node.get_servers_info_by_service(service_name):
78+
print(info, end=line_end)
79+
80+
except NotImplementedError as e:
81+
return str(e)

0 commit comments

Comments
 (0)