|
|
@ -7,139 +7,81 @@ namespace i2p |
|
|
|
{ |
|
|
|
{ |
|
|
|
namespace util |
|
|
|
namespace util |
|
|
|
{ |
|
|
|
{ |
|
|
|
namespace DaemonQt |
|
|
|
bool DaemonQT::init(int argc, char* argv[]) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
return Daemon_Singleton::init(argc, argv); |
|
|
|
void Worker::startDaemon() { |
|
|
|
} |
|
|
|
qDebug("Performing daemon start..."); |
|
|
|
|
|
|
|
DaemonQTImpl::start(); |
|
|
|
|
|
|
|
qDebug("Daemon started."); |
|
|
|
|
|
|
|
emit resultReady(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void Worker::restartDaemon() { |
|
|
|
|
|
|
|
qDebug("Performing daemon restart..."); |
|
|
|
|
|
|
|
DaemonQTImpl::restart(); |
|
|
|
|
|
|
|
qDebug("Daemon restarted."); |
|
|
|
|
|
|
|
emit resultReady(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
void Worker::stopDaemon() { |
|
|
|
|
|
|
|
qDebug("Performing daemon stop..."); |
|
|
|
|
|
|
|
DaemonQTImpl::stop(); |
|
|
|
|
|
|
|
qDebug("Daemon stopped."); |
|
|
|
|
|
|
|
emit resultReady(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Controller::Controller() { |
|
|
|
|
|
|
|
Worker *worker = new Worker; |
|
|
|
|
|
|
|
worker->moveToThread(&workerThread); |
|
|
|
|
|
|
|
connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater); |
|
|
|
|
|
|
|
connect(this, &Controller::startDaemon, worker, &Worker::startDaemon); |
|
|
|
|
|
|
|
connect(this, &Controller::stopDaemon, worker, &Worker::stopDaemon); |
|
|
|
|
|
|
|
connect(this, &Controller::restartDaemon, worker, &Worker::restartDaemon); |
|
|
|
|
|
|
|
connect(worker, &Worker::resultReady, this, &Controller::handleResults); |
|
|
|
|
|
|
|
workerThread.start(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
Controller::~Controller() { |
|
|
|
|
|
|
|
qDebug("Closing and waiting for daemon worker thread..."); |
|
|
|
|
|
|
|
workerThread.quit(); |
|
|
|
|
|
|
|
workerThread.wait(); |
|
|
|
|
|
|
|
qDebug("Waiting for daemon worker thread finished."); |
|
|
|
|
|
|
|
if(i2p::util::DaemonQt::DaemonQTImpl::isRunning()) { |
|
|
|
|
|
|
|
qDebug("Stopping the daemon..."); |
|
|
|
|
|
|
|
i2p::util::DaemonQt::DaemonQTImpl::stop(); |
|
|
|
|
|
|
|
qDebug("Stopped the daemon."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static DaemonQTImpl::runningChangedCallback DaemonQTImpl_runningChanged; |
|
|
|
|
|
|
|
static bool DaemonQTImpl_running; |
|
|
|
|
|
|
|
static QMutex* mutex; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool DaemonQTImpl::init(int argc, char* argv[]){mutex=new QMutex(QMutex::Recursive);setRunningCallback(0);DaemonQTImpl_running=false;return Daemon.init(argc,argv);} |
|
|
|
|
|
|
|
void DaemonQTImpl::deinit(){delete mutex;} |
|
|
|
|
|
|
|
void DaemonQTImpl::start(){QMutexLocker locker(mutex);setRunning(true);Daemon.start();} |
|
|
|
|
|
|
|
void DaemonQTImpl::stop(){QMutexLocker locker(mutex);Daemon.stop();setRunning(false);} |
|
|
|
|
|
|
|
void DaemonQTImpl::restart(){QMutexLocker locker(mutex);stop();start();} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DaemonQTImpl::setRunningCallback(runningChangedCallback cb){DaemonQTImpl_runningChanged=cb;} |
|
|
|
|
|
|
|
bool DaemonQTImpl::isRunning(){return DaemonQTImpl_running;} |
|
|
|
|
|
|
|
void DaemonQTImpl::setRunning(bool newValue){ |
|
|
|
|
|
|
|
bool oldValue = DaemonQTImpl_running; |
|
|
|
|
|
|
|
if(oldValue!=newValue) { |
|
|
|
|
|
|
|
DaemonQTImpl_running = newValue; |
|
|
|
|
|
|
|
if(DaemonQTImpl_runningChanged!=0)DaemonQTImpl_runningChanged(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
|
|
|
#include <memory> |
|
|
|
|
|
|
|
#include "mainwindow.h" |
|
|
|
|
|
|
|
#include <QApplication> |
|
|
|
|
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
#include "../../Daemon.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace i2p |
|
|
|
namespace i2p |
|
|
|
{ |
|
|
|
{ |
|
|
|
namespace util |
|
|
|
namespace qt |
|
|
|
{ |
|
|
|
{ |
|
|
|
class DaemonQTImpl: public std::enable_shared_from_this<DaemonQTImpl> |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DaemonQTImpl (int argc, char* argv[]): |
|
|
|
|
|
|
|
m_App (argc, argv) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Run () |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
MainWindow w(m_App); |
|
|
|
|
|
|
|
w.show (); |
|
|
|
|
|
|
|
m_App.exec(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
void Worker::startDaemon() { |
|
|
|
|
|
|
|
qDebug("Performing daemon start..."); |
|
|
|
void StartDaemon () |
|
|
|
DaemonQTImpl::start(); |
|
|
|
{ |
|
|
|
qDebug("Daemon started."); |
|
|
|
Daemon.start (); |
|
|
|
emit resultReady(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void Worker::restartDaemon() { |
|
|
|
|
|
|
|
qDebug("Performing daemon restart..."); |
|
|
|
|
|
|
|
DaemonQTImpl::restart(); |
|
|
|
|
|
|
|
qDebug("Daemon restarted."); |
|
|
|
|
|
|
|
emit resultReady(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void Worker::stopDaemon() { |
|
|
|
|
|
|
|
qDebug("Performing daemon stop..."); |
|
|
|
|
|
|
|
DaemonQTImpl::stop(); |
|
|
|
|
|
|
|
qDebug("Daemon stopped."); |
|
|
|
|
|
|
|
emit resultReady(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void StopDaemon () |
|
|
|
Controller::Controller() { |
|
|
|
{ |
|
|
|
Worker *worker = new Worker; |
|
|
|
Daemon.stop (); |
|
|
|
worker->moveToThread(&workerThread); |
|
|
|
} |
|
|
|
connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater); |
|
|
|
|
|
|
|
connect(this, &Controller::startDaemon, worker, &Worker::startDaemon); |
|
|
|
|
|
|
|
connect(this, &Controller::stopDaemon, worker, &Worker::stopDaemon); |
|
|
|
|
|
|
|
connect(this, &Controller::restartDaemon, worker, &Worker::restartDaemon); |
|
|
|
|
|
|
|
connect(worker, &Worker::resultReady, this, &Controller::handleResults); |
|
|
|
|
|
|
|
workerThread.start(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Controller::~Controller() { |
|
|
|
|
|
|
|
qDebug("Closing and waiting for daemon worker thread..."); |
|
|
|
|
|
|
|
workerThread.quit(); |
|
|
|
|
|
|
|
workerThread.wait(); |
|
|
|
|
|
|
|
qDebug("Waiting for daemon worker thread finished."); |
|
|
|
|
|
|
|
if(DaemonQTImpl::isRunning()) { |
|
|
|
|
|
|
|
qDebug("Stopping the daemon..."); |
|
|
|
|
|
|
|
DaemonQTImpl::stop(); |
|
|
|
|
|
|
|
qDebug("Stopped the daemon."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool IsRunning () const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return Daemon.running; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QApplication m_App; |
|
|
|
static DaemonQTImpl::runningChangedCallback DaemonQTImpl_runningChanged; |
|
|
|
}; |
|
|
|
static bool DaemonQTImpl_running; |
|
|
|
|
|
|
|
static QMutex* mutex; |
|
|
|
|
|
|
|
|
|
|
|
bool DaemonQT::init(int argc, char* argv[]) |
|
|
|
bool DaemonQTImpl::init(int argc, char* argv[]){mutex=new QMutex(QMutex::Recursive);setRunningCallback(0);DaemonQTImpl_running=false;return Daemon.init(argc,argv);} |
|
|
|
{ |
|
|
|
void DaemonQTImpl::deinit(){delete mutex;} |
|
|
|
m_Impl = std::make_shared<DaemonQTImpl> (argc, argv); |
|
|
|
void DaemonQTImpl::start(){QMutexLocker locker(mutex);setRunning(true);Daemon.start();} |
|
|
|
return Daemon_Singleton::init(argc, argv); |
|
|
|
void DaemonQTImpl::stop(){QMutexLocker locker(mutex);Daemon.stop();setRunning(false);} |
|
|
|
} |
|
|
|
void DaemonQTImpl::restart(){QMutexLocker locker(mutex);stop();start();} |
|
|
|
|
|
|
|
|
|
|
|
void DaemonQT::run () |
|
|
|
void DaemonQTImpl::setRunningCallback(runningChangedCallback cb){DaemonQTImpl_runningChanged=cb;} |
|
|
|
{ |
|
|
|
bool DaemonQTImpl::isRunning(){return DaemonQTImpl_running;} |
|
|
|
if (m_Impl) |
|
|
|
void DaemonQTImpl::setRunning(bool newValue){ |
|
|
|
{ |
|
|
|
bool oldValue = DaemonQTImpl_running; |
|
|
|
m_Impl->Run (); |
|
|
|
if(oldValue!=newValue) { |
|
|
|
m_Impl = nullptr; |
|
|
|
DaemonQTImpl_running = newValue; |
|
|
|
|
|
|
|
if(DaemonQTImpl_runningChanged!=0)DaemonQTImpl_runningChanged(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|