New API class.

This commit is contained in:
XMRig 2019-03-30 00:16:01 +07:00
parent 9cb43f9883
commit dd036368e2
11 changed files with 178 additions and 74 deletions

View file

@ -43,10 +43,16 @@
#endif
#ifdef XMRIG_FEATURE_API
# include "api/Api.h"
#endif
class xmrig::ControllerPrivate
{
public:
inline ControllerPrivate(Process *process) :
api(nullptr),
config(nullptr),
network(nullptr),
process(process)
@ -55,11 +61,16 @@ public:
inline ~ControllerPrivate()
{
# ifdef XMRIG_FEATURE_API
delete api;
# endif
delete network;
delete config;
}
Api *api;
Config *config;
Network *network;
Process *process;
@ -79,6 +90,14 @@ xmrig::Controller::~Controller()
}
xmrig::Api *xmrig::Controller::api() const
{
assert(d_ptr->api != nullptr);
return d_ptr->api;
}
bool xmrig::Controller::isReady() const
{
return d_ptr->config && d_ptr->network;
@ -102,6 +121,10 @@ int xmrig::Controller::init()
return 1;
}
# ifdef XMRIG_FEATURE_API
d_ptr->api = new Api(this);
# endif
Platform::init(config()->userAgent());
Platform::setProcessPriority(d_ptr->config->priority());
@ -165,8 +188,22 @@ void xmrig::Controller::onNewConfig(IConfig *config)
}
void xmrig::Controller::start()
{
network()->connect();
# ifdef XMRIG_FEATURE_API
api()->start();
# endif
}
void xmrig::Controller::stop()
{
# ifdef XMRIG_FEATURE_API
api()->stop();
# endif
ConfigLoader::release();
delete d_ptr->network;

View file

@ -35,6 +35,7 @@ class StatsData;
namespace xmrig {
class Api;
class Config;
class ControllerPrivate;
class IControllerListener;
@ -48,12 +49,14 @@ public:
Controller(Process *process);
~Controller() override;
Api *api() const;
bool isReady() const;
Config *config() const;
int init();
Network *network() const;
void addListener(IControllerListener *listener);
void save();
void start();
void stop();
protected: