|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | | -import importlib |
16 | 15 | import time |
| 16 | +from typing import Optional |
17 | 17 |
|
18 | 18 | import rclpy |
19 | 19 | from rclpy.qos import QoSPresetProfiles |
| 20 | +from rclpy.qos import QoSProfile |
20 | 21 | from ros2cli.helpers import collect_stdin |
21 | 22 | from ros2cli.node import NODE_NAME_PREFIX |
22 | 23 | from ros2service.api import ServiceNameCompleter |
|
25 | 26 | from ros2service.verb import VerbExtension |
26 | 27 | from ros2topic.api import add_qos_arguments, profile_configure_short_keys |
27 | 28 | from rosidl_runtime_py import set_message_fields |
| 29 | +from rosidl_runtime_py.utilities import get_service |
28 | 30 | import yaml |
29 | 31 |
|
30 | 32 |
|
@@ -77,23 +79,15 @@ def main(self, *, args): |
77 | 79 | args.service_type, args.service_name, values, period, default_profile) |
78 | 80 |
|
79 | 81 |
|
80 | | -def requester(service_type, service_name, values, period, qos_profile): |
81 | | - # TODO(wjwwood) this logic should come from a rosidl related package |
| 82 | +def requester(service_type: str, service_name: str, values, period: Optional[float], |
| 83 | + qos_profile: QoSProfile) -> None: |
82 | 84 | try: |
83 | 85 | parts = service_type.split('/') |
84 | | - if len(parts) == 2: |
85 | | - parts = [parts[0], 'srv', parts[1]] |
86 | 86 | package_name = parts[0] |
87 | | - module = importlib.import_module('.'.join(parts[:-1])) |
88 | 87 | srv_name = parts[-1] |
89 | | - srv_module = getattr(module, srv_name) |
90 | | - except (AttributeError, ModuleNotFoundError, ValueError): |
| 88 | + srv_module = get_service(service_type) |
| 89 | + except (AttributeError, ModuleNotFoundError): |
91 | 90 | raise RuntimeError('The passed service type is invalid') |
92 | | - try: |
93 | | - srv_module.Request |
94 | | - srv_module.Response |
95 | | - except AttributeError: |
96 | | - raise RuntimeError('The passed type is not a service') |
97 | 91 |
|
98 | 92 | values_dictionary = yaml.safe_load(values) |
99 | 93 |
|
|
0 commit comments