From e39ddeeea2fda5a823e71b63117a6184ba505cc7 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 30 Mar 2019 21:27:54 +0700 Subject: [PATCH] Removed IConfigCreator/ConfigCreator and changed file structure. --- CMakeLists.txt | 9 ++-- src/App.cpp | 2 +- src/App_win.cpp | 2 +- src/Summary.cpp | 2 +- src/api/Api.cpp | 2 +- src/api/Httpd.cpp | 2 +- src/base/kernel/Entry.cpp | 2 +- src/common/config/ConfigLoader.cpp | 22 ++++---- src/common/config/ConfigLoader.h | 4 +- src/common/config/ConfigWatcher.cpp | 7 ++- src/common/config/ConfigWatcher.h | 4 +- src/common/interfaces/IConfig.h | 2 + src/common/interfaces/IConfigCreator.h | 47 ----------------- src/core/ConfigCreator.h | 50 ------------------- src/core/Controller.cpp | 2 +- src/core/{ => config}/Config.cpp | 5 +- src/core/{ => config}/Config.h | 3 +- src/core/{ => config}/ConfigLoader_default.h | 0 src/core/{ => config}/ConfigLoader_platform.h | 0 src/core/{ => config}/usage.h | 0 src/net/Network.cpp | 2 +- src/net/strategies/DonateStrategy.cpp | 2 +- src/workers/Hashrate.cpp | 2 +- src/workers/Workers.cpp | 2 +- 24 files changed, 36 insertions(+), 139 deletions(-) delete mode 100644 src/common/interfaces/IConfigCreator.h delete mode 100644 src/core/ConfigCreator.h rename src/core/{ => config}/Config.cpp (98%) rename src/core/{ => config}/Config.h (96%) rename src/core/{ => config}/ConfigLoader_default.h (100%) rename src/core/{ => config}/ConfigLoader_platform.h (100%) rename src/core/{ => config}/usage.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc8a82d8..f1eeeeef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,13 +31,14 @@ set(HEADERS src/common/crypto/Algorithm.h src/common/crypto/keccak.h src/common/interfaces/IConfig.h - src/common/interfaces/IConfigCreator.h src/common/interfaces/ICpuInfo.h src/common/Platform.h src/common/utils/mm_malloc.h src/common/xmrig.h - src/core/ConfigLoader_default.h - src/core/ConfigLoader_platform.h + src/core/config/Config.h + src/core/config/ConfigLoader_default.h + src/core/config/ConfigLoader_platform.h + src/core/config/usage.h src/core/Controller.h src/interfaces/IJobResultListener.h src/interfaces/IThread.h @@ -89,7 +90,7 @@ set(SOURCES src/common/crypto/Algorithm.cpp src/common/crypto/keccak.cpp src/common/Platform.cpp - src/core/Config.cpp + src/core/config/Config.cpp src/core/Controller.cpp src/Mem.cpp src/net/Network.cpp diff --git a/src/App.cpp b/src/App.cpp index f7e80ef7..38e335c2 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -35,7 +35,7 @@ #include "base/kernel/Signals.h" #include "common/cpu/Cpu.h" #include "common/Platform.h" -#include "core/Config.h" +#include "core/config/Config.h" #include "core/Controller.h" #include "crypto/CryptoNight.h" #include "Mem.h" diff --git a/src/App_win.cpp b/src/App_win.cpp index 57f57a6d..a41ed505 100644 --- a/src/App_win.cpp +++ b/src/App_win.cpp @@ -29,7 +29,7 @@ #include "App.h" #include "core/Controller.h" -#include "core/Config.h" +#include "core/config/Config.h" void xmrig::App::background() diff --git a/src/Summary.cpp b/src/Summary.cpp index b7c5d7df..697e2373 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -31,7 +31,7 @@ #include "base/io/log/Log.h" #include "base/net/stratum/Pool.h" #include "common/cpu/Cpu.h" -#include "core/Config.h" +#include "core/config/Config.h" #include "core/Controller.h" #include "crypto/Asm.h" #include "Mem.h" diff --git a/src/api/Api.cpp b/src/api/Api.cpp index b29a6454..527565ed 100644 --- a/src/api/Api.cpp +++ b/src/api/Api.cpp @@ -32,7 +32,7 @@ #include "api/requests/HttpApiRequest.h" #include "base/tools/Buffer.h" #include "common/crypto/keccak.h" -#include "core/Config.h" +#include "core/config/Config.h" #include "core/Controller.h" #include "version.h" diff --git a/src/api/Httpd.cpp b/src/api/Httpd.cpp index 444fdb3e..38b477aa 100644 --- a/src/api/Httpd.cpp +++ b/src/api/Httpd.cpp @@ -31,7 +31,7 @@ #include "base/net/http/HttpRequest.h" #include "base/net/http/HttpServer.h" #include "base/net/tools/TcpServer.h" -#include "core/Config.h" +#include "core/config/Config.h" #include "core/Controller.h" diff --git a/src/base/kernel/Entry.cpp b/src/base/kernel/Entry.cpp index 5af4db78..1834cb82 100644 --- a/src/base/kernel/Entry.cpp +++ b/src/base/kernel/Entry.cpp @@ -34,7 +34,7 @@ #include "base/kernel/Entry.h" #include "base/kernel/Process.h" -#include "core/usage.h" +#include "core/config/usage.h" #include "version.h" diff --git a/src/common/config/ConfigLoader.cpp b/src/common/config/ConfigLoader.cpp index 4b251fa2..6f145440 100644 --- a/src/common/config/ConfigLoader.cpp +++ b/src/common/config/ConfigLoader.cpp @@ -36,20 +36,19 @@ #include "common/config/ConfigWatcher.h" #include "common/interfaces/IConfig.h" #include "common/Platform.h" -#include "core/ConfigCreator.h" -#include "core/ConfigLoader_platform.h" +#include "core/config/Config.h" +#include "core/config/ConfigLoader_platform.h" #include "rapidjson/document.h" #include "rapidjson/error/en.h" #include "rapidjson/fwd.h" #ifdef XMRIG_FEATURE_EMBEDDED_CONFIG -# include "core/ConfigLoader_default.h" +# include "core/config/ConfigLoader_default.h" #endif xmrig::ConfigWatcher *xmrig::ConfigLoader::m_watcher = nullptr; -xmrig::IConfigCreator *xmrig::ConfigLoader::m_creator = nullptr; xmrig::IConfigListener *xmrig::ConfigLoader::m_listener = nullptr; @@ -106,7 +105,7 @@ bool xmrig::ConfigLoader::loadFromJSON(xmrig::IConfig *config, const rapidjson:: bool xmrig::ConfigLoader::reload(xmrig::IConfig *oldConfig, const char *json) { - xmrig::IConfig *config = m_creator->create(); + IConfig *config = Config::create(); if (!loadFromJSON(config, json)) { delete config; @@ -135,17 +134,16 @@ bool xmrig::ConfigLoader::watch(IConfig *config) assert(m_watcher == nullptr); - m_watcher = new xmrig::ConfigWatcher(config->fileName(), m_creator, m_listener); + m_watcher = new xmrig::ConfigWatcher(config->fileName(), m_listener); return true; } -xmrig::IConfig *xmrig::ConfigLoader::load(Process *process, IConfigCreator *creator, IConfigListener *listener) +xmrig::IConfig *xmrig::ConfigLoader::load(Process *process, IConfigListener *listener) { - m_creator = creator; m_listener = listener; - xmrig::IConfig *config = m_creator->create(); + IConfig *config = Config::create(); int key; int argc = process->arguments().argc(); char **argv = process->arguments().argv(); @@ -171,7 +169,7 @@ xmrig::IConfig *xmrig::ConfigLoader::load(Process *process, IConfigCreator *crea if (!config->finalize()) { delete config; - config = m_creator->create(); + config = Config::create(); loadFromFile(config, process->location(Process::ExeLocation, "config.json")); } @@ -179,7 +177,7 @@ xmrig::IConfig *xmrig::ConfigLoader::load(Process *process, IConfigCreator *crea if (!config->finalize()) { delete config; - config = m_creator->create(); + config = Config::create(); loadFromJSON(config, default_config); } # endif @@ -203,10 +201,8 @@ xmrig::IConfig *xmrig::ConfigLoader::load(Process *process, IConfigCreator *crea void xmrig::ConfigLoader::release() { delete m_watcher; - delete m_creator; m_watcher = nullptr; - m_creator = nullptr; } diff --git a/src/common/config/ConfigLoader.h b/src/common/config/ConfigLoader.h index 99d6143f..322aafcf 100644 --- a/src/common/config/ConfigLoader.h +++ b/src/common/config/ConfigLoader.h @@ -39,7 +39,6 @@ namespace xmrig { class ConfigWatcher; -class IConfigCreator; class IConfigListener; class IConfig; class Process; @@ -53,7 +52,7 @@ public: static bool loadFromJSON(IConfig *config, const rapidjson::Document &doc); static bool reload(IConfig *oldConfig, const char *json); static bool watch(IConfig *config); - static IConfig *load(Process *process, IConfigCreator *creator, IConfigListener *listener); + static IConfig *load(Process *process, IConfigListener *listener); static void release(); private: @@ -62,7 +61,6 @@ private: static void parseJSON(IConfig *config, const struct option *option, const rapidjson::Value &object); static ConfigWatcher *m_watcher; - static IConfigCreator *m_creator; static IConfigListener *m_listener; }; diff --git a/src/common/config/ConfigWatcher.cpp b/src/common/config/ConfigWatcher.cpp index c3168ac9..1c70547e 100644 --- a/src/common/config/ConfigWatcher.cpp +++ b/src/common/config/ConfigWatcher.cpp @@ -28,11 +28,10 @@ #include "base/kernel/interfaces/IConfigListener.h" #include "common/config/ConfigLoader.h" #include "common/config/ConfigWatcher.h" -#include "core/ConfigCreator.h" +#include "core/config/Config.h" -xmrig::ConfigWatcher::ConfigWatcher(const String &path, IConfigCreator *creator, IConfigListener *listener) : - m_creator(creator), +xmrig::ConfigWatcher::ConfigWatcher(const String &path, IConfigListener *listener) : m_listener(listener) { m_watcher = new Watcher(path, this); @@ -50,7 +49,7 @@ void xmrig::ConfigWatcher::onFileChanged(const String &fileName) { LOG_WARN("\"%s\" was changed, reloading configuration", fileName.data()); - IConfig *config = m_creator->create(); + IConfig *config = Config::create(); ConfigLoader::loadFromFile(config, fileName); if (!config->finalize()) { diff --git a/src/common/config/ConfigWatcher.h b/src/common/config/ConfigWatcher.h index c2c3ee29..77b41cf5 100644 --- a/src/common/config/ConfigWatcher.h +++ b/src/common/config/ConfigWatcher.h @@ -37,7 +37,6 @@ struct option; namespace xmrig { -class IConfigCreator; class IConfigListener; class Watcher; @@ -45,14 +44,13 @@ class Watcher; class ConfigWatcher : public IWatcherListener { public: - ConfigWatcher(const String &path, IConfigCreator *creator, IConfigListener *listener); + ConfigWatcher(const String &path, IConfigListener *listener); ~ConfigWatcher() override; protected: void onFileChanged(const String &fileName) override; private: - IConfigCreator *m_creator; IConfigListener *m_listener; Watcher *m_watcher; }; diff --git a/src/common/interfaces/IConfig.h b/src/common/interfaces/IConfig.h index d7b7944a..2228d2c9 100644 --- a/src/common/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -152,6 +152,8 @@ public: virtual void getJSON(rapidjson::Document &doc) const = 0; virtual void parseJSON(const rapidjson::Document &doc) = 0; virtual void setFileName(const char *fileName) = 0; + + static IConfig *create(); }; diff --git a/src/common/interfaces/IConfigCreator.h b/src/common/interfaces/IConfigCreator.h deleted file mode 100644 index c2e0e62e..00000000 --- a/src/common/interfaces/IConfigCreator.h +++ /dev/null @@ -1,47 +0,0 @@ -/* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef XMRIG_ICONFIGCREATOR_H -#define XMRIG_ICONFIGCREATOR_H - - -namespace xmrig { - - -class IConfig; - - -class IConfigCreator -{ -public: - virtual ~IConfigCreator() = default; - - virtual IConfig *create() const = 0; -}; - - -} /* namespace xmrig */ - - -#endif // XMRIG_ICONFIGCREATOR_H diff --git a/src/core/ConfigCreator.h b/src/core/ConfigCreator.h deleted file mode 100644 index 054eb78c..00000000 --- a/src/core/ConfigCreator.h +++ /dev/null @@ -1,50 +0,0 @@ -/* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2016-2018 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef __CONFIGCREATOR_H__ -#define __CONFIGCREATOR_H__ - - -#include "common/interfaces/IConfigCreator.h" -#include "core/Config.h" - - -namespace xmrig { - - -class IConfig; - - -class ConfigCreator : public IConfigCreator -{ -public: - inline IConfig *create() const override - { - return new Config(); - } -}; - - -} /* namespace xmrig */ - - -#endif // __CONFIGCREATOR_H__ diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index fe1537f3..fbe4a427 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -33,7 +33,7 @@ #include "common/config/ConfigLoader.h" #include "common/cpu/Cpu.h" #include "common/Platform.h" -#include "core/Config.h" +#include "core/config/Config.h" #include "core/Controller.h" #include "net/Network.h" diff --git a/src/core/Config.cpp b/src/core/config/Config.cpp similarity index 98% rename from src/core/Config.cpp rename to src/core/config/Config.cpp index a1c91548..5b337197 100644 --- a/src/core/Config.cpp +++ b/src/core/config/Config.cpp @@ -30,8 +30,7 @@ #include "base/io/log/Log.h" #include "common/config/ConfigLoader.h" #include "common/cpu/Cpu.h" -#include "core/Config.h" -#include "core/ConfigCreator.h" +#include "core/config/Config.h" #include "crypto/Asm.h" #include "crypto/CryptoNight_constants.h" #include "rapidjson/document.h" @@ -129,7 +128,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const xmrig::Config *xmrig::Config::load(Process *process, IConfigListener *listener) { - return static_cast(ConfigLoader::load(process, new ConfigCreator(), listener)); + return static_cast(ConfigLoader::load(process, listener)); } diff --git a/src/core/Config.h b/src/core/config/Config.h similarity index 96% rename from src/core/Config.h rename to src/core/config/Config.h index d7df9cd9..261955c5 100644 --- a/src/core/Config.h +++ b/src/core/config/Config.h @@ -78,8 +78,9 @@ public: inline bool isShouldSave() const { return (m_shouldSave || m_upgrade) && isAutoSave(); } inline const std::vector &threads() const { return m_threads.list; } inline int priority() const { return m_priority; } - inline int threadsCount() const { return m_threads.list.size(); } + inline int threadsCount() const { return static_cast(m_threads.list.size()); } inline int64_t affinity() const { return m_threads.mask; } + inline static IConfig *create() { return new Config(); } inline ThreadsMode threadsMode() const { return m_threads.mode; } static Config *load(Process *process, IConfigListener *listener); diff --git a/src/core/ConfigLoader_default.h b/src/core/config/ConfigLoader_default.h similarity index 100% rename from src/core/ConfigLoader_default.h rename to src/core/config/ConfigLoader_default.h diff --git a/src/core/ConfigLoader_platform.h b/src/core/config/ConfigLoader_platform.h similarity index 100% rename from src/core/ConfigLoader_platform.h rename to src/core/config/ConfigLoader_platform.h diff --git a/src/core/usage.h b/src/core/config/usage.h similarity index 100% rename from src/core/usage.h rename to src/core/config/usage.h diff --git a/src/net/Network.cpp b/src/net/Network.cpp index fa0d00a4..02489b8d 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -37,7 +37,7 @@ #include "base/net/stratum/SubmitResult.h" #include "base/tools/Chrono.h" #include "base/tools/Timer.h" -#include "core/Config.h" +#include "core/config/Config.h" #include "core/Controller.h" #include "net/Network.h" #include "net/strategies/DonateStrategy.h" diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index adfb9a99..9275bde9 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -35,7 +35,7 @@ #include "common/crypto/keccak.h" #include "common/Platform.h" #include "common/xmrig.h" -#include "core/Config.h" +#include "core/config/Config.h" #include "core/Controller.h" #include "net/Network.h" #include "net/strategies/DonateStrategy.h" diff --git a/src/workers/Hashrate.cpp b/src/workers/Hashrate.cpp index b2abdf29..568817cd 100644 --- a/src/workers/Hashrate.cpp +++ b/src/workers/Hashrate.cpp @@ -32,7 +32,7 @@ #include "base/io/log/Log.h" #include "base/tools/Handle.h" -#include "core/Config.h" +#include "core/config/Config.h" #include "core/Controller.h" #include "workers/Hashrate.h" diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 79045df7..1e22f403 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -30,7 +30,7 @@ #include "api/Api.h" #include "base/io/log/Log.h" #include "base/tools/Handle.h" -#include "core/Config.h" +#include "core/config/Config.h" #include "core/Controller.h" #include "crypto/CryptoNight_constants.h" #include "interfaces/IJobResultListener.h"