8
8
#endif
9
9
10
10
#include < qt/bitcoin.h>
11
- #include < qt/bitcoingui.h>
12
11
13
12
#include < chainparams.h>
14
13
#include < fs.h>
14
+ #include < init.h>
15
+ #include < interfaces/handler.h>
16
+ #include < interfaces/node.h>
17
+ #include < net.h>
18
+ #include < node/context.h>
19
+ #include < node/ui_interface.h>
20
+ #include < noui.h>
21
+ #include < qt/bitcoingui.h>
15
22
#include < qt/clientmodel.h>
16
23
#include < qt/guiconstants.h>
17
24
#include < qt/guiutil.h>
25
+ #include < qt/initexecutor.h>
18
26
#include < qt/intro.h>
19
- #include < net.h>
20
27
#include < qt/networkstyle.h>
21
28
#include < qt/optionsmodel.h>
22
29
#include < qt/splashscreen.h>
23
30
#include < qt/utilitydialog.h>
24
31
#include < qt/winshutdownmonitor.h>
32
+ #include < stacktraces.h>
33
+ #include < uint256.h>
25
34
#include < util/string.h>
35
+ #include < util/system.h>
36
+ #include < util/threadnames.h>
37
+ #include < util/translation.h>
38
+ #include < validation.h>
26
39
27
40
#ifdef ENABLE_WALLET
28
41
#include < qt/paymentserver.h>
29
42
#include < qt/walletcontroller.h>
30
43
#include < qt/walletmodel.h>
31
44
#endif // ENABLE_WALLET
32
45
33
- #include < init.h>
34
- #include < interfaces/handler.h>
35
- #include < interfaces/node.h>
36
- #include < node/context.h>
37
- #include < node/ui_interface.h>
38
- #include < noui.h>
39
- #include < stacktraces.h>
40
- #include < uint256.h>
41
- #include < util/system.h>
42
- #include < util/threadnames.h>
43
- #include < util/translation.h>
44
- #include < validation.h>
45
-
46
46
#include < boost/signals2/connection.hpp>
47
47
#include < memory>
48
48
52
52
#include < QLibraryInfo>
53
53
#include < QLocale>
54
54
#include < QMessageBox>
55
- #include < QProcess>
56
55
#include < QSettings>
57
56
#include < QThread>
58
57
#include < QTimer>
@@ -208,72 +207,11 @@ void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, cons
208
207
}
209
208
}
210
209
211
- BitcoinCore::BitcoinCore (interfaces::Node& node) :
212
- QObject(), m_node(node)
213
- {
214
- }
215
-
216
- void BitcoinCore::handleRunawayException (const std::exception_ptr e)
217
- {
218
- PrintExceptionContinue (e, " Runaway exception" );
219
- Q_EMIT runawayException (QString::fromStdString (m_node.getWarnings ().translated ));
220
- }
221
-
222
- void BitcoinCore::initialize ()
223
- {
224
- try
225
- {
226
- util::ThreadRename (" qt-init" );
227
- qDebug () << __func__ << " : Running initialization in thread" ;
228
- interfaces::BlockAndHeaderTipInfo tip_info;
229
- bool rv = m_node.appInitMain (&tip_info);
230
- Q_EMIT initializeResult (rv, tip_info);
231
- } catch (...) {
232
- handleRunawayException (std::current_exception ());
233
- }
234
- }
235
-
236
- void BitcoinCore::restart (QStringList args)
237
- {
238
- static bool executing_restart{false };
239
-
240
- if (!executing_restart) { // Only restart 1x, no matter how often a user clicks on a restart-button
241
- executing_restart = true ;
242
- try
243
- {
244
- qDebug () << __func__ << " : Running Restart in thread" ;
245
- m_node.appPrepareShutdown ();
246
- qDebug () << __func__ << " : Shutdown finished" ;
247
- Q_EMIT shutdownResult ();
248
- CExplicitNetCleanup::callCleanup ();
249
- QProcess::startDetached (QApplication::applicationFilePath (), args);
250
- qDebug () << __func__ << " : Restart initiated..." ;
251
- QApplication::quit ();
252
- } catch (...) {
253
- handleRunawayException (std::current_exception ());
254
- }
255
- }
256
- }
257
-
258
- void BitcoinCore::shutdown ()
259
- {
260
- try
261
- {
262
- qDebug () << __func__ << " : Running Shutdown in thread" ;
263
- m_node.appShutdown ();
264
- qDebug () << __func__ << " : Shutdown finished" ;
265
- Q_EMIT shutdownResult ();
266
- } catch (...) {
267
- handleRunawayException (std::current_exception ());
268
- }
269
- }
270
-
271
210
static int qt_argc = 1 ;
272
211
static const char * qt_argv = " dash-qt" ;
273
212
274
213
BitcoinApplication::BitcoinApplication ():
275
214
QApplication(qt_argc, const_cast <char **>(&qt_argv)),
276
- coreThread(nullptr ),
277
215
optionsModel(nullptr ),
278
216
clientModel(nullptr ),
279
217
window(nullptr ),
@@ -287,13 +225,7 @@ BitcoinApplication::BitcoinApplication():
287
225
288
226
BitcoinApplication::~BitcoinApplication ()
289
227
{
290
- if (coreThread)
291
- {
292
- qDebug () << __func__ << " : Stopping thread" ;
293
- coreThread->quit ();
294
- coreThread->wait ();
295
- qDebug () << __func__ << " : Stopped thread" ;
296
- }
228
+ m_executor.reset ();
297
229
298
230
delete window;
299
231
window = nullptr ;
@@ -350,23 +282,16 @@ bool BitcoinApplication::baseInitialize()
350
282
351
283
void BitcoinApplication::startThread ()
352
284
{
353
- if (coreThread)
354
- return ;
355
- coreThread = new QThread (this );
356
- BitcoinCore *executor = new BitcoinCore (node ());
357
- executor->moveToThread (coreThread);
285
+ assert (!m_executor);
286
+ m_executor.emplace (node ());
358
287
359
288
/* communication to and from thread */
360
- connect (executor, &BitcoinCore::initializeResult, this , &BitcoinApplication::initializeResult);
361
- connect (executor, &BitcoinCore::shutdownResult, this , &BitcoinApplication::shutdownResult);
362
- connect (executor, &BitcoinCore::runawayException, this , &BitcoinApplication::handleRunawayException);
363
- connect (this , &BitcoinApplication::requestedInitialize, executor, &BitcoinCore::initialize);
364
- connect (this , &BitcoinApplication::requestedShutdown, executor, &BitcoinCore::shutdown);
365
- connect (window, &BitcoinGUI::requestedRestart, executor, &BitcoinCore::restart);
366
- /* make sure executor object is deleted in its own thread */
367
- connect (coreThread, &QThread::finished, executor, &QObject::deleteLater);
368
-
369
- coreThread->start ();
289
+ connect (&m_executor.value (), &InitExecutor::initializeResult, this , &BitcoinApplication::initializeResult);
290
+ connect (&m_executor.value (), &InitExecutor::shutdownResult, this , &BitcoinApplication::shutdownResult);
291
+ connect (&m_executor.value (), &InitExecutor::runawayException, this , &BitcoinApplication::handleRunawayException);
292
+ connect (this , &BitcoinApplication::requestedInitialize, &m_executor.value (), &InitExecutor::initialize);
293
+ connect (this , &BitcoinApplication::requestedShutdown, &m_executor.value (), &InitExecutor::shutdown);
294
+ connect (window, &BitcoinGUI::requestedRestart, &m_executor.value (), &InitExecutor::restart);
370
295
}
371
296
372
297
void BitcoinApplication::parameterSetup ()
@@ -399,7 +324,6 @@ void BitcoinApplication::requestShutdown()
399
324
shutdownWindow.reset (ShutdownWindow::showShutdownWindow (window));
400
325
401
326
qDebug () << __func__ << " : Requesting shutdown" ;
402
- startThread ();
403
327
window->hide ();
404
328
// Must disconnect node signals otherwise current thread can deadlock since
405
329
// no event loop is running.
0 commit comments