Move dry-run option to common code.

This commit is contained in:
XMRig 2018-06-05 11:48:31 +07:00
parent 48a214c3f1
commit dba78717fa
4 changed files with 25 additions and 23 deletions

View file

@ -44,6 +44,7 @@ xmrig::CommonConfig::CommonConfig() :
m_apiRestricted(true),
m_background(false),
m_colors(true),
m_dryRun(false),
m_syslog(false),
# ifdef XMRIG_PROXY_PROJECT
@ -172,9 +173,15 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable)
case ApiIPv6Key: /* ipv6 */
m_apiIPv6 = enable;
break;
case ApiRestrictedKey: /* restricted */
m_apiRestricted = enable;
break;
case IConfig::DryRunKey: /* --dry-run */
m_dryRun = enable;
break;
default:
break;
@ -259,6 +266,7 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg)
case KeepAliveKey: /* --keepalive */
case NicehashKey: /* --nicehash */
case ApiIPv6Key: /* --api-ipv6 */
case DryRunKey: /* --dry-run */
return parseBoolean(key, true);
case ColorKey: /* --no-color */

View file

@ -47,6 +47,7 @@ public:
inline bool isApiRestricted() const { return m_apiRestricted; }
inline bool isBackground() const { return m_background; }
inline bool isColors() const { return m_colors; }
inline bool isDryRun() const { return m_dryRun; }
inline bool isSyslog() const { return m_syslog; }
inline const char *apiToken() const { return m_apiToken.data(); }
inline const char *apiWorkerId() const { return m_apiWorkerId.data(); }
@ -85,6 +86,7 @@ protected:
bool m_apiRestricted;
bool m_background;
bool m_colors;
bool m_dryRun;
bool m_syslog;
bool m_watch;
int m_apiPort;

View file

@ -43,7 +43,6 @@ static char affinity_tmp[20] = { 0 };
xmrig::Config::Config() : xmrig::CommonConfig(),
m_aesMode(AES_AUTO),
m_algoVariant(AV_AUTO),
m_dryRun(false),
m_hugePages(true),
m_safe(false),
m_maxCpuUsage(75),
@ -192,19 +191,15 @@ bool xmrig::Config::parseBoolean(int key, bool enable)
}
switch (key) {
case IConfig::SafeKey: /* --safe */
case SafeKey: /* --safe */
m_safe = enable;
break;
case IConfig::HugePagesKey: /* --no-huge-pages */
case HugePagesKey: /* --no-huge-pages */
m_hugePages = enable;
break;
case IConfig::DryRunKey: /* --dry-run */
m_dryRun = enable;
break;
case IConfig::HardwareAESKey: /* hw-aes config only */
case HardwareAESKey: /* hw-aes config only */
m_aesMode = enable ? AES_HW : AES_SOFT;
break;
@ -223,19 +218,18 @@ bool xmrig::Config::parseString(int key, const char *arg)
}
switch (key) {
case xmrig::IConfig::AVKey: /* --av */
case xmrig::IConfig::MaxCPUUsageKey: /* --max-cpu-usage */
case xmrig::IConfig::CPUPriorityKey: /* --cpu-priority */
case AVKey: /* --av */
case MaxCPUUsageKey: /* --max-cpu-usage */
case CPUPriorityKey: /* --cpu-priority */
return parseUint64(key, strtol(arg, nullptr, 10));
case xmrig::IConfig::SafeKey: /* --safe */
case xmrig::IConfig::DryRunKey: /* --dry-run */
case SafeKey: /* --safe */
return parseBoolean(key, true);
case xmrig::IConfig::HugePagesKey: /* --no-huge-pages */
case HugePagesKey: /* --no-huge-pages */
return parseBoolean(key, false);
case xmrig::IConfig::ThreadsKey: /* --threads */
case ThreadsKey: /* --threads */
if (strncmp(arg, "all", 3) == 0) {
m_threads.count = Cpu::threads();
return true;
@ -243,7 +237,7 @@ bool xmrig::Config::parseString(int key, const char *arg)
return parseUint64(key, strtol(arg, nullptr, 10));
case xmrig::IConfig::CPUAffinityKey: /* --cpu-affinity */
case CPUAffinityKey: /* --cpu-affinity */
{
const char *p = strstr(arg, "0x");
return parseUint64(key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10));
@ -264,7 +258,7 @@ bool xmrig::Config::parseUint64(int key, uint64_t arg)
}
switch (key) {
case xmrig::IConfig::CPUAffinityKey: /* --cpu-affinity */
case CPUAffinityKey: /* --cpu-affinity */
if (arg) {
m_threads.mask = arg;
}
@ -303,25 +297,25 @@ void xmrig::Config::parseJSON(const rapidjson::Document &doc)
bool xmrig::Config::parseInt(int key, int arg)
{
switch (key) {
case xmrig::IConfig::ThreadsKey: /* --threads */
case ThreadsKey: /* --threads */
if (arg >= 0 && arg < 1024) {
m_threads.count = arg;
}
break;
case xmrig::IConfig::AVKey: /* --av */
case AVKey: /* --av */
if (arg >= AV_AUTO && arg < AV_MAX) {
m_algoVariant = static_cast<AlgoVariant>(arg);
}
break;
case xmrig::IConfig::MaxCPUUsageKey: /* --max-cpu-usage */
case MaxCPUUsageKey: /* --max-cpu-usage */
if (m_maxCpuUsage > 0 && arg <= 100) {
m_maxCpuUsage = arg;
}
break;
case xmrig::IConfig::CPUPriorityKey: /* --cpu-priority */
case CPUPriorityKey: /* --cpu-priority */
if (arg >= 0 && arg <= 5) {
m_priority = arg;
}

View file

@ -77,7 +77,6 @@ public:
inline AesMode aesMode() const { return m_aesMode; }
inline AlgoVariant algoVariant() const { return m_algoVariant; }
inline bool isDryRun() const { return m_dryRun; }
inline bool isHugePages() const { return m_hugePages; }
inline const std::vector<IThread *> &threads() const { return m_threads.list; }
inline int priority() const { return m_priority; }
@ -117,7 +116,6 @@ private:
AesMode m_aesMode;
AlgoVariant m_algoVariant;
bool m_dryRun;
bool m_hugePages;
bool m_safe;
int m_maxCpuUsage;