i2pd/qt/i2pd_qt/DaemonQT.h

88 lines
1.6 KiB
C
Raw Normal View History

#ifndef DAEMONQT_H
#define DAEMONQT_H
#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 ();
~DaemonQTImpl ();
typedef void (*runningChangedCallback)();
/**
* @brief init
* @param argc
* @param argv
* @return success
*/
2016-06-17 15:25:28 +00:00
bool init(int argc, char* argv[]);
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:
Worker (DaemonQTImpl& daemon);
private:
DaemonQTImpl& m_Daemon;
public slots:
void startDaemon();
void restartDaemon();
void stopDaemon();
signals:
2017-02-01 19:09:57 +00:00
void resultReady(bool failed, QString failureMessage);
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:
DaemonQTImpl& m_Daemon;
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