Update and move Title class.

This commit is contained in:
XMRig 2022-04-27 12:14:20 +07:00
parent 603eb261c5
commit 9a0cd68ea5
No known key found for this signature in database
GPG key ID: 446A53638BE94409
9 changed files with 240 additions and 123 deletions

View file

@ -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

View file

@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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"

View file

@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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

View file

@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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"

View file

@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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"

View file

@ -1,58 +0,0 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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);
}

View file

@ -1,50 +0,0 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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 */

View file

@ -0,0 +1,124 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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 &current)
{
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("<enabled=") CYAN("%d")
MAGENTA(", value=") "\"%s\""
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;
}

View file

@ -0,0 +1,74 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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 &current);
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