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