mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 23:45:35 +08:00
refactor: Move period usage of CThreadedReader in subclass
This commit is contained in:
@@ -28,11 +28,7 @@ namespace swift::core
|
||||
return cats;
|
||||
}
|
||||
|
||||
CThreadedReader::CThreadedReader(QObject *owner, const QString &name) : CContinuousWorker(owner, name)
|
||||
{
|
||||
connect(&m_updateTimer, &QTimer::timeout, this, &CThreadedReader::doWork);
|
||||
m_updateTimer.setSingleShot(true);
|
||||
}
|
||||
CThreadedReader::CThreadedReader(QObject *owner, const QString &name) : CContinuousWorker(owner, name) {}
|
||||
|
||||
qint64 CThreadedReader::lastModifiedMsSinceEpoch(QNetworkReply *nwReply) const
|
||||
{
|
||||
@@ -51,12 +47,6 @@ namespace swift::core
|
||||
m_updateTimestamp = updateTimestamp;
|
||||
}
|
||||
|
||||
void CThreadedReader::startReader()
|
||||
{
|
||||
Q_ASSERT(m_initialTime > 0);
|
||||
QTimer::singleShot(m_initialTime, this, [=] { this->doWork(); });
|
||||
}
|
||||
|
||||
CUrlLogList CThreadedReader::getUrlLogList() const
|
||||
{
|
||||
QReadLocker l(&m_lock);
|
||||
@@ -96,29 +86,6 @@ namespace swift::core
|
||||
Q_ASSERT_X(this->thread() == QThread::currentThread(), Q_FUNC_INFO, "Wrong object thread");
|
||||
}
|
||||
|
||||
void CThreadedReader::setInitialAndPeriodicTime(int initialTime, int periodicTime)
|
||||
{
|
||||
m_initialTime = initialTime;
|
||||
m_periodicTime = periodicTime;
|
||||
|
||||
// if timer is active start with delta time
|
||||
// remark: will be reset in doWork
|
||||
if (m_updateTimer.isActive())
|
||||
{
|
||||
const int oldPeriodicTime = m_updateTimer.interval();
|
||||
const int delta = m_periodicTime - oldPeriodicTime + m_updateTimer.remainingTime();
|
||||
m_updateTimer.start(qMax(delta, 0));
|
||||
}
|
||||
}
|
||||
|
||||
void CThreadedReader::doWork()
|
||||
{
|
||||
if (!doWorkCheck()) { return; }
|
||||
this->doWorkImpl();
|
||||
Q_ASSERT(m_periodicTime > 0);
|
||||
m_updateTimer.start(m_periodicTime); // restart
|
||||
}
|
||||
|
||||
bool CThreadedReader::doWorkCheck() const
|
||||
{
|
||||
// sApp->hasWebDataServices() cannot be used, as some readers are already used during init phase
|
||||
|
||||
Reference in New Issue
Block a user