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 <util/system.h>
9 #include <util/threadnames.h>
10 
11 #include <exception>
12 
13 #include <QDebug>
14 #include <QObject>
15 #include <QString>
16 #include <QThread>
17 
19  : QObject(), m_node(node)
20 {
21  this->moveToThread(&m_thread);
22  m_thread.start();
23 }
24 
26 {
27  qDebug() << __func__ << ": Stopping thread";
28  m_thread.quit();
29  m_thread.wait();
30  qDebug() << __func__ << ": Stopped thread";
31 }
32 
33 void InitExecutor::handleRunawayException(const std::exception* e)
34 {
35  PrintExceptionContinue(e, "Runaway exception");
36  Q_EMIT runawayException(QString::fromStdString(m_node.getWarnings().translated));
37 }
38 
40 {
41  try {
42  util::ThreadRename("qt-init");
43  qDebug() << __func__ << ": Running initialization in thread";
45  bool rv = m_node.appInitMain(&tip_info);
46  Q_EMIT initializeResult(rv, tip_info);
47  } catch (const std::exception& e) {
49  } catch (...) {
50  handleRunawayException(nullptr);
51  }
52 }
53 
55 {
56  try {
57  qDebug() << __func__ << ": Running Shutdown in thread";
59  qDebug() << __func__ << ": Shutdown finished";
60  Q_EMIT shutdownResult();
61  } catch (const std::exception& e) {
63  } catch (...) {
64  handleRunawayException(nullptr);
65  }
66 }
InitExecutor::~InitExecutor
~InitExecutor()
Definition: initexecutor.cpp:25
InitExecutor::shutdown
void shutdown()
Definition: initexecutor.cpp:54
InitExecutor::m_node
interfaces::Node & m_node
Definition: initexecutor.h:42
m_node
NodeContext & m_node
Definition: bitcoin-node.cpp:38
InitExecutor::runawayException
void runawayException(const QString &message)
interfaces::BlockAndHeaderTipInfo
Block and header tip information.
Definition: node.h:44
interfaces::Node::appShutdown
virtual void appShutdown()=0
Stop node.
InitExecutor::shutdownResult
void shutdownResult()
node.h
util::ThreadRename
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
InitExecutor::m_thread
QThread m_thread
Definition: initexecutor.h:43
bilingual_str::translated
std::string translated
Definition: translation.h:18
InitExecutor::initialize
void initialize()
Definition: initexecutor.cpp:39
interfaces::Node
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:54
system.h
InitExecutor::InitExecutor
InitExecutor(interfaces::Node &node)
Definition: initexecutor.cpp:18
initexecutor.h
interfaces::Node::getWarnings
virtual bilingual_str getWarnings()=0
Get warnings.
node
Definition: interfaces.cpp:68
InitExecutor::handleRunawayException
void handleRunawayException(const std::exception *e)
Pass fatal exception message to UI thread.
Definition: initexecutor.cpp:33
PrintExceptionContinue
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
Definition: system.cpp:779
InitExecutor::initializeResult
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)
threadnames.h
interfaces::Node::appInitMain
virtual bool appInitMain(interfaces::BlockAndHeaderTipInfo *tip_info=nullptr)=0
Start node.