Refactor mining pool stats fetch to a class
This commit is contained in:
parent
c91428dd5f
commit
ac13098824
6 changed files with 100 additions and 88 deletions
|
@ -2,18 +2,44 @@
|
|||
|
||||
#include <Arduino.h>
|
||||
#include <HTTPClient.h>
|
||||
#include "mining_pool/pool_factory.hpp"
|
||||
#include <utils.hpp>
|
||||
#include <memory>
|
||||
|
||||
#include "lib/config.hpp"
|
||||
#include "lib/shared.hpp"
|
||||
#include "lib/mining_pool/mining_pool_interface.hpp"
|
||||
#include "mining_pool/pool_factory.hpp"
|
||||
|
||||
extern TaskHandle_t miningPoolStatsFetchTaskHandle;
|
||||
class MiningPoolStatsFetch {
|
||||
public:
|
||||
static MiningPoolStatsFetch& getInstance() {
|
||||
static MiningPoolStatsFetch instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void setupMiningPoolStatsFetchTask();
|
||||
void taskMiningPoolStatsFetch(void *pvParameters);
|
||||
void setup();
|
||||
std::string getHashRate() const;
|
||||
int getDailyEarnings() const;
|
||||
TaskHandle_t getTaskHandle() const { return taskHandle; }
|
||||
static void taskWrapper(void* pvParameters);
|
||||
static void downloadLogoTaskWrapper(void* pvParameters);
|
||||
|
||||
// Pool interface methods
|
||||
MiningPoolInterface* getPool();
|
||||
const MiningPoolInterface* getPool() const;
|
||||
LogoData getLogo() const;
|
||||
|
||||
std::string getMiningPoolStatsHashRate();
|
||||
int getMiningPoolStatsDailyEarnings();
|
||||
private:
|
||||
MiningPoolStatsFetch() = default;
|
||||
~MiningPoolStatsFetch() = default;
|
||||
MiningPoolStatsFetch(const MiningPoolStatsFetch&) = delete;
|
||||
MiningPoolStatsFetch& operator=(const MiningPoolStatsFetch&) = delete;
|
||||
|
||||
std::unique_ptr<MiningPoolInterface>& getMiningPool();
|
||||
LogoData getMiningPoolLogo();
|
||||
void task();
|
||||
void downloadLogoTask();
|
||||
|
||||
TaskHandle_t taskHandle = nullptr;
|
||||
std::string hashrate;
|
||||
int dailyEarnings = 0;
|
||||
std::unique_ptr<MiningPoolInterface> currentPool;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue