|
| 1 | +# Copyright 2025 Open Source Robotics Foundation, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from typing import List |
| 16 | +from typing import Optional |
| 17 | + |
| 18 | +from launch.action import Action |
| 19 | +from launch.event import Event |
| 20 | +from launch.event_handlers import OnShutdown |
| 21 | +from launch.launch_context import LaunchContext |
| 22 | +from launch.launch_description_entity import LaunchDescriptionEntity |
| 23 | +from launch.some_entities_type import SomeEntitiesType |
| 24 | +from rmw_test_fixture_implementation import rmw_test_isolation_start |
| 25 | +from rmw_test_fixture_implementation import rmw_test_isolation_stop |
| 26 | + |
| 27 | + |
| 28 | +class EnableRmwIsolation(Action): |
| 29 | + """Action which enables isolation of ROS communication using rmw_test_fixture.""" |
| 30 | + |
| 31 | + def __init__(self, **kwargs) -> None: |
| 32 | + """Create a EnableRmwIsolation action.""" |
| 33 | + super().__init__(**kwargs) |
| 34 | + |
| 35 | + def __on_shutdown(self, event: Event, context: LaunchContext) -> Optional[SomeEntitiesType]: |
| 36 | + rmw_test_isolation_stop() |
| 37 | + |
| 38 | + def execute(self, context: LaunchContext) -> Optional[List[LaunchDescriptionEntity]]: |
| 39 | + rmw_test_isolation_start() |
| 40 | + context.register_event_handler(OnShutdown( |
| 41 | + on_shutdown=self.__on_shutdown)) |
0 commit comments