mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 21:56:43 +08:00
* discussion: https://dev.vatsim-germany.org/boards/22/topics/2027?r=2040#message-2040 * fixed bug with ATC station component, wrong signals for booked stations * booked stations loading to frequently (for each minor change such as online), changed to timestamp based concept * update booked stations with receiving ATIS/voiceroom to online * CDigestSignal class: new class and methods for collecting signals, avoiding too many signals - one of the cures for the performance issues * fixed bug found during testing, missing start for timers when connecting to network
This commit is contained in:
36
src/blackmisc/digestsignal.cpp
Normal file
36
src/blackmisc/digestsignal.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "digestsignal.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
void CDigestSignal::ps_inputSignal()
|
||||
{
|
||||
if (m_timer.isActive())
|
||||
{
|
||||
m_timer.start();
|
||||
}
|
||||
|
||||
m_inputsCount++;
|
||||
if (m_inputsCount >= m_maxInputsPerDigest)
|
||||
{
|
||||
ps_timeout();
|
||||
}
|
||||
}
|
||||
|
||||
void CDigestSignal::ps_timeout()
|
||||
{
|
||||
m_timer.stop();
|
||||
m_inputsCount = 0;
|
||||
emit digestSignal();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
58
src/blackmisc/digestsignal.h
Normal file
58
src/blackmisc/digestsignal.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_DIGESTSIGNAL_H
|
||||
#define BLACKMISC_DIGESTSIGNAL_H
|
||||
|
||||
#include <QTimer>
|
||||
#include <QObject>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
//! Receive 1..n signal, collect them over time, and resend afer n milliseconds
|
||||
class CDigestSignal : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
template <class T, class F1, class F2>
|
||||
CDigestSignal(T *sender, F1 inputSignal, F2 digestSignal, int maxDelayMs = 500, int maxInputsPerDigest = 3)
|
||||
: m_maxInputsPerDigest(maxInputsPerDigest)
|
||||
{
|
||||
QObject::connect(sender, inputSignal, this, &CDigestSignal::ps_inputSignal);
|
||||
QObject::connect(this, &CDigestSignal::digestSignal, sender, digestSignal);
|
||||
|
||||
QObject::connect(&m_timer, &QTimer::timeout, this, &CDigestSignal::ps_timeout);
|
||||
m_timer.setSingleShot(true);
|
||||
m_timer.setInterval(maxDelayMs);
|
||||
}
|
||||
|
||||
signals:
|
||||
//! Send digest signal
|
||||
void digestSignal();
|
||||
|
||||
private slots:
|
||||
//! Received input signal
|
||||
void ps_inputSignal();
|
||||
|
||||
//! Timer timed out
|
||||
void ps_timeout();
|
||||
|
||||
private:
|
||||
QTimer m_timer;
|
||||
const int m_maxInputsPerDigest = 3;
|
||||
int m_inputsCount = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user