/* * 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace ROS2SimulationInterfaces { 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::Activate() { ROS2SimulationInterfacesRequestBus::Handler::BusConnect(); AZ::ApplicationTypeQuery appType; bool isAppEditor; AZ::ComponentApplicationBus::Broadcast(&AZ::ComponentApplicationBus::Events::QueryApplicationType, appType); isAppEditor = (appType.IsValid() && appType.IsEditor()); rclcpp::Node::SharedPtr ros2Node = rclcpp::Node::SharedPtr(ROS2::ROS2Interface::Get()->GetNode()); AZ_Assert(ros2Node, "ROS2 node is not available."); RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); if (!isAppEditor) { // services related to world loading and unloading are available only in GameLauncher // prevent creation of those service handlers RegisterInterface(ros2Node); RegisterInterface(ros2Node); RegisterInterface(ros2Node); } } void ROS2SimulationInterfacesSystemComponent::Deactivate() { ROS2SimulationInterfacesRequestBus::Handler::BusDisconnect(); for (auto& [handlerType, handler] : m_availableRos2Interface) { handler.reset(); } m_availableRos2Interface.clear(); m_externallyRegisteredFeatures.clear(); } void ROS2SimulationInterfacesSystemComponent::AddSimulationFeatures(const AZStd::unordered_set& features) { m_externallyRegisteredFeatures.insert(features.begin(), features.end()); } AZStd::unordered_set ROS2SimulationInterfacesSystemComponent::GetSimulationFeatures() { AZStd::unordered_set result; // add externally registered features result.insert(m_externallyRegisteredFeatures.begin(), m_externallyRegisteredFeatures.end()); // add features from existing handlers for (auto& [handlerType, handler] : m_availableRos2Interface) { auto features = handler->GetProvidedFeatures(); result.insert(features.begin(), features.end()); } return result; } } // namespace ROS2SimulationInterfaces