diff --git a/src/base/kernel/Base.cpp b/src/base/kernel/Base.cpp index b83e9f22d..76a9deb83 100644 --- a/src/base/kernel/Base.cpp +++ b/src/base/kernel/Base.cpp @@ -220,7 +220,7 @@ void xmrig::Base::start() } if (config()->isWatch()) { - d_ptr->watcher = new Watcher(config()->fileName(), this); + d_ptr->watcher = new Watcher(config()->path(), this); } } @@ -258,7 +258,7 @@ bool xmrig::Base::reload(const rapidjson::Value &json) } auto config = new Config(); - if (!config->read(reader, d_ptr->config->fileName())) { + if (!config->read(reader, d_ptr->config->path())) { delete config; return false; diff --git a/src/base/kernel/config/BaseConfig.cpp b/src/base/kernel/config/BaseConfig.cpp index a4a607339..e045ef15d 100644 --- a/src/base/kernel/config/BaseConfig.cpp +++ b/src/base/kernel/config/BaseConfig.cpp @@ -80,9 +80,9 @@ const char *BaseConfig::kTls = "tls"; } // namespace xmrig -bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName) +bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *path) { - m_fileName = fileName; + m_path = path; if (reader.isEmpty()) { return false; @@ -122,15 +122,22 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName) bool xmrig::BaseConfig::save() { - if (m_fileName.isNull()) { + rapidjson::Document doc; + + return save(doc); +} + + +bool xmrig::BaseConfig::save(rapidjson::Document &doc) +{ + if (m_path.isNull()) { return false; } - rapidjson::Document doc; getJSON(doc); - if (Json::save(m_fileName, doc)) { - LOG_NOTICE("%s " WHITE_BOLD("configuration saved to: \"%s\""), Tags::config(), m_fileName.data()); + if (Json::save(m_path, doc)) { + LOG_NOTICE("%s " WHITE_BOLD("configuration saved to: \"%s\""), Tags::config(), m_path.data()); return true; } diff --git a/src/base/kernel/config/BaseConfig.h b/src/base/kernel/config/BaseConfig.h index d3518be55..8be72dad6 100644 --- a/src/base/kernel/config/BaseConfig.h +++ b/src/base/kernel/config/BaseConfig.h @@ -86,12 +86,14 @@ public: inline const TlsConfig &tls() const { return m_tls; } # endif - inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); } - inline const String &fileName() const override { return m_fileName; } - inline void setFileName(const char *fileName) override { m_fileName = fileName; } + inline bool isWatch() const override { return m_watch && !m_path.isNull(); } + inline const String &path() const override { return m_path; } + inline uint32_t id() const override { return 0; } + inline void setPath(const char *path) override { m_path = path; } - bool read(const IJsonReader &reader, const char *fileName) override; - bool save() override; + bool read(const IJsonReader &reader, const char *path) override; + bool save(); + bool save(rapidjson::Document &doc) override; static void printVersions(); @@ -106,8 +108,8 @@ protected: Pools m_pools; String m_apiId; String m_apiWorkerId; - String m_fileName; String m_logFile; + String m_path; String m_userAgent; Title m_title; uint32_t m_printTime = 60; diff --git a/src/base/kernel/interfaces/IConfig.h b/src/base/kernel/interfaces/IConfig.h index ed76f4cd2..2ca0ec1e3 100644 --- a/src/base/kernel/interfaces/IConfig.h +++ b/src/base/kernel/interfaces/IConfig.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,6 +21,7 @@ #include "3rdparty/rapidjson/fwd.h" +#include "base/tools/Object.h" namespace xmrig { @@ -33,6 +34,9 @@ class String; class IConfig { public: + XMRIG_DISABLE_COPY_MOVE(IConfig) + +# ifndef XMRIG_FEATURE_EVENTS enum Keys { // common AlgorithmKey = 'a', @@ -164,19 +168,28 @@ public: NvmlKey = 1209, HealthPrintTimeKey = 1210, }; +# endif - virtual ~IConfig() = default; + IConfig() = default; + virtual ~IConfig() = default; - virtual bool isWatch() const = 0; - virtual bool read(const IJsonReader &reader, const char *fileName) = 0; - virtual bool save() = 0; - virtual const String &fileName() const = 0; - virtual void getJSON(rapidjson::Document &doc) const = 0; - virtual void setFileName(const char *fileName) = 0; + virtual bool save(rapidjson::Document &doc) = 0; + virtual const String &path() const = 0; + virtual uint32_t id() const = 0; + +# ifdef XMRIG_FEATURE_EVENTS + virtual bool isValid() const = 0; + virtual const String &name() const = 0; +# else + virtual bool isWatch() const = 0; + virtual bool read(const IJsonReader &reader, const char *path) = 0; + virtual void getJSON(rapidjson::Document &doc) const = 0; + virtual void setPath(const char *path) = 0; +# endif }; -} /* namespace xmrig */ +} // namespace xmrig #endif // XMRIG_ICONFIG_H