Changeset View
Changeset View
Standalone View
Standalone View
src/qt/bitcoin.cpp
Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | |||||
* Class encapsulating Bitcoin ABC startup and shutdown. | * Class encapsulating Bitcoin ABC startup and shutdown. | ||||
* Allows running startup and shutdown in a different thread from the UI thread. | * Allows running startup and shutdown in a different thread from the UI thread. | ||||
*/ | */ | ||||
class BitcoinABC : public QObject { | class BitcoinABC : public QObject { | ||||
Q_OBJECT | Q_OBJECT | ||||
public: | public: | ||||
explicit BitcoinABC(); | explicit BitcoinABC(); | ||||
/** | |||||
* Basic initialization, before starting initialization/shutdown thread. | |||||
* Return true on success. | |||||
*/ | |||||
static bool baseInitialize(Config &config, RPCServer &rpcServer); | |||||
public Q_SLOTS: | public Q_SLOTS: | ||||
void initialize(Config *config, | void initialize(Config *config, | ||||
HTTPRPCRequestProcessor *httpRPCRequestProcessor); | HTTPRPCRequestProcessor *httpRPCRequestProcessor); | ||||
void shutdown(); | void shutdown(); | ||||
Q_SIGNALS: | Q_SIGNALS: | ||||
void initializeResult(bool success); | void initializeResult(bool success); | ||||
void shutdownResult(); | void shutdownResult(); | ||||
Show All 13 Lines | |||||
public: | public: | ||||
explicit BitcoinApplication(int &argc, char **argv); | explicit BitcoinApplication(int &argc, char **argv); | ||||
~BitcoinApplication(); | ~BitcoinApplication(); | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
/// Create payment server | /// Create payment server | ||||
void createPaymentServer(); | void createPaymentServer(); | ||||
#endif | #endif | ||||
/// parameter interaction/setup based on rules | |||||
void parameterSetup(); | |||||
/// Create options model | /// Create options model | ||||
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 | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 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"))); | ||||
} | } | ||||
bool BitcoinABC::baseInitialize(Config &config, RPCServer &rpcServer) { | |||||
if (!AppInitBasicSetup()) { | |||||
return false; | |||||
} | |||||
if (!AppInitParameterInteraction(config, rpcServer)) { | |||||
return false; | |||||
} | |||||
if (!AppInitSanityChecks()) { | |||||
return false; | |||||
} | |||||
if (!AppInitLockDataDirectory()) { | |||||
return false; | |||||
} | |||||
return true; | |||||
} | |||||
void BitcoinABC::initialize(Config *cfg, | void BitcoinABC::initialize(Config *cfg, | ||||
HTTPRPCRequestProcessor *httpRPCRequestProcessor) { | HTTPRPCRequestProcessor *httpRPCRequestProcessor) { | ||||
Config &config(*cfg); | Config &config(*cfg); | ||||
try { | try { | ||||
qDebug() << __func__ << ": Running initialization in thread"; | qDebug() << __func__ << ": Running initialization in thread"; | ||||
bool rv = AppInitMain(config, *httpRPCRequestProcessor, threadGroup, | bool rv = AppInitMain(config, *httpRPCRequestProcessor, threadGroup, | ||||
scheduler); | scheduler); | ||||
Q_EMIT initializeResult(rv); | Q_EMIT initializeResult(rv); | ||||
▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | void BitcoinApplication::startThread() { | ||||
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() { | |||||
InitLogging(); | |||||
InitParameterInteraction(); | |||||
} | |||||
void BitcoinApplication::requestInitialize( | void BitcoinApplication::requestInitialize( | ||||
Config &config, HTTPRPCRequestProcessor &httpRPCRequestProcessor, | Config &config, HTTPRPCRequestProcessor &httpRPCRequestProcessor, | ||||
RPCServer &rpcServer) { | 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! | ||||
▲ Show 20 Lines • Show All 307 Lines • ▼ Show 20 Lines | |||||
#if defined(Q_OS_WIN) | #if defined(Q_OS_WIN) | ||||
// Install global event filter for processing Windows session related | // Install global event filter for processing Windows session related | ||||
// Windows messages (WM_QUERYENDSESSION and WM_ENDSESSION) | // Windows messages (WM_QUERYENDSESSION and WM_ENDSESSION) | ||||
qApp->installNativeEventFilter(new WinShutdownMonitor()); | qApp->installNativeEventFilter(new WinShutdownMonitor()); | ||||
#endif | #endif | ||||
// Install qDebug() message handler to route to debug.log | // Install qDebug() message handler to route to debug.log | ||||
qInstallMessageHandler(DebugMessageHandler); | qInstallMessageHandler(DebugMessageHandler); | ||||
// Allow parameter interaction before we create the options model | // Allow parameter interaction before we create the options model | ||||
app.parameterSetup(); | ParameterSetup(); | ||||
// Load GUI settings from QSettings | // Load GUI settings from QSettings | ||||
app.createOptionsModel(gArgs.IsArgSet("-resetguisettings")); | app.createOptionsModel(gArgs.IsArgSet("-resetguisettings")); | ||||
// Subscribe to global signals from core | // Subscribe to global signals from core | ||||
uiInterface.InitMessage.connect(InitMessage); | uiInterface.InitMessage.connect(InitMessage); | ||||
// 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()); | ||||
RPCServer rpcServer; | RPCServer rpcServer; | ||||
HTTPRPCRequestProcessor httpRPCRequestProcessor(config, rpcServer); | HTTPRPCRequestProcessor httpRPCRequestProcessor(config, rpcServer); | ||||
int rv = EXIT_SUCCESS; | int rv = EXIT_SUCCESS; | ||||
try { | try { | ||||
app.createWindow(&config, networkStyle.data()); | app.createWindow(&config, networkStyle.data()); | ||||
// Perform base initialization before spinning up | // Perform base initialization before spinning up | ||||
// initialization/shutdown thread. This is acceptable because this | // initialization/shutdown thread. This is acceptable because this | ||||
// function only contains steps that are quick to execute, so the GUI | // function only contains steps that are quick to execute, so the GUI | ||||
// thread won't be held up. | // thread won't be held up. | ||||
if (BitcoinABC::baseInitialize(config, rpcServer)) { | if (AppInitBase(config, rpcServer)) { | ||||
app.requestInitialize(config, httpRPCRequestProcessor, rpcServer); | 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(); | ||||
Show All 17 Lines |