Changeset View
Changeset View
Standalone View
Standalone View
src/qt/bitcoin.cpp
Show First 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | |||||
public Q_SLOTS: | public Q_SLOTS: | ||||
void initialize(Config *config, | void initialize(Config *config, | ||||
HTTPRPCRequestProcessor *httpRPCRequestProcessor, | HTTPRPCRequestProcessor *httpRPCRequestProcessor, | ||||
RPCServer *rpcServer); | RPCServer *rpcServer); | ||||
void shutdown(); | void shutdown(); | ||||
Q_SIGNALS: | Q_SIGNALS: | ||||
void initializeResult(int retval); | void initializeResult(bool success); | ||||
void shutdownResult(int retval); | void shutdownResult(); | ||||
void runawayException(const QString &message); | void runawayException(const QString &message); | ||||
private: | private: | ||||
boost::thread_group threadGroup; | boost::thread_group threadGroup; | ||||
CScheduler scheduler; | CScheduler scheduler; | ||||
/// Pass fatal exception message to UI thread | /// Pass fatal exception message to UI thread | ||||
void handleRunawayException(const std::exception *e); | void handleRunawayException(const std::exception *e); | ||||
Show All 28 Lines | #endif | ||||
/// Get process return value | /// Get process return value | ||||
int getReturnValue() { return returnValue; } | int getReturnValue() { return returnValue; } | ||||
/// Get window identifier of QMainWindow (BitcoinGUI) | /// Get window identifier of QMainWindow (BitcoinGUI) | ||||
WId getMainWinId() const; | WId getMainWinId() const; | ||||
public Q_SLOTS: | public Q_SLOTS: | ||||
void initializeResult(int retval); | void initializeResult(bool success); | ||||
void shutdownResult(int retval); | void shutdownResult(); | ||||
/// Handle runaway exceptions. Shows a message box with the problem and | /// Handle runaway exceptions. Shows a message box with the problem and | ||||
/// quits the program. | /// quits the program. | ||||
void handleRunawayException(const QString &message); | void handleRunawayException(const QString &message); | ||||
Q_SIGNALS: | Q_SIGNALS: | ||||
void requestedInitialize(Config *config, | void requestedInitialize(Config *config, | ||||
HTTPRPCRequestProcessor *httpRPCRequestProcessor, | HTTPRPCRequestProcessor *httpRPCRequestProcessor, | ||||
RPCServer *rpcServer); | RPCServer *rpcServer); | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | try { | ||||
return; | return; | ||||
} | } | ||||
if (!AppInitSanityChecks()) { | if (!AppInitSanityChecks()) { | ||||
Q_EMIT initializeResult(false); | Q_EMIT initializeResult(false); | ||||
return; | return; | ||||
} | } | ||||
int rv = AppInitMain(config, *httpRPCRequestProcessor, threadGroup, | bool rv = AppInitMain(config, *httpRPCRequestProcessor, threadGroup, | ||||
scheduler); | scheduler); | ||||
Q_EMIT initializeResult(rv); | Q_EMIT initializeResult(rv); | ||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
handleRunawayException(&e); | handleRunawayException(&e); | ||||
} catch (...) { | } catch (...) { | ||||
handleRunawayException(nullptr); | handleRunawayException(nullptr); | ||||
} | } | ||||
} | } | ||||
void BitcoinABC::shutdown() { | void BitcoinABC::shutdown() { | ||||
try { | try { | ||||
qDebug() << __func__ << ": Running Shutdown in thread"; | qDebug() << __func__ << ": Running Shutdown in thread"; | ||||
Interrupt(threadGroup); | Interrupt(threadGroup); | ||||
threadGroup.join_all(); | threadGroup.join_all(); | ||||
Shutdown(); | Shutdown(); | ||||
qDebug() << __func__ << ": Shutdown finished"; | qDebug() << __func__ << ": Shutdown finished"; | ||||
Q_EMIT shutdownResult(1); | Q_EMIT shutdownResult(); | ||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
handleRunawayException(&e); | handleRunawayException(&e); | ||||
} catch (...) { | } catch (...) { | ||||
handleRunawayException(nullptr); | handleRunawayException(nullptr); | ||||
} | } | ||||
} | } | ||||
BitcoinApplication::BitcoinApplication(int &argc, char **argv) | BitcoinApplication::BitcoinApplication(int &argc, char **argv) | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | |||||
void BitcoinApplication::startThread() { | void BitcoinApplication::startThread() { | ||||
if (coreThread) return; | if (coreThread) return; | ||||
coreThread = new QThread(this); | coreThread = new QThread(this); | ||||
BitcoinABC *executor = new BitcoinABC(); | BitcoinABC *executor = new BitcoinABC(); | ||||
executor->moveToThread(coreThread); | executor->moveToThread(coreThread); | ||||
/* communication to and from thread */ | /* communication to and from thread */ | ||||
connect(executor, SIGNAL(initializeResult(int)), this, | connect(executor, SIGNAL(initializeResult(bool)), this, | ||||
SLOT(initializeResult(int))); | SLOT(initializeResult(bool))); | ||||
connect(executor, SIGNAL(shutdownResult(int)), this, | connect(executor, SIGNAL(shutdownResult()), this, SLOT(shutdownResult())); | ||||
SLOT(shutdownResult(int))); | |||||
connect(executor, SIGNAL(runawayException(QString)), this, | connect(executor, SIGNAL(runawayException(QString)), this, | ||||
SLOT(handleRunawayException(QString))); | SLOT(handleRunawayException(QString))); | ||||
// Note on how Qt works: it tries to directly invoke methods if the signal | // Note on how Qt works: it tries to directly invoke methods if the signal | ||||
// is emitted on the same thread that the target object 'lives' on. | // is emitted on the same thread that the target object 'lives' on. | ||||
// But if the target object 'lives' on another thread (executor here does) | // But if the target object 'lives' on another thread (executor here does) | ||||
// the SLOT will be invoked asynchronously at a later time in the thread | // the SLOT will be invoked asynchronously at a later time in the thread | ||||
// of the target object. So.. we pass a pointer around. If you pass | // of the target object. So.. we pass a pointer around. If you pass | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | #endif | ||||
clientModel = 0; | clientModel = 0; | ||||
StartShutdown(); | StartShutdown(); | ||||
// Request shutdown from core thread | // Request shutdown from core thread | ||||
Q_EMIT requestedShutdown(); | Q_EMIT requestedShutdown(); | ||||
} | } | ||||
void BitcoinApplication::initializeResult(int retval) { | void BitcoinApplication::initializeResult(bool success) { | ||||
qDebug() << __func__ << ": Initialization result: " << retval; | qDebug() << __func__ << ": Initialization result: " << success; | ||||
// Set exit result: 0 if successful, 1 if failure | returnValue = success ? EXIT_SUCCESS : EXIT_FAILURE; | ||||
returnValue = retval ? 0 : 1; | if (success) { | ||||
if (retval) { | |||||
// Log this only after AppInit2 finishes, as then logging setup is | // Log this only after AppInit2 finishes, as then logging setup is | ||||
// guaranteed complete. | // guaranteed complete. | ||||
qWarning() << "Platform customization:" << platformStyle->getName(); | qWarning() << "Platform customization:" << platformStyle->getName(); | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
PaymentServer::LoadRootCAs(); | PaymentServer::LoadRootCAs(); | ||||
paymentServer->setOptionsModel(optionsModel); | paymentServer->setOptionsModel(optionsModel); | ||||
#endif | #endif | ||||
Show All 38 Lines | #ifdef ENABLE_WALLET | ||||
QTimer::singleShot(100, paymentServer, SLOT(uiReady())); | QTimer::singleShot(100, paymentServer, SLOT(uiReady())); | ||||
#endif | #endif | ||||
} else { | } else { | ||||
// Exit main loop. | // Exit main loop. | ||||
quit(); | quit(); | ||||
} | } | ||||
} | } | ||||
void BitcoinApplication::shutdownResult(int retval) { | void BitcoinApplication::shutdownResult() { | ||||
qDebug() << __func__ << ": Shutdown result: " << retval; | |||||
// Exit main loop after shutdown finished. | // Exit main loop after shutdown finished. | ||||
quit(); | quit(); | ||||
} | } | ||||
void BitcoinApplication::handleRunawayException(const QString &message) { | void BitcoinApplication::handleRunawayException(const QString &message) { | ||||
QMessageBox::critical( | QMessageBox::critical( | ||||
0, "Runaway exception", | 0, "Runaway exception", | ||||
BitcoinGUI::tr("A fatal error occurred. Bitcoin can no longer continue " | BitcoinGUI::tr("A fatal error occurred. Bitcoin can no longer continue " | ||||
▲ Show 20 Lines • Show All 258 Lines • Show Last 20 Lines |