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:
Klaus Basan
2017-07-10 18:13:44 +02:00
committed by Mathew Sutcliffe
parent 2fbd2c6382
commit b6b1b96ec4
14 changed files with 86 additions and 84 deletions

View File

@@ -52,7 +52,7 @@ namespace BlackCore
//! \threadsafe
bool updatedWithinLastMs(qint64 timeLastMs);
//! Network accessable?
//! Network accessible?
bool isNetworkAccessible() const;
//! Is marked as read failed
@@ -71,13 +71,8 @@ namespace BlackCore
//! \threadsafe
void pauseReader();
//! Is shutting down?
//! \threadsafe
bool isShuttingDown() const;
//! Graceful shutdown
//! \threadsafe
void gracefulShutdown();
//! Used in unit test
void markAsUsedInUnitTest() { m_unitTest = true; }
protected:
mutable QReadWriteLock m_lock {QReadWriteLock::Recursive}; //!< lock which can be used from the derived classes
@@ -95,22 +90,29 @@ namespace BlackCore
//! \threadsafe
bool didContentChange(const QString &content, int startPosition = -1);
//! \copydoc BlackMisc::CContinuousWorker::cleanup
virtual void cleanup() override;
//! Set initial and periodic times
void setInitialAndPeriodicTime(int initialTime, int periodicTime);
//! This method does the actual work in the derived class
virtual void doWorkImpl() {}
//! Still enabled etc.
bool doWorkCheck() const;
private:
//! Trigger doWorkImpl
void doWork();
int m_initialTime = -1; //!< Initial start delay
int m_periodicTime = -1; //!< Periodic time after which the task is repeated
QDateTime m_updateTimestamp; //!< when file/resource was read
uint m_contentHash = 0; //!< has of the content given
std::atomic<bool> m_markedAsFailed { false }; //!< marker if reading failed
std::atomic<bool> m_shutdown { false }; //!< marker it is shutting down
QTimer m_updateTimer { this };
int m_initialTime = -1; //!< Initial start delay
int m_periodicTime = -1; //!< Periodic time after which the task is repeated
QDateTime m_updateTimestamp; //!< when file/resource was read
uint m_contentHash = 0; //!< has of the content given
std::atomic<bool> m_markedAsFailed { false }; //!< marker if reading failed
QTimer m_updateTimer { this };
bool m_unitTest { false }; //!< mark as unit test
};
} // namespace