mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-25 03:56:00 +00:00
Added IConsoleListener
This commit is contained in:
parent
583f45e2da
commit
776f77a8d4
10 changed files with 104 additions and 5 deletions
|
@ -14,6 +14,7 @@ set(HEADERS
|
||||||
src/Console.h
|
src/Console.h
|
||||||
src/Cpu.h
|
src/Cpu.h
|
||||||
src/interfaces/IClientListener.h
|
src/interfaces/IClientListener.h
|
||||||
|
src/interfaces/IConsoleListener.h
|
||||||
src/interfaces/IJobResultListener.h
|
src/interfaces/IJobResultListener.h
|
||||||
src/interfaces/ILogBackend.h
|
src/interfaces/ILogBackend.h
|
||||||
src/interfaces/IStrategy.h
|
src/interfaces/IStrategy.h
|
||||||
|
|
35
src/App.cpp
35
src/App.cpp
|
@ -64,7 +64,7 @@ App::App(int argc, char **argv) :
|
||||||
|
|
||||||
if (!m_options->background()) {
|
if (!m_options->background()) {
|
||||||
Log::add(new ConsoleLog(m_options->colors()));
|
Log::add(new ConsoleLog(m_options->colors()));
|
||||||
m_console = new Console();
|
m_console = new Console(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_options->logFile()) {
|
if (m_options->logFile()) {
|
||||||
|
@ -125,6 +125,39 @@ int App::exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void App::onConsoleCommand(char command)
|
||||||
|
{
|
||||||
|
switch (command) {
|
||||||
|
case 'h':
|
||||||
|
case 'H':
|
||||||
|
Workers::printHashrate(true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'p':
|
||||||
|
case 'P':
|
||||||
|
LOG_INFO(m_options->colors() ? "\x1B[01;33mpaused\x1B[0m, press \x1B[01;35mr\x1B[0m to resume" : "paused, press 'r' to resume");
|
||||||
|
Workers::setEnabled(false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'r':
|
||||||
|
case 'R':
|
||||||
|
if (!Workers::isEnabled()) {
|
||||||
|
LOG_INFO(m_options->colors() ? "\x1B[01;32mresumed" : "resumed");
|
||||||
|
Workers::setEnabled(true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
LOG_WARN("Ctrl+C received, exiting");
|
||||||
|
close();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void App::close()
|
void App::close()
|
||||||
{
|
{
|
||||||
m_network->stop();
|
m_network->stop();
|
||||||
|
|
|
@ -28,12 +28,15 @@
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include "interfaces/IConsoleListener.h"
|
||||||
|
|
||||||
|
|
||||||
class Console;
|
class Console;
|
||||||
class Network;
|
class Network;
|
||||||
class Options;
|
class Options;
|
||||||
|
|
||||||
|
|
||||||
class App
|
class App : public IConsoleListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
App(int argc, char **argv);
|
App(int argc, char **argv);
|
||||||
|
@ -41,6 +44,9 @@ public:
|
||||||
|
|
||||||
int exec();
|
int exec();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void onConsoleCommand(char command) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void background();
|
void background();
|
||||||
void close();
|
void close();
|
||||||
|
|
|
@ -23,9 +23,11 @@
|
||||||
|
|
||||||
|
|
||||||
#include "Console.h"
|
#include "Console.h"
|
||||||
|
#include "interfaces/IConsoleListener.h"
|
||||||
|
|
||||||
|
|
||||||
Console::Console()
|
Console::Console(IConsoleListener *listener)
|
||||||
|
: m_listener(listener)
|
||||||
{
|
{
|
||||||
m_tty.data = this;
|
m_tty.data = this;
|
||||||
uv_tty_init(uv_default_loop(), &m_tty, 0, 1);
|
uv_tty_init(uv_default_loop(), &m_tty, 0, 1);
|
||||||
|
@ -50,6 +52,6 @@ void Console::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nread == 1) {
|
if (nread == 1) {
|
||||||
printf("%c\n", buf->base[0]);
|
static_cast<Console*>(stream->data)->m_listener->onConsoleCommand(buf->base[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,16 +28,20 @@
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
|
||||||
|
|
||||||
|
class IConsoleListener;
|
||||||
|
|
||||||
|
|
||||||
class Console
|
class Console
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Console();
|
Console(IConsoleListener *listener);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
|
static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
|
||||||
static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
|
static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
|
||||||
|
|
||||||
char m_buf[1];
|
char m_buf[1];
|
||||||
|
IConsoleListener *m_listener;
|
||||||
uv_tty_t m_tty;
|
uv_tty_t m_tty;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
37
src/interfaces/IConsoleListener.h
Normal file
37
src/interfaces/IConsoleListener.h
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/* XMRig
|
||||||
|
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||||
|
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||||
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
|
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ICONSOLELISTENER_H__
|
||||||
|
#define __ICONSOLELISTENER_H__
|
||||||
|
|
||||||
|
|
||||||
|
class IConsoleListener
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~IConsoleListener() {}
|
||||||
|
|
||||||
|
virtual void onConsoleCommand(char command) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // __ICONSOLELISTENER_H__
|
|
@ -69,6 +69,10 @@ void DoubleWorker::start()
|
||||||
}
|
}
|
||||||
while (Workers::isPaused());
|
while (Workers::isPaused());
|
||||||
|
|
||||||
|
if (Workers::sequence() == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
consumeJob();
|
consumeJob();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,10 @@ void SingleWorker::start()
|
||||||
}
|
}
|
||||||
while (Workers::isPaused());
|
while (Workers::isPaused());
|
||||||
|
|
||||||
|
if (Workers::sequence() == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
consumeJob();
|
consumeJob();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,12 @@ Job Workers::job()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Workers::printHashrate(bool detail)
|
||||||
|
{
|
||||||
|
m_hashrate->print();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Workers::setEnabled(bool enabled)
|
void Workers::setEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
if (m_enabled == enabled) {
|
if (m_enabled == enabled) {
|
||||||
|
@ -121,6 +127,7 @@ void Workers::stop()
|
||||||
m_hashrate->stop();
|
m_hashrate->stop();
|
||||||
|
|
||||||
uv_close(reinterpret_cast<uv_handle_t*>(&m_async), nullptr);
|
uv_close(reinterpret_cast<uv_handle_t*>(&m_async), nullptr);
|
||||||
|
m_paused = 0;
|
||||||
m_sequence = 0;
|
m_sequence = 0;
|
||||||
|
|
||||||
for (size_t i = 0; i < m_workers.size(); ++i) {
|
for (size_t i = 0; i < m_workers.size(); ++i) {
|
||||||
|
|
|
@ -43,6 +43,7 @@ class Workers
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Job job();
|
static Job job();
|
||||||
|
static void printHashrate(bool detail);
|
||||||
static void setEnabled(bool enabled);
|
static void setEnabled(bool enabled);
|
||||||
static void setJob(const Job &job);
|
static void setJob(const Job &job);
|
||||||
static void start(int64_t affinity);
|
static void start(int64_t affinity);
|
||||||
|
|
Loading…
Reference in a new issue