mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-26 17:52:13 +01:00
qt, refactor: Move InitExecutor class into its own module
This change makes InitExecutor class re-usable by an alternative GUI, e.g., QML-based one.
This commit is contained in:
parent
dbcf56b6c6
commit
c82165a557
@ -24,6 +24,7 @@
|
||||
<ClCompile Include="..\..\src\qt\csvmodelwriter.cpp" />
|
||||
<ClCompile Include="..\..\src\qt\editaddressdialog.cpp" />
|
||||
<ClCompile Include="..\..\src\qt\guiutil.cpp" />
|
||||
<ClCompile Include="..\..\src\qt\initexecutor.cpp" />
|
||||
<ClCompile Include="..\..\src\qt\intro.cpp" />
|
||||
<ClCompile Include="..\..\src\qt\modaloverlay.cpp" />
|
||||
<ClCompile Include="..\..\src\qt\networkstyle.cpp" />
|
||||
@ -78,6 +79,7 @@
|
||||
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_csvmodelwriter.cpp" />
|
||||
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_editaddressdialog.cpp" />
|
||||
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_guiutil.cpp" />
|
||||
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_initexecutor.cpp" />
|
||||
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_intro.cpp" />
|
||||
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_modaloverlay.cpp" />
|
||||
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_networkstyle.cpp" />
|
||||
|
@ -40,9 +40,9 @@ QT_MOC_CPP = \
|
||||
qt/moc_askpassphrasedialog.cpp \
|
||||
qt/moc_createwalletdialog.cpp \
|
||||
qt/moc_bantablemodel.cpp \
|
||||
qt/moc_bitcoin.cpp \
|
||||
qt/moc_bitcoinaddressvalidator.cpp \
|
||||
qt/moc_bitcoinamountfield.cpp \
|
||||
qt/moc_bitcoin.cpp \
|
||||
qt/moc_bitcoingui.cpp \
|
||||
qt/moc_bitcoinunits.cpp \
|
||||
qt/moc_clientmodel.cpp \
|
||||
@ -51,6 +51,7 @@ QT_MOC_CPP = \
|
||||
qt/moc_csvmodelwriter.cpp \
|
||||
qt/moc_editaddressdialog.cpp \
|
||||
qt/moc_guiutil.cpp \
|
||||
qt/moc_initexecutor.cpp \
|
||||
qt/moc_intro.cpp \
|
||||
qt/moc_macdockiconhandler.cpp \
|
||||
qt/moc_macnotificationhandler.cpp \
|
||||
@ -109,9 +110,9 @@ BITCOIN_QT_H = \
|
||||
qt/addresstablemodel.h \
|
||||
qt/askpassphrasedialog.h \
|
||||
qt/bantablemodel.h \
|
||||
qt/bitcoin.h \
|
||||
qt/bitcoinaddressvalidator.h \
|
||||
qt/bitcoinamountfield.h \
|
||||
qt/bitcoin.h \
|
||||
qt/bitcoingui.h \
|
||||
qt/bitcoinunits.h \
|
||||
qt/clientmodel.h \
|
||||
@ -122,6 +123,7 @@ BITCOIN_QT_H = \
|
||||
qt/editaddressdialog.h \
|
||||
qt/guiconstants.h \
|
||||
qt/guiutil.h \
|
||||
qt/initexecutor.h \
|
||||
qt/intro.h \
|
||||
qt/macdockiconhandler.h \
|
||||
qt/macnotificationhandler.h \
|
||||
@ -227,6 +229,7 @@ BITCOIN_QT_BASE_CPP = \
|
||||
qt/clientmodel.cpp \
|
||||
qt/csvmodelwriter.cpp \
|
||||
qt/guiutil.cpp \
|
||||
qt/initexecutor.cpp \
|
||||
qt/intro.cpp \
|
||||
qt/modaloverlay.cpp \
|
||||
qt/networkstyle.cpp \
|
||||
|
@ -7,12 +7,19 @@
|
||||
#endif
|
||||
|
||||
#include <qt/bitcoin.h>
|
||||
#include <qt/bitcoingui.h>
|
||||
|
||||
#include <chainparams.h>
|
||||
#include <init.h>
|
||||
#include <interfaces/handler.h>
|
||||
#include <interfaces/node.h>
|
||||
#include <node/context.h>
|
||||
#include <node/ui_interface.h>
|
||||
#include <noui.h>
|
||||
#include <qt/bitcoingui.h>
|
||||
#include <qt/clientmodel.h>
|
||||
#include <qt/guiconstants.h>
|
||||
#include <qt/guiutil.h>
|
||||
#include <qt/initexecutor.h>
|
||||
#include <qt/intro.h>
|
||||
#include <qt/networkstyle.h>
|
||||
#include <qt/optionsmodel.h>
|
||||
@ -20,6 +27,11 @@
|
||||
#include <qt/splashscreen.h>
|
||||
#include <qt/utilitydialog.h>
|
||||
#include <qt/winshutdownmonitor.h>
|
||||
#include <uint256.h>
|
||||
#include <util/system.h>
|
||||
#include <util/threadnames.h>
|
||||
#include <util/translation.h>
|
||||
#include <validation.h>
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
#include <qt/paymentserver.h>
|
||||
@ -27,18 +39,6 @@
|
||||
#include <qt/walletmodel.h>
|
||||
#endif // ENABLE_WALLET
|
||||
|
||||
#include <init.h>
|
||||
#include <interfaces/handler.h>
|
||||
#include <interfaces/node.h>
|
||||
#include <node/context.h>
|
||||
#include <node/ui_interface.h>
|
||||
#include <noui.h>
|
||||
#include <uint256.h>
|
||||
#include <util/system.h>
|
||||
#include <util/threadnames.h>
|
||||
#include <util/translation.h>
|
||||
#include <validation.h>
|
||||
|
||||
#include <boost/signals2/connection.hpp>
|
||||
#include <memory>
|
||||
|
||||
@ -155,58 +155,6 @@ void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, cons
|
||||
}
|
||||
}
|
||||
|
||||
InitExecutor::InitExecutor(interfaces::Node& node) :
|
||||
QObject(), m_node(node)
|
||||
{
|
||||
this->moveToThread(&m_thread);
|
||||
m_thread.start();
|
||||
}
|
||||
|
||||
InitExecutor::~InitExecutor()
|
||||
{
|
||||
qDebug() << __func__ << ": Stopping thread";
|
||||
m_thread.quit();
|
||||
m_thread.wait();
|
||||
qDebug() << __func__ << ": Stopped thread";
|
||||
}
|
||||
|
||||
void InitExecutor::handleRunawayException(const std::exception *e)
|
||||
{
|
||||
PrintExceptionContinue(e, "Runaway exception");
|
||||
Q_EMIT runawayException(QString::fromStdString(m_node.getWarnings().translated));
|
||||
}
|
||||
|
||||
void InitExecutor::initialize()
|
||||
{
|
||||
try
|
||||
{
|
||||
util::ThreadRename("qt-init");
|
||||
qDebug() << __func__ << ": Running initialization in thread";
|
||||
interfaces::BlockAndHeaderTipInfo tip_info;
|
||||
bool rv = m_node.appInitMain(&tip_info);
|
||||
Q_EMIT initializeResult(rv, tip_info);
|
||||
} catch (const std::exception& e) {
|
||||
handleRunawayException(&e);
|
||||
} catch (...) {
|
||||
handleRunawayException(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void InitExecutor::shutdown()
|
||||
{
|
||||
try
|
||||
{
|
||||
qDebug() << __func__ << ": Running Shutdown in thread";
|
||||
m_node.appShutdown();
|
||||
qDebug() << __func__ << ": Shutdown finished";
|
||||
Q_EMIT shutdownResult();
|
||||
} catch (const std::exception& e) {
|
||||
handleRunawayException(&e);
|
||||
} catch (...) {
|
||||
handleRunawayException(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
static int qt_argc = 1;
|
||||
static const char* qt_argv = "bitcoin-qt";
|
||||
|
||||
|
@ -10,13 +10,13 @@
|
||||
#endif
|
||||
|
||||
#include <interfaces/node.h>
|
||||
#include <qt/initexecutor.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QThread>
|
||||
|
||||
class BitcoinGUI;
|
||||
class ClientModel;
|
||||
@ -29,33 +29,6 @@ class WalletController;
|
||||
class WalletModel;
|
||||
|
||||
|
||||
/** Class encapsulating Bitcoin Core startup and shutdown.
|
||||
* Allows running startup and shutdown in a different thread from the UI thread.
|
||||
*/
|
||||
class InitExecutor: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit InitExecutor(interfaces::Node& node);
|
||||
~InitExecutor();
|
||||
|
||||
public Q_SLOTS:
|
||||
void initialize();
|
||||
void shutdown();
|
||||
|
||||
Q_SIGNALS:
|
||||
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info);
|
||||
void shutdownResult();
|
||||
void runawayException(const QString &message);
|
||||
|
||||
private:
|
||||
/// Pass fatal exception message to UI thread
|
||||
void handleRunawayException(const std::exception *e);
|
||||
|
||||
interfaces::Node& m_node;
|
||||
QThread m_thread;
|
||||
};
|
||||
|
||||
/** Main Bitcoin application object */
|
||||
class BitcoinApplication: public QApplication
|
||||
{
|
||||
|
68
src/qt/initexecutor.cpp
Normal file
68
src/qt/initexecutor.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
// Copyright (c) 2014-2021 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <qt/initexecutor.h>
|
||||
|
||||
#include <interfaces/node.h>
|
||||
#include <util/system.h>
|
||||
#include <util/threadnames.h>
|
||||
|
||||
#include <exception>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QThread>
|
||||
|
||||
InitExecutor::InitExecutor(interfaces::Node& node) :
|
||||
QObject(), m_node(node)
|
||||
{
|
||||
this->moveToThread(&m_thread);
|
||||
m_thread.start();
|
||||
}
|
||||
|
||||
InitExecutor::~InitExecutor()
|
||||
{
|
||||
qDebug() << __func__ << ": Stopping thread";
|
||||
m_thread.quit();
|
||||
m_thread.wait();
|
||||
qDebug() << __func__ << ": Stopped thread";
|
||||
}
|
||||
|
||||
void InitExecutor::handleRunawayException(const std::exception *e)
|
||||
{
|
||||
PrintExceptionContinue(e, "Runaway exception");
|
||||
Q_EMIT runawayException(QString::fromStdString(m_node.getWarnings().translated));
|
||||
}
|
||||
|
||||
void InitExecutor::initialize()
|
||||
{
|
||||
try
|
||||
{
|
||||
util::ThreadRename("qt-init");
|
||||
qDebug() << __func__ << ": Running initialization in thread";
|
||||
interfaces::BlockAndHeaderTipInfo tip_info;
|
||||
bool rv = m_node.appInitMain(&tip_info);
|
||||
Q_EMIT initializeResult(rv, tip_info);
|
||||
} catch (const std::exception& e) {
|
||||
handleRunawayException(&e);
|
||||
} catch (...) {
|
||||
handleRunawayException(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void InitExecutor::shutdown()
|
||||
{
|
||||
try
|
||||
{
|
||||
qDebug() << __func__ << ": Running Shutdown in thread";
|
||||
m_node.appShutdown();
|
||||
qDebug() << __func__ << ": Shutdown finished";
|
||||
Q_EMIT shutdownResult();
|
||||
} catch (const std::exception& e) {
|
||||
handleRunawayException(&e);
|
||||
} catch (...) {
|
||||
handleRunawayException(nullptr);
|
||||
}
|
||||
}
|
46
src/qt/initexecutor.h
Normal file
46
src/qt/initexecutor.h
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2014-2021 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_QT_INITEXECUTOR_H
|
||||
#define BITCOIN_QT_INITEXECUTOR_H
|
||||
|
||||
#include <interfaces/node.h>
|
||||
|
||||
#include <exception>
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QString;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
/** Class encapsulating Bitcoin Core startup and shutdown.
|
||||
* Allows running startup and shutdown in a different thread from the UI thread.
|
||||
*/
|
||||
class InitExecutor: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit InitExecutor(interfaces::Node& node);
|
||||
~InitExecutor();
|
||||
|
||||
public Q_SLOTS:
|
||||
void initialize();
|
||||
void shutdown();
|
||||
|
||||
Q_SIGNALS:
|
||||
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info);
|
||||
void shutdownResult();
|
||||
void runawayException(const QString &message);
|
||||
|
||||
private:
|
||||
/// Pass fatal exception message to UI thread
|
||||
void handleRunawayException(const std::exception *e);
|
||||
|
||||
interfaces::Node& m_node;
|
||||
QThread m_thread;
|
||||
};
|
||||
|
||||
#endif // BITCOIN_QT_INITEXECUTOR_H
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include <interfaces/node.h>
|
||||
#include <qt/bitcoin.h>
|
||||
#include <qt/initexecutor.h>
|
||||
#include <qt/test/apptests.h>
|
||||
#include <qt/test/rpcnestedtests.h>
|
||||
#include <qt/test/uritests.h>
|
||||
|
Loading…
x
Reference in New Issue
Block a user