blob: 7e7f1e32204e60c286e329fde3832d3f3779a339 [file] [log] [blame]
#ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_FAN_TACH_H_
#define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_FAN_TACH_H_
#include <cstddef>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "absl/base/thread_annotations.h"
#include "absl/status/statusor.h"
#include "absl/synchronization/mutex.h"
#include "boost/asio.hpp" //NOLINT: boost::asio is commonly used in BMC
#include "boost/circular_buffer.hpp" //NOLINT: boost is commonly used in BMC
#include "entity_common_config.pb.h"
#include "fan_tach_config.pb.h"
#include "hal_common_config.pb.h"
#include "reading_range_config.pb.h"
#include "threshold_config.pb.h"
#include "tlbmc/hal/sysfs/hwmon.h"
#include "sensor.pb.h"
#include "tlbmc/sensors/fan_controller.h"
#include "tlbmc/sensors/ixc_hwmon_based_sensor.h"
#include "tlbmc/sensors/sensor.h"
namespace milotic_tlbmc {
class FanTachometer : public IXcHwmonBasedSensor {
private:
class Token;
public:
// Enables the PWM if not already enabled and returns a sensor that can be
// used to read the PWM from the device.
// Note:
// 1. The `io_context` must run only on a single thread.
static absl::StatusOr<std::shared_ptr<Sensor>> Create(
const FanTachConfig& config, const FanController& fan_controller,
const std::shared_ptr<boost::asio::io_context>& io_context,
const HwmonSysfs& hwmon_sysfs,
std::optional<NotificationCb> on_batch_notify = std::nullopt);
FanTachometer(Token token, FanTachType sensor_type,
const std::string& input_dev_path,
const std::string& sensor_name,
const HalCommonConfig& hwmon_common_config,
const ThresholdConfigs& threshold_configs,
const ReadingRangeConfigs& reading_range_configs,
const EntityCommonConfig& entity_common_config,
const std::shared_ptr<boost::asio::io_context>& io_context,
std::optional<NotificationCb> on_batch_notify,
const HwmonSysfs& hwmon_sysfs);
~FanTachometer() override = default;
void HandleRefreshResult(const boost::system::error_code& error,
size_t bytes_read) override
ABSL_LOCKS_EXCLUDED(sensor_data_mutex_);
protected:
FanTachometer() = default;
private:
class Token {
private:
explicit Token() = default;
friend FanTachometer;
};
const FanTachType sensor_type_ = TACH_SENSOR_TYPE_UNKNOWN;
const std::string sensor_name_;
};
} // namespace milotic_tlbmc
#endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_FAN_TACH_H_