Update base.

This commit is contained in:
XMRig 2020-04-29 14:17:33 +07:00
parent b38046db46
commit 46e49cde0b
No known key found for this signature in database
GPG key ID: 446A53638BE94409
40 changed files with 162 additions and 244 deletions

View file

@ -52,7 +52,7 @@ bool xmrig::Arguments::hasArg(const char *name) const
}
const char *xmrig::Arguments::value(const char *key) const
const char *xmrig::Arguments::value(const char *key1, const char *key2) const
{
const size_t size = m_data.size();
if (size < 3) {
@ -60,7 +60,7 @@ const char *xmrig::Arguments::value(const char *key) const
}
for (size_t i = 1; i < size - 1; ++i) {
if (m_data[i] == key) {
if (m_data[i] == key1 || (key2 && m_data[i] == key2)) {
return m_data[i + 1];
}
}

View file

@ -41,7 +41,7 @@ public:
Arguments(int argc, char **argv);
bool hasArg(const char *name) const;
const char *value(const char *key) const;
const char *value(const char *key1, const char *key2 = nullptr) const;
inline char **argv() const { return m_argv; }
inline const std::vector<String> &data() const { return m_data; }

View file

@ -23,11 +23,11 @@
*/
#include <ctype.h>
#include "base/tools/String.h"
#include "rapidjson/document.h"
#include "3rdparty/rapidjson/document.h"
#include <cctype>
xmrig::String::String(const char *str) :

View file

@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/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
@ -26,13 +26,13 @@
#define XMRIG_STRING_H
#include "3rdparty/rapidjson/fwd.h"
#include <utility>
#include <vector>
#include "rapidjson/fwd.h"
namespace xmrig {
@ -85,11 +85,11 @@ public:
rapidjson::Value toJSON() const;
rapidjson::Value toJSON(rapidjson::Document &doc) const;
std::vector<xmrig::String> split(char sep) const;
std::vector<String> split(char sep) const;
String &toLower();
String &toUpper();
static String join(const std::vector<xmrig::String> &vec, char sep);
static String join(const std::vector<String> &vec, char sep);
private:
void copy(const char *str);

View file

@ -1,12 +1,6 @@
/* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/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
@ -23,22 +17,20 @@
*/
#include "base/tools/Timer.h"
#include "base/kernel/interfaces/ITimerListener.h"
#include "base/tools/Handle.h"
#include "base/tools/Timer.h"
xmrig::Timer::Timer(ITimerListener *listener) :
m_listener(listener),
m_timer(nullptr)
m_listener(listener)
{
init();
}
xmrig::Timer::Timer(ITimerListener *listener, uint64_t timeout, uint64_t repeat) :
m_listener(listener),
m_timer(nullptr)
m_listener(listener)
{
init();
start(timeout, repeat);
@ -63,6 +55,15 @@ void xmrig::Timer::setRepeat(uint64_t repeat)
}
void xmrig::Timer::singleShot(uint64_t timeout, int id)
{
m_id = id;
stop();
start(timeout, 0);
}
void xmrig::Timer::start(uint64_t timeout, uint64_t repeat)
{
uv_timer_start(m_timer, onTimer, timeout, repeat);
@ -71,6 +72,7 @@ void xmrig::Timer::start(uint64_t timeout, uint64_t repeat)
void xmrig::Timer::stop()
{
setRepeat(0);
uv_timer_stop(m_timer);
}
@ -85,7 +87,7 @@ void xmrig::Timer::init()
void xmrig::Timer::onTimer(uv_timer_t *handle)
{
const Timer *timer = static_cast<Timer *>(handle->data);
const auto timer = static_cast<Timer *>(handle->data);
timer->m_listener->onTimer(timer);
}

View file

@ -1,12 +1,6 @@
/* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/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
@ -26,10 +20,13 @@
#define XMRIG_TIMER_H
#include <stdint.h>
using uv_timer_t = struct uv_timer_s;
typedef struct uv_timer_s uv_timer_t;
#include "base/tools/Object.h"
#include <cstdint>
namespace xmrig {
@ -41,12 +38,17 @@ class ITimerListener;
class Timer
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Timer);
Timer(ITimerListener *listener);
Timer(ITimerListener *listener, uint64_t timeout, uint64_t repeat);
~Timer();
inline int id() const { return m_id; }
uint64_t repeat() const;
void setRepeat(uint64_t repeat);
void singleShot(uint64_t timeout, int id = 0);
void start(uint64_t timeout, uint64_t repeat);
void stop();
@ -55,8 +57,9 @@ private:
static void onTimer(uv_timer_t *handle);
int m_id = 0;
ITimerListener *m_listener;
uv_timer_t *m_timer;
uv_timer_t *m_timer = nullptr;
};