From fe9d2a0e1d9220f6882672d7fed16350869593a7 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 18 Aug 2019 01:01:28 +0700 Subject: [PATCH] Added ConfigPrivate class. --- src/backend/opencl/OclBackend.cpp | 1 + src/core/Miner.cpp | 5 +++ src/core/config/Config.cpp | 72 +++++++++++++++++++++++++++---- src/core/config/Config.h | 45 +++++++------------ 4 files changed, 84 insertions(+), 39 deletions(-) diff --git a/src/backend/opencl/OclBackend.cpp b/src/backend/opencl/OclBackend.cpp index 6c7bd7da1..7c9fdefe0 100644 --- a/src/backend/opencl/OclBackend.cpp +++ b/src/backend/opencl/OclBackend.cpp @@ -30,6 +30,7 @@ #include "backend/common/interfaces/IWorker.h" #include "backend/common/Workers.h" #include "backend/opencl/OclBackend.h" +#include "backend/opencl/OclConfig.h" #include "backend/opencl/OclLaunchData.h" #include "base/io/log/Log.h" #include "base/net/stratum/Job.h" diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index 448c19948..91c0e920c 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -55,6 +55,11 @@ #endif +#ifdef XMRIG_ALGO_RANDOMX +# include "crypto/rx/RxConfig.h" +#endif + + namespace xmrig { diff --git a/src/core/config/Config.cpp b/src/core/config/Config.cpp index 768a6e3bb..33e5e54fe 100644 --- a/src/core/config/Config.cpp +++ b/src/core/config/Config.cpp @@ -38,6 +38,16 @@ #include "rapidjson/prettywriter.h" +#ifdef XMRIG_ALGO_RANDOMX +# include "crypto/rx/RxConfig.h" +#endif + + +#ifdef XMRIG_FEATURE_OPENCL +# include "backend/opencl/OclConfig.h" +#endif + + namespace xmrig { static const char *kCPU = "cpu"; @@ -51,14 +61,58 @@ static const char *kRandomX = "randomx"; static const char *kOcl = "opencl"; #endif + +class ConfigPrivate +{ +public: + CpuConfig cpu; + +# ifdef XMRIG_ALGO_RANDOMX + RxConfig rx; +# endif + +# ifdef XMRIG_FEATURE_OPENCL + OclConfig cl; +# endif +}; + } -xmrig::Config::Config() : BaseConfig() +xmrig::Config::Config() : BaseConfig(), + d_ptr(new ConfigPrivate()) { } +xmrig::Config::~Config() +{ + delete d_ptr; +} + + +const xmrig::CpuConfig &xmrig::Config::cpu() const +{ + return d_ptr->cpu; +} + + +#ifdef XMRIG_FEATURE_OPENCL +const xmrig::OclConfig &xmrig::Config::cl() const +{ + return d_ptr->cl; +} +#endif + + +#ifdef XMRIG_ALGO_RANDOMX +const xmrig::RxConfig &xmrig::Config::rx() const +{ + return d_ptr->rx; +} +#endif + + bool xmrig::Config::isShouldSave() const { if (!isAutoSave()) { @@ -70,12 +124,12 @@ bool xmrig::Config::isShouldSave() const } # ifdef XMRIG_FEATURE_OPENCL - if (m_cl.isShouldSave()) { + if (cl().isShouldSave()) { return true; } # endif - return (m_shouldSave || m_upgrade || m_cpu.isShouldSave()); + return (m_upgrade || cpu().isShouldSave()); } @@ -85,16 +139,16 @@ bool xmrig::Config::read(const IJsonReader &reader, const char *fileName) return false; } - m_cpu.read(reader.getValue(kCPU), version()); + d_ptr->cpu.read(reader.getValue(kCPU), version()); # ifdef XMRIG_ALGO_RANDOMX - if (!m_rx.read(reader.getValue(kRandomX))) { + if (!d_ptr->rx.read(reader.getValue(kRandomX))) { m_upgrade = true; } # endif # ifdef XMRIG_FEATURE_OPENCL - m_cl.read(reader.getValue(kOcl)); + d_ptr->cl.read(reader.getValue(kOcl)); # endif return true; @@ -121,13 +175,13 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const doc.AddMember("colors", Log::colors, allocator); # ifdef XMRIG_ALGO_RANDOMX - doc.AddMember(StringRef(kRandomX), m_rx.toJSON(doc), allocator); + doc.AddMember(StringRef(kRandomX), rx().toJSON(doc), allocator); # endif - doc.AddMember(StringRef(kCPU), m_cpu.toJSON(doc), allocator); + doc.AddMember(StringRef(kCPU), cpu().toJSON(doc), allocator); # ifdef XMRIG_FEATURE_OPENCL - doc.AddMember(StringRef(kOcl), m_cl.toJSON(doc), allocator); + doc.AddMember(StringRef(kOcl), cl().toJSON(doc), allocator); # endif doc.AddMember("donate-level", m_pools.donateLevel(), allocator); diff --git a/src/core/config/Config.h b/src/core/config/Config.h index d250ec4b7..7c7bc5338 100644 --- a/src/core/config/Config.h +++ b/src/core/config/Config.h @@ -34,52 +34,37 @@ #include "rapidjson/fwd.h" -#ifdef XMRIG_ALGO_RANDOMX -# include "crypto/rx/RxConfig.h" -#endif - - -#ifdef XMRIG_FEATURE_OPENCL -# include "backend/opencl/OclConfig.h" -#endif - - namespace xmrig { +class ConfigPrivate; class IThread; +class RxConfig; +class OclConfig; class Config : public BaseConfig { public: Config(); + ~Config() override; + + const CpuConfig &cpu() const; + +# ifdef XMRIG_FEATURE_OPENCL + const OclConfig &cl() const; +# endif + +# ifdef XMRIG_ALGO_RANDOMX + const RxConfig &rx() const; +# endif bool isShouldSave() const; bool read(const IJsonReader &reader, const char *fileName) override; void getJSON(rapidjson::Document &doc) const override; - inline const CpuConfig &cpu() const { return m_cpu; } - -# ifdef XMRIG_ALGO_RANDOMX - inline const RxConfig &rx() const { return m_rx; } -# endif - -# ifdef XMRIG_FEATURE_OPENCL - inline const OclConfig &cl() const { return m_cl; } -# endif - private: - bool m_shouldSave = false; - CpuConfig m_cpu; - -# ifdef XMRIG_ALGO_RANDOMX - RxConfig m_rx; -# endif - -# ifdef XMRIG_FEATURE_OPENCL - OclConfig m_cl; -# endif + ConfigPrivate *d_ptr; };