/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #include "ROS2SimulationInterfacesSystemComponent.h" #include #include #include #include #include #include #include #include namespace ROS2SimulationInterfaces { namespace { template void RegisterInterface( AZStd::unordered_map>& interfacesMap, rclcpp::Node::SharedPtr ros2Node) { AZStd::shared_ptr handler = AZStd::make_shared(); handler->Initialize(ros2Node); interfacesMap[handler->GetTypeName()] = AZStd::move(handler); handler.reset(); }; } // namespace AZ_COMPONENT_IMPL( ROS2SimulationInterfacesSystemComponent, "ROS2SimulationInterfacesSystemComponent", ROS2SimulationInterfacesSystemComponentTypeId); void ROS2SimulationInterfacesSystemComponent::Reflect(AZ::ReflectContext* context) { if (auto serializeContext = azrtti_cast(context)) { serializeContext->Class()->Version(0); } } void ROS2SimulationInterfacesSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { provided.push_back(AZ_CRC_CE("ROS2SimulationInterfacesService")); } void ROS2SimulationInterfacesSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) { incompatible.push_back(AZ_CRC_CE("ROS2SimulationInterfacesService")); } void ROS2SimulationInterfacesSystemComponent::GetRequiredServices( [[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& required) { required.push_back(AZ_CRC_CE("ROS2Service")); } void ROS2SimulationInterfacesSystemComponent::GetDependentServices( [[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& dependent) { } void ROS2SimulationInterfacesSystemComponent::Init() { } void ROS2SimulationInterfacesSystemComponent::Activate() { ROS2SimulationInterfacesRequestBus::Handler::BusConnect(); rclcpp::Node::SharedPtr ros2Node = rclcpp::Node::SharedPtr(ROS2::ROS2Interface::Get()->GetNode()); AZ_Assert(ros2Node, "ROS2 node is not available."); RegisterInterface(m_availableRos2Interface, ros2Node); RegisterInterface(m_availableRos2Interface, ros2Node); RegisterInterface(m_availableRos2Interface, ros2Node); RegisterInterface(m_availableRos2Interface, ros2Node); RegisterInterface(m_availableRos2Interface, ros2Node); RegisterInterface(m_availableRos2Interface, ros2Node); RegisterInterface(m_availableRos2Interface, ros2Node); RegisterInterface(m_availableRos2Interface, ros2Node); RegisterInterface(m_availableRos2Interface, ros2Node); RegisterInterface(m_availableRos2Interface, ros2Node); RegisterInterface(m_availableRos2Interface, ros2Node); RegisterInterface(m_availableRos2Interface, ros2Node); RegisterInterface(m_availableRos2Interface, ros2Node); } void ROS2SimulationInterfacesSystemComponent::Deactivate() { ROS2SimulationInterfacesRequestBus::Handler::BusDisconnect(); for (auto& [handlerType, handler] : m_availableRos2Interface) { handler.reset(); } } AZStd::unordered_set ROS2SimulationInterfacesSystemComponent::GetSimulationFeatures() { AZStd::unordered_set result; for (auto& [handlerType, handler] : m_availableRos2Interface) { auto features = handler->GetProvidedFeatures(); result.insert(features.begin(), features.end()); } return result; } } // namespace ROS2SimulationInterfaces