mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 15:25:35 +08:00
Ref T105, use new style with threaded readers
* use doWorkCheck * relaxed doWorkCheck in unit tests * removed isShuttingDown, gracefulShutdown * set timer object name (in case something is wrong, we might see the name in the log)
This commit is contained in:
committed by
Mathew Sutcliffe
parent
2fbd2c6382
commit
b6b1b96ec4
@@ -35,13 +35,12 @@ namespace BlackCore
|
||||
CContinuousWorker(owner, name)
|
||||
{
|
||||
connect(&m_updateTimer, &QTimer::timeout, this, &CThreadedReader::doWork);
|
||||
m_updateTimer.setObjectName(getName());
|
||||
m_updateTimer.setSingleShot(true);
|
||||
}
|
||||
|
||||
CThreadedReader::~CThreadedReader()
|
||||
{
|
||||
gracefulShutdown();
|
||||
}
|
||||
{ }
|
||||
|
||||
qint64 CThreadedReader::lastModifiedMsSinceEpoch(QNetworkReply *nwReply) const
|
||||
{
|
||||
@@ -73,17 +72,6 @@ namespace BlackCore
|
||||
return sApp->isNetworkAccessible();
|
||||
}
|
||||
|
||||
void CThreadedReader::gracefulShutdown()
|
||||
{
|
||||
// if not in main thread stop, otherwise it makes no sense to abandon
|
||||
if (this->m_shutdown) { return; }
|
||||
this->m_shutdown = true;
|
||||
if (!CThreadUtils::isCurrentThreadObjectThread(this))
|
||||
{
|
||||
this->abandonAndWait();
|
||||
}
|
||||
}
|
||||
|
||||
void CThreadedReader::startReader()
|
||||
{
|
||||
Q_ASSERT(m_initialTime > 0);
|
||||
@@ -95,14 +83,6 @@ namespace BlackCore
|
||||
QTimer::singleShot(0, &m_updateTimer, &QTimer::stop);
|
||||
}
|
||||
|
||||
bool CThreadedReader::isShuttingDown() const
|
||||
{
|
||||
if (!sApp) { return true; } // sApp object is gone, whole system shutdown
|
||||
if (this->m_shutdown) { return true; } // marked as shutdown
|
||||
if (this->isAbandoned()) { return true; } // worker abandoned
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CThreadedReader::didContentChange(const QString &content, int startPosition)
|
||||
{
|
||||
uint oldHash = 0;
|
||||
@@ -119,6 +99,11 @@ namespace BlackCore
|
||||
return true;
|
||||
}
|
||||
|
||||
void CThreadedReader::cleanup()
|
||||
{
|
||||
m_updateTimer.stop();
|
||||
}
|
||||
|
||||
bool CThreadedReader::isMarkedAsFailed() const
|
||||
{
|
||||
return this->m_markedAsFailed;
|
||||
@@ -149,10 +134,16 @@ namespace BlackCore
|
||||
|
||||
void CThreadedReader::doWork()
|
||||
{
|
||||
if (isFinished()) { return; }
|
||||
if (!doWorkCheck()) { return; }
|
||||
doWorkImpl();
|
||||
Q_ASSERT(m_periodicTime > 0);
|
||||
m_updateTimer.start(m_periodicTime);
|
||||
m_updateTimer.start(m_periodicTime); // restart
|
||||
}
|
||||
|
||||
bool CThreadedReader::doWorkCheck() const
|
||||
{
|
||||
if (!m_unitTest && (!sApp || !sApp->hasWebDataServices())) { return false; }
|
||||
if (!isEnabled()) { return false; }
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user