blob: 25031d0ed93cdf38822955c4888901436498d350 [file] [log] [blame]
#ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_FAN_CONTROLLER_H_
#define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_FAN_CONTROLLER_H_
#include <cstdint>
#include <memory>
#include <string_view>
#include <unordered_map>
#include "absl/status/statusor.h"
#include "boost/filesystem/path.hpp" //NOLINT: boost::filesystem::path is commonly used in BMC
#include "fan_controller_config.pb.h"
#include "i2c_common_config.pb.h"
#include "tlbmc/hal/sysfs/i2c.h"
namespace milotic_tlbmc {
class FanController {
private:
class Token;
public:
struct Tachometers {
boost::filesystem::path tach_input;
};
struct Pwm {
boost::filesystem::path pwm;
boost::filesystem::path pwm_enable;
};
// Load the device if not already loaded and returns the controller.
static absl::StatusOr<std::shared_ptr<FanController>> Create(
const FanControllerConfig& config, const I2cSysfs& i2c_sysfs);
// Returns the driver name for the given sensor type.
static absl::StatusOr<std::string_view> GetDriverName(
FanControllerType sensor_type);
// Returns the tachometers of the fan controller.
const std::unordered_map<uint32_t, Tachometers>& GetIndexToTachs() const {
return index_to_tachs_;
}
// Returns the pwms of the fan controller.
const std::unordered_map<uint32_t, Pwm>& GetIndexToPwms() const {
return index_to_pwms_;
}
bool ControllerHasSensor(const I2cCommonConfig& config) const {
return config.bus() == config_.i2c_common_config().bus() &&
config.address() == config_.i2c_common_config().address();
}
const I2cCommonConfig& GetI2cCommonConfig() const {
return config_.i2c_common_config();
}
FanController(Token token, const FanControllerConfig& config,
const std::unordered_map<uint32_t, Tachometers>& tachs,
const std::unordered_map<uint32_t, Pwm>& pwms);
protected:
FanController() = default;
private:
class Token {
private:
explicit Token() = default;
friend FanController;
};
const FanControllerConfig config_;
const std::unordered_map<uint32_t, Tachometers> index_to_tachs_;
const std::unordered_map<uint32_t, Pwm> index_to_pwms_;
};
} // namespace milotic_tlbmc
#endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_FAN_CONTROLLER_H_