i2pd/qt/i2pd_qt/DaemonQT.h

89 lines
1.7 KiB
C
Raw Normal View History

#ifndef DAEMONQT_H
#define DAEMONQT_H
2018-06-26 11:25:16 +00:00
#include <memory>
#include <QObject>
#include <QThread>
2016-06-17 15:25:28 +00:00
#include <QMutex>
2017-02-01 19:09:57 +00:00
#include <QMessageBox>
namespace i2p
{
2016-06-17 14:26:51 +00:00
namespace qt
{
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
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();
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 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
class Controller : public QObject
{
Q_OBJECT
QThread workerThread;
public:
2016-06-17 15:25:28 +00:00
Controller(DaemonQTImpl& daemon);
~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
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);
}
}
signals:
void startDaemon();
void stopDaemon();
void restartDaemon();
};
}
}
#endif // DAEMONQT_H