Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
qt
initexecutor.cpp
Go to the documentation of this file.
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
#include <
qt/initexecutor.h
>
6
7
#include <
interfaces/node.h
>
8
#include <
util/exception.h
>
9
#include <
util/threadnames.h
>
10
11
#include <exception>
12
13
#include <QDebug>
14
#include <QMetaObject>
15
#include <QObject>
16
#include <QString>
17
#include <QThread>
18
19
InitExecutor::InitExecutor
(
interfaces::Node
&
node
)
20
: QObject(),
m_node
(
node
)
21
{
22
m_context
.moveToThread(&
m_thread
);
23
m_thread
.start();
24
}
25
26
InitExecutor::~InitExecutor
()
27
{
28
qDebug() << __func__ <<
": Stopping thread"
;
29
m_thread
.quit();
30
m_thread
.wait();
31
qDebug() << __func__ <<
": Stopped thread"
;
32
}
33
34
void
InitExecutor::handleRunawayException
(
const
std::exception* e)
35
{
36
PrintExceptionContinue
(e,
"Runaway exception"
);
37
Q_EMIT
runawayException
(QString::fromStdString(
m_node
.getWarnings().translated));
38
}
39
40
void
InitExecutor::initialize
()
41
{
42
QMetaObject::invokeMethod(&
m_context
, [
this
] {
43
try
{
44
util::ThreadRename
(
"qt-init"
);
45
qDebug() <<
"Running initialization in thread"
;
46
interfaces::BlockAndHeaderTipInfo
tip_info;
47
bool
rv =
m_node
.appInitMain(&tip_info);
48
Q_EMIT
initializeResult
(rv, tip_info);
49
}
catch
(
const
std::exception& e) {
50
handleRunawayException
(&e);
51
}
catch
(...) {
52
handleRunawayException
(
nullptr
);
53
}
54
});
55
}
56
57
void
InitExecutor::shutdown
()
58
{
59
QMetaObject::invokeMethod(&
m_context
, [
this
] {
60
try
{
61
qDebug() <<
"Running Shutdown in thread"
;
62
m_node
.appShutdown();
63
qDebug() <<
"Shutdown finished"
;
64
Q_EMIT
shutdownResult
();
65
}
catch
(
const
std::exception& e) {
66
handleRunawayException
(&e);
67
}
catch
(...) {
68
handleRunawayException
(
nullptr
);
69
}
70
});
71
}
InitExecutor::shutdown
void shutdown()
Definition
initexecutor.cpp:57
InitExecutor::initialize
void initialize()
Definition
initexecutor.cpp:40
InitExecutor::handleRunawayException
void handleRunawayException(const std::exception *e)
Pass fatal exception message to UI thread.
Definition
initexecutor.cpp:34
InitExecutor::~InitExecutor
~InitExecutor()
Definition
initexecutor.cpp:26
InitExecutor::initializeResult
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)
InitExecutor::m_context
QObject m_context
Definition
initexecutor.h:43
InitExecutor::runawayException
void runawayException(const QString &message)
InitExecutor::shutdownResult
void shutdownResult()
InitExecutor::InitExecutor
InitExecutor(interfaces::Node &node)
Definition
initexecutor.cpp:19
InitExecutor::m_node
interfaces::Node & m_node
Definition
initexecutor.h:42
InitExecutor::m_thread
QThread m_thread
Definition
initexecutor.h:44
interfaces::Node
Top-level interface for a bitcoin node (bitcoind process).
Definition
node.h:70
PrintExceptionContinue
void PrintExceptionContinue(const std::exception *pex, std::string_view thread_name)
Definition
exception.cpp:36
initexecutor.h
node
Definition
messages.h:21
util::ThreadRename
void ThreadRename(const std::string &)
Definition
threadnames.cpp:55
node.h
interfaces::BlockAndHeaderTipInfo
Block and header tip information.
Definition
node.h:50
threadnames.h
exception.h
Generated on
for Bitcoin Core by
1.17.0