SetEntityInfoServiceHandler.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "SetEntityInfoServiceHandler.h"
  9. #include <ROS2/Clock/ROS2ClockRequestBus.h>
  10. #include <ROS2/Utilities/ROS2Conversions.h>
  11. #include <SimulationInterfaces/SimulationEntityManagerRequestBus.h>
  12. namespace ROS2SimulationInterfaces
  13. {
  14. AZStd::unordered_set<SimulationFeatureType> SetEntityInfoServiceHandler::GetProvidedFeatures()
  15. {
  16. return AZStd::unordered_set<SimulationFeatureType>{ SimulationFeatures::ENTITY_INFO_SETTING };
  17. }
  18. AZStd::optional<SetEntityInfoServiceHandler::Response> SetEntityInfoServiceHandler::HandleServiceRequest(
  19. const std::shared_ptr<rmw_request_id_t> header, const Request& request)
  20. {
  21. AZStd::string entityName = request.entity.c_str();
  22. SimulationInterfaces::EntityInfo entityInfo;
  23. entityInfo.m_category = request.info.category.category;
  24. entityInfo.m_description = request.info.description.c_str();
  25. AZStd::ranges::transform(request.info.tags, AZStd::back_inserter(entityInfo.m_tags), &std::string::c_str);
  26. AZ::Outcome<void, SimulationInterfaces::FailedResult> outcome;
  27. SimulationInterfaces::SimulationEntityManagerRequestBus::BroadcastResult(
  28. outcome, &SimulationInterfaces::SimulationEntityManagerRequests::SetEntityInfo, entityName, entityInfo);
  29. Response response;
  30. response.result.result = simulation_interfaces::msg::Result::RESULT_OK;
  31. if (!outcome.IsSuccess())
  32. {
  33. const auto& failedResult = outcome.GetError();
  34. response.result.result = failedResult.m_errorCode;
  35. response.result.error_message = failedResult.m_errorString.c_str();
  36. return response;
  37. }
  38. response.result.result = simulation_interfaces::msg::Result::RESULT_OK;
  39. return response;
  40. }
  41. } // namespace ROS2SimulationInterfaces