Compare commits
3 Commits
409ee7aa35
...
cb8cfd6da8
| Author | SHA1 | Date | |
|---|---|---|---|
| cb8cfd6da8 | |||
| 159d55c2a2 | |||
| fabcf5a146 |
20
CMakeLists.txt
Normal file
20
CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# Root cmake file sketch (might change it later)
|
||||||
|
# Author: Unai Blazquez
|
||||||
|
# License: GPL-3-or-later
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
project(azkoyen_ipc_test LANGUAGES CXX)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
# Core library
|
||||||
|
add_library(core
|
||||||
|
src/core/SysfsRead.cxx
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
|
|
||||||
|
#tests
|
||||||
|
enable_testing()
|
||||||
|
add_subdirectory(tests)
|
||||||
40
include/SysfsRead.hpp
Normal file
40
include/SysfsRead.hpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// 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:
|
||||||
|
std::filesystem::path m_path; // Path to the input file.
|
||||||
|
};
|
||||||
5
tests/test_sysfs_read.cxx
Normal file
5
tests/test_sysfs_read.cxx
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "SysfsRead.hpp"
|
||||||
Loading…
x
Reference in New Issue
Block a user