ROS2SimulationInterfacesSystemComponent.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #pragma once
  9. #include <AzCore/Component/Component.h>
  10. #include <AzCore/std/containers/unordered_map.h>
  11. #include <AzCore/std/containers/unordered_set.h>
  12. #include <AzCore/std/smart_ptr/make_shared.h>
  13. #include <AzCore/std/smart_ptr/shared_ptr.h>
  14. #include <AzCore/std/string/string.h>
  15. #include <AzFramework/API/ApplicationAPI.h>
  16. #include <Interfaces/ISimulationFeaturesBase.h>
  17. #include <SimulationInterfaces/ROS2SimulationInterfacesRequestBus.h>
  18. namespace ROS2SimulationInterfaces
  19. {
  20. class ROS2SimulationInterfacesSystemComponent
  21. : public AZ::Component
  22. , public ROS2SimulationInterfacesRequestBus::Handler
  23. {
  24. public:
  25. AZ_COMPONENT_DECL(ROS2SimulationInterfacesSystemComponent);
  26. static void Reflect(AZ::ReflectContext* context);
  27. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  28. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  29. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  30. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  31. ROS2SimulationInterfacesSystemComponent() = default;
  32. ~ROS2SimulationInterfacesSystemComponent() = default;
  33. protected:
  34. // AZ::Component interface implementation
  35. void Activate() override;
  36. void Deactivate() override;
  37. // ROS2SimulationInterfacesRequestBus override
  38. AZStd::unordered_set<SimulationFeatureType> GetSimulationFeatures() override;
  39. void AddSimulationFeatures(const AZStd::unordered_set<SimulationFeatureType>& features) override;
  40. private:
  41. AZStd::unordered_map<AZStd::string, AZStd::shared_ptr<ISimulationFeaturesBase>> m_availableRos2Interface;
  42. AZStd::unordered_set<SimulationFeatureType> m_externallyRegisteredFeatures;
  43. template<typename T>
  44. void RegisterInterface(rclcpp::Node::SharedPtr ros2Node)
  45. {
  46. AZStd::shared_ptr handler = AZStd::make_shared<T>();
  47. handler->Initialize(ros2Node);
  48. if (handler->IsValid())
  49. {
  50. m_availableRos2Interface[handler->GetTypeName()] = AZStd::move(handler);
  51. }
  52. handler.reset();
  53. };
  54. };
  55. } // namespace ROS2SimulationInterfaces