aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/DaemonManager.h
blob: 428630e17cd348029343d20be0b61ee788673c0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef DAEMONMANAGER_H
#define DAEMONMANAGER_H

#include <QObject>
#include <QUrl>
#include <QProcess>

class DaemonManager : public QObject
{
    Q_OBJECT

public:

    static DaemonManager * instance(const QStringList *args);

    Q_INVOKABLE bool start(const QString &flags, bool testnet);
    Q_INVOKABLE bool stop(bool testnet);

    // return true if daemon process is started
    Q_INVOKABLE bool running(bool testnet) const;
    // Send daemon command from qml and prints output in console window.
    Q_INVOKABLE bool sendCommand(const QString &cmd, bool testnet) const;
    Q_INVOKABLE void exit();

private:

    bool sendCommand(const QString &cmd, bool testnet, QString &message) const;
    bool startWatcher(bool testnet) const;
    bool stopWatcher(bool testnet) const;
signals:
    void daemonStarted() const;
    void daemonStopped() const;
    void daemonStartFailure() const;
    void daemonConsoleUpdated(QString message) const;

public slots:
    void printOutput();
    void printError();
    void stateChanged(QProcess::ProcessState state);

private:
    explicit DaemonManager(QObject *parent = 0);
    static DaemonManager * m_instance;
    static QStringList m_clArgs;
    QProcess *m_daemon;
    bool initialized = false;
    QString m_monerod;
    bool m_has_daemon = true;
    bool m_app_exit = false;

};

#endif // DAEMONMANAGER_H