initexecutor.h raw
1 // Copyright (c) 2014-present The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5 #ifndef BITCOIN_QT_INITEXECUTOR_H
6 #define BITCOIN_QT_INITEXECUTOR_H
7
8 #include <interfaces/node.h>
9
10 #include <exception>
11
12 #include <QObject>
13 #include <QThread>
14
15 QT_BEGIN_NAMESPACE
16 class QString;
17 QT_END_NAMESPACE
18
19 /** Class encapsulating Bitcoin Core startup and shutdown.
20 * Allows running startup and shutdown in a different thread from the UI thread.
21 */
22 class InitExecutor : public QObject
23 {
24 Q_OBJECT
25 public:
26 explicit InitExecutor(interfaces::Node& node);
27 ~InitExecutor();
28
29 public Q_SLOTS:
30 void initialize();
31 void shutdown();
32
33 Q_SIGNALS:
34 void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info);
35 void shutdownResult();
36 void runawayException(const QString& message);
37
38 private:
39 /// Pass fatal exception message to UI thread
40 void handleRunawayException(const std::exception* e);
41
42 interfaces::Node& m_node;
43 QObject m_context;
44 QThread m_thread;
45 };
46
47 #endif // BITCOIN_QT_INITEXECUTOR_H
48