2021-12-13 05:59:27 +01:00
|
|
|
#ifndef FORTUNA_SEED_FILE_MANAGER_H
|
|
|
|
#define FORTUNA_SEED_FILE_MANAGER_H
|
|
|
|
|
|
|
|
#include "accumulator.h"
|
|
|
|
#include "do_task.h"
|
|
|
|
|
2022-01-21 05:32:23 +01:00
|
|
|
#include <atomic>
|
2022-01-09 11:58:38 +01:00
|
|
|
#include <chrono>
|
2022-01-21 05:32:23 +01:00
|
|
|
#include <mutex>
|
2022-01-09 11:58:38 +01:00
|
|
|
#include <string>
|
|
|
|
|
2021-12-13 05:59:27 +01:00
|
|
|
namespace fortuna {
|
|
|
|
|
|
|
|
class SeedFileManager {
|
|
|
|
public:
|
2022-01-10 04:25:03 +01:00
|
|
|
struct conf {
|
2022-01-09 11:58:38 +01:00
|
|
|
// std::chrono::minutes write_interval{10};
|
2022-01-23 20:27:14 +01:00
|
|
|
// 10 minutes (as the standard recommends) is a lot, go with 10s
|
|
|
|
const std::chrono::seconds write_interval{10};
|
2022-02-07 23:16:03 +01:00
|
|
|
std::string seed_f_path{"/var/tmp/.fortuna.seed"};
|
2022-01-20 05:36:06 +01:00
|
|
|
std::size_t seed_f_length{64};
|
2021-12-13 05:59:27 +01:00
|
|
|
|
2022-02-03 00:49:40 +01:00
|
|
|
conf(){}
|
2021-12-13 05:59:27 +01:00
|
|
|
};
|
|
|
|
|
2022-01-21 05:35:47 +01:00
|
|
|
auto is_job_running() const -> bool;
|
2022-01-09 11:58:38 +01:00
|
|
|
auto do_stuff() -> void;
|
2022-01-23 20:18:59 +01:00
|
|
|
auto get_write_interval() const -> std::chrono::seconds;
|
2022-01-09 11:58:38 +01:00
|
|
|
|
2022-01-22 18:36:51 +01:00
|
|
|
explicit SeedFileManager(std::shared_ptr<fortuna::accumulator::Accumulator>
|
|
|
|
accumulator) noexcept;
|
2022-01-09 11:58:38 +01:00
|
|
|
~SeedFileManager() noexcept;
|
|
|
|
|
|
|
|
protected:
|
2022-01-21 05:32:23 +01:00
|
|
|
auto set_job_running(bool) -> void;
|
2021-12-29 04:51:40 +01:00
|
|
|
|
2021-12-13 05:59:27 +01:00
|
|
|
private:
|
|
|
|
const conf config;
|
2022-01-21 05:32:23 +01:00
|
|
|
mutable std::recursive_mutex mtx;
|
|
|
|
std::atomic<bool> IS_RUNNING{false};
|
2021-12-13 05:59:27 +01:00
|
|
|
DoTask do_task;
|
2022-01-22 18:36:51 +01:00
|
|
|
std::shared_ptr<fortuna::accumulator::Accumulator> _p_accumulator;
|
2021-12-13 05:59:27 +01:00
|
|
|
|
2022-01-20 05:36:06 +01:00
|
|
|
auto seed_file_exists() const -> bool;
|
2021-12-13 05:59:27 +01:00
|
|
|
auto write_seed_file() -> void;
|
|
|
|
auto update_seed_file() -> void;
|
|
|
|
|
|
|
|
}; // class SeedFileManager
|
|
|
|
|
|
|
|
} // namespace fortuna
|
|
|
|
|
|
|
|
#endif // FORTUNA_SEED_FILE_MANAGER_H
|