2015-10-16 02:46:17 +02:00
|
|
|
#pragma once
|
|
|
|
#ifndef MESSMER_CPPUTILS_RANDOM_RANDOMGENERATORTHREAD_H
|
|
|
|
#define MESSMER_CPPUTILS_RANDOM_RANDOMGENERATORTHREAD_H
|
|
|
|
|
2015-11-07 09:00:25 +01:00
|
|
|
#include "../thread/LoopThread.h"
|
2015-10-16 02:46:17 +02:00
|
|
|
#include "ThreadsafeRandomDataBuffer.h"
|
|
|
|
#include <cryptopp/cryptopp/osrng.h>
|
|
|
|
|
|
|
|
namespace cpputils {
|
|
|
|
//TODO Test
|
2015-11-27 14:05:30 +01:00
|
|
|
class RandomGeneratorThread final {
|
2015-10-16 02:46:17 +02:00
|
|
|
public:
|
|
|
|
RandomGeneratorThread(ThreadsafeRandomDataBuffer *buffer, size_t minSize, size_t maxSize);
|
2015-10-28 15:00:24 +01:00
|
|
|
|
|
|
|
void start();
|
2015-10-16 02:46:17 +02:00
|
|
|
|
|
|
|
private:
|
2015-11-12 22:07:20 +01:00
|
|
|
bool _loopIteration();
|
2015-10-16 02:46:17 +02:00
|
|
|
Data _generateRandomData(size_t size);
|
|
|
|
|
|
|
|
CryptoPP::AutoSeededRandomPool _randomGenerator;
|
|
|
|
ThreadsafeRandomDataBuffer *_buffer;
|
|
|
|
size_t _minSize;
|
|
|
|
size_t _maxSize;
|
|
|
|
|
2015-10-28 15:00:24 +01:00
|
|
|
//This has to be the last member, because it has to be destructed first - otherwise the thread could still be
|
|
|
|
//running while the RandomGeneratorThread object is invalid.
|
|
|
|
LoopThread _thread;
|
|
|
|
|
2015-10-16 02:46:17 +02:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(RandomGeneratorThread);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|