From 9a0cd68ea5f1225b37edfe13e9ca88e662fb3405 Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 27 Apr 2022 12:14:20 +0700 Subject: [PATCH] Update and move Title class. --- src/base/base.cmake | 4 +- src/base/io/log/backends/ConsoleLog.cpp | 13 ++- src/base/io/log/backends/ConsoleLog.h | 15 ++- src/base/kernel/config/BaseConfig.cpp | 12 ++- src/base/kernel/config/BaseConfig.h | 13 ++- src/base/kernel/config/Title.cpp | 58 ----------- src/base/kernel/config/Title.h | 50 ---------- src/base/kernel/private/Title.cpp | 124 ++++++++++++++++++++++++ src/base/kernel/private/Title.h | 74 ++++++++++++++ 9 files changed, 240 insertions(+), 123 deletions(-) delete mode 100644 src/base/kernel/config/Title.cpp delete mode 100644 src/base/kernel/config/Title.h create mode 100644 src/base/kernel/private/Title.cpp create mode 100644 src/base/kernel/private/Title.h diff --git a/src/base/base.cmake b/src/base/base.cmake index 7a64c587..bf89391c 100644 --- a/src/base/base.cmake +++ b/src/base/base.cmake @@ -21,7 +21,7 @@ set(HEADERS_BASE src/base/kernel/Base.h src/base/kernel/config/BaseConfig.h src/base/kernel/config/BaseTransform.h - src/base/kernel/config/Title.h + src/base/kernel/private/Title.h src/base/kernel/constants.h src/base/kernel/Entry.h src/base/kernel/interfaces/IAsyncListener.h @@ -111,7 +111,7 @@ set(SOURCES_BASE src/base/kernel/Base.cpp src/base/kernel/config/BaseConfig.cpp src/base/kernel/config/BaseTransform.cpp - src/base/kernel/config/Title.cpp + src/base/kernel/private/Title.cpp src/base/kernel/Entry.cpp src/base/kernel/Lib.cpp src/base/kernel/OS.cpp diff --git a/src/base/io/log/backends/ConsoleLog.cpp b/src/base/io/log/backends/ConsoleLog.cpp index a18fe7d9..5d893060 100644 --- a/src/base/io/log/backends/ConsoleLog.cpp +++ b/src/base/io/log/backends/ConsoleLog.cpp @@ -1,7 +1,7 @@ /* XMRig * Copyright (c) 2019 Spudz76 - * 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 @@ -15,11 +15,18 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . + * + * Additional permission under GNU GPL version 3 section 7 + * + * If you modify this Program, or any covered work, by linking or combining + * it with OpenSSL (or a modified version of that library), containing parts + * covered by the terms of OpenSSL License and SSLeay License, the licensors + * of this Program grant you additional permission to convey the resulting work. */ #include "base/io/log/backends/ConsoleLog.h" #include "base/io/log/Log.h" -#include "base/kernel/config/Title.h" +#include "base/kernel/private/Title.h" #include "base/tools/Handle.h" diff --git a/src/base/io/log/backends/ConsoleLog.h b/src/base/io/log/backends/ConsoleLog.h index 2d248a92..26600ed5 100644 --- a/src/base/io/log/backends/ConsoleLog.h +++ b/src/base/io/log/backends/ConsoleLog.h @@ -1,7 +1,7 @@ /* XMRig * Copyright (c) 2019 Spudz76 - * 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 @@ -15,6 +15,13 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . + * + * Additional permission under GNU GPL version 3 section 7 + * + * If you modify this Program, or any covered work, by linking or combining + * it with OpenSSL (or a modified version of that library), containing parts + * covered by the terms of OpenSSL License and SSLeay License, the licensors + * of this Program grant you additional permission to convey the resulting work. */ #ifndef XMRIG_CONSOLELOG_H @@ -59,7 +66,7 @@ private: }; -} /* namespace xmrig */ +} // namespace xmrig -#endif /* XMRIG_CONSOLELOG_H */ +#endif // XMRIG_CONSOLELOG_H diff --git a/src/base/kernel/config/BaseConfig.cpp b/src/base/kernel/config/BaseConfig.cpp index 37982999..799880f6 100644 --- a/src/base/kernel/config/BaseConfig.cpp +++ b/src/base/kernel/config/BaseConfig.cpp @@ -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 @@ -14,9 +14,15 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . + * + * Additional permission under GNU GPL version 3 section 7 + * + * If you modify this Program, or any covered work, by linking or combining + * it with OpenSSL (or a modified version of that library), containing parts + * covered by the terms of OpenSSL License and SSLeay License, the licensors + * of this Program grant you additional permission to convey the resulting work. */ - #include "base/kernel/config/BaseConfig.h" #include "3rdparty/rapidjson/document.h" #include "base/io/json/Json.h" diff --git a/src/base/kernel/config/BaseConfig.h b/src/base/kernel/config/BaseConfig.h index fae6d981..d3518be5 100644 --- a/src/base/kernel/config/BaseConfig.h +++ b/src/base/kernel/config/BaseConfig.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 @@ -14,13 +14,20 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . + * + * Additional permission under GNU GPL version 3 section 7 + * + * If you modify this Program, or any covered work, by linking or combining + * it with OpenSSL (or a modified version of that library), containing parts + * covered by the terms of OpenSSL License and SSLeay License, the licensors + * of this Program grant you additional permission to convey the resulting work. */ #ifndef XMRIG_BASECONFIG_H #define XMRIG_BASECONFIG_H -#include "base/kernel/config/Title.h" +#include "base/kernel/private/Title.h" #include "base/kernel/interfaces/IConfig.h" #include "base/net/http/Http.h" #include "base/net/stratum/Pools.h" diff --git a/src/base/kernel/config/Title.cpp b/src/base/kernel/config/Title.cpp deleted file mode 100644 index 030aa727..00000000 --- a/src/base/kernel/config/Title.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* XMRig - * Copyright (c) 2018-2020 SChernykh - * Copyright (c) 2016-2020 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 . - */ - - -#include "base/kernel/config/Title.h" -#include "3rdparty/rapidjson/document.h" -#include "base/io/Env.h" -#include "version.h" - - -xmrig::Title::Title(const rapidjson::Value &value) -{ - if (value.IsBool()) { - m_enabled = value.GetBool(); - } - else if (value.IsString()) { - m_value = value.GetString(); - } -} - - -rapidjson::Value xmrig::Title::toJSON() const -{ - if (isEnabled() && !m_value.isNull()) { - return m_value.toJSON(); - } - - return rapidjson::Value(m_enabled); -} - - -xmrig::String xmrig::Title::value() const -{ - if (!isEnabled()) { - return {}; - } - - if (m_value.isNull()) { - return APP_NAME " " APP_VERSION; - } - - return Env::expand(m_value); -} diff --git a/src/base/kernel/config/Title.h b/src/base/kernel/config/Title.h deleted file mode 100644 index 452869dc..00000000 --- a/src/base/kernel/config/Title.h +++ /dev/null @@ -1,50 +0,0 @@ -/* XMRig - * Copyright (c) 2018-2020 SChernykh - * Copyright (c) 2016-2020 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_TITLE_H -#define XMRIG_TITLE_H - - -#include "3rdparty/rapidjson/fwd.h" -#include "base/tools/String.h" - - -namespace xmrig { - - -class Title -{ -public: - Title() = default; - Title(const rapidjson::Value &value); - - inline bool isEnabled() const { return m_enabled; } - - rapidjson::Value toJSON() const; - String value() const; - -private: - bool m_enabled = true; - String m_value; -}; - - -} // namespace xmrig - - -#endif /* XMRIG_TITLE_H */ diff --git a/src/base/kernel/private/Title.cpp b/src/base/kernel/private/Title.cpp new file mode 100644 index 00000000..933016c9 --- /dev/null +++ b/src/base/kernel/private/Title.cpp @@ -0,0 +1,124 @@ +/* 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 + * 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 . + * + * Additional permission under GNU GPL version 3 section 7 + * + * If you modify this Program, or any covered work, by linking or combining + * it with OpenSSL (or a modified version of that library), containing parts + * covered by the terms of OpenSSL License and SSLeay License, the licensors + * of this Program grant you additional permission to convey the resulting work. + */ + +#include "base/kernel/private/Title.h" +#include "3rdparty/rapidjson/document.h" +#include "base/io/Env.h" +#include "base/kernel/interfaces/IJsonReader.h" +#include "base/tools/Arguments.h" +#include "version.h" + + +#ifdef APP_DEBUG +# include "base/io/log/Log.h" +# include "base/kernel/Config.h" +#endif + + +const char *xmrig::Title::kField = "title"; + + +xmrig::Title::Title(const Arguments &arguments) +{ +# ifdef XMRIG_DEPRECATED + if (arguments.contains("--no-title")) { + m_enabled = false; + + return; + } +# endif + + const size_t pos = arguments.pos("--title"); + if (pos) { + m_value = arguments.value(pos + 1U); + m_enabled = !m_value.isEmpty(); + } +} + + +xmrig::Title::Title(const IJsonReader &reader, const Title ¤t) +{ + if (!parse(reader.getValue(kField))) { + m_value = current.m_value; + m_enabled = current.m_enabled; + } +} + + +rapidjson::Value xmrig::Title::toJSON() const +{ + return isEnabled() ? m_value.toJSON() : rapidjson::Value(m_enabled); +} + + +xmrig::String xmrig::Title::value() const +{ + if (!isEnabled()) { + return {}; + } + + if (m_value.isNull()) { + return APP_NAME " " APP_VERSION; + } + + return Env::expand(m_value); +} + + +void xmrig::Title::print() const +{ +# ifdef APP_DEBUG + LOG_DEBUG("%s " MAGENTA_BOLD("TITLE") + MAGENTA(""), + Config::tag(), m_enabled, m_value.data()); +# endif +} + + +void xmrig::Title::save(rapidjson::Document &doc) const +{ + doc.AddMember(rapidjson::StringRef(kField), toJSON(), doc.GetAllocator()); +} + + +bool xmrig::Title::parse(const rapidjson::Value &value) +{ + if (value.IsBool()) { + m_enabled = value.GetBool(); + + return true; + } + + if (value.IsString()) { + m_value = value.GetString(); + m_enabled = !m_value.isEmpty(); + + return true; + } + + return false; +} diff --git a/src/base/kernel/private/Title.h b/src/base/kernel/private/Title.h new file mode 100644 index 00000000..5a93d897 --- /dev/null +++ b/src/base/kernel/private/Title.h @@ -0,0 +1,74 @@ +/* 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 + * 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 . + * + * Additional permission under GNU GPL version 3 section 7 + * + * If you modify this Program, or any covered work, by linking or combining + * it with OpenSSL (or a modified version of that library), containing parts + * covered by the terms of OpenSSL License and SSLeay License, the licensors + * of this Program grant you additional permission to convey the resulting work. + */ + +#ifndef XMRIG_TITLE_H +#define XMRIG_TITLE_H + + +#include "3rdparty/rapidjson/fwd.h" +#include "base/tools/String.h" + + +namespace xmrig { + + +class Arguments; +class IJsonReader; + + +class Title +{ +public: + static const char *kField; + + Title() = default; + Title(bool enabled) : m_enabled(enabled) {} + Title(const Arguments &arguments); + Title(const IJsonReader &reader, const Title ¤t); + inline Title(const rapidjson::Value &value) { parse(value); } + + inline bool isEnabled() const { return m_enabled; } + inline bool isEqual(const Title &other) const { return (m_enabled == other.m_enabled && m_value == other.m_value); } + + inline bool operator!=(const Title &other) const { return !isEqual(other); } + inline bool operator==(const Title &other) const { return isEqual(other); } + + rapidjson::Value toJSON() const; + String value() const; + void print() const; + void save(rapidjson::Document &doc) const; + +private: + bool parse(const rapidjson::Value &value); + + bool m_enabled = true; + String m_value; +}; + + +} // namespace xmrig + + +#endif // XMRIG_TITLE_H