Add class Timer.
This commit is contained in:
parent
bbf0d11a51
commit
9a6a5a94b5
13 changed files with 271 additions and 73 deletions
|
@ -35,7 +35,7 @@
|
|||
#include "base/net/stratum/Client.h"
|
||||
#include "base/net/stratum/SubmitResult.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
#include "base/tools/Handle.h"
|
||||
#include "base/tools/Timer.h"
|
||||
#include "common/log/Log.h"
|
||||
#include "core/Config.h"
|
||||
#include "core/Controller.h"
|
||||
|
@ -58,16 +58,13 @@ xmrig::Network::Network(Controller *controller) :
|
|||
m_donate = new DonateStrategy(controller->config()->donateLevel(), pools.data().front().user(), controller->config()->algorithm().algo(), this);
|
||||
}
|
||||
|
||||
m_timer = new uv_timer_t;
|
||||
m_timer->data = this;
|
||||
uv_timer_init(uv_default_loop(), m_timer);
|
||||
uv_timer_start(m_timer, Network::onTick, kTickInterval, kTickInterval);
|
||||
m_timer = new Timer(this, kTickInterval, kTickInterval);
|
||||
}
|
||||
|
||||
|
||||
xmrig::Network::~Network()
|
||||
{
|
||||
Handle::close(m_timer);
|
||||
delete m_timer;
|
||||
|
||||
if (m_donate) {
|
||||
delete m_donate;
|
||||
|
@ -215,9 +212,3 @@ void xmrig::Network::tick()
|
|||
Api::tick(m_state);
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Network::onTick(uv_timer_t *handle)
|
||||
{
|
||||
static_cast<Network*>(handle->data)->tick();
|
||||
}
|
||||
|
|
|
@ -27,11 +27,11 @@
|
|||
|
||||
|
||||
#include <vector>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "api/NetworkState.h"
|
||||
#include "base/kernel/interfaces/IStrategyListener.h"
|
||||
#include "base/kernel/interfaces/ITimerListener.h"
|
||||
#include "common/interfaces/IControllerListener.h"
|
||||
#include "interfaces/IJobResultListener.h"
|
||||
|
||||
|
@ -43,7 +43,7 @@ class Controller;
|
|||
class IStrategy;
|
||||
|
||||
|
||||
class Network : public IJobResultListener, public IStrategyListener, public IControllerListener
|
||||
class Network : public IJobResultListener, public IStrategyListener, public IControllerListener, public ITimerListener
|
||||
{
|
||||
public:
|
||||
Network(Controller *controller);
|
||||
|
@ -52,6 +52,8 @@ public:
|
|||
void connect();
|
||||
|
||||
protected:
|
||||
inline void onTimer(const Timer *) override { tick(); }
|
||||
|
||||
void onActive(IStrategy *strategy, Client *client) override;
|
||||
void onConfigChanged(Config *config, Config *previousConfig) override;
|
||||
void onJob(IStrategy *strategy, Client *client, const Job &job) override;
|
||||
|
@ -66,12 +68,10 @@ private:
|
|||
void setJob(Client *client, const Job &job, bool donate);
|
||||
void tick();
|
||||
|
||||
static void onTick(uv_timer_t *handle);
|
||||
|
||||
IStrategy *m_donate;
|
||||
IStrategy *m_strategy;
|
||||
NetworkState m_state;
|
||||
uv_timer_t *m_timer;
|
||||
Timer *m_timer;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue