-
Notifications
You must be signed in to change notification settings - Fork 19
/
API.hpp
43 lines (35 loc) · 922 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
// (c) 2021-present Pttn (https://riecoin.xyz/rieMiner)
#ifndef HEADER_API_hpp
#define HEADER_API_hpp
#include <thread>
#include "Client.hpp"
class API {
bool _running{false};
std::thread _thread;
uint16_t _port;
std::shared_ptr<Client> _client{nullptr};
double _uptime{0.}, _cps{0.}, _r{0.}, _bpd{0.};
void _process();
public:
API(const uint16_t port) : _port(port) {};
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 setClient(const std::shared_ptr<Client> &client) {_client = client;}
void setStats(const double, const double, const double, const double);
};
#endif