| #ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_COLLECTOR_SENSOR_COLLECTOR_AGGREGATOR_H_ |
| #define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_COLLECTOR_SENSOR_COLLECTOR_AGGREGATOR_H_ |
| |
| #include <memory> |
| #include <string> |
| #include <vector> |
| |
| #include "absl/base/nullability.h" |
| #include "absl/status/status.h" |
| #include <nlohmann/json_fwd.hpp> |
| #include "tlbmc/collector/bulk_sensor_collector_base.h" |
| #include "tlbmc/collector/monitoring_change_base.h" |
| #include "tlbmc/collector/sensor_collector.h" |
| #include "sensor.pb.h" |
| #include "tlbmc/sensors/sensor.h" |
| namespace milotic_tlbmc { |
| |
| // Aggregates calls to the underlying sensor collectors. |
| // Note: underlying sensor collectors are not owned by this class and must |
| // outlive it. |
| class SensorCollectorAggregator { |
| public: |
| explicit SensorCollectorAggregator( |
| SensorCollector* absl_nonnull collector, |
| BulkSensorCollectorBase* bulk_collector = nullptr) |
| : sensor_collector_(collector), bulk_sensor_collector_(bulk_collector) {} |
| |
| SensorCollectorAggregator(SensorCollectorAggregator&&) = default; |
| |
| SensorCollectorAggregator(const SensorCollectorAggregator&) = delete; |
| SensorCollectorAggregator& operator=(const SensorCollectorAggregator&) = |
| delete; |
| SensorCollectorAggregator& operator=(SensorCollectorAggregator&&) = delete; |
| |
| // Delegate all calls to the underlying sensor collectors |
| std::vector<std::string> GetAllSharedMemorySensorKeys() const; |
| std::shared_ptr<const Sensor> GetSensorBySensorKey( |
| const std::string& sensor_key) const; |
| std::shared_ptr<const Sensor> GetSensorByConfigKeyAndSensorKey( |
| const std::string& board_config_key, const std::string& sensor_key) const; |
| absl::Status WriteToSensor(const std::string& sensor_key, |
| const SensorValue& value); |
| absl::Status SetDevpathForSensor(std::string_view sensor_key, |
| std::string_view devpath); |
| void StartSensorCollection(); |
| |
| // Delegate calls to the underlying sensor collector and sort the results by |
| // key. |
| std::vector<std::shared_ptr<const Sensor>> GetAllSensors() const; |
| std::vector<std::string> GetAllSensorKeysByConfigKey( |
| const std::string& board_config_key) const; |
| |
| void HandleNewlyFoundFru(const std::string& config_key); |
| |
| // Creates a MonitoringChangeBase, a transaction-like object, which is used to |
| // apply sampling interval and batch size changes. |
| std::unique_ptr<MonitoringChangeBase> CreateMonitoringChange(); |
| |
| void ToJson(nlohmann::json& json) const; |
| |
| private: |
| SensorCollector* sensor_collector_; |
| BulkSensorCollectorBase* bulk_sensor_collector_; |
| }; |
| } // namespace milotic_tlbmc |
| |
| #endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_COLLECTOR_SENSOR_COLLECTOR_AGGREGATOR_H_ |