blob: a4c060ef0276fe1ec35725d6f213e49b8b98a670 [file] [log] [blame]
#ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_NIC_SENSOR_H_
#define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_NIC_SENSOR_H_
#include <memory>
#include <optional>
#include <string>
#include "absl/container/flat_hash_map.h"
#include "absl/functional/any_invocable.h"
#include "absl/status/statusor.h"
#include "boost/asio.hpp" //NOLINT: boost::asio is commonly used in BMC
#include "nic_telemetry_config.pb.h"
#include "tlbmc/hal/nic_veeprom/interface.h"
#include "sensor.pb.h"
#include "tlbmc/sensors/sensor.h"
namespace milotic_tlbmc {
class NicSensor : public Sensor,
public std::enable_shared_from_this<NicSensor> {
private:
class Token;
public:
static absl::StatusOr<std::shared_ptr<NicSensor>> Create(
const std::string& sensor_name,
nic_veeprom::NicTelemetryName telemetry_name, SensorUnit sensor_unit,
const EntityCommonConfig& entity_common_config,
const ThresholdConfigs& threshold_configs,
const ReadingRangeConfigs& reading_range_configs,
const std::shared_ptr<boost::asio::io_context>& io_context,
const nic_veeprom::Accessor& accessor,
std::optional<NotificationCb> on_batch_notify = std::nullopt);
NicSensor(Token token, const std::string& sensor_name,
nic_veeprom::NicTelemetryName telemetry_name,
SensorUnit sensor_unit,
const EntityCommonConfig& entity_common_config,
const ThresholdConfigs& threshold_configs,
const ReadingRangeConfigs& reading_range_configs,
const std::shared_ptr<boost::asio::io_context>& io_context,
const nic_veeprom::Accessor& accessor,
std::optional<NotificationCb> on_batch_notify = std::nullopt);
~NicSensor() override = default;
void RefreshOnceAsync(
absl::AnyInvocable<void(const std::shared_ptr<const SensorValue>&)>
callback) override;
protected:
absl::StatusOr<const std::shared_ptr<const SensorValue>> GetSensorValue() {
return accessor_.GetSensorValue(telemetry_name_);
}
private:
class Token {
private:
explicit Token() = default;
friend NicSensor;
};
const nic_veeprom::NicTelemetryName telemetry_name_;
const SensorUnit sensor_unit_;
std::shared_ptr<boost::asio::io_context> io_context_;
const nic_veeprom::Accessor& accessor_;
};
} // namespace milotic_tlbmc
#endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_NIC_SENSOR_H_