Added classes Process and Arguments.
This commit is contained in:
parent
0450c31449
commit
f4d2dec628
18 changed files with 373 additions and 82 deletions
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 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
|
||||
|
@ -36,40 +36,9 @@
|
|||
#include "Platform.h"
|
||||
|
||||
|
||||
char Platform::m_defaultConfigName[520] = { 0 };
|
||||
xmrig::String Platform::m_userAgent;
|
||||
|
||||
|
||||
const char *Platform::defaultConfigName()
|
||||
{
|
||||
size_t size = 520;
|
||||
|
||||
if (*m_defaultConfigName) {
|
||||
return m_defaultConfigName;
|
||||
}
|
||||
|
||||
if (uv_exepath(m_defaultConfigName, &size) < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (size < 500) {
|
||||
# ifdef WIN32
|
||||
char *p = strrchr(m_defaultConfigName, '\\');
|
||||
# else
|
||||
char *p = strrchr(m_defaultConfigName, '/');
|
||||
# endif
|
||||
|
||||
if (p) {
|
||||
strcpy(p + 1, "config.json");
|
||||
return m_defaultConfigName;
|
||||
}
|
||||
}
|
||||
|
||||
*m_defaultConfigName = '\0';
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void Platform::init(const char *userAgent)
|
||||
{
|
||||
# ifndef XMRIG_NO_TLS
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 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
|
||||
|
@ -36,19 +36,17 @@ class Platform
|
|||
{
|
||||
public:
|
||||
static bool setThreadAffinity(uint64_t cpu_id);
|
||||
static const char *defaultConfigName();
|
||||
static uint32_t setTimerResolution(uint32_t resolution);
|
||||
static void init(const char *userAgent);
|
||||
static void restoreTimerResolution();
|
||||
static void setProcessPriority(int priority);
|
||||
static void setThreadPriority(int priority);
|
||||
|
||||
static inline const char *userAgent() { return m_userAgent.data(); }
|
||||
static inline const char *userAgent() { return m_userAgent; }
|
||||
|
||||
private:
|
||||
static char *createUserAgent();
|
||||
|
||||
static char m_defaultConfigName[520];
|
||||
static xmrig::String m_userAgent;
|
||||
};
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
|
||||
#include "base/io/Json.h"
|
||||
#include "base/kernel/interfaces/IConfigListener.h"
|
||||
#include "base/kernel/Process.h"
|
||||
#include "common/config/ConfigLoader.h"
|
||||
#include "common/config/ConfigWatcher.h"
|
||||
#include "common/interfaces/IConfig.h"
|
||||
|
@ -144,13 +145,15 @@ bool xmrig::ConfigLoader::reload(xmrig::IConfig *oldConfig, const char *json)
|
|||
}
|
||||
|
||||
|
||||
xmrig::IConfig *xmrig::ConfigLoader::load(int argc, char **argv, IConfigCreator *creator, IConfigListener *listener)
|
||||
xmrig::IConfig *xmrig::ConfigLoader::load(Process *process, IConfigCreator *creator, IConfigListener *listener)
|
||||
{
|
||||
m_creator = creator;
|
||||
m_listener = listener;
|
||||
|
||||
xmrig::IConfig *config = m_creator->create();
|
||||
int key;
|
||||
int argc = process->arguments().argc();
|
||||
char **argv = process->arguments().argv();
|
||||
|
||||
while (1) {
|
||||
key = getopt_long(argc, argv, short_options, options, nullptr);
|
||||
|
@ -174,7 +177,7 @@ xmrig::IConfig *xmrig::ConfigLoader::load(int argc, char **argv, IConfigCreator
|
|||
delete config;
|
||||
|
||||
config = m_creator->create();
|
||||
loadFromFile(config, Platform::defaultConfigName());
|
||||
loadFromFile(config, process->location(Process::ExeLocation, "config.json"));
|
||||
}
|
||||
|
||||
if (!config->finalize()) {
|
||||
|
|
|
@ -42,6 +42,7 @@ class ConfigWatcher;
|
|||
class IConfigCreator;
|
||||
class IConfigListener;
|
||||
class IConfig;
|
||||
class Process;
|
||||
|
||||
|
||||
class ConfigLoader
|
||||
|
@ -51,7 +52,7 @@ public:
|
|||
static bool loadFromJSON(IConfig *config, const char *json);
|
||||
static bool loadFromJSON(IConfig *config, const rapidjson::Document &doc);
|
||||
static bool reload(IConfig *oldConfig, const char *json);
|
||||
static IConfig *load(int argc, char **argv, IConfigCreator *creator, IConfigListener *listener);
|
||||
static IConfig *load(Process *process, IConfigCreator *creator, IConfigListener *listener);
|
||||
static void release();
|
||||
|
||||
static inline bool isDone() { return m_done; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue