2016-06-17 16:47:17 +03:00
|
|
|
#ifndef DAEMONQT_H
|
|
|
|
#define DAEMONQT_H
|
|
|
|
|
2018-06-26 14:25:16 +03:00
|
|
|
#include <memory>
|
2016-06-17 16:49:49 +03:00
|
|
|
#include <QObject>
|
|
|
|
#include <QThread>
|
2016-06-17 18:25:28 +03:00
|
|
|
#include <QMutex>
|
2017-02-01 22:09:57 +03:00
|
|
|
#include <QMessageBox>
|
2016-06-17 16:49:49 +03:00
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
2016-06-17 17:26:51 +03:00
|
|
|
namespace qt
|
2016-06-17 16:49:49 +03:00
|
|
|
{
|
|
|
|
class DaemonQTImpl
|
|
|
|
{
|
|
|
|
public:
|
2016-06-17 18:25:28 +03:00
|
|
|
|
|
|
|
DaemonQTImpl ();
|
2018-01-06 06:48:51 +03:00
|
|
|
~DaemonQTImpl ();
|
2016-06-17 18:25:28 +03:00
|
|
|
|
2016-06-17 16:49:49 +03:00
|
|
|
typedef void (*runningChangedCallback)();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief init
|
|
|
|
* @param argc
|
|
|
|
* @param argv
|
|
|
|
* @return success
|
|
|
|
*/
|
2018-05-19 18:03:49 +03:00
|
|
|
bool init(int argc, char* argv[], std::shared_ptr<std::ostream> logstream);
|
2016-06-17 18:25:28 +03:00
|
|
|
void start();
|
|
|
|
void stop();
|
|
|
|
void restart();
|
|
|
|
void setRunningCallback(runningChangedCallback cb);
|
|
|
|
bool isRunning();
|
2016-06-17 16:49:49 +03:00
|
|
|
private:
|
2016-06-17 18:25:28 +03:00
|
|
|
void setRunning(bool running);
|
2017-02-01 22:09:57 +03:00
|
|
|
void showError(std::string errorMsg);
|
2016-06-17 18:25:28 +03:00
|
|
|
private:
|
|
|
|
QMutex* mutex;
|
|
|
|
bool m_IsRunning;
|
|
|
|
runningChangedCallback m_RunningChangedCallback;
|
2016-06-17 16:49:49 +03:00
|
|
|
};
|
|
|
|
|
2016-06-17 18:25:28 +03:00
|
|
|
class Worker : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
|
2018-01-06 06:48:51 +03:00
|
|
|
Worker (DaemonQTImpl& daemon);
|
2016-06-17 18:25:28 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2018-01-06 06:48:51 +03:00
|
|
|
DaemonQTImpl& m_Daemon;
|
2016-06-17 18:25:28 +03:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void startDaemon();
|
|
|
|
void restartDaemon();
|
|
|
|
void stopDaemon();
|
|
|
|
|
|
|
|
signals:
|
2017-02-01 22:09:57 +03:00
|
|
|
void resultReady(bool failed, QString failureMessage);
|
2018-01-06 06:48:51 +03:00
|
|
|
};
|
2016-06-17 18:25:28 +03:00
|
|
|
|
2016-06-17 16:49:49 +03:00
|
|
|
class Controller : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
QThread workerThread;
|
|
|
|
public:
|
2016-06-17 18:25:28 +03:00
|
|
|
Controller(DaemonQTImpl& daemon);
|
2016-06-17 16:49:49 +03:00
|
|
|
~Controller();
|
2016-06-17 18:25:28 +03:00
|
|
|
private:
|
2018-01-06 06:48:51 +03:00
|
|
|
DaemonQTImpl& m_Daemon;
|
2016-06-17 18:25:28 +03:00
|
|
|
|
2016-06-17 16:49:49 +03:00
|
|
|
public slots:
|
2017-02-01 22:09:57 +03:00
|
|
|
void handleResults(bool failed, QString failureMessage){
|
|
|
|
if(failed){
|
|
|
|
QMessageBox::critical(0, QObject::tr("Error"), failureMessage);
|
|
|
|
}
|
|
|
|
}
|
2016-06-17 16:49:49 +03:00
|
|
|
signals:
|
|
|
|
void startDaemon();
|
|
|
|
void stopDaemon();
|
|
|
|
void restartDaemon();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-17 16:47:17 +03:00
|
|
|
#endif // DAEMONQT_H
|