From 83dad62d4b9ca0f3aee0d78756fbc4a5294cb585 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 29 Dec 2016 01:09:54 +0100 Subject: [PATCH] refs #846, return CStatusMessageList instead bool, more detailed info * renamed to ps_setupHandlingCompleted * removed m_startUpCompleted --- src/blackcore/application.cpp | 87 ++++++++++++++++++++--------------- src/blackcore/application.h | 23 +++++---- 2 files changed, 61 insertions(+), 49 deletions(-) diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index 78af54f79..f9ecd1667 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -134,7 +134,7 @@ namespace BlackCore // global setup sApp = this; this->m_setupReader.reset(new CSetupReader(this)); - connect(this->m_setupReader.data(), &CSetupReader::setupAvailable, this, &CApplication::ps_setupAvailable); + connect(this->m_setupReader.data(), &CSetupReader::setupHandlingCompleted, this, &CApplication::ps_setupHandlingCompleted); connect(this->m_setupReader.data(), &CSetupReader::updateInfoAvailable, this, &CApplication::updateInfoAvailable); this->m_parser.addOptions(this->m_setupReader->getCmdLineOptions()); @@ -317,7 +317,7 @@ namespace BlackCore } else { - return CStatusMessage(getLogCategories(), CStatusMessage::SeverityError, "No reader for setup/version"); + return CStatusMessage(this).error("No reader for setup/version"); } } @@ -516,29 +516,29 @@ namespace BlackCore eventLoop.exec(); } - bool CApplication::useContexts(const CCoreFacadeConfig &coreConfig) + CStatusMessageList CApplication::useContexts(const CCoreFacadeConfig &coreConfig) { Q_ASSERT_X(this->m_parsed, Q_FUNC_INFO, "Call this function after parsing"); this->m_useContexts = true; this->m_coreFacadeConfig = coreConfig; + // if not yet initialized, init web data services if (!this->m_useWebData) { - bool s = this->useWebDataServices(CWebReaderFlags::AllReaders, CDatabaseReaderConfigList::forPilotClient()); - if (!s) { return false; } + const CStatusMessageList msgs = this->useWebDataServices(CWebReaderFlags::AllReaders, CDatabaseReaderConfigList::forPilotClient()); + if (msgs.hasErrorMessages()) { return msgs; } } - return this->startCoreFacade(); // will do nothing if setup is not yet loaded + return this->startCoreFacadeAndWebDataServices(); // will do nothing if setup is not yet loaded } - bool CApplication::useWebDataServices(const CWebReaderFlags::WebReader webReaders, const CDatabaseReaderConfigList &dbReaderConfig) + CStatusMessageList CApplication::useWebDataServices(const CWebReaderFlags::WebReader webReaders, const CDatabaseReaderConfigList &dbReaderConfig) { Q_ASSERT_X(this->m_webDataServices.isNull(), Q_FUNC_INFO, "Services already started"); BLACK_VERIFY_X(QSslSocket::supportsSsl(), Q_FUNC_INFO, "No SSL"); if (!QSslSocket::supportsSsl()) { - this->cmdLineErrorMessage("No SSL supported, can`t be used"); - return false; + return CStatusMessage(this).error("No SSL supported, can`t be used"); } this->m_webReadersUsed = webReaders; @@ -547,11 +547,12 @@ namespace BlackCore return this->startWebDataServices(); } - bool CApplication::startCoreFacade() + CStatusMessageList CApplication::startCoreFacadeAndWebDataServices() { - if (!this->m_useContexts) { return true; } // we do not use context, so no need to startup - if (!this->m_parsed) { return false; } - if (!this->m_setupReader || !this->m_setupReader->isSetupAvailable()) { return false; } + Q_ASSERT_X(this->m_parsed, Q_FUNC_INFO, "Call this function after parsing"); + + if (!this->m_useContexts) { return CStatusMessage(this).error("No need to start core facade"); } // we do not use context, so no need to startup + if (!this->m_setupReader || !this->m_setupReader->isSetupAvailable()) { return CStatusMessage(this).error("No setup reader or setup available"); } Q_ASSERT_X(this->m_coreFacade.isNull(), Q_FUNC_INFO, "Cannot alter facade"); Q_ASSERT_X(this->m_setupReader, Q_FUNC_INFO, "No facade without setup possible"); @@ -559,29 +560,35 @@ namespace BlackCore this->startWebDataServices(); - CLogMessage(this).info("Will start core facade now"); + const CStatusMessageList msgs(CStatusMessage(this).info("Will start core facade now")); this->m_coreFacade.reset(new CCoreFacade(this->m_coreFacadeConfig)); emit this->coreFacadeStarted(); - return true; + return msgs; } - bool CApplication::startWebDataServices() + CStatusMessageList CApplication::startWebDataServices() { - if (!this->m_useWebData) { return true; } - if (!this->m_parsed) { return false; } - if (!this->m_setupReader || !this->m_setupReader->isSetupAvailable()) { return false; } + Q_ASSERT_X(this->m_parsed, Q_FUNC_INFO, "Call this function after parsing"); + + if (!this->m_useWebData) { return CStatusMessage(this).warning("No need to start web data services"); } + if (!this->m_setupReader || !this->m_setupReader->isSetupAvailable()) { return CStatusMessage(this).error("No setup reader or setup available"); } Q_ASSERT_X(this->m_setupReader, Q_FUNC_INFO, "No web data services without setup possible"); + CStatusMessageList msgs; if (!this->m_webDataServices) { - CLogMessage(this).info("Will start web data services now"); + msgs.push_back(CStatusMessage(this).info("Will start web data services now")); this->m_webDataServices.reset( new CWebDataServices(this->m_webReadersUsed, this->m_dbReaderConfig, {}, this) ); } + else + { + msgs.push_back(CStatusMessage(this).info("Web data services already running")); + } emit webDataServicesStarted(true); - return true; + return msgs; } void CApplication::initLogging() @@ -606,7 +613,7 @@ namespace BlackCore // dev. system this->m_cmdDevelopment = QCommandLineOption({ "dev", "development" }, - QCoreApplication::translate("application", "Dev.system feature?"), + QCoreApplication::translate("application", "Dev. system features?"), "development"); this->addParserOption(this->m_cmdDevelopment); @@ -695,14 +702,16 @@ namespace BlackCore this->m_fileLogger->close(); } - void CApplication::ps_setupAvailable(bool available) + void CApplication::ps_setupHandlingCompleted(bool available) { if (available) { - this->m_started = this->asyncWebAndContextStart(); + // start follow ups when setup is avaialable + const CStatusMessageList msgs = this->asyncWebAndContextStart(); + this->m_started = msgs.isSuccess(); } - this->m_startUpCompleted = true; - emit setupAvailable(available); + + emit this->setupHandlingCompleted(available); if (this->m_signalStartup) { @@ -715,13 +724,15 @@ namespace BlackCore // void } - bool CApplication::asyncWebAndContextStart() + CStatusMessageList CApplication::asyncWebAndContextStart() { - if (this->m_started) { return true; } + if (this->m_started) { return CStatusMessage(this).info("Already started "); } // follow up startups - bool s = this->startWebDataServices(); - return s && this->startCoreFacade(); + CStatusMessageList msgs = this->startWebDataServices(); + if (msgs.isFailure()) return msgs; + msgs.push_back(this->startCoreFacadeAndWebDataServices()); + return msgs; } void CApplication::severeStartupProblem(const CStatusMessage &message) @@ -995,19 +1006,19 @@ namespace BlackCore #ifdef BLACK_USE_CRASHPAD base::FilePath qstringToFilePath(const QString &str) { -#ifdef Q_OS_WIN +# ifdef Q_OS_WIN return base::FilePath(str.toStdWString()); -#else +# else return base::FilePath(str.toStdString()); -#endif +# endif } #endif - void CApplication::initCrashHandler() + BlackMisc::CStatusMessageList CApplication::initCrashHandler() { #ifdef BLACK_USE_CRASHPAD // No crash handling for unit tests - if (isUnitTest()) { return; } + if (isUnitTest()) { return CStatusMessage(this).info("No crash handler for unit tests"); } static const QString extension = CBuildConfig::isRunningOnWindowsNtPlatform() ? ".exe" : QString(); static const QString handler = CDirectoryUtils::applicationDirectoryPath() + "/" + "swift_crashpad_handler" + extension; @@ -1018,8 +1029,7 @@ namespace BlackCore if (!QFileInfo::exists(handler)) { - CLogMessage(this).warning("%1 not found. Cannot init crash handler!") << handler; - return; + return CStatusMessage(this).warning("%1 not found. Cannot init crash handler!") << handler; } CUrl serverUrl; @@ -1037,6 +1047,9 @@ namespace BlackCore m_crashpadClient->StartHandler(qstringToFilePath(handler), qstringToFilePath(database), serverUrl.getFullUrl().toStdString(), annotations, {}, false); m_crashpadClient->UseHandler(); + return CStatusMessage(this).info("Using crash handler"); +#else + return CStatusMessage(this).info("Not using crash handler"); #endif } diff --git a/src/blackcore/application.h b/src/blackcore/application.h index 8f52dbb37..c935e4cd6 100644 --- a/src/blackcore/application.h +++ b/src/blackcore/application.h @@ -265,11 +265,11 @@ namespace BlackCore //! Init the contexts part and start core facade //! \sa coreFacadeStarted - bool useContexts(const CCoreFacadeConfig &coreConfig); + BlackMisc::CStatusMessageList useContexts(const CCoreFacadeConfig &coreConfig); //! Init web data services and start them //! \sa webDataServicesStarted - bool useWebDataServices(const CWebReaderFlags::WebReader webReader, const BlackCore::Db::CDatabaseReaderConfigList &dbReaderConfig); + BlackMisc::CStatusMessageList useWebDataServices(const CWebReaderFlags::WebReader webReader, const BlackCore::Db::CDatabaseReaderConfigList &dbReaderConfig); //! Get the facade CCoreFacade *getCoreFacade() { return m_coreFacade.data(); } @@ -344,8 +344,8 @@ namespace BlackCore const BlackMisc::CSlot &callback); signals: - //! Setup available (cache, web load, ..) - void setupAvailable(bool success); + //! Setup available (cache, web load, ..) or failed to load setup + void setupHandlingCompleted(bool success); //! Update info available (cache, web load) void updateInfoAvailable(bool success); @@ -362,7 +362,7 @@ namespace BlackCore protected slots: //! Setup read/synchronized - void ps_setupAvailable(bool available); + void ps_setupHandlingCompleted(bool available); //! Startup completed virtual void ps_startupCompleted(); @@ -381,7 +381,7 @@ namespace BlackCore virtual bool parsingHookIn() { return true; } //! Can be used to start special services - virtual bool startHookIn() { return true; } + virtual BlackMisc::CStatusMessageList startHookIn() { return BlackMisc::CStatusMessageList(); } //! Flag set or explicitly set to true bool isSetOrTrue(const QCommandLineOption &option) const; @@ -393,11 +393,11 @@ namespace BlackCore //! Start the core facade //! \note does nothing when setup is not yet loaded - bool startCoreFacade(); + BlackMisc::CStatusMessageList startCoreFacadeAndWebDataServices(); //! Start the web data services //! \note does nothing when setup is not yet loaded - bool startWebDataServices(); + BlackMisc::CStatusMessageList startWebDataServices(); //! executable name static const QString &executable(); @@ -415,7 +415,6 @@ namespace BlackCore QCommandLineOption m_cmdClearCache {"clearcache"}; //!< Clear cache bool m_parsed = false; //!< Parsing accomplished? bool m_started = false; //!< started with success? - bool m_startUpCompleted = false; //!< startup phase completed? Can mean startup failed bool m_startSetupReader = false; //!< start the setup reader private: @@ -429,7 +428,7 @@ namespace BlackCore bool initIsRunningInDeveloperEnvironment() const; //! Async. start when setup is loaded - bool asyncWebAndContextStart(); + BlackMisc::CStatusMessageList asyncWebAndContextStart(); //! Implementation for getFromNetwork(), postToNetwork() and headerFromNetwork() QNetworkReply *httpRequestImpl(const QNetworkRequest &request, @@ -457,9 +456,9 @@ namespace BlackCore bool m_autoSaveSettings = true;//!< automatically saving all settings // -------------- crashpad ----------------- - void initCrashHandler(); + BlackMisc::CStatusMessageList initCrashHandler(); void crashDumpUploadEnabledChanged(); - + #ifdef BLACK_USE_CRASHPAD std::unique_ptr m_crashpadClient; std::unique_ptr m_crashReportDatabase;