accumulator: move logic to source file
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-01-10 06:23:26 +01:00
parent ebcc4f87d5
commit ebb1e46e1c
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 36 additions and 24 deletions

View File

@ -2,6 +2,7 @@
#define FORTUNA_ACCUMULATOR_CPP
#include "accumulator.h"
#include <chrono>
#include <thread>
@ -17,6 +18,31 @@ Accumulator::Accumulator() noexcept {
}
Accumulator::~Accumulator() noexcept {};
auto Accumulator::set_gen(fortuna::generator::Generator& gen) -> void {
this->Gen = std::move(&gen);
}
auto Accumulator::get_random_data(uint n_bytes) -> std::string {
std::string data{""};
try {
data = this->Gen->generate_random_data(n_bytes);
}
catch (std::exception& e) {
fmt::print("{}", e.what());
}
return data;
}
auto Accumulator::call_reseed(const std::string& seed) -> void {
try {
this->Gen->reseed(seed);
}
catch (std::exception& e) {
fmt::print("{}", e.what());
}
}
} // namespace accumulator
} // namespace fortuna

View File

@ -4,7 +4,9 @@
#include "event_adder_impl.h"
#include "generator.h"
#include "pool.h"
#include <fmt/core.h>
#include <algorithm>
#include <exception>
@ -13,7 +15,7 @@ namespace accumulator {
class Accumulator {
private:
fortuna::generator::Generator *Gen;
fortuna::generator::Generator* Gen;
protected:
uint src_count{0};
@ -29,27 +31,11 @@ public:
[[maybe_unused]] bool scheduled;
}
auto set_gen(fortuna::generator::Generator& Gen) -> void {
this->Gen = std::move(&Gen);
}
auto set_gen(fortuna::generator::Generator& Gen) -> void;
auto get_random_data(uint n_bytes) -> std::string {
std::string data{""};
try {
data = this->Gen->generate_random_data(n_bytes);
} catch(std::exception& e) {
fmt::print("{}", e.what());
}
return data;
}
auto get_random_data(uint n_bytes) -> std::string;
auto call_reseed(const std::string& seed) -> void {
try {
this->Gen->reseed(seed);
} catch(std::exception& e) {
fmt::print("{}", e.what());
}
}
auto call_reseed(const std::string& seed) -> void;
auto wait_for(uint milliseconds) -> void;
@ -66,9 +52,9 @@ public:
Accumulator() noexcept;
~Accumulator() noexcept;
}; //class Accumulator
}; // class Accumulator
} //namespace accumulator
} //namespace fortuna
} // namespace accumulator
} // namespace fortuna
#endif//FORTUNA_ACCUMULATOR_H
#endif // FORTUNA_ACCUMULATOR_H