| #ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_CONFIG_ENTITY_CONFIG_H_ |
| #define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_CONFIG_ENTITY_CONFIG_H_ |
| |
| #include <memory> |
| #include <string> |
| #include <utility> |
| #include <vector> |
| |
| #include "absl/status/status.h" |
| #include "absl/status/statusor.h" |
| #include "absl/strings/string_view.h" |
| #include "absl/types/span.h" |
| #include "nlohmann/json.hpp" |
| #include "tlbmc/collector/sensor_collector.h" |
| #include "fan_controller_config.pb.h" |
| #include "fan_pwm_config.pb.h" |
| #include "fan_tach_config.pb.h" |
| #include "hwmon_temp_sensor_config.pb.h" |
| #include "intel_cpu_sensor_config.pb.h" |
| #include "nic_telemetry_config.pb.h" |
| #include "psu_sensor_config.pb.h" |
| #include "shared_mem_sensor_config.pb.h" |
| #include "topology_config.pb.h" |
| #include "virtual_sensor_config.pb.h" |
| #include "fru.pb.h" |
| #include "router_interface.h" |
| |
| namespace milotic_tlbmc { |
| |
| // A config in `EntityConfig` is similar to a Entity Manager config. |
| // The class is responsible for parsing all the configs, calculate topologies, |
| // and generates reactor (e.g. sensors) configs. |
| class EntityConfig { |
| public: |
| // Returns all the hardware monitor temperature sensor configs found on the |
| // system. |
| virtual absl::StatusOr<absl::Span<const HwmonTempSensorConfig>> |
| GetAllHwmonTempSensorConfigs() const = 0; |
| // Returns all the power supply unit sensor configs found on the system. |
| virtual absl::StatusOr<absl::Span<const PsuSensorConfig>> |
| GetAllPsuSensorConfigs() const = 0; |
| virtual absl::StatusOr<absl::Span<const FanControllerConfig>> |
| GetAllFanControllerConfigs() const = 0; |
| virtual absl::StatusOr<absl::Span<const FanPwmConfig>> GetAllFanPwmConfigs() |
| const = 0; |
| virtual absl::StatusOr<absl::Span<const FanTachConfig>> GetAllFanTachConfigs() |
| const = 0; |
| virtual absl::StatusOr<absl::Span<const SharedMemSensorConfig>> |
| GetAllSharedMemSensorConfigs() const = 0; |
| virtual absl::StatusOr<absl::Span<const IntelCpuSensorConfig>> |
| GetAllIntelCpuSensorConfigs() const = 0; |
| virtual absl::StatusOr<absl::Span<const VirtualSensorConfig>> |
| GetAllVirtualSensorConfigs() const = 0; |
| virtual absl::StatusOr<absl::Span<const NicTelemetryConfig>> |
| GetAllNicTelemetryConfigs() const = 0; |
| // Returns the topology of the given FRU identified by the given FRU key. |
| virtual absl::StatusOr<const TopologyConfigNode*> GetFruTopology( |
| absl::string_view fru_key) const = 0; |
| // Returns the topology of the given config key. |
| virtual absl::StatusOr<const TopologyConfigNode*> GetFruTopologyByConfig( |
| absl::string_view config_key) const = 0; |
| // Returns the topology config of all configs. |
| virtual absl::StatusOr<const TopologyConfig*> GetTopologyConfig() const = 0; |
| // Returns all the config keys. Sorted in alphabetical order. |
| virtual absl::StatusOr<std::vector<std::string>> GetAllConfigKeys() const = 0; |
| // Returns the config key of the given FRU key. |
| virtual absl::StatusOr<std::string> GetConfigKeyByFruKey( |
| absl::string_view fru_key) const = 0; |
| // Returns the FRU key of the given config key. |
| virtual absl::StatusOr<std::string> GetFruKeyByConfigKey( |
| absl::string_view config_key) const = 0; |
| // Returns the fan info of the given config key. (fan_id, fan_key) |
| // fan_id: the name of the fan. |
| // fan_key: the FRU key of the fan. |
| virtual absl::StatusOr<std::vector<std::pair<std::string, std::string>>> |
| GetFanInfoByConfigKey(absl::string_view config_key) const = 0; |
| // Returns the devpath of the given FRU key. |
| virtual absl::StatusOr<std::string> GetFruDevpath( |
| absl::string_view fru_key) const = 0; |
| virtual absl::StatusOr<const Fru*> GetFru(absl::string_view key) const = 0; |
| virtual absl::StatusOr<const FruTable*> GetAllFrus() const = 0; |
| virtual bool IsConfigKeyOwningAllSensors( |
| absl::string_view config_key) const = 0; |
| virtual void UpdateFruAndTopology(const RawFruTable& fru_table, |
| const RawFru& raw_fru) = 0; |
| virtual void SetSmartRouter(::crow::RouterInterface* smart_router) = 0; |
| virtual void SetSensorCollector(SensorCollector* sensor_collector) = 0; |
| virtual nlohmann::json ToJson() const = 0; |
| virtual ~EntityConfig() = default; |
| }; |
| |
| class EmptyEntityConfigImpl final : public EntityConfig { |
| public: |
| static std::unique_ptr<EntityConfig> Create(); |
| EmptyEntityConfigImpl() = default; |
| ~EmptyEntityConfigImpl() override = default; |
| |
| absl::StatusOr<absl::Span<const HwmonTempSensorConfig>> |
| GetAllHwmonTempSensorConfigs() const override; |
| absl::StatusOr<absl::Span<const PsuSensorConfig>> GetAllPsuSensorConfigs() |
| const override; |
| absl::StatusOr<absl::Span<const FanControllerConfig>> |
| GetAllFanControllerConfigs() const override; |
| absl::StatusOr<absl::Span<const FanPwmConfig>> GetAllFanPwmConfigs() |
| const override; |
| absl::StatusOr<absl::Span<const FanTachConfig>> GetAllFanTachConfigs() |
| const override; |
| absl::StatusOr<absl::Span<const SharedMemSensorConfig>> |
| GetAllSharedMemSensorConfigs() const override; |
| absl::StatusOr<absl::Span<const IntelCpuSensorConfig>> |
| GetAllIntelCpuSensorConfigs() const override; |
| absl::StatusOr<absl::Span<const VirtualSensorConfig>> |
| GetAllVirtualSensorConfigs() const override; |
| absl::StatusOr<absl::Span<const NicTelemetryConfig>> |
| GetAllNicTelemetryConfigs() const override; |
| absl::StatusOr<const TopologyConfigNode*> GetFruTopology( |
| absl::string_view fru_key) const override; |
| absl::StatusOr<const TopologyConfigNode*> GetFruTopologyByConfig( |
| absl::string_view config_key) const override; |
| absl::StatusOr<const TopologyConfig*> GetTopologyConfig() const override; |
| absl::StatusOr<std::vector<std::string>> GetAllConfigKeys() const override; |
| absl::StatusOr<std::string> GetConfigKeyByFruKey( |
| absl::string_view fru_key) const override; |
| absl::StatusOr<std::string> GetFruKeyByConfigKey( |
| absl::string_view config_key) const override; |
| absl::StatusOr<std::vector<std::pair<std::string, std::string>>> |
| GetFanInfoByConfigKey(absl::string_view config_key) const override; |
| absl::StatusOr<std::string> GetFruDevpath( |
| absl::string_view fru_key) const override; |
| absl::StatusOr<const Fru*> GetFru(absl::string_view key) const override; |
| absl::StatusOr<const FruTable*> GetAllFrus() const override; |
| bool IsConfigKeyOwningAllSensors(absl::string_view config_key) const override; |
| void UpdateFruAndTopology(const RawFruTable& fru_table, |
| const RawFru& raw_fru) override; |
| void SetSmartRouter(::crow::RouterInterface* smart_router) override; |
| void SetSensorCollector(SensorCollector* sensor_collector) override; |
| nlohmann::json ToJson() const override; |
| }; |
| |
| } // namespace milotic_tlbmc |
| |
| #endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_CONFIG_ENTITY_CONFIG_H_ |