blob: 24ae7ba73d3d56e5a3a1b1fdb2bbe22d88f57c52 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
// 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 <qt/guiutil.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)
{
m_context.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()
{
GUIUtil::ObjectInvoke(&m_context, [this] {
try {
util::ThreadRename("qt-init");
qDebug() << "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()
{
GUIUtil::ObjectInvoke(&m_context, [this] {
try {
qDebug() << "Running Shutdown in thread";
m_node.appShutdown();
qDebug() << "Shutdown finished";
Q_EMIT shutdownResult();
} catch (const std::exception& e) {
handleRunawayException(&e);
} catch (...) {
handleRunawayException(nullptr);
}
});
}
|