GetSimulationFeaturesServiceHandler.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 "GetSimulationFeaturesServiceHandler.h"
  9. #include <AzCore/base.h>
  10. #include <AzCore/std/containers/unordered_set.h>
  11. #include <SimulationInterfaces/SimulationFeaturesAggregatorRequestBus.h>
  12. namespace ROS2SimulationInterfaces
  13. {
  14. AZStd::unordered_set<SimulationFeatureType> GetSimulationFeaturesServiceHandler::GetProvidedFeatures()
  15. {
  16. // standard doesn't define specific feature id for this service
  17. return AZStd::unordered_set<SimulationFeatureType>{};
  18. }
  19. AZStd::optional<GetSimulationFeaturesServiceHandler::Response> GetSimulationFeaturesServiceHandler::HandleServiceRequest(
  20. const std::shared_ptr<rmw_request_id_t> header, const Request& request)
  21. {
  22. // call bus to get simulation features in ROS2SimulationInterfaces Gem side
  23. AZStd::unordered_set<SimulationFeatureType> ros2Interfaces;
  24. ROS2SimulationInterfacesRequestBus::BroadcastResult(ros2Interfaces, &ROS2SimulationInterfacesRequests::GetSimulationFeatures);
  25. // call bus to get simulation features on SimulationInterfaces Gem side
  26. AZStd::unordered_set<SimulationInterfaces::SimulationFeatureType> o3deInterfaces;
  27. SimulationInterfaces::SimulationFeaturesAggregatorRequestBus::BroadcastResult(
  28. o3deInterfaces, &SimulationInterfaces::SimulationFeaturesAggregatorRequests::GetSimulationFeatures);
  29. // create common features and return it;
  30. // common features are logical AND between two sets
  31. AZStd::unordered_set<SimulationFeatureType> commonFeatures;
  32. commonFeatures.insert(ros2Interfaces.begin(), ros2Interfaces.end());
  33. commonFeatures.insert(o3deInterfaces.begin(), o3deInterfaces.end());
  34. Response response;
  35. for (auto id : commonFeatures)
  36. {
  37. if (ros2Interfaces.contains(id) && o3deInterfaces.contains(SimulationInterfaces::SimulationFeatureType(id)))
  38. {
  39. response.features.features.emplace_back(id);
  40. }
  41. }
  42. return response;
  43. }
  44. } // namespace ROS2SimulationInterfaces