45 lines
1.3 KiB
C++
45 lines
1.3 KiB
C++
// SysfsRead.hpp
|
|
//
|
|
// SPDX-License-Identifier GPL-3.0-or-later
|
|
// Author: Unai Blazquez Gomez <unaibg2000@gmail.com>
|
|
|
|
#pragma once
|
|
|
|
#include <filesystem>
|
|
|
|
enum class SysfsStatus
|
|
{
|
|
/// @brief File cannot be opened or does not exist.
|
|
Unreachable,
|
|
/// @brief File exists but is just empty.
|
|
Empty,
|
|
/// @brief File content indicates taht production is enabled (e.g. "1")
|
|
Enabled,
|
|
/// @brief File requests a cooldown ("error: temp too high")
|
|
ErrorTempTooHigh,
|
|
/// @brief File contains an UnexpectedValue; producer must not send.
|
|
UnexpectedValue
|
|
};
|
|
|
|
class SysfsReader
|
|
{
|
|
public:
|
|
/// @brief Construct a SysfsReader bound to a specific input file path.
|
|
/// @param input_path Path to the sysfs-like input file.
|
|
explicit SysfsReader(const std::filesystem::path& input_path);
|
|
|
|
/// @brief Read and interpret the current status of the input file.
|
|
///
|
|
/// This function never throws on common I/O errors; instead it reports them
|
|
/// via the SysfsStatus enum.
|
|
/// @return Interpreted status of the input file
|
|
SysfsStatus read_status() const;
|
|
|
|
private:
|
|
/// @brief Helper method for trimming trailing whitespaces and
|
|
/// newline indicators
|
|
/// @param String from the m_path file
|
|
static void trim_in_place(std::string& string);
|
|
std::filesystem::path m_path; // Path to the input file.
|
|
};
|