| #ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_HWMON_INPUT_DEVICE_H_ |
| #define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_HWMON_INPUT_DEVICE_H_ |
| |
| #include <array> |
| #include <cstddef> |
| #include <fstream> |
| #include <memory> |
| #include <string> |
| #include <string_view> |
| |
| #include "absl/functional/any_invocable.h" |
| #include "boost/asio.hpp" // NOLINT: boost::asio is commonly used in BMC |
| #include "boost/asio/error.hpp" // NOLINT |
| #include "boost/asio/random_access_file.hpp" // NOLINT: boost::asio is commonly used in BMC |
| #include "boost/filesystem.hpp" // NOLINT: boost::filesystem is commonly used in BMC |
| #include "boost/filesystem/operations.hpp" // NOLINT |
| #include "boost/system/detail/error_code.hpp" // NOLINT: boost::asio is commonly used in BMC |
| |
| namespace milotic_tlbmc { |
| |
| // This class abstracts the input device reading for Hwmon. We want to use |
| // iouring if possible but default to ifstream otherwise. |
| class HwmonInputDevice { |
| public: |
| HwmonInputDevice(const std::shared_ptr<boost::asio::io_context>& io_context, |
| std::string_view input_dev_path); |
| |
| virtual void ReadAndProcess( |
| absl::AnyInvocable<void(const boost::system::error_code&, size_t)> |
| callback, |
| std::array<char, 128>& read_buffer); |
| |
| virtual ~HwmonInputDevice(); |
| |
| protected: |
| std::shared_ptr<boost::asio::io_context> io_context_; |
| std::string input_dev_path_; |
| std::shared_ptr<boost::asio::random_access_file> io_uring_input_device_; |
| std::ifstream ifstream_input_device_; |
| }; |
| |
| } // namespace milotic_tlbmc |
| |
| #endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_HWMON_INPUT_DEVICE_H_ |