| #ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_HAL_SYSFS_IIO_H_ |
| #define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_HAL_SYSFS_IIO_H_ |
| |
| #include <string> |
| |
| #include "absl/status/statusor.h" |
| #include "boost/filesystem.hpp" // NOLINT: boost::filesystem is commonly used in BMC |
| #include "sensor.pb.h" |
| |
| namespace milotic_tlbmc { |
| |
| struct IioSysfsConfig { |
| std::string iio_sysfs_path = "/sys/bus/iio/devices/"; |
| }; |
| |
| // The class is thread-safe. |
| class IioSysfs { |
| public: |
| // Default constructor for unit tests. |
| IioSysfs() : IioSysfs(IioSysfsConfig()) {} |
| |
| explicit IioSysfs(const IioSysfsConfig& config) : config_(config) {} |
| |
| virtual ~IioSysfs() = default; |
| |
| // Returns the sysfs sensor path of `channel_name`. One ADC device might have |
| // multiple channels, and `channel_name` here is the name of the file that |
| // stores the sensor reading of that channel under the device directory. |
| virtual absl::StatusOr<boost::filesystem::path> GetSensorPath( |
| const std::string& device_name, const std::string& channel_name) const; |
| |
| private: |
| // Returns the sysfs device directory path of `root_iio_device_name`. The |
| // input `root_iio_device_name` matches the content of the "name" file under |
| // the device directory. |
| virtual absl::StatusOr<boost::filesystem::path> GetIioDeviceDirectory( |
| const std::string& root_iio_device_name) const; |
| |
| const IioSysfsConfig config_; |
| }; |
| |
| } // namespace milotic_tlbmc |
| |
| #endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_HAL_SYSFS_IIO_H_ |