Changeset View
Changeset View
Standalone View
Standalone View
src/qt/bitcoin.cpp
Show First 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
class BitcoinABC : public QObject { | class BitcoinABC : public QObject { | ||||
Q_OBJECT | Q_OBJECT | ||||
public: | public: | ||||
explicit BitcoinABC(); | explicit BitcoinABC(); | ||||
public Q_SLOTS: | public Q_SLOTS: | ||||
void initialize(Config *config, | void initialize(Config *config, | ||||
HTTPRPCRequestProcessor *httpRPCRequestProcessor); | HTTPRPCRequestProcessor *httpRPCRequestProcessor, | ||||
RPCServer *rpcServer); | |||||
void shutdown(); | void shutdown(); | ||||
Q_SIGNALS: | Q_SIGNALS: | ||||
void initializeResult(int retval); | void initializeResult(int retval); | ||||
void shutdownResult(int retval); | void shutdownResult(int retval); | ||||
void runawayException(const QString &message); | void runawayException(const QString &message); | ||||
private: | private: | ||||
Show All 21 Lines | #endif | ||||
void createOptionsModel(bool resetSettings); | void createOptionsModel(bool resetSettings); | ||||
/// Create main window | /// Create main window | ||||
void createWindow(const Config *, const NetworkStyle *networkStyle); | void createWindow(const Config *, const NetworkStyle *networkStyle); | ||||
/// Create splash screen | /// Create splash screen | ||||
void createSplashScreen(const NetworkStyle *networkStyle); | void createSplashScreen(const NetworkStyle *networkStyle); | ||||
/// Request core initialization | /// Request core initialization | ||||
void requestInitialize(Config &config, | void requestInitialize(Config &config, | ||||
HTTPRPCRequestProcessor &httpRPCRequestProcessor); | HTTPRPCRequestProcessor &httpRPCRequestProcessor, | ||||
RPCServer &rpcServer); | |||||
/// Request core shutdown | /// Request core shutdown | ||||
void requestShutdown(Config &config); | void requestShutdown(Config &config); | ||||
/// 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(int retval); | ||||
void shutdownResult(int retval); | void shutdownResult(int retval); | ||||
/// 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); | |||||
void requestedShutdown(); | void requestedShutdown(); | ||||
void stopThread(); | void stopThread(); | ||||
void splashFinished(QWidget *window); | void splashFinished(QWidget *window); | ||||
private: | private: | ||||
QThread *coreThread; | QThread *coreThread; | ||||
OptionsModel *optionsModel; | OptionsModel *optionsModel; | ||||
ClientModel *clientModel; | ClientModel *clientModel; | ||||
Show All 15 Lines | |||||
BitcoinABC::BitcoinABC() : QObject() {} | BitcoinABC::BitcoinABC() : QObject() {} | ||||
void BitcoinABC::handleRunawayException(const std::exception *e) { | void BitcoinABC::handleRunawayException(const std::exception *e) { | ||||
PrintExceptionContinue(e, "Runaway exception"); | PrintExceptionContinue(e, "Runaway exception"); | ||||
Q_EMIT runawayException(QString::fromStdString(GetWarnings("gui"))); | Q_EMIT runawayException(QString::fromStdString(GetWarnings("gui"))); | ||||
} | } | ||||
void BitcoinABC::initialize(Config *cfg, | void BitcoinABC::initialize(Config *cfg, | ||||
HTTPRPCRequestProcessor *httpRPCRequestProcessor) { | HTTPRPCRequestProcessor *httpRPCRequestProcessor, | ||||
RPCServer *rpcSrv) { | |||||
Config &config(*cfg); | Config &config(*cfg); | ||||
RPCServer &rpcServer = *rpcSrv; | |||||
try { | try { | ||||
qDebug() << __func__ << ": Running AppInit2 in thread"; | qDebug() << __func__ << ": Running AppInit2 in thread"; | ||||
if (!AppInitBasicSetup()) { | if (!AppInitBasicSetup()) { | ||||
Q_EMIT initializeResult(false); | Q_EMIT initializeResult(false); | ||||
return; | return; | ||||
} | } | ||||
if (!AppInitParameterInteraction(config)) { | if (!AppInitParameterInteraction(config, rpcServer)) { | ||||
Q_EMIT initializeResult(false); | Q_EMIT initializeResult(false); | ||||
return; | return; | ||||
} | } | ||||
if (!AppInitSanityChecks()) { | if (!AppInitSanityChecks()) { | ||||
Q_EMIT initializeResult(false); | Q_EMIT initializeResult(false); | ||||
return; | return; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | void BitcoinApplication::startThread() { | ||||
// a reference around (even if it's non-const) you'll get Qt generating | // a reference around (even if it's non-const) you'll get Qt generating | ||||
// code to copy-construct the parameter in question (Q_DECLARE_METATYPE | // code to copy-construct the parameter in question (Q_DECLARE_METATYPE | ||||
// and qRegisterMetaType generate this code). For the Config class, | // and qRegisterMetaType generate this code). For the Config class, | ||||
// which is noncopyable, we can't do this. So.. we have to pass | // which is noncopyable, we can't do this. So.. we have to pass | ||||
// pointers to Config around. Make sure Config &/Config * isn't a | // pointers to Config around. Make sure Config &/Config * isn't a | ||||
// temporary (eg it lives somewhere aside from the stack) or this will | // temporary (eg it lives somewhere aside from the stack) or this will | ||||
// crash because initialize() gets executed in another thread at some | // crash because initialize() gets executed in another thread at some | ||||
// unspecified time (after) requestedInitialize() is emitted! | // unspecified time (after) requestedInitialize() is emitted! | ||||
connect(this, | connect(this, SIGNAL(requestedInitialize( | ||||
SIGNAL(requestedInitialize(Config *, HTTPRPCRequestProcessor *)), | Config *, HTTPRPCRequestProcessor *, RPCServer *)), | ||||
executor, SLOT(initialize(Config *, HTTPRPCRequestProcessor *))); | executor, | ||||
SLOT(initialize(Config *, HTTPRPCRequestProcessor *, RPCServer *))); | |||||
connect(this, SIGNAL(requestedShutdown()), executor, SLOT(shutdown())); | connect(this, SIGNAL(requestedShutdown()), executor, SLOT(shutdown())); | ||||
/* make sure executor object is deleted in its own thread */ | /* make sure executor object is deleted in its own thread */ | ||||
connect(this, SIGNAL(stopThread()), executor, SLOT(deleteLater())); | connect(this, SIGNAL(stopThread()), executor, SLOT(deleteLater())); | ||||
connect(this, SIGNAL(stopThread()), coreThread, SLOT(quit())); | connect(this, SIGNAL(stopThread()), coreThread, SLOT(quit())); | ||||
coreThread->start(); | coreThread->start(); | ||||
} | } | ||||
void BitcoinApplication::parameterSetup() { | void BitcoinApplication::parameterSetup() { | ||||
InitLogging(); | InitLogging(); | ||||
InitParameterInteraction(); | InitParameterInteraction(); | ||||
} | } | ||||
void BitcoinApplication::requestInitialize( | void BitcoinApplication::requestInitialize( | ||||
Config &config, HTTPRPCRequestProcessor &httpRPCRequestProcessor) { | Config &config, HTTPRPCRequestProcessor &httpRPCRequestProcessor, | ||||
RPCServer &rpcServer) { | |||||
qDebug() << __func__ << ": Requesting initialize"; | qDebug() << __func__ << ": Requesting initialize"; | ||||
startThread(); | startThread(); | ||||
// IMPORTANT: config must NOT be a reference to a temporary because below | // IMPORTANT: config must NOT be a reference to a temporary because below | ||||
// signal may be connected to a slot that will be executed as a queued | // signal may be connected to a slot that will be executed as a queued | ||||
// connection in another thread! | // connection in another thread! | ||||
Q_EMIT requestedInitialize(&config, &httpRPCRequestProcessor); | Q_EMIT requestedInitialize(&config, &httpRPCRequestProcessor, &rpcServer); | ||||
} | } | ||||
void BitcoinApplication::requestShutdown(Config &config) { | void BitcoinApplication::requestShutdown(Config &config) { | ||||
// Show a simple window indicating shutdown status. Do this first as some of | // Show a simple window indicating shutdown status. Do this first as some of | ||||
// the steps may take some time below, for example the RPC console may still | // the steps may take some time below, for example the RPC console may still | ||||
// be executing a command. | // be executing a command. | ||||
shutdownWindow.reset(ShutdownWindow::showShutdownWindow(window)); | shutdownWindow.reset(ShutdownWindow::showShutdownWindow(window)); | ||||
▲ Show 20 Lines • Show All 314 Lines • ▼ Show 20 Lines | #endif | ||||
// Get global config | // Get global config | ||||
Config &config = const_cast<Config &>(GetConfig()); | Config &config = const_cast<Config &>(GetConfig()); | ||||
if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && | if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && | ||||
!gArgs.GetBoolArg("-min", false)) | !gArgs.GetBoolArg("-min", false)) | ||||
app.createSplashScreen(networkStyle.data()); | app.createSplashScreen(networkStyle.data()); | ||||
HTTPRPCRequestProcessor httpRPCRequestProcessor(config); | RPCServer rpcServer; | ||||
HTTPRPCRequestProcessor httpRPCRequestProcessor(config, rpcServer); | |||||
try { | try { | ||||
app.createWindow(&config, networkStyle.data()); | app.createWindow(&config, networkStyle.data()); | ||||
app.requestInitialize(config, httpRPCRequestProcessor); | app.requestInitialize(config, httpRPCRequestProcessor, rpcServer); | ||||
#if defined(Q_OS_WIN) | #if defined(Q_OS_WIN) | ||||
WinShutdownMonitor::registerShutdownBlockReason( | WinShutdownMonitor::registerShutdownBlockReason( | ||||
QObject::tr("%1 didn't yet exit safely...") | QObject::tr("%1 didn't yet exit safely...") | ||||
.arg(QObject::tr(PACKAGE_NAME)), | .arg(QObject::tr(PACKAGE_NAME)), | ||||
(HWND)app.getMainWinId()); | (HWND)app.getMainWinId()); | ||||
#endif | #endif | ||||
app.exec(); | app.exec(); | ||||
app.requestShutdown(config); | app.requestShutdown(config); | ||||
Show All 11 Lines |