fix: build now succeded. Added logging capabilities also

This commit is contained in:
2026-03-10 17:26:32 +00:00
parent 36093e6c73
commit 5b6f20a70a
3 changed files with 77 additions and 26 deletions

View File

@@ -4,12 +4,14 @@
// Author: Unai Blazquez <unaibg2000@gmail.com>
#include <atomic>
#include <chrono>
#include <filesystem>
#include <functional>
#include <thread>
#include "SysfsRead.hpp"
using RandomFn = std::function<int()>;
using LogFn = std::function<void(const std::string&)>;
using SleepFn = std::function<void(std::chrono::milliseconds)>;
class Producer
{
@@ -17,11 +19,9 @@ class Producer
/// @brief Construct a Producer bound to a sysfs-like control file.
/// @param sysfs_path Path to the control file (e.g. "./fake_sysfs_input").
/// @param send_fn Function called whenever a new integer should be sent.
/// @param sleep_fn Stub for sleeping function, allows reducing sleep on
/// testing
Producer(const std::filesystem::path& sysfs_path,
std::function<void(int)> send_fn, RandomFn random_fn,
SleepFn sleep_fn = default_sleep);
LogFn log_fn = nullptr, SleepFn sleep_fn = default_sleep);
/// @brief Start the worker thread. Safe to call only once.
void start();
@@ -42,5 +42,7 @@ class Producer
{
std::this_thread::sleep_for(d);
}
LogFn m_log;
std::function<void(int)> m_send;
std::chrono::milliseconds compute_delay(SysfsStatus status) const;
};