mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-13 07:35:41 +08:00
refactor: Clean up CThreadedReader
This commit is contained in:
@@ -664,7 +664,7 @@ namespace swift::core::db
|
|||||||
if (CEntityFlags::isSingleEntity(entity))
|
if (CEntityFlags::isSingleEntity(entity))
|
||||||
{
|
{
|
||||||
emit this->entityDownloadProgress(entity, logId, m_networkReplyProgress, m_networkReplyCurrent,
|
emit this->entityDownloadProgress(entity, logId, m_networkReplyProgress, m_networkReplyCurrent,
|
||||||
m_networkReplyNax, url);
|
m_networkReplyMax, url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ namespace swift::core
|
|||||||
m_updateTimer.setSingleShot(true);
|
m_updateTimer.setSingleShot(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
CThreadedReader::~CThreadedReader() {}
|
|
||||||
|
|
||||||
qint64 CThreadedReader::lastModifiedMsSinceEpoch(QNetworkReply *nwReply) const
|
qint64 CThreadedReader::lastModifiedMsSinceEpoch(QNetworkReply *nwReply) const
|
||||||
{
|
{
|
||||||
return CNetworkUtils::lastModifiedMsSinceEpoch(nwReply);
|
return CNetworkUtils::lastModifiedMsSinceEpoch(nwReply);
|
||||||
@@ -53,28 +51,12 @@ namespace swift::core
|
|||||||
m_updateTimestamp = updateTimestamp;
|
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::startReader()
|
void CThreadedReader::startReader()
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_initialTime > 0);
|
Q_ASSERT(m_initialTime > 0);
|
||||||
QTimer::singleShot(m_initialTime, this, [=] { this->doWork(); });
|
QTimer::singleShot(m_initialTime, this, [=] { this->doWork(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadedReader::pauseReader() { QTimer::singleShot(0, &m_updateTimer, &QTimer::stop); }
|
|
||||||
|
|
||||||
bool CThreadedReader::hasPendingUrls() const
|
|
||||||
{
|
|
||||||
QReadLocker l(&m_lock);
|
|
||||||
return m_urlReadLog.hasPending();
|
|
||||||
}
|
|
||||||
|
|
||||||
CUrlLogList CThreadedReader::getUrlLogList() const
|
CUrlLogList CThreadedReader::getUrlLogList() const
|
||||||
{
|
{
|
||||||
QReadLocker l(&m_lock);
|
QReadLocker l(&m_lock);
|
||||||
@@ -170,7 +152,7 @@ namespace swift::core
|
|||||||
|
|
||||||
QPair<qint64, qint64> CThreadedReader::getNetworkReplyBytes() const
|
QPair<qint64, qint64> CThreadedReader::getNetworkReplyBytes() const
|
||||||
{
|
{
|
||||||
return QPair<qint64, qint64>(m_networkReplyCurrent, m_networkReplyNax);
|
return QPair<qint64, qint64>(m_networkReplyCurrent, m_networkReplyMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CThreadedReader::networkReplyProgress(int logId, qint64 current, qint64 max, const QUrl &url)
|
void CThreadedReader::networkReplyProgress(int logId, qint64 current, qint64 max, const QUrl &url)
|
||||||
@@ -178,7 +160,7 @@ namespace swift::core
|
|||||||
// max can be -1 if file size is not available
|
// max can be -1 if file size is not available
|
||||||
m_networkReplyProgress = (current > 0 && max > 0) ? static_cast<int>((current * 100) / max) : -1;
|
m_networkReplyProgress = (current > 0 && max > 0) ? static_cast<int>((current * 100) / max) : -1;
|
||||||
m_networkReplyCurrent = current;
|
m_networkReplyCurrent = current;
|
||||||
m_networkReplyNax = max;
|
m_networkReplyMax = max;
|
||||||
|
|
||||||
Q_UNUSED(url);
|
Q_UNUSED(url);
|
||||||
Q_UNUSED(logId);
|
Q_UNUSED(logId);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace swift::core
|
|||||||
static const QStringList &getLogCategories();
|
static const QStringList &getLogCategories();
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~CThreadedReader();
|
virtual ~CThreadedReader() = default;
|
||||||
|
|
||||||
//! Thread safe, get update timestamp
|
//! Thread safe, get update timestamp
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
@@ -47,10 +47,6 @@ namespace swift::core
|
|||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
void setUpdateTimestamp(const QDateTime &updateTimestamp = QDateTime::currentDateTimeUtc());
|
void setUpdateTimestamp(const QDateTime &updateTimestamp = QDateTime::currentDateTimeUtc());
|
||||||
|
|
||||||
//! Was setup read within last xx milliseconds
|
|
||||||
//! \threadsafe
|
|
||||||
bool updatedWithinLastMs(qint64 timeLastMs);
|
|
||||||
|
|
||||||
//! Is marked as read failed
|
//! Is marked as read failed
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
//! \deprecated likely to be removed
|
//! \deprecated likely to be removed
|
||||||
@@ -69,26 +65,14 @@ namespace swift::core
|
|||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
void startReader();
|
void startReader();
|
||||||
|
|
||||||
//! Pauses the reader
|
|
||||||
//! \threadsafe
|
|
||||||
void pauseReader();
|
|
||||||
|
|
||||||
//! Used in unit test
|
//! Used in unit test
|
||||||
//! \remark needs to be done before started in different thread
|
//! \remark needs to be done before started in different thread
|
||||||
void markAsUsedInUnitTest() { m_unitTest = true; }
|
void markAsUsedInUnitTest() { m_unitTest = true; }
|
||||||
|
|
||||||
//! Has pending URLs?
|
|
||||||
//! \threadsafe
|
|
||||||
bool hasPendingUrls() const;
|
|
||||||
|
|
||||||
//! Get the URL log list
|
//! Get the URL log list
|
||||||
//! \threadsafe
|
//! \threadsafe
|
||||||
swift::misc::network::CUrlLogList getUrlLogList() const;
|
swift::misc::network::CUrlLogList getUrlLogList() const;
|
||||||
|
|
||||||
//! Progress 0..100
|
|
||||||
//! \threadsafe
|
|
||||||
int getNetworkReplyProgress() const { return m_networkReplyProgress; }
|
|
||||||
|
|
||||||
//! Max./current bytes
|
//! Max./current bytes
|
||||||
QPair<qint64, qint64> getNetworkReplyBytes() const;
|
QPair<qint64, qint64> getNetworkReplyBytes() const;
|
||||||
|
|
||||||
@@ -98,7 +82,7 @@ namespace swift::core
|
|||||||
}; //!< lock which can be used from the derived classes
|
}; //!< lock which can be used from the derived classes
|
||||||
std::atomic_int m_networkReplyProgress; //!< Progress percentage 0...100
|
std::atomic_int m_networkReplyProgress; //!< Progress percentage 0...100
|
||||||
std::atomic_llong m_networkReplyCurrent; //!< current bytes
|
std::atomic_llong m_networkReplyCurrent; //!< current bytes
|
||||||
std::atomic_llong m_networkReplyNax; //!< max bytes
|
std::atomic_llong m_networkReplyMax; //!< max bytes
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CThreadedReader(QObject *owner, const QString &name);
|
CThreadedReader(QObject *owner, const QString &name);
|
||||||
@@ -106,7 +90,7 @@ namespace swift::core
|
|||||||
//! When was reply last modified, -1 if N/A
|
//! When was reply last modified, -1 if N/A
|
||||||
qint64 lastModifiedMsSinceEpoch(QNetworkReply *nwReply) const;
|
qint64 lastModifiedMsSinceEpoch(QNetworkReply *nwReply) const;
|
||||||
|
|
||||||
//! Make sure everthing runs correctly in own thread
|
//! Make sure everything runs correctly in own thread
|
||||||
void threadAssertCheck() const;
|
void threadAssertCheck() const;
|
||||||
|
|
||||||
//! Stores new content hash and returns if content changed (based on hash value
|
//! Stores new content hash and returns if content changed (based on hash value
|
||||||
|
|||||||
Reference in New Issue
Block a user