Move static algo name conversions to Pool class.

This commit is contained in:
XMRig 2018-04-11 06:39:24 +07:00
parent 36ef254c73
commit 1ebaf677e0
5 changed files with 49 additions and 47 deletions

View file

@ -39,25 +39,6 @@
#include "xmrig.h"
static const char *algoNames[] = {
"cryptonight",
"cryptonight-lite",
"cryptonight-heavy"
};
static const char *algoNamesShort[] = {
"cn",
"cn-lite",
"cn-heavy"
};
#if defined(_WIN32) && !defined(strcasecmp)
# define strcasecmp _stricmp
#endif
xmrig::CommonConfig::CommonConfig() :
m_algorithm(CRYPTONIGHT),
m_adjusted(false),
@ -93,12 +74,6 @@ xmrig::CommonConfig::~CommonConfig()
}
const char *xmrig::CommonConfig::algoName(Algo algorithm)
{
return algoNames[algorithm];
}
bool xmrig::CommonConfig::adjust()
{
if (m_adjusted) {
@ -353,21 +328,5 @@ bool xmrig::CommonConfig::parseInt(int key, int arg)
void xmrig::CommonConfig::setAlgo(const char *algo)
{
if (strcasecmp(algo, "cryptonight-light") == 0) {
fprintf(stderr, "Algorithm \"cryptonight-light\" is deprecated, use \"cryptonight-lite\" instead\n");
m_algorithm = CRYPTONIGHT_LITE;
return;
}
const size_t size = sizeof(algoNames) / sizeof(algoNames[0]);
assert(size == (sizeof(algoNamesShort) / sizeof(algoNamesShort[0])));
for (size_t i = 0; i < size; i++) {
if (strcasecmp(algo, algoNames[i]) == 0 || strcasecmp(algo, algoNamesShort[i]) == 0) {
m_algorithm = static_cast<Algo>(i);
break;
}
}
m_algorithm = Pool::algorithm(algo);
}

View file

@ -30,8 +30,8 @@
#include "core/utils/c_str.h"
#include "interfaces/IConfig.h"
#include "xmrig.h"
#include "net/Pool.h"
#include "xmrig.h"
namespace xmrig {
@ -43,15 +43,13 @@ public:
CommonConfig();
~CommonConfig();
static const char *algoName(Algo algorithm);
inline Algo algorithm() const { return m_algorithm; }
inline bool isApiIPv6() const { return m_apiIPv6; }
inline bool isApiRestricted() const { return m_apiRestricted; }
inline bool isBackground() const { return m_background; }
inline bool isColors() const { return m_colors; }
inline bool isSyslog() const { return m_syslog; }
inline const char *algoName() const { return algoName(m_algorithm); }
inline const char *algoName() const { return Pool::algoName(m_algorithm); }
inline const char *apiToken() const { return m_apiToken.data(); }
inline const char *apiWorkerId() const { return m_apiWorkerId.data(); }
inline const char *logFile() const { return m_logFile.data(); }

View file

@ -36,6 +36,20 @@
#endif
static const char *algoNames[] = {
"cryptonight",
"cryptonight-lite",
"cryptonight-heavy"
};
static const char *algoNamesShort[] = {
"cn",
"cn-lite",
"cn-heavy"
};
Pool::Pool() :
m_nicehash(false),
m_keepAlive(0),
@ -89,6 +103,34 @@ Pool::Pool(const char *host, uint16_t port, const char *user, const char *passwo
}
const char *Pool::algoName(xmrig::Algo algorithm)
{
return algoNames[algorithm];
}
xmrig::Algo Pool::algorithm(const char *algo)
{
if (strcasecmp(algo, "cryptonight-light") == 0) {
fprintf(stderr, "Algorithm \"cryptonight-light\" is deprecated, use \"cryptonight-lite\" instead\n");
return xmrig::CRYPTONIGHT_LITE;
}
const size_t size = sizeof(algoNames) / sizeof(algoNames[0]);
assert(size == (sizeof(algoNamesShort) / sizeof(algoNamesShort[0])));
for (size_t i = 0; i < size; i++) {
if (strcasecmp(algo, algoNames[i]) == 0 || strcasecmp(algo, algoNamesShort[i]) == 0) {
return static_cast<xmrig::Algo>(i);
}
}
return xmrig::CRYPTONIGHT;
}
bool Pool::parse(const char *url)
{
assert(url != nullptr);

View file

@ -51,6 +51,9 @@ public:
xmrig::Variant variant = xmrig::VARIANT_AUTO
);
static const char *algoName(xmrig::Algo algorithm);
static xmrig::Algo algorithm(const char *algo);
inline bool isNicehash() const { return m_nicehash; }
inline bool isValid() const { return !m_host.isNull() && m_port > 0; }
inline const char *host() const { return m_host.data(); }

View file

@ -204,7 +204,7 @@ rapidjson::Value xmrig::CpuThread::toAPI(rapidjson::Document &doc) const
auto &allocator = doc.GetAllocator();
obj.AddMember("type", "cpu", allocator);
obj.AddMember("algo", rapidjson::StringRef(CommonConfig::algoName(algorithm())), allocator);
obj.AddMember("algo", rapidjson::StringRef(Pool::algoName(algorithm())), allocator);
obj.AddMember("av", m_av, allocator);
obj.AddMember("low_power_mode", multiway(), allocator);
obj.AddMember("affine_to_cpu", affinity(), allocator);