From dbb67b385b1b0dc4be6f76f7ccec32143c9cd522 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Wed, 8 Nov 2017 19:01:09 +0000 Subject: [PATCH] Ref T184 Moved CTokenBucket from BlackCore to BlackMisc. --- src/blackcore/vatsim/networkvatlib.h | 4 ++-- src/blackgui/components/mappingcomponent.h | 4 ++-- src/{blackcore => blackmisc}/tokenbucket.cpp | 10 ++++++---- src/{blackcore => blackmisc}/tokenbucket.h | 14 +++++++------- 4 files changed, 17 insertions(+), 15 deletions(-) rename src/{blackcore => blackmisc}/tokenbucket.cpp (88%) rename src/{blackcore => blackmisc}/tokenbucket.h (84%) diff --git a/src/blackcore/vatsim/networkvatlib.h b/src/blackcore/vatsim/networkvatlib.h index e76f3f23b..90765d9c8 100644 --- a/src/blackcore/vatsim/networkvatlib.h +++ b/src/blackcore/vatsim/networkvatlib.h @@ -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; diff --git a/src/blackgui/components/mappingcomponent.h b/src/blackgui/components/mappingcomponent.h index e5cf2b5cb..82b1a2cba 100644 --- a/src/blackgui/components/mappingcomponent.h +++ b/src/blackgui/components/mappingcomponent.h @@ -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 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; }; diff --git a/src/blackcore/tokenbucket.cpp b/src/blackmisc/tokenbucket.cpp similarity index 88% rename from src/blackcore/tokenbucket.cpp rename to src/blackmisc/tokenbucket.cpp index 83abf863a..822bbf2fe 100644 --- a/src/blackcore/tokenbucket.cpp +++ b/src/blackmisc/tokenbucket.cpp @@ -7,14 +7,16 @@ * contained in the LICENSE file. */ -#include "blackcore/tokenbucket.h" +#include "blackmisc/tokenbucket.h" #include "blackmisc/pq/units.h" #include -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(m_numTokensToRefill * deltaSeconds / m_interval.value(BlackMisc::PhysicalQuantities::CTimeUnit::s())); + const int numberOfTokens = static_cast(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; } diff --git a/src/blackcore/tokenbucket.h b/src/blackmisc/tokenbucket.h similarity index 84% rename from src/blackcore/tokenbucket.h rename to src/blackmisc/tokenbucket.h index cb631142b..267e88ae4 100644 --- a/src/blackcore/tokenbucket.h +++ b/src/blackmisc/tokenbucket.h @@ -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 -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 };