mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 19:05:31 +08:00
* only call this->abandonAndWait() when not in main thread (also slack discussion MS/KB) * make sure web data service start to read even if setup reader signal was missed * add timestamp to setupreader to detect "recently read" in case signal is missed
This commit is contained in:
@@ -36,7 +36,10 @@ namespace BlackCore
|
|||||||
// initialized by local file for testing
|
// initialized by local file for testing
|
||||||
// I do not even need to start in background here
|
// I do not even need to start in background here
|
||||||
CLogMessage(this).info("Using local bootstrap file: %1") << localFileName;
|
CLogMessage(this).info("Using local bootstrap file: %1") << localFileName;
|
||||||
emit this->setupSynchronized(true);
|
BlackMisc::singleShot(1000, QThread::currentThread(), [ = ]()
|
||||||
|
{
|
||||||
|
emit this->setupSynchronized(true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -272,6 +275,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();
|
||||||
|
this->setUpdateTimestamp();
|
||||||
emit versionSynchronized(true);
|
emit versionSynchronized(true);
|
||||||
return; // success
|
return; // success
|
||||||
}
|
}
|
||||||
@@ -295,6 +299,7 @@ namespace BlackCore
|
|||||||
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();
|
||||||
|
this->setUpdateTimestamp();
|
||||||
emit versionSynchronized(true);
|
emit versionSynchronized(true);
|
||||||
return; // success
|
return; // success
|
||||||
} // cache
|
} // cache
|
||||||
|
|||||||
@@ -39,9 +39,22 @@ namespace BlackCore
|
|||||||
QObject(parent), m_readerFlags(readerFlags), m_autoReadAfterSetupMs(autoReadAfterSetupSynchronizedMs)
|
QObject(parent), m_readerFlags(readerFlags), m_autoReadAfterSetupMs(autoReadAfterSetupSynchronizedMs)
|
||||||
{
|
{
|
||||||
this->setObjectName("CWebDataReader");
|
this->setObjectName("CWebDataReader");
|
||||||
connect(&CSetupReader::instance(), &CSetupReader::setupSynchronized, this, &CWebDataServices::ps_setupRead);
|
|
||||||
this->initReaders(readerFlags);
|
this->initReaders(readerFlags);
|
||||||
this->initWriters();
|
this->initWriters();
|
||||||
|
if (autoReadAfterSetupSynchronizedMs >= 0)
|
||||||
|
{
|
||||||
|
// wait for setup read completion
|
||||||
|
// in case this was already fired or will never be fired set a time out
|
||||||
|
if (CSetupReader::instance().updatedWithinLastMs(10 * 1000))
|
||||||
|
{
|
||||||
|
QTimer::singleShot(500, this, &CWebDataServices::ps_setupTimedOut);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
connect(&CSetupReader::instance(), &CSetupReader::setupSynchronized, this, &CWebDataServices::ps_setupRead);
|
||||||
|
QTimer::singleShot(10 * 1000, this, &CWebDataServices::ps_setupTimedOut);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QMetaObject::Connection> CWebDataServices::connectDataReadSignal(QObject *receiver, std::function<void(CEntityFlags::Entity, CEntityFlags::ReadState, int)> dataRead)
|
QList<QMetaObject::Connection> CWebDataServices::connectDataReadSignal(QObject *receiver, std::function<void(CEntityFlags::Entity, CEntityFlags::ReadState, int)> dataRead)
|
||||||
@@ -153,6 +166,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
CEntityFlags::Entity CWebDataServices::triggerRead(CEntityFlags::Entity whatToRead)
|
CEntityFlags::Entity CWebDataServices::triggerRead(CEntityFlags::Entity whatToRead)
|
||||||
{
|
{
|
||||||
|
m_initialRead = true;
|
||||||
CEntityFlags::Entity triggeredRead = CEntityFlags::NoEntity;
|
CEntityFlags::Entity triggeredRead = CEntityFlags::NoEntity;
|
||||||
if (m_vatsimDataFileReader)
|
if (m_vatsimDataFileReader)
|
||||||
{
|
{
|
||||||
@@ -486,6 +500,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
if (m_autoReadAfterSetupMs >= 0)
|
if (m_autoReadAfterSetupMs >= 0)
|
||||||
{
|
{
|
||||||
|
if (m_initialRead) { return; }
|
||||||
CLogMessage(this).info("Setup synchronized, will trigger read of web service data");
|
CLogMessage(this).info("Setup synchronized, will trigger read of web service data");
|
||||||
this->readInBackground(CEntityFlags::AllEntities, m_autoReadAfterSetupMs);
|
this->readInBackground(CEntityFlags::AllEntities, m_autoReadAfterSetupMs);
|
||||||
}
|
}
|
||||||
@@ -501,8 +516,15 @@ namespace BlackCore
|
|||||||
CLogMessage(this).debug() << "Setup changed";
|
CLogMessage(this).debug() << "Setup changed";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CWebDataServices::ps_setupTimedOut()
|
||||||
|
{
|
||||||
|
if (this->m_initialRead) { return; }
|
||||||
|
this->ps_setupRead(true);
|
||||||
|
}
|
||||||
|
|
||||||
void CWebDataServices::readInBackground(CEntityFlags::Entity entities, int delayMs)
|
void CWebDataServices::readInBackground(CEntityFlags::Entity entities, int delayMs)
|
||||||
{
|
{
|
||||||
|
m_initialRead = true;
|
||||||
if (delayMs > 100)
|
if (delayMs > 100)
|
||||||
{
|
{
|
||||||
BlackMisc::singleShot(delayMs, QThread::currentThread(), [ = ]()
|
BlackMisc::singleShot(delayMs, QThread::currentThread(), [ = ]()
|
||||||
|
|||||||
@@ -268,6 +268,9 @@ namespace BlackCore
|
|||||||
//! Setup has been changed
|
//! Setup has been changed
|
||||||
void ps_setupChanged();
|
void ps_setupChanged();
|
||||||
|
|
||||||
|
//! Setup timed out
|
||||||
|
void ps_setupTimedOut();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Init the readers
|
//! Init the readers
|
||||||
void initReaders(CWebReaderFlags::WebReader flags);
|
void initReaders(CWebReaderFlags::WebReader flags);
|
||||||
@@ -276,7 +279,8 @@ namespace BlackCore
|
|||||||
void initWriters();
|
void initWriters();
|
||||||
|
|
||||||
CWebReaderFlags::WebReader m_readerFlags = CWebReaderFlags::WebReaderFlag::None; //!< which readers are available
|
CWebReaderFlags::WebReader m_readerFlags = CWebReaderFlags::WebReaderFlag::None; //!< which readers are available
|
||||||
int m_autoReadAfterSetupMs = -1; //!< directly read all known readers after setup was syncronized
|
int m_autoReadAfterSetupMs = -1; //!< directly read all known readers after setup was syncronized
|
||||||
|
bool m_initialRead = false; //!< Initial read conducted
|
||||||
BlackCore::CData<BlackCore::Data::GlobalSetup> m_setup {this, &CWebDataServices::ps_setupChanged}; //!< setup cache
|
BlackCore::CData<BlackCore::Data::GlobalSetup> m_setup {this, &CWebDataServices::ps_setupChanged}; //!< setup cache
|
||||||
|
|
||||||
// for reading XML and VATSIM data files
|
// for reading XML and VATSIM data files
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "threadedreader.h"
|
#include "threadedreader.h"
|
||||||
|
#include "blackmisc/threadutils.h"
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::Network;
|
using namespace BlackMisc::Network;
|
||||||
@@ -48,6 +49,14 @@ namespace BlackMisc
|
|||||||
this->m_updateTimestamp = updateTimestamp;
|
this->m_updateTimestamp = updateTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CThreadedReader::updatedWithinLastMs(qint64 timeLastMs)
|
||||||
|
{
|
||||||
|
QDateTime dt(getUpdateTimestamp());
|
||||||
|
if (dt.isNull() || !dt.isValid()) { return false; }
|
||||||
|
qint64 delta = QDateTime::currentMSecsSinceEpoch() - dt.toMSecsSinceEpoch();
|
||||||
|
return delta <= timeLastMs;
|
||||||
|
}
|
||||||
|
|
||||||
void CThreadedReader::requestReload()
|
void CThreadedReader::requestReload()
|
||||||
{
|
{
|
||||||
// default implementation, subclasses shall override as required
|
// default implementation, subclasses shall override as required
|
||||||
@@ -56,11 +65,16 @@ namespace BlackMisc
|
|||||||
|
|
||||||
void CThreadedReader::gracefulShutdown()
|
void CThreadedReader::gracefulShutdown()
|
||||||
{
|
{
|
||||||
this->abandonAndWait();
|
// if not in main thread stop, otherwise it makes no sense to abandon
|
||||||
|
if (!CThreadUtils::isCurrentThreadObjectThread(this))
|
||||||
|
{
|
||||||
|
this->abandonAndWait();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CThreadedReader::~CThreadedReader()
|
CThreadedReader::~CThreadedReader()
|
||||||
{
|
{
|
||||||
|
gracefulShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadedReader::setInterval(int updatePeriodMs)
|
void CThreadedReader::setInterval(int updatePeriodMs)
|
||||||
|
|||||||
@@ -30,21 +30,25 @@ namespace BlackMisc
|
|||||||
class BLACKMISC_EXPORT CThreadedReader : public CContinuousWorker
|
class BLACKMISC_EXPORT CThreadedReader : public CContinuousWorker
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
//! Destructor
|
||||||
|
virtual ~CThreadedReader();
|
||||||
|
|
||||||
//! Thread safe, set update timestamp
|
//! Thread safe, set update timestamp
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
QDateTime getUpdateTimestamp() const;
|
QDateTime getUpdateTimestamp() const;
|
||||||
|
|
||||||
//! Thread safe, set update timestamp
|
//! Thread safe, set update timestamp
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
void setUpdateTimestamp(const QDateTime &updateTimestamp);
|
void setUpdateTimestamp(const QDateTime &updateTimestamp = QDateTime::currentDateTimeUtc());
|
||||||
|
|
||||||
|
//! Was setup read within last xx milliseconds
|
||||||
|
//! \threadsafe
|
||||||
|
bool updatedWithinLastMs(qint64 timeLastMs);
|
||||||
|
|
||||||
//! Request new reading
|
//! Request new reading
|
||||||
//! \note override as required, default is to call initialize()
|
//! \note override as required, default is to call initialize()
|
||||||
virtual void requestReload();
|
virtual void requestReload();
|
||||||
|
|
||||||
//! Destructor
|
|
||||||
virtual ~CThreadedReader();
|
|
||||||
|
|
||||||
//! Set the update time
|
//! Set the update time
|
||||||
//! \param updatePeriodMs <=0 stops the timer
|
//! \param updatePeriodMs <=0 stops the timer
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
|
|||||||
Reference in New Issue
Block a user