/* * 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 "GetEntitiesServiceHandler.h" #include #include #include namespace ROS2SimulationInterfaces { AZStd::unordered_set GetEntitiesServiceHandler::GetProvidedFeatures() { return AZStd::unordered_set{ SimulationFeatures::ENTITY_TAGS, SimulationFeatures::ENTITY_BOUNDS_BOX, SimulationFeatures::ENTITY_BOUNDS_CONVEX, SimulationFeatures::ENTITY_CATEGORIES }; } AZStd::optional GetEntitiesServiceHandler::HandleServiceRequest( const std::shared_ptr header, const Request& request) { AZ::Outcome outcome; Response response; response.result.result = simulation_interfaces::msg::Result::RESULT_OK; const auto getFilterResult = Utils::GetEntityFiltersFromRequest(request); if (!getFilterResult.IsSuccess()) { response.result.result = simulation_interfaces::msg::Result::RESULT_OPERATION_FAILED; response.result.error_message = getFilterResult.GetError().c_str(); return response; } const SimulationInterfaces::EntityFilters filter = getFilterResult.GetValue(); SimulationInterfaces::SimulationEntityManagerRequestBus::BroadcastResult( outcome, &SimulationInterfaces::SimulationEntityManagerRequests::GetEntities, filter); std::vector& stdEntities = response.entities; if (!outcome.IsSuccess()) { const auto& failedResult = outcome.GetError(); response.result.result = aznumeric_cast(failedResult.m_errorCode); response.result.error_message = failedResult.m_errorString.c_str(); return response; } const auto& entityNameList = outcome.GetValue(); AZStd::transform( entityNameList.begin(), entityNameList.end(), std::back_inserter(stdEntities), [](const AZStd::string& entityName) { return entityName.c_str(); }); response.entities = stdEntities; return response; } } // namespace ROS2SimulationInterfaces