refs #521, reading of setup and version

* fixed in launcher so reloading works (this also uses fixed URL list)
* signal for version synchronized
* removed setupreader.h where possible -> less compile dependencies
* removed redundant logging
* removed unused cleanup override
* connect &QCoreApplication::aboutToQuit in threaded reader
This commit is contained in:
Klaus Basan
2015-11-25 03:44:19 +01:00
parent 530ddb3d9f
commit 94a277ee8e
8 changed files with 56 additions and 25 deletions

View File

@@ -90,6 +90,7 @@ namespace BlackCore
if (url.isEmpty()) if (url.isEmpty())
{ {
CLogMessage(this).warning("Cannot read update info, failed URLs: %1") << this->m_updateInfoUrls.read()->getFailedUrls(); CLogMessage(this).warning("Cannot read update info, failed URLs: %1") << this->m_updateInfoUrls.read()->getFailedUrls();
emit versionSynchronized(false);
return; return;
} }
QNetworkRequest request(url); QNetworkRequest request(url);
@@ -144,7 +145,6 @@ namespace BlackCore
if (this->isFinishedOrShutdown()) if (this->isFinishedOrShutdown())
{ {
CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("Terminated loading bootstrap files"); CLogMessage(this).info("Terminated loading bootstrap files");
nwReply->abort(); nwReply->abort();
emit setupSynchronized(false); emit setupSynchronized(false);
@@ -234,9 +234,9 @@ namespace BlackCore
if (this->isFinishedOrShutdown()) if (this->isFinishedOrShutdown())
{ {
CLogMessage(this).debug() << Q_FUNC_INFO;
CLogMessage(this).info("Terminated loading of update info"); CLogMessage(this).info("Terminated loading of update info");
nwReply->abort(); nwReply->abort();
emit versionSynchronized(false);
return; // stop, terminate straight away, ending thread return; // stop, terminate straight away, ending thread
} }
@@ -263,6 +263,7 @@ namespace BlackCore
if (sameVersionLoaded) if (sameVersionLoaded)
{ {
CLogMessage(this).info("Same update info loaded from %1 as already in data cache %2") << urlString << m_updateInfo.getFilename(); CLogMessage(this).info("Same update info loaded from %1 as already in data cache %2") << urlString << m_updateInfo.getFilename();
emit versionSynchronized(true);
return; // success return; // success
} }
@@ -279,11 +280,13 @@ namespace BlackCore
if (!m.isEmpty()) if (!m.isEmpty())
{ {
CLogMessage(this).preformatted(m); CLogMessage(this).preformatted(m);
emit versionSynchronized(false);
return; // issue with cache return; // issue with cache
} }
else else
{ {
CLogMessage(this).info("Update info: Updated data cache in %1") << m_updateInfo.getFilename(); CLogMessage(this).info("Update info: Updated data cache in %1") << m_updateInfo.getFilename();
emit versionSynchronized(true);
return; // success return; // success
} // cache } // cache
} // outdated? } // outdated?
@@ -302,6 +305,10 @@ namespace BlackCore
{ {
QTimer::singleShot(500, this, &CSetupReader::ps_readSetup); QTimer::singleShot(500, this, &CSetupReader::ps_readSetup);
} }
else
{
emit versionSynchronized(false);
}
} // method } // method
} // namespace } // namespace

View File

@@ -37,6 +37,9 @@ namespace BlackCore
//! Setup has been read //! Setup has been read
void setupSynchronized(bool success); void setupSynchronized(bool success);
//! Version bas been read
void versionSynchronized(bool success);
protected slots: protected slots:
//! \copydoc CThreadedReader::initialize //! \copydoc CThreadedReader::initialize
virtual void initialize() override; virtual void initialize() override;

View File

@@ -35,8 +35,8 @@ using namespace BlackMisc::Weather;
namespace BlackCore namespace BlackCore
{ {
CWebDataServices::CWebDataServices( CWebDataServices::CWebDataServices(
CWebReaderFlags::WebReader readerFlags, int autoReadAfterSetupSynchronized, QObject *parent) : CWebReaderFlags::WebReader readerFlags, int autoReadAfterSetupSynchronizedMs, QObject *parent) :
QObject(parent), m_readerFlags(readerFlags), m_autoReadAfterSetupMs(autoReadAfterSetupSynchronized) QObject(parent), m_readerFlags(readerFlags), m_autoReadAfterSetupMs(autoReadAfterSetupSynchronizedMs)
{ {
this->setObjectName("CWebDataReader"); this->setObjectName("CWebDataReader");
connect(&CSetupReader::instance(), &CSetupReader::setupSynchronized, this, &CWebDataServices::ps_setupRead); connect(&CSetupReader::instance(), &CSetupReader::setupSynchronized, this, &CWebDataServices::ps_setupRead);

View File

@@ -14,7 +14,6 @@
#include "blackcore/blackcoreexport.h" #include "blackcore/blackcoreexport.h"
#include "blackcore/webreaderflags.h" #include "blackcore/webreaderflags.h"
#include "blackcore/setupreader.h"
#include "blackcore/data/globalsetup.h" #include "blackcore/data/globalsetup.h"
#include "blackmisc/aviation/atcstationlist.h" #include "blackmisc/aviation/atcstationlist.h"
#include "blackmisc/aviation/liverylist.h" #include "blackmisc/aviation/liverylist.h"
@@ -53,7 +52,7 @@ namespace BlackCore
public: public:
//! Constructor //! Constructor
CWebDataServices(CWebReaderFlags::WebReader readerFlags, CWebDataServices(CWebReaderFlags::WebReader readerFlags,
int autoReadAfterSetupSynchronized, QObject *parent = nullptr); int autoReadAfterSetupSynchronizedMs, QObject *parent = nullptr);
//! Shutdown //! Shutdown
void gracefulShutdown(); void gracefulShutdown();

View File

@@ -17,7 +17,11 @@ namespace BlackMisc
CThreadedReader::CThreadedReader(QObject *owner, const QString &name) : CThreadedReader::CThreadedReader(QObject *owner, const QString &name) :
CContinuousWorker(owner, name), CContinuousWorker(owner, name),
m_updateTimer(new QTimer(this)) m_updateTimer(new QTimer(this))
{ } {
bool c = connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, &CThreadedReader::gracefulShutdown);
Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
Q_UNUSED(c);
}
qint64 CThreadedReader::lastModifiedMsSinceEpoch(QNetworkReply *nwReply) const qint64 CThreadedReader::lastModifiedMsSinceEpoch(QNetworkReply *nwReply) const
{ {
@@ -51,7 +55,10 @@ namespace BlackMisc
void CThreadedReader::requestStop() void CThreadedReader::requestStop()
{ {
QMetaObject::invokeMethod(m_updateTimer, "stop"); if (m_updateTimer)
{
QMetaObject::invokeMethod(m_updateTimer, "stop");
}
} }
void CThreadedReader::requestReload() void CThreadedReader::requestReload()
@@ -62,6 +69,7 @@ namespace BlackMisc
void CThreadedReader::gracefulShutdown() void CThreadedReader::gracefulShutdown()
{ {
if (this->m_shutdown) { return; }
this->m_shutdown = true; this->m_shutdown = true;
this->requestStop(); this->requestStop();
this->quit(); this->quit();
@@ -69,12 +77,7 @@ namespace BlackMisc
CThreadedReader::~CThreadedReader() CThreadedReader::~CThreadedReader()
{ {
cleanup(); this->m_shutdown = true;
}
void CThreadedReader::cleanup()
{
// cleanup code would go here
} }
void CThreadedReader::setInterval(int updatePeriodMs) void CThreadedReader::setInterval(int updatePeriodMs)

View File

@@ -49,9 +49,6 @@ namespace BlackMisc
//! Destructor //! Destructor
virtual ~CThreadedReader(); virtual ~CThreadedReader();
//! \copydoc CContinuousWorker::cleanup
virtual void cleanup() override;
//! Set the update time //! Set the update time
//! \param updatePeriodMs <=0 stops the timer //! \param updatePeriodMs <=0 stops the timer
//! \threadsafe //! \threadsafe
@@ -61,6 +58,7 @@ namespace BlackMisc
//! \threadsafe //! \threadsafe
int interval() const; int interval() const;
public slots:
//! Graceful shutdown //! Graceful shutdown
//! \threadsafe //! \threadsafe
void gracefulShutdown(); void gracefulShutdown();

View File

@@ -11,7 +11,7 @@
#include "ui_swiftlauncher.h" #include "ui_swiftlauncher.h"
#include "blackgui/stylesheetutility.h" #include "blackgui/stylesheetutility.h"
#include "blackcore/dbusserver.h" #include "blackcore/dbusserver.h"
#include "blackcore/data/updateinfo.h" #include "blackcore/setupreader.h"
#include "blackmisc/network/networkutils.h" #include "blackmisc/network/networkutils.h"
#include "blackmisc/icons.h" #include "blackmisc/icons.h"
#include "blackmisc/project.h" #include "blackmisc/project.h"
@@ -49,10 +49,12 @@ CSwiftLauncher::CSwiftLauncher(QWidget *parent) :
connect(ui->tb_SwiftGui, &QPushButton::pressed, this, &CSwiftLauncher::ps_startButtonPressed); connect(ui->tb_SwiftGui, &QPushButton::pressed, this, &CSwiftLauncher::ps_startButtonPressed);
connect(ui->tb_Database, &QPushButton::pressed, this, &CSwiftLauncher::ps_startButtonPressed); connect(ui->tb_Database, &QPushButton::pressed, this, &CSwiftLauncher::ps_startButtonPressed);
connect(ui->tb_BackToMain, &QToolButton::pressed, this, &CSwiftLauncher::ps_showMainPage); connect(ui->tb_BackToMain, &QToolButton::pressed, this, &CSwiftLauncher::ps_showMainPage);
connect(&CSetupReader::instance(), &CSetupReader::versionSynchronized, this, &CSwiftLauncher::ps_loadedSetup);
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_L), this, SLOT(ps_showLogPage())); new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_L), this, SLOT(ps_showLogPage()));
this->ui->le_DBusServerPort->setValidator(new QIntValidator(0, 65535, this)); this->ui->le_DBusServerPort->setValidator(new QIntValidator(0, 65535, this));
QTimer::singleShot(5000, this, &CSwiftLauncher::ps_loadedSetup); //deferred init of setup
// QTimer::singleShot(5000, this, &CSwiftLauncher::ps_loadedSetup); //deferred init of setup
} }
CSwiftLauncher::~CSwiftLauncher() CSwiftLauncher::~CSwiftLauncher()
@@ -254,11 +256,21 @@ QString CSwiftLauncher::toCmdLine(const QString &exe, const QStringList &exeArgs
void CSwiftLauncher::ps_loadSetup() void CSwiftLauncher::ps_loadSetup()
{ {
CSetupReader::instance().requestReload(); if (!this->ui->le_LatestVersion->text().isEmpty())
{
this->ui->le_LatestVersion->setText("");
CSetupReader::instance().requestReload();
}
} }
void CSwiftLauncher::ps_loadedSetup() void CSwiftLauncher::ps_loadedSetup(bool success)
{ {
if (!success)
{
CLogMessage(this).warning("Loading setup or version information failed");
return;
}
CUpdateInfo updateInfo(this->m_updateInfo.get()); CUpdateInfo updateInfo(this->m_updateInfo.get());
QString latestVersion(updateInfo.getLatestVersion()) ; // need to get this from somewhere QString latestVersion(updateInfo.getLatestVersion()) ; // need to get this from somewhere
CUrlList downloadUrls(updateInfo.getDownloadUrls()); CUrlList downloadUrls(updateInfo.getDownloadUrls());
@@ -278,6 +290,11 @@ void CSwiftLauncher::ps_loadedSetup()
this->displayLatestNews(); this->displayLatestNews();
} }
void CSwiftLauncher::ps_changedCache()
{
this->ps_loadedSetup(true);
}
void CSwiftLauncher::ps_startButtonPressed() void CSwiftLauncher::ps_startButtonPressed()
{ {
QObject *sender = QObject::sender(); QObject *sender = QObject::sender();

View File

@@ -14,7 +14,8 @@
#include <QDialog> #include <QDialog>
#include <QScopedPointer> #include <QScopedPointer>
#include "blackcore/setupreader.h" #include "blackcore/data/globalsetup.h"
#include "blackcore/data/updateinfo.h"
#include "blackgui/enableforframelesswindow.h" #include "blackgui/enableforframelesswindow.h"
#include "blackgui/overlaymessagesframe.h" #include "blackgui/overlaymessagesframe.h"
#include "swiftguistandard/guimodeenums.h" #include "swiftguistandard/guimodeenums.h"
@@ -58,8 +59,8 @@ protected:
private: private:
QScopedPointer<Ui::CSwiftLauncher> ui; QScopedPointer<Ui::CSwiftLauncher> ui;
BlackCore::CData<BlackCore::Data::GlobalSetup> m_setup { this, &CSwiftLauncher::ps_loadedSetup }; //!< setup cache BlackCore::CData<BlackCore::Data::GlobalSetup> m_setup { this, &CSwiftLauncher::ps_changedCache }; //!< setup cache
BlackCore::CData<BlackCore::Data::UpdateInfo> m_updateInfo { this, &CSwiftLauncher::ps_loadedSetup }; BlackCore::CData<BlackCore::Data::UpdateInfo> m_updateInfo { this, &CSwiftLauncher::ps_changedCache }; //!< version cache
QString m_executable; QString m_executable;
QStringList m_executableArgs; QStringList m_executableArgs;
@@ -113,7 +114,10 @@ private slots:
void ps_loadSetup(); void ps_loadSetup();
//! Loaded latest version //! Loaded latest version
void ps_loadedSetup(); void ps_loadedSetup(bool success);
//! Cache values have been changed
void ps_changedCache();
//! Start button pressed //! Start button pressed
void ps_startButtonPressed(); void ps_startButtonPressed();