forked from dashpay/dash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
7 changed files
with
136 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters