void CryptobullionCore::shutdown() { try { printf("Running Shutdown in thread\n"); threadGroup.interrupt_all(); threadGroup.join_all(); Shutdown(0); printf("Shutdown finished\n"); emit shutdownResult(1); } catch (std::exception& e) { handleRunawayException(&e); } catch (...) { handleRunawayException(NULL); } }
void CryptobullionCore::initialize() { try { printf("Running AppInit2 in thread\n"); int rv = AppInit2(threadGroup); if(rv) { /* Start a dummy RPC thread if no RPC thread is active yet * to handle timeouts. */ //StartDummyRPCThread(); } emit initializeResult(rv); } catch (std::exception& e) { handleRunawayException(&e); } catch (...) { handleRunawayException(NULL); } }
void CryptobullionApplication::startThread() { coreThread = new QThread(this); CryptobullionCore *executor = new CryptobullionCore(); executor->moveToThread(coreThread); /* communication to and from thread */ connect(executor, SIGNAL(initializeResult(int)), this, SLOT(initializeResult(int))); connect(executor, SIGNAL(shutdownResult(int)), this, SLOT(shutdownResult(int))); connect(executor, SIGNAL(runawayException(QString)), this, SLOT(handleRunawayException(QString))); connect(this, SIGNAL(requestedInitialize()), executor, SLOT(initialize())); connect(this, SIGNAL(requestedShutdown()), executor, SLOT(shutdown())); /* make sure executor object is deleted in its own thread */ connect(this, SIGNAL(stopThread()), executor, SLOT(deleteLater())); connect(this, SIGNAL(stopThread()), coreThread, SLOT(quit())); coreThread->start(); }
int main(int argc, char *argv[]) { // Do this early as we don't want to bother initializing if we are just calling IPC for (int i = 1; i < argc; i++) { if (strlen(argv[i]) > 8 && strncasecmp(argv[i], "bitshekel:", 9) == 0) { const char *strURL = argv[i]; try { boost::interprocess::message_queue mq(boost::interprocess::open_only, "BitcoinURL"); if(mq.try_send(strURL, strlen(strURL), 0)) exit(0); else break; } catch (boost::interprocess::interprocess_exception &ex) { break; } } } // Internal string conversion is all UTF-8 QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForTr()); Q_INIT_RESOURCE(bitcoin); QApplication app(argc, argv); // Command-line options take precedence: ParseParameters(argc, argv); // ... then bitcoin.conf: if (!ReadConfigFile(mapArgs, mapMultiArgs)) { fprintf(stderr, "Error: Specified directory does not exist\n"); return 1; } // Application identification (must be set before OptionsModel is initialized, // as it is used to locate QSettings) app.setOrganizationName("Bitcoin"); app.setOrganizationDomain("bitcoin.org"); if(GetBoolArg("-testnet")) // Separate UI settings for testnet app.setApplicationName("Bitshekel-Qt-testnet"); else app.setApplicationName("Bitshekel-Qt"); // ... then GUI settings: OptionsModel optionsModel; // Get desired locale ("en_US") from command line or system locale QString lang_territory = QString::fromStdString(GetArg("-lang", QLocale::system().name().toStdString())); // Load language files for configured locale: // - First load the translator for the base language, without territory // - Then load the more specific locale translator QString lang = lang_territory; lang.truncate(lang_territory.lastIndexOf('_')); // "en" QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator; qtTranslatorBase.load(QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" + lang); if (!qtTranslatorBase.isEmpty()) app.installTranslator(&qtTranslatorBase); qtTranslator.load(QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" + lang_territory); if (!qtTranslator.isEmpty()) app.installTranslator(&qtTranslator); translatorBase.load(":/translations/"+lang); if (!translatorBase.isEmpty()) app.installTranslator(&translatorBase); translator.load(":/translations/"+lang_territory); if (!translator.isEmpty()) app.installTranslator(&translator); QSplashScreen splash(QPixmap(":/images/splash"), 0); if (GetBoolArg("-splash", true) && !GetBoolArg("-min")) { splash.show(); splash.setAutoFillBackground(true); splashref = &splash; } app.processEvents(); app.setQuitOnLastWindowClosed(false); try { if(AppInit2(argc, argv)) { { // Put this in a block, so that BitcoinGUI is cleaned up properly before // calling Shutdown() in case of exceptions. optionsModel.Upgrade(); // Must be done after AppInit2 BitcoinGUI window; if (splashref) splash.finish(&window); ClientModel clientModel(&optionsModel); WalletModel walletModel(pwalletMain, &optionsModel); guiref = &window; window.setClientModel(&clientModel); window.setWalletModel(&walletModel); // If -min option passed, start window minimized. if(GetBoolArg("-min")) { window.showMinimized(); } else { window.show(); } // Place this here as guiref has to be defined if we dont want to lose URLs ipcInit(); // Check for URL in argv for (int i = 1; i < argc; i++) { if (strlen(argv[i]) > 8 && strncasecmp(argv[i], "bitshekel:", 9) == 0) { const char *strURL = argv[i]; try { boost::interprocess::message_queue mq(boost::interprocess::open_only, "BitcoinURL"); mq.try_send(strURL, strlen(strURL), 0); } catch (boost::interprocess::interprocess_exception &ex) { } } } app.exec(); guiref = 0; } Shutdown(NULL); } else { return 1; } } catch (std::exception& e) { handleRunawayException(&e); } catch (...) { handleRunawayException(NULL); } return 0; }