Ref T105, use timer in base class CContinuousWorker

* remove unused cleanup
* object name set in base class
This commit is contained in:
Klaus Basan
2017-07-11 03:54:52 +02:00
committed by Mathew Sutcliffe
parent 4a7ad09e46
commit 0bfd9a55a2
7 changed files with 11 additions and 73 deletions

View File

@@ -39,10 +39,9 @@ namespace BlackCore
// all in new thread from here on
this->setObjectName(getName());
m_timer.setObjectName(this->objectName().append(":m_timer"));
m_timer.start(7500);
m_updateTimer.start(7500);
m_lastWatchdogCallMsSinceEpoch = QDateTime::currentMSecsSinceEpoch();
bool c = connect(&m_timer, &QTimer::timeout, this, &CAirspaceAnalyzer::onTimeout);
bool c = connect(&m_updateTimer, &QTimer::timeout, this, &CAirspaceAnalyzer::onTimeout);
Q_ASSERT(c);
// disconnect
@@ -105,11 +104,11 @@ namespace BlackCore
if (newStatus == INetwork::Disconnected)
{
this->clear();
this->m_timer.stop();
this->m_updateTimer.stop();
}
else if (newStatus == INetwork::Connected)
{
this->m_timer.start();
this->m_updateTimer.start();
}
}
@@ -129,11 +128,6 @@ namespace BlackCore
m_latestAircraftSnapshot = CAirspaceAircraftSnapshot();
}
void CAirspaceAnalyzer::cleanup()
{
m_timer.stop();
}
void CAirspaceAnalyzer::watchdogRemoveAircraftCallsign(const CCallsign &callsign)
{
m_aircraftCallsignTimestamps.remove(callsign);
@@ -149,7 +143,7 @@ namespace BlackCore
qint64 currentTimeMsEpoch = QDateTime::currentMSecsSinceEpoch();
qint64 callDiffMs = currentTimeMsEpoch - m_lastWatchdogCallMsSinceEpoch;
qint64 callThresholdMs = static_cast<int>(m_timer.interval() * 1.5);
qint64 callThresholdMs = static_cast<int>(m_updateTimer.interval() * 1.5);
m_lastWatchdogCallMsSinceEpoch = currentTimeMsEpoch;
// this is a trick to not remove everything while debugging

View File

@@ -89,10 +89,6 @@ namespace BlackCore
//! New aircraft snapshot
void airspaceAircraftSnapshot(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &snapshot);
protected:
//! \copydoc BlackMisc::CContinuousWorker::cleanup
virtual void cleanup() override;
private:
//! Remove callsign from watch list
void watchdogRemoveAircraftCallsign(const BlackMisc::Aviation::CCallsign &callsign);
@@ -119,8 +115,6 @@ namespace BlackCore
//! Analyze the airspace
void analyzeAirspace();
QTimer m_timer { this }; //!< multi purpose timer for snapshots and watchdog
// watchdog
CCallsignTimestampSet m_aircraftCallsignTimestamps; //!< for watchdog (pilots)
CCallsignTimestampSet m_atcCallsignTimestamps; //!< for watchdog (ATC)

View File

@@ -37,38 +37,7 @@ namespace BlackCore
CContinuousWorker(owner, "Background data updater")
{
connect(&m_updateTimer, &QTimer::timeout, this, &CBackgroundDataUpdater::doWork);
m_updateTimer.setObjectName(getName());
}
void CBackgroundDataUpdater::initialize()
{
m_updateTimer.start(60 * 1000);
}
void CBackgroundDataUpdater::cleanup()
{
m_updateTimer.stop();
}
void CBackgroundDataUpdater::startUpdating(int updateTimeSecs)
{
if (!CThreadUtils::isCurrentThreadObjectThread(this))
{
// shift in correct thread
QTimer::singleShot(0, this, [this, updateTimeSecs] { this->startUpdating(updateTimeSecs); });
return;
}
if (updateTimeSecs < 0)
{
setEnabled(false);
QTimer::singleShot(0, &m_updateTimer, &QTimer::stop);
}
else
{
setEnabled(true);
m_updateTimer.start(1000 * updateTimeSecs);
}
m_updateTimer.setInterval(60 * 1000);
}
void CBackgroundDataUpdater::doWork()

View File

@@ -35,20 +35,9 @@ namespace BlackCore
//! Constructor
CBackgroundDataUpdater(QObject *owner);
//! Enable updates
void startUpdating(int updateTimeSecs);
protected:
//! \copydoc BlackMisc::CContinuousWorker::initialize
virtual void initialize() override;
//! \copydoc BlackMisc::CContinuousWorker::cleanup
virtual void cleanup() override;
private:
int m_cycle = 0; //!< cycle
bool m_inWork = false; //!< indicates a running update
QTimer m_updateTimer { this };
BlackMisc::Simulation::Data::CModelCaches m_modelCaches { false, this }; //!< caches
BlackMisc::Simulation::Data::CModelSetCaches m_modelSetCaches { false, this }; //!< caches

View File

@@ -28,7 +28,6 @@
#include <QObject>
#include <QReadWriteLock>
#include <QString>
#include <QTimer>
#include <QtGlobal>
#include <QNetworkReply>

View File

@@ -35,7 +35,6 @@ namespace BlackCore
CContinuousWorker(owner, name)
{
connect(&m_updateTimer, &QTimer::timeout, this, &CThreadedReader::doWork);
m_updateTimer.setObjectName(getName());
m_updateTimer.setSingleShot(true);
}
@@ -99,11 +98,6 @@ namespace BlackCore
return true;
}
void CThreadedReader::cleanup()
{
m_updateTimer.stop();
}
bool CThreadedReader::isMarkedAsFailed() const
{
return this->m_markedAsFailed;
@@ -124,10 +118,13 @@ namespace BlackCore
{
m_initialTime = initialTime;
m_periodicTime = periodicTime;
// if timer is active start with delta time
// remark: will be reset in doWork
if (m_updateTimer.isActive())
{
int oldPeriodicTime = m_updateTimer.interval();
int delta = m_periodicTime - oldPeriodicTime + m_updateTimer.remainingTime();
const int oldPeriodicTime = m_updateTimer.interval();
const int delta = m_periodicTime - oldPeriodicTime + m_updateTimer.remainingTime();
m_updateTimer.start(qMax(delta, 0));
}
}

View File

@@ -90,9 +90,6 @@ 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);
@@ -111,7 +108,6 @@ namespace BlackCore
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