GetCurrentWorldServiceHandler.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 "GetCurrentWorldServiceHandler.h"
  9. #include <AzCore/std/string/string.h>
  10. #include <Clients/CommonUtilities.h>
  11. #include <SimulationInterfaces/LevelManagerRequestBus.h>
  12. #include <SimulationInterfaces/WorldResource.h>
  13. #include <simulation_interfaces/msg/result.hpp>
  14. namespace ROS2SimulationInterfaces
  15. {
  16. AZStd::unordered_set<SimulationFeatureType> GetCurrentWorldServiceHandler::GetProvidedFeatures()
  17. {
  18. return AZStd::unordered_set<SimulationFeatureType>{ SimulationFeatures::WORLD_INFO_GETTING };
  19. }
  20. AZStd::optional<GetCurrentWorldServiceHandler::Response> GetCurrentWorldServiceHandler::HandleServiceRequest(
  21. const std::shared_ptr<rmw_request_id_t> header, const Request& request)
  22. {
  23. AZ::Outcome<SimulationInterfaces::WorldResource, SimulationInterfaces::FailedResult> currentWorld;
  24. SimulationInterfaces::LevelManagerRequestBus::BroadcastResult(
  25. currentWorld, &SimulationInterfaces::LevelManagerRequests::GetCurrentWorld);
  26. Response response;
  27. if (!currentWorld.IsSuccess())
  28. {
  29. response.result.result = currentWorld.GetError().m_errorCode;
  30. response.result.error_message = currentWorld.GetError().m_errorString.c_str();
  31. }
  32. else
  33. {
  34. response.result.result = simulation_interfaces::msg::Result::RESULT_OK;
  35. response.world = SimulationInterfaces::Utils::ConvertToRos2WorldResource(currentWorld.GetValue());
  36. }
  37. return response;
  38. }
  39. } // namespace ROS2SimulationInterfaces