xmrig/src/core/Controller.cpp

91 lines
2.1 KiB
C++
Raw Normal View History

2018-03-27 07:01:38 +00:00
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* 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>
2019-02-14 21:59:20 +00:00
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
2018-03-27 07:01:38 +00:00
*
* 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 <assert.h>
#include "common/cpu/Cpu.h"
2018-04-13 00:23:01 +00:00
#include "common/Platform.h"
2018-03-27 07:01:38 +00:00
#include "core/Controller.h"
#include "net/Network.h"
2018-03-27 07:01:38 +00:00
2019-04-05 15:14:01 +00:00
xmrig::Controller::Controller(Process *process) :
Base(process),
m_network(nullptr)
2018-03-27 07:01:38 +00:00
{
}
xmrig::Controller::~Controller()
{
2019-04-05 15:14:01 +00:00
delete m_network;
2019-03-29 17:16:01 +00:00
}
2018-03-31 10:51:33 +00:00
bool xmrig::Controller::isReady() const
{
2019-04-05 15:14:01 +00:00
return Base::isReady() && m_network;
2018-03-27 07:01:38 +00:00
}
2019-02-14 22:42:46 +00:00
int xmrig::Controller::init()
2018-03-27 07:01:38 +00:00
{
Cpu::init();
2019-04-05 15:14:01 +00:00
const int rc = Base::init();
if (rc != 0) {
return rc;
}
2018-03-27 07:01:38 +00:00
2019-04-05 15:14:01 +00:00
m_network = new Network(this);
2018-03-27 07:01:38 +00:00
return 0;
}
2019-04-05 15:14:01 +00:00
void xmrig::Controller::start()
2018-03-27 07:01:38 +00:00
{
2019-04-05 15:14:01 +00:00
Base::start();
2018-03-27 07:01:38 +00:00
2019-04-05 15:14:01 +00:00
network()->connect();
2018-03-27 07:01:38 +00:00
}
2019-03-15 17:44:15 +00:00
2019-04-05 15:14:01 +00:00
void xmrig::Controller::stop()
2019-03-29 17:16:01 +00:00
{
2019-04-05 15:14:01 +00:00
Base::stop();
2019-03-31 16:22:36 +00:00
2019-04-05 15:14:01 +00:00
delete m_network;
m_network = nullptr;
2019-03-29 17:16:01 +00:00
}
2019-04-05 15:14:01 +00:00
xmrig::Network *xmrig::Controller::network() const
2019-03-15 17:44:15 +00:00
{
2019-04-05 15:14:01 +00:00
assert(m_network != nullptr);
2019-03-15 17:44:15 +00:00
2019-04-05 15:14:01 +00:00
return m_network;
2019-03-15 17:44:15 +00:00
}