Bitcoin Core 22.99.0
P2P Digital Currency
initexecutor.cpp
Go to the documentation of this file.
1// Copyright (c) 2014-2021 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#include <qt/initexecutor.h>
6
7#include <interfaces/node.h>
8#include <qt/guiutil.h>
9#include <util/system.h>
10#include <util/threadnames.h>
11
12#include <exception>
13
14#include <QDebug>
15#include <QObject>
16#include <QString>
17#include <QThread>
18
20 : QObject(), m_node(node)
21{
22 m_context.moveToThread(&m_thread);
23 m_thread.start();
24}
25
27{
28 qDebug() << __func__ << ": Stopping thread";
29 m_thread.quit();
30 m_thread.wait();
31 qDebug() << __func__ << ": Stopped thread";
32}
33
34void InitExecutor::handleRunawayException(const std::exception* e)
35{
36 PrintExceptionContinue(e, "Runaway exception");
37 Q_EMIT runawayException(QString::fromStdString(m_node.getWarnings().translated));
38}
39
41{
43 try {
44 util::ThreadRename("qt-init");
45 qDebug() << "Running initialization in thread";
47 bool rv = m_node.appInitMain(&tip_info);
48 Q_EMIT initializeResult(rv, tip_info);
49 } catch (const std::exception& e) {
51 } catch (...) {
53 }
54 });
55}
56
58{
60 try {
61 qDebug() << "Running Shutdown in thread";
63 qDebug() << "Shutdown finished";
64 Q_EMIT shutdownResult();
65 } catch (const std::exception& e) {
67 } catch (...) {
69 }
70 });
71}
NodeContext m_node
Definition: bitcoin-gui.cpp:36
void initialize()
void handleRunawayException(const std::exception *e)
Pass fatal exception message to UI thread.
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)
QObject m_context
Definition: initexecutor.h:43
void runawayException(const QString &message)
InitExecutor(interfaces::Node &node)
interfaces::Node & m_node
Definition: initexecutor.h:42
QThread m_thread
Definition: initexecutor.h:44
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:55
virtual bilingual_str getWarnings()=0
Get warnings.
virtual void appShutdown()=0
Stop node.
virtual bool appInitMain(interfaces::BlockAndHeaderTipInfo *tip_info=nullptr)=0
Start node.
void ObjectInvoke(QObject *object, Fn &&function, Qt::ConnectionType connection=Qt::QueuedConnection)
Queue a function to run in an object's event loop.
Definition: guiutil.h:368
void ThreadRename(std::string &&)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name.
Definition: threadnames.cpp:57
std::string translated
Definition: translation.h:18
Block and header tip information.
Definition: node.h:45
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
Definition: system.cpp:781