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

View file

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

View file

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

View file

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