Added ConfigPrivate class.

This commit is contained in:
XMRig 2019-08-18 01:01:28 +07:00
parent bd07f1d455
commit fe9d2a0e1d
4 changed files with 84 additions and 39 deletions

View file

@ -30,6 +30,7 @@
#include "backend/common/interfaces/IWorker.h" #include "backend/common/interfaces/IWorker.h"
#include "backend/common/Workers.h" #include "backend/common/Workers.h"
#include "backend/opencl/OclBackend.h" #include "backend/opencl/OclBackend.h"
#include "backend/opencl/OclConfig.h"
#include "backend/opencl/OclLaunchData.h" #include "backend/opencl/OclLaunchData.h"
#include "base/io/log/Log.h" #include "base/io/log/Log.h"
#include "base/net/stratum/Job.h" #include "base/net/stratum/Job.h"

View file

@ -55,6 +55,11 @@
#endif #endif
#ifdef XMRIG_ALGO_RANDOMX
# include "crypto/rx/RxConfig.h"
#endif
namespace xmrig { namespace xmrig {

View file

@ -38,6 +38,16 @@
#include "rapidjson/prettywriter.h" #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 { namespace xmrig {
static const char *kCPU = "cpu"; static const char *kCPU = "cpu";
@ -51,14 +61,58 @@ static const char *kRandomX = "randomx";
static const char *kOcl = "opencl"; static const char *kOcl = "opencl";
#endif #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 bool xmrig::Config::isShouldSave() const
{ {
if (!isAutoSave()) { if (!isAutoSave()) {
@ -70,12 +124,12 @@ bool xmrig::Config::isShouldSave() const
} }
# ifdef XMRIG_FEATURE_OPENCL # ifdef XMRIG_FEATURE_OPENCL
if (m_cl.isShouldSave()) { if (cl().isShouldSave()) {
return true; return true;
} }
# endif # 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; return false;
} }
m_cpu.read(reader.getValue(kCPU), version()); d_ptr->cpu.read(reader.getValue(kCPU), version());
# ifdef XMRIG_ALGO_RANDOMX # ifdef XMRIG_ALGO_RANDOMX
if (!m_rx.read(reader.getValue(kRandomX))) { if (!d_ptr->rx.read(reader.getValue(kRandomX))) {
m_upgrade = true; m_upgrade = true;
} }
# endif # endif
# ifdef XMRIG_FEATURE_OPENCL # ifdef XMRIG_FEATURE_OPENCL
m_cl.read(reader.getValue(kOcl)); d_ptr->cl.read(reader.getValue(kOcl));
# endif # endif
return true; return true;
@ -121,13 +175,13 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
doc.AddMember("colors", Log::colors, allocator); doc.AddMember("colors", Log::colors, allocator);
# ifdef XMRIG_ALGO_RANDOMX # ifdef XMRIG_ALGO_RANDOMX
doc.AddMember(StringRef(kRandomX), m_rx.toJSON(doc), allocator); doc.AddMember(StringRef(kRandomX), rx().toJSON(doc), allocator);
# endif # endif
doc.AddMember(StringRef(kCPU), m_cpu.toJSON(doc), allocator); doc.AddMember(StringRef(kCPU), cpu().toJSON(doc), allocator);
# ifdef XMRIG_FEATURE_OPENCL # ifdef XMRIG_FEATURE_OPENCL
doc.AddMember(StringRef(kOcl), m_cl.toJSON(doc), allocator); doc.AddMember(StringRef(kOcl), cl().toJSON(doc), allocator);
# endif # endif
doc.AddMember("donate-level", m_pools.donateLevel(), allocator); doc.AddMember("donate-level", m_pools.donateLevel(), allocator);

View file

@ -34,52 +34,37 @@
#include "rapidjson/fwd.h" #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 { namespace xmrig {
class ConfigPrivate;
class IThread; class IThread;
class RxConfig;
class OclConfig;
class Config : public BaseConfig class Config : public BaseConfig
{ {
public: public:
Config(); 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 isShouldSave() const;
bool read(const IJsonReader &reader, const char *fileName) override; bool read(const IJsonReader &reader, const char *fileName) override;
void getJSON(rapidjson::Document &doc) const 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: private:
bool m_shouldSave = false; ConfigPrivate *d_ptr;
CpuConfig m_cpu;
# ifdef XMRIG_ALGO_RANDOMX
RxConfig m_rx;
# endif
# ifdef XMRIG_FEATURE_OPENCL
OclConfig m_cl;
# endif
}; };