mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 05:26:45 +08:00
Ref T184 Moved CTokenBucket from BlackCore to BlackMisc.
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
#include "blackcore/blackcoreexport.h"
|
||||
#include "blackcore/network.h"
|
||||
#include "blackcore/vatsim/vatsimsettings.h"
|
||||
#include "blackcore/tokenbucket.h"
|
||||
#include "blackmisc/tokenbucket.h"
|
||||
#include "blackmisc/simulation/ownaircraftprovider.h"
|
||||
#include "blackmisc/simulation/simulatorplugininfo.h"
|
||||
#include "blackmisc/aviation/aircrafticaocode.h"
|
||||
@@ -217,7 +217,7 @@ namespace BlackCore
|
||||
QString m_ownLiveryDescription; //!< "buffered livery", as this must not change when connected
|
||||
BlackMisc::Aviation::CCallsignSet m_interimPositionReceivers; //!< all aircraft receiving interim positions
|
||||
BlackMisc::Aviation::CAircraftParts m_sentAircraftConfig; //!< aircraft parts sent
|
||||
CTokenBucket m_tokenBucket; //!< used with aircraft parts messages
|
||||
BlackMisc::CTokenBucket m_tokenBucket; //!< used with aircraft parts messages
|
||||
|
||||
QTimer m_scheduledConfigUpdate;
|
||||
QTimer m_processingTimer;
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
#define BLACKGUI_COMPONENTS_MAPPINGCOMPONENT_H
|
||||
|
||||
#include "blackcore/network.h"
|
||||
#include "blackcore/tokenbucket.h"
|
||||
#include "blackgui/overlaymessagesframe.h"
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackgui/components/enablefordockwidgetinfoarea.h"
|
||||
#include "blackgui/settings/viewupdatesettings.h"
|
||||
#include "blackmisc/tokenbucket.h"
|
||||
#include "blackmisc/identifiable.h"
|
||||
#include "blackmisc/identifier.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
@@ -150,7 +150,7 @@ namespace BlackGui
|
||||
BlackMisc::CSettingReadOnly<BlackGui::Settings::TViewUpdateSettings> m_settings { this, &CMappingComponent::ps_settingsChanged }; //!< settings changed
|
||||
bool m_missedRenderedAircraftUpdate = true; //! Rendered aircraft need update
|
||||
QTimer m_updateTimer { this };
|
||||
BlackCore::CTokenBucket m_bucket { 3, BlackMisc::PhysicalQuantities::CTime(5.0, BlackMisc::PhysicalQuantities::CTimeUnit::s()), 1};
|
||||
BlackMisc::CTokenBucket m_bucket { 3, BlackMisc::PhysicalQuantities::CTime(5.0, BlackMisc::PhysicalQuantities::CTimeUnit::s()), 1};
|
||||
BlackGui::Views::CCheckBoxDelegate *m_currentMappingsViewDelegate = nullptr; //! checkbox in view
|
||||
BlackMisc::CIdentifier m_identifier;
|
||||
};
|
||||
|
||||
@@ -7,14 +7,16 @@
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackcore/tokenbucket.h"
|
||||
#include "blackmisc/tokenbucket.h"
|
||||
#include "blackmisc/pq/units.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
namespace BlackCore
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
CTokenBucket::CTokenBucket(int capacity, const BlackMisc::PhysicalQuantities::CTime &interval, int numTokensToRefill)
|
||||
CTokenBucket::CTokenBucket(int capacity, const CTime &interval, int numTokensToRefill)
|
||||
: m_capacity(capacity), m_interval(interval), m_numTokensToRefill(numTokensToRefill) {}
|
||||
|
||||
bool CTokenBucket::tryConsume(int numTokens)
|
||||
@@ -50,7 +52,7 @@ namespace BlackCore
|
||||
{
|
||||
const auto now = QDateTime::currentDateTime();
|
||||
const auto deltaSeconds = m_lastReplenishmentTime.secsTo(now);
|
||||
const int numberOfTokens = static_cast<int>(m_numTokensToRefill * deltaSeconds / m_interval.value(BlackMisc::PhysicalQuantities::CTimeUnit::s()));
|
||||
const int numberOfTokens = static_cast<int>(m_numTokensToRefill * deltaSeconds / m_interval.value(CTimeUnit::s()));
|
||||
|
||||
// Update the time only when replenishment actually took place. We will end up in a infinite loop otherwise.
|
||||
if (numberOfTokens > 0) { m_lastReplenishmentTime = now; }
|
||||
@@ -7,14 +7,14 @@
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef BLACKCORE_TOKENBUCKET_H
|
||||
#define BLACKCORE_TOKENBUCKET_H
|
||||
#ifndef BLACKMISC_TOKENBUCKET_H
|
||||
#define BLACKMISC_TOKENBUCKET_H
|
||||
|
||||
#include "blackcore/blackcoreexport.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/pq/time.h"
|
||||
#include <QDateTime>
|
||||
|
||||
namespace BlackCore
|
||||
namespace BlackMisc
|
||||
{
|
||||
/*!
|
||||
* \brief Token bucket algorithm
|
||||
@@ -23,11 +23,11 @@ namespace BlackCore
|
||||
* generation. Each time a packet needs to be generated and sent a token is consumed. If no token is available, consumption
|
||||
* will fail the the packet cannot be sent.
|
||||
*/
|
||||
class BLACKCORE_EXPORT CTokenBucket
|
||||
class BLACKMISC_EXPORT CTokenBucket
|
||||
{
|
||||
public:
|
||||
//! Constructor for given replenishment policy
|
||||
CTokenBucket(int capacity, const BlackMisc::PhysicalQuantities::CTime &interval, int numTokensToRefill);
|
||||
CTokenBucket(int capacity, const PhysicalQuantities::CTime &interval, int numTokensToRefill);
|
||||
|
||||
//! Try to consume a number of tokens
|
||||
bool tryConsume(int numTokens = 1);
|
||||
@@ -47,7 +47,7 @@ namespace BlackCore
|
||||
|
||||
int m_capacity = 10; //!< Maximum capacity of tokens
|
||||
int m_availableTokens = 10; //!< Currently available tokens. The initial value is 10
|
||||
BlackMisc::PhysicalQuantities::CTime m_interval; //!< Refill interval, e.g. every 5 secs
|
||||
PhysicalQuantities::CTime m_interval; //!< Refill interval, e.g. every 5 secs
|
||||
int m_numTokensToRefill; //!< Number of tokens to be refilled each interval
|
||||
QDateTime m_lastReplenishmentTime = QDateTime::currentDateTime(); //!< Last time
|
||||
};
|
||||
Reference in New Issue
Block a user