forked from RiecoinTeam/rieMiner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
API.hpp
45 lines (38 loc) · 982 Bytes
/
API.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// (c) 2021-2022 Pttn (https://riecoin.dev/en/rieMiner)
#ifndef HEADER_API_hpp
#define HEADER_API_hpp
#include <thread>
#include "main.hpp"
#include "tools.hpp"
class Miner;
class Client;
class API {
bool _running;
std::thread _thread;
uint16_t _port;
std::shared_ptr<Miner> _miner;
std::shared_ptr<Client> _client;
void _process();
public:
API(const uint16_t port) : _running(false), _port(port), _miner(nullptr), _client(nullptr) {};
bool running() {return _running;}
void start() {
if (_running)
logger.log("The API is already running\n"s, MessageType::ERROR);
else {
_running = true;
_thread = std::thread(&API::_process, this);
}
}
void stop() {
if (!_running)
logger.log("The API is already stopped\n"s, MessageType::ERROR);
else {
_running = false;
_thread.join();
}
}
void setMiner(const std::shared_ptr<Miner> &miner) {_miner = miner;}
void setClient(const std::shared_ptr<Client> &client) {_client = client;}
};
#endif