From c0eec894ebc8e0b8d813d7d8aef1d095c4dd0a04 Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Sun, 17 Nov 2024 14:44:34 +0100 Subject: [PATCH 1/4] feat: Add custom X-Plane dataref for connection state Fixes #304 --- .../simulator/xplane/simulatorxplane.cpp | 1 + .../xplane/xswiftbusserviceproxy.cpp | 5 ++ .../simulator/xplane/xswiftbusserviceproxy.h | 3 ++ src/xswiftbus/CMakeLists.txt | 1 + src/xswiftbus/custom_datarefs.h | 24 +++++++++ src/xswiftbus/datarefs.h | 49 +++++++++++++++++++ .../org.swift_project.xswiftbus.service.xml | 3 ++ src/xswiftbus/service.cpp | 11 +++++ src/xswiftbus/service.h | 5 ++ 9 files changed, 102 insertions(+) create mode 100644 src/xswiftbus/custom_datarefs.h diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index 67b389b518..5cace5c507 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -217,6 +217,7 @@ namespace swift::simplugin::xplane void CSimulatorXPlane::setFlightNetworkConnected(bool connected) { if (connected && !this->isShuttingDownOrDisconnected()) { m_serviceProxy->resetFrameTotals(); } + m_serviceProxy->setFlightNetworkConnected(connected); CSimulatorPluginCommon::setFlightNetworkConnected(connected); } diff --git a/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp b/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp index a4748c9ff4..bc20402c6c 100644 --- a/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp +++ b/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp @@ -368,6 +368,11 @@ namespace swift::simplugin::xplane void CXSwiftBusServiceProxy::resetFrameTotals() { m_dbusInterface->callDBus(QLatin1String("resetFrameTotals")); } + void CXSwiftBusServiceProxy::setFlightNetworkConnected(bool connected) + { + m_dbusInterface->callDBus(QLatin1String("setFlightNetworkConnected"), connected); + } + double CXSwiftBusServiceProxy::getLatitudeDeg() const { return m_dbusInterface->callDBusRet(QLatin1String("getLatitudeDeg")); diff --git a/src/plugins/simulator/xplane/xswiftbusserviceproxy.h b/src/plugins/simulator/xplane/xswiftbusserviceproxy.h index c4dbccd1b1..4dd703ea60 100644 --- a/src/plugins/simulator/xplane/xswiftbusserviceproxy.h +++ b/src/plugins/simulator/xplane/xswiftbusserviceproxy.h @@ -219,6 +219,9 @@ namespace swift::simplugin::xplane //! \copydoc XSwiftBus::CService::resetFrameTotals void resetFrameTotals(); + //! \copydoc XSwiftBus::CService::setFlightNetworkConnected + void setFlightNetworkConnected(bool connected); + //! @{ //! \copydoc XSwiftBus::CService::getLatitudeDeg double getLatitudeDeg() const; diff --git a/src/xswiftbus/CMakeLists.txt b/src/xswiftbus/CMakeLists.txt index d0b5265405..1cb9579239 100644 --- a/src/xswiftbus/CMakeLists.txt +++ b/src/xswiftbus/CMakeLists.txt @@ -12,6 +12,7 @@ add_library(xswiftbus SHARED command.h config.cpp config.h + custom_datarefs.h datarefs.h dbuscallbacks.h dbusconnection.cpp diff --git a/src/xswiftbus/custom_datarefs.h b/src/xswiftbus/custom_datarefs.h new file mode 100644 index 0000000000..626c93310f --- /dev/null +++ b/src/xswiftbus/custom_datarefs.h @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: Copyright (C) swift Project Community / Contributors +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 + +#ifndef SWIFT_SIM_XSWIFTBUS_CUSTOM_DATAREFS_H +#define SWIFT_SIM_XSWIFTBUS_CUSTOM_DATAREFS_H + +namespace XSwiftBus +{ + //! Is swift connected to a network? + struct TSwiftNetworkConnected + { + //! Dataref name + static constexpr const char *name() { return "org/swift-project/xswiftbus/connected"; } + //! Can be written to? + static constexpr bool writable = false; + //! Dataref type + using type = int; + //! Not an array dataref + static constexpr bool is_array = false; + }; + +} // namespace XSwiftBus + +#endif // SWIFT_SIM_XSWIFTBUS_CUSTOM_DATAREFS_H diff --git a/src/xswiftbus/datarefs.h b/src/xswiftbus/datarefs.h index b2a430aaf4..7e050f2f7c 100644 --- a/src/xswiftbus/datarefs.h +++ b/src/xswiftbus/datarefs.h @@ -223,6 +223,55 @@ namespace XSwiftBus XPLMDataRef m_ref; }; + /*! + * Class providing a custom variable + dataref + * \tparam DataRefTraits The trait class representing the dataref. + */ + template + class CustomDataRef + { + public: + //! Constructor + CustomDataRef() + { + if constexpr (std::is_same_v) + { + m_ref = XPLMRegisterDataAccessor(DataRefTraits::name(), xplmType_Int, 0, read, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, this, NULL); + } + else { XPLMDebugString("Unsupported custom dataref type\n"); } + if (!m_ref) + { + XPLMDebugString("Missing dataref:"); + XPLMDebugString(DataRefTraits::name()); + XPLMDebugString("\n"); + } + } + + CustomDataRef(const CustomDataRef &) = delete; + CustomDataRef &operator=(const CustomDataRef &) = delete; + CustomDataRef(CustomDataRef &&other) = default; + CustomDataRef &operator=(CustomDataRef &&other) = default; + ~CustomDataRef() { XPLMUnregisterDataAccessor(m_ref); } + + static typename DataRefTraits::type read(void *refcon) + { + return reinterpret_cast(refcon)->get(); + } + + //! True if the dataref exists + bool isValid() const { return m_ref != nullptr; } + + //! Set the value + void set(typename DataRefTraits::type val) { m_datarefVal = val; } + + //! Get the value + typename DataRefTraits::type get() const { return m_datarefVal; } + + XPLMDataRef m_ref; + typename DataRefTraits::type m_datarefVal; + }; + template <> inline void DataRefImpl::implSet(int d) { diff --git a/src/xswiftbus/org.swift_project.xswiftbus.service.xml b/src/xswiftbus/org.swift_project.xswiftbus.service.xml index ef6bb9a6b0..9a0898725f 100644 --- a/src/xswiftbus/org.swift_project.xswiftbus.service.xml +++ b/src/xswiftbus/org.swift_project.xswiftbus.service.xml @@ -115,6 +115,9 @@ R"XML( + + + diff --git a/src/xswiftbus/service.cpp b/src/xswiftbus/service.cpp index b9645df9db..123910cd4d 100644 --- a/src/xswiftbus/service.cpp +++ b/src/xswiftbus/service.cpp @@ -94,6 +94,7 @@ namespace XSwiftBus this->updateAirportsInRange(); this->updateMessageBoxFromSettings(); m_framePeriodSampler->show(); + m_swiftNetworkConnected.set(0); } CService::~CService() = default; @@ -136,6 +137,8 @@ namespace XSwiftBus } } + void CService::setFlightNetworkConnected(bool connected) { m_swiftNetworkConnected.set(connected); } + void CService::addTextMessage(const std::string &text, double red, double green, double blue) { if (text.empty()) { return; } @@ -550,6 +553,14 @@ namespace XSwiftBus maybeSendEmptyDBusReply(wantsReply, sender, serial); queueDBusCall([=]() { resetFrameTotals(); }); } + else if (message.getMethodName() == "setFlightNetworkConnected") + { + maybeSendEmptyDBusReply(wantsReply, sender, serial); + bool connected = false; + message.beginArgumentRead(); + message.getArgument(connected); + queueDBusCall([=]() { setFlightNetworkConnected(connected); }); + } else if (message.getMethodName() == "getLatitudeDeg") { queueDBusCall([=]() { sendDBusReply(sender, serial, getLatitudeDeg()); }); diff --git a/src/xswiftbus/service.h b/src/xswiftbus/service.h index 45b9854708..b6f746aabc 100644 --- a/src/xswiftbus/service.h +++ b/src/xswiftbus/service.h @@ -16,6 +16,7 @@ #include "messages.h" #include "navdatareference.h" #include "terrainprobe.h" +#include "custom_datarefs.h" #include #include #include @@ -123,6 +124,9 @@ namespace XSwiftBus //! Reset the monitoring of total miles and minutes lost due to low frame rate. void resetFrameTotals(); + //! Set the current connection state + void setFlightNetworkConnected(bool connected); + //! Get aircraft latitude in degrees double getLatitudeDeg() const { return m_latitude.get(); } @@ -361,6 +365,7 @@ namespace XSwiftBus DataRef m_sceneryIsLoading; int m_sceneryWasLoading = 0; + CustomDataRef m_swiftNetworkConnected; StringDataRef m_liveryPath; StringDataRef m_icao; StringDataRef m_descrip; From 54f603436cb06f842518f82f273c737fd8c20f35 Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Mon, 18 Nov 2024 19:37:14 +0100 Subject: [PATCH 2/4] refactor: Remove unused code This was only used for Qt 5.8 on Win. --- src/misc/dbus.cpp | 22 ---------------------- src/misc/dbus.h | 9 +-------- 2 files changed, 1 insertion(+), 30 deletions(-) diff --git a/src/misc/dbus.cpp b/src/misc/dbus.cpp index e7f3ae3193..e317f98c12 100644 --- a/src/misc/dbus.cpp +++ b/src/misc/dbus.cpp @@ -3,28 +3,6 @@ #include "misc/dbus.h" -#ifdef Q_OS_WIN -# include - -# include - -// https://blogs.msdn.microsoft.com/oldnewthing/20131105-00/?p=2733 -// See https://bugreports.qt.io/browse/QTBUG-53031 for more details -// why this is necessary. -void preventQtDBusDllUnload() -{ - // Only Qt 5.8.0 is affected. - if (qVersion() != QByteArray("5.8.0")) { return; } - - static HMODULE dbusDll; - GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_PIN, - reinterpret_cast(&QDBusConnection::staticMetaObject), &dbusDll); - Q_ASSERT(dbusDll); -} -#else -void preventQtDBusDllUnload() {} -#endif - QDBusArgument &operator<<(QDBusArgument &arg, const std::string &s) { arg.beginStructure(); diff --git a/src/misc/dbus.h b/src/misc/dbus.h index b2783714ba..4151d8325e 100644 --- a/src/misc/dbus.h +++ b/src/misc/dbus.h @@ -78,11 +78,4 @@ const QDBusArgument &operator>>(const QDBusArgument &arg, QFlags &value) return arg; } -// *INDENT-ON* - -//! Windows: prevents unloading of QtDBus shared library until the process is terminated. -//! QtDBus must have been loaded already by the calling process. -//! Does nothing on non-Windows platforms. -SWIFT_MISC_EXPORT void preventQtDBusDllUnload(); - -#endif // guard +#endif // SWIFT_MISC_DBUS_H From 82bd1b1116b9caf75d74c9fc48040dcc07432955 Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Tue, 19 Nov 2024 08:20:42 +0100 Subject: [PATCH 3/4] refactor(afv): Fix some clang-tidy warnings --- src/core/afv/audio/callsigndelaycache.cpp | 20 ++++++++++--------- src/core/afv/audio/callsigndelaycache.h | 8 ++++---- src/core/afv/audio/callsignsampleprovider.cpp | 4 +--- src/core/afv/audio/callsignsampleprovider.h | 4 +--- src/core/afv/audio/input.cpp | 3 --- src/core/afv/audio/input.h | 2 -- src/core/afv/audio/output.cpp | 1 - src/core/afv/audio/output.h | 8 ++++---- src/core/afv/audio/receiversampleprovider.cpp | 14 +++++-------- src/core/afv/audio/receiversampleprovider.h | 7 +++---- src/core/afv/audio/soundcardsampleprovider.h | 4 ++-- src/core/afv/clients/afvclient.cpp | 11 ---------- src/core/afv/clients/afvclient.h | 3 --- .../afv/connection/apiserverconnection.cpp | 1 - src/core/afv/connection/apiserverconnection.h | 2 -- src/core/afv/connection/clientconnection.h | 3 ++- .../afv/connection/clientconnectiondata.cpp | 2 -- .../afv/connection/clientconnectiondata.h | 3 +-- src/core/afv/constants.h | 2 +- src/core/afv/crypto/cryptodtochannel.cpp | 6 ++++-- src/core/afv/crypto/cryptodtochannel.h | 4 +--- src/core/afv/crypto/cryptodtoheaderdto.h | 2 +- src/core/afv/crypto/cryptodtomode.h | 2 +- src/core/afv/crypto/cryptodtoserializer.cpp | 2 -- src/core/afv/crypto/cryptodtoserializer.h | 12 +++++------ src/core/afv/dto.h | 18 ++++++++--------- src/core/afv/model/afvmapreader.h | 2 +- src/core/afv/model/atcstationmodel.h | 9 +++------ 28 files changed, 61 insertions(+), 98 deletions(-) diff --git a/src/core/afv/audio/callsigndelaycache.cpp b/src/core/afv/audio/callsigndelaycache.cpp index e91daf8053..5c0cb6b456 100644 --- a/src/core/afv/audio/callsigndelaycache.cpp +++ b/src/core/afv/audio/callsigndelaycache.cpp @@ -3,33 +3,35 @@ #include "core/afv/audio/callsigndelaycache.h" +#include + namespace swift::core::afv::audio { void CallsignDelayCache::initialise(const QString &callsign) { if (!m_delayCache.contains(callsign)) { m_delayCache[callsign] = delayDefault; } - if (!successfulTransmissionsCache.contains(callsign)) { successfulTransmissionsCache[callsign] = 0; } + if (!m_successfulTransmissionsCache.contains(callsign)) { m_successfulTransmissionsCache[callsign] = 0; } } int CallsignDelayCache::get(const QString &callsign) { return m_delayCache[callsign]; } void CallsignDelayCache::underflow(const QString &callsign) { - if (!successfulTransmissionsCache.contains(callsign)) return; + if (!m_successfulTransmissionsCache.contains(callsign)) return; - successfulTransmissionsCache[callsign] = 0; + m_successfulTransmissionsCache[callsign] = 0; increaseDelayMs(callsign); } void CallsignDelayCache::success(const QString &callsign) { - if (!successfulTransmissionsCache.contains(callsign)) return; + if (!m_successfulTransmissionsCache.contains(callsign)) return; - successfulTransmissionsCache[callsign]++; - if (successfulTransmissionsCache[callsign] > 5) + m_successfulTransmissionsCache[callsign]++; + if (m_successfulTransmissionsCache[callsign] > 5) { decreaseDelayMs(callsign); - successfulTransmissionsCache[callsign] = 0; + m_successfulTransmissionsCache[callsign] = 0; } } @@ -38,7 +40,7 @@ namespace swift::core::afv::audio if (!m_delayCache.contains(callsign)) return; m_delayCache[callsign] += delayIncrement; - if (m_delayCache[callsign] > delayMax) { m_delayCache[callsign] = delayMax; } + m_delayCache[callsign] = std::min(m_delayCache[callsign], delayMax); } void CallsignDelayCache::decreaseDelayMs(const QString &callsign) @@ -46,7 +48,7 @@ namespace swift::core::afv::audio if (!m_delayCache.contains(callsign)) return; m_delayCache[callsign] -= delayIncrement; - if (m_delayCache[callsign] < delayMin) { m_delayCache[callsign] = delayMin; } + m_delayCache[callsign] = std::max(m_delayCache[callsign], delayMin); } CallsignDelayCache &CallsignDelayCache::instance() diff --git a/src/core/afv/audio/callsigndelaycache.h b/src/core/afv/audio/callsigndelaycache.h index 86e18887cf..40c02f74e7 100644 --- a/src/core/afv/audio/callsigndelaycache.h +++ b/src/core/afv/audio/callsigndelaycache.h @@ -3,8 +3,8 @@ //! \file -#ifndef SWIFT_ORE_AFV_AUDIO_CALLSIGNDELAYCACHE_H -#define SWIFT_ORE_AFV_AUDIO_CALLSIGNDELAYCACHE_H +#ifndef SWIFT_CORE_AFV_AUDIO_CALLSIGNDELAYCACHE_H +#define SWIFT_CORE_AFV_AUDIO_CALLSIGNDELAYCACHE_H #include #include @@ -46,9 +46,9 @@ namespace swift::core::afv::audio static constexpr int delayMax = 300; QHash m_delayCache; - QHash successfulTransmissionsCache; + QHash m_successfulTransmissionsCache; }; } // namespace swift::core::afv::audio -#endif // guard +#endif // SWIFT_CORE_AFV_AUDIO_CALLSIGNDELAYCACHE_H diff --git a/src/core/afv/audio/callsignsampleprovider.cpp b/src/core/afv/audio/callsignsampleprovider.cpp index f6df3d3369..6eb2f2e6c2 100644 --- a/src/core/afv/audio/callsignsampleprovider.cpp +++ b/src/core/afv/audio/callsignsampleprovider.cpp @@ -3,7 +3,6 @@ #include "core/afv/audio/callsignsampleprovider.h" -#include #include #include #include @@ -205,8 +204,7 @@ namespace swift::core::afv::audio { double crackleFactor = (((qExp(m_distanceRatio) * qPow(m_distanceRatio, -4.0)) / 350.0) - 0.00776652); - if (crackleFactor < 0.0) { crackleFactor = 0.0; } - if (crackleFactor > 0.20) { crackleFactor = 0.20; } + crackleFactor = std::clamp(crackleFactor, 0.0, 0.2); m_crackleSoundProvider->setGain(crackleFactor * 2); m_whiteNoise->setGain(m_whiteNoiseGainMin); diff --git a/src/core/afv/audio/callsignsampleprovider.h b/src/core/afv/audio/callsignsampleprovider.h index 2f3dc0a4a1..abb0bd65ad 100644 --- a/src/core/afv/audio/callsignsampleprovider.h +++ b/src/core/afv/audio/callsignsampleprovider.h @@ -8,7 +8,6 @@ #include #include -#include #include #include @@ -17,7 +16,6 @@ #include "sound/sampleprovider/bufferedwaveprovider.h" #include "sound/sampleprovider/equalizersampleprovider.h" #include "sound/sampleprovider/mixingsampleprovider.h" -#include "sound/sampleprovider/pinknoisegenerator.h" #include "sound/sampleprovider/resourcesoundsampleprovider.h" #include "sound/sampleprovider/sawtoothgenerator.h" #include "sound/sampleprovider/simplecompressoreffect.h" @@ -108,4 +106,4 @@ namespace swift::core::afv::audio }; } // namespace swift::core::afv::audio -#endif // guard +#endif // SWIFT_CORE_AFV_AUDIO_CALLSIGNSAMPLEPROVIDER_H diff --git a/src/core/afv/audio/input.cpp b/src/core/afv/audio/input.cpp index a5198360ed..8fe04e3f25 100644 --- a/src/core/afv/audio/input.cpp +++ b/src/core/afv/audio/input.cpp @@ -8,8 +8,6 @@ #include #include -#include -#include #include #include "misc/logmessage.h" @@ -49,7 +47,6 @@ namespace swift::core::afv::audio const int byteCount = 1920 * m_format.channelCount(); while (m_buffer.size() > byteCount) { - // qDebug() << QDateTime::currentMSecsSinceEpoch() << "CAudioInputBuffer::writeData " << m_buffer.size(); emit frameAvailable(m_buffer.left(byteCount)); m_buffer.remove(0, byteCount); } diff --git a/src/core/afv/audio/input.h b/src/core/afv/audio/input.h index 26bfda3951..893c15b0b8 100644 --- a/src/core/afv/audio/input.h +++ b/src/core/afv/audio/input.h @@ -15,8 +15,6 @@ #endif #include -#include -#include #include namespace swift::core::afv::audio diff --git a/src/core/afv/audio/output.cpp b/src/core/afv/audio/output.cpp index ea97683b98..60f6df4871 100644 --- a/src/core/afv/audio/output.cpp +++ b/src/core/afv/audio/output.cpp @@ -5,7 +5,6 @@ #include -#include #include #include "misc/logmessage.h" diff --git a/src/core/afv/audio/output.h b/src/core/afv/audio/output.h index e2f00a4f0f..a23ce795d1 100644 --- a/src/core/afv/audio/output.h +++ b/src/core/afv/audio/output.h @@ -45,10 +45,10 @@ namespace swift::core::afv::audio #endif //! \copydoc QIODevice::readData - virtual qint64 readData(char *data, qint64 maxlen) override; + qint64 readData(char *data, qint64 maxlen) override; //! \copydoc QIODevice::writeData - virtual qint64 writeData(const char *data, qint64 len) override; + qint64 writeData(const char *data, qint64 len) override; private: swift::sound::sample_provider::ISampleProvider *m_sampleProvider = nullptr; //!< related provider @@ -71,7 +71,7 @@ namespace swift::core::afv::audio COutput(QObject *parent = nullptr); //! Dtor - virtual ~COutput() override { this->stop(); } + ~COutput() override { this->stop(); } //! Start output void start(const swift::misc::audio::CAudioDeviceInfo &outputDevice, @@ -103,4 +103,4 @@ namespace swift::core::afv::audio }; } // namespace swift::core::afv::audio -#endif // guard +#endif // SWIFT_CORE_AFV_AUDIO_OUTPUT_H diff --git a/src/core/afv/audio/receiversampleprovider.cpp b/src/core/afv/audio/receiversampleprovider.cpp index 5c75f100ad..f3d3bbffea 100644 --- a/src/core/afv/audio/receiversampleprovider.cpp +++ b/src/core/afv/audio/receiversampleprovider.cpp @@ -5,7 +5,6 @@ #include "core/afv/audio/receiversampleprovider.h" -#include #include #include "misc/logmessage.h" @@ -65,9 +64,8 @@ namespace swift::core::afv::audio int CReceiverSampleProvider::activeCallsigns() const { - const int numberOfCallsigns = - static_cast(std::count_if(m_voiceInputs.begin(), m_voiceInputs.end(), - [](const CCallsignSampleProvider *p) { return p->inUse() == true; })); + const int numberOfCallsigns = static_cast(std::count_if( + m_voiceInputs.begin(), m_voiceInputs.end(), [](const CCallsignSampleProvider *p) { return p->inUse(); })); return numberOfCallsigns; } @@ -92,11 +90,9 @@ namespace swift::core::afv::audio if (m_doClickWhenAppropriate && numberOfInUseInputs == 0) { - CResourceSoundSampleProvider *resourceSound = - new CResourceSoundSampleProvider(Samples::instance().click(), m_mixer); + auto *resourceSound = new CResourceSoundSampleProvider(Samples::instance().click(), m_mixer); m_mixer->addMixerInput(resourceSound); m_doClickWhenAppropriate = false; - // CLogMessage(this).debug(u"AFV Click..."); } //! \todo KB 2020-04 not entirely correct, as it can be the number is the same, but changed callsign @@ -132,7 +128,7 @@ namespace swift::core::afv::audio if (!voiceInput) { it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), - [](const CCallsignSampleProvider *p) { return p->inUse() == false; }); + [](const CCallsignSampleProvider *p) { return !p->inUse(); }); if (it != m_voiceInputs.end()) { voiceInput = *it; @@ -162,7 +158,7 @@ namespace swift::core::afv::audio if (!voiceInput) { it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), - [](const CCallsignSampleProvider *p) { return p->inUse() == false; }); + [](const CCallsignSampleProvider *p) { return !p->inUse(); }); if (it != m_voiceInputs.end()) { voiceInput = *it; diff --git a/src/core/afv/audio/receiversampleprovider.h b/src/core/afv/audio/receiversampleprovider.h index 77c7865eef..2e171252c8 100644 --- a/src/core/afv/audio/receiversampleprovider.h +++ b/src/core/afv/audio/receiversampleprovider.h @@ -11,7 +11,6 @@ #include "core/afv/audio/callsignsampleprovider.h" #include "misc/audio/audiosettings.h" #include "misc/aviation/callsignset.h" -#include "misc/logcategories.h" #include "sound/sampleprovider/mixingsampleprovider.h" #include "sound/sampleprovider/sampleprovider.h" #include "sound/sampleprovider/sinusgenerator.h" @@ -22,7 +21,7 @@ namespace swift::core::afv::audio //! Arguments struct TransceiverReceivingCallsignsChangedArgs { - quint16 transceiverID; //!< transceiver id + quint16 transceiverID {}; //!< transceiver id QStringList receivingCallsigns; //!< callsigns }; @@ -58,7 +57,7 @@ namespace swift::core::afv::audio //! @} //! \copydoc swift::sound::sample_provider::ISampleProvider::readSamples - virtual int readSamples(QVector &samples, qint64 count) override; + int readSamples(QVector &samples, qint64 count) override; //! @{ //! Add samples @@ -117,4 +116,4 @@ namespace swift::core::afv::audio Q_DECLARE_METATYPE(swift::core::afv::audio::TransceiverReceivingCallsignsChangedArgs) -#endif // guard +#endif // SWIFT_CORE_AFV_AUDIO_RECEIVERSAMPLEPROVIDER_H diff --git a/src/core/afv/audio/soundcardsampleprovider.h b/src/core/afv/audio/soundcardsampleprovider.h index 86e6888157..0debeea32b 100644 --- a/src/core/afv/audio/soundcardsampleprovider.h +++ b/src/core/afv/audio/soundcardsampleprovider.h @@ -35,7 +35,7 @@ namespace swift::core::afv::audio void pttUpdate(bool active, const QVector &txTransceivers); //! \copydoc swift::sound::sample_provider::ISampleProvider::readSamples - virtual int readSamples(QVector &samples, qint64 count) override; + int readSamples(QVector &samples, qint64 count) override; //! Add OPUS samples void addOpusSamples(const IAudioDto &audioDto, const QVector &rxTransceivers); @@ -65,4 +65,4 @@ namespace swift::core::afv::audio } // namespace swift::core::afv::audio -#endif // guard +#endif // SWIFT_CORE_AFV_AUDIO_SOUNDCARDSAMPLEPROVIDER_H diff --git a/src/core/afv/clients/afvclient.cpp b/src/core/afv/clients/afvclient.cpp index 7bb293165a..4175b2b615 100644 --- a/src/core/afv/clients/afvclient.cpp +++ b/src/core/afv/clients/afvclient.cpp @@ -3,8 +3,6 @@ #include "core/afv/clients/afvclient.h" -#include - #ifdef Q_OS_WIN # include "comdef.h" #endif @@ -33,15 +31,6 @@ using namespace swift::sound::sample_provider; namespace swift::core::afv::clients { - constexpr int CAfvClient::PositionUpdatesMs; - constexpr int CAfvClient::SampleRate; - constexpr int CAfvClient::FrameSize; - constexpr double CAfvClient::MinDbIn; - constexpr double CAfvClient::MaxDbIn; - constexpr double CAfvClient::MinDbOut; - constexpr double CAfvClient::MaxDbOut; - constexpr quint32 CAfvClient::UniCom; - const QStringList &CAfvClient::getLogCategories() { static const QStringList cats { CLogCategories::audio(), CLogCategories::vatsimSpecific() }; diff --git a/src/core/afv/clients/afvclient.h b/src/core/afv/clients/afvclient.h index a182628326..de4b1c9443 100644 --- a/src/core/afv/clients/afvclient.h +++ b/src/core/afv/clients/afvclient.h @@ -8,9 +8,6 @@ #include -#include -#include -#include #include #include #include diff --git a/src/core/afv/connection/apiserverconnection.cpp b/src/core/afv/connection/apiserverconnection.cpp index 60eee4208c..4a3f1a3ecb 100644 --- a/src/core/afv/connection/apiserverconnection.cpp +++ b/src/core/afv/connection/apiserverconnection.cpp @@ -5,7 +5,6 @@ #include #include -#include #include #include #include diff --git a/src/core/afv/connection/apiserverconnection.h b/src/core/afv/connection/apiserverconnection.h index 241c5488f9..958008cea3 100644 --- a/src/core/afv/connection/apiserverconnection.h +++ b/src/core/afv/connection/apiserverconnection.h @@ -6,8 +6,6 @@ #ifndef SWIFT_CORE_AFV_CONNECTION_APISERVERCONNECTION_H #define SWIFT_CORE_AFV_CONNECTION_APISERVERCONNECTION_H -#include -#include #include #include #include diff --git a/src/core/afv/connection/clientconnection.h b/src/core/afv/connection/clientconnection.h index f21704f14f..85cb19ed3e 100644 --- a/src/core/afv/connection/clientconnection.h +++ b/src/core/afv/connection/clientconnection.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "core/afv/connection/apiserverconnection.h" #include "core/afv/connection/clientconnectiondata.h" @@ -137,4 +138,4 @@ namespace swift::core::afv::connection }; } // namespace swift::core::afv::connection -#endif // guard +#endif // SWIFT_CORE_AFV_CONNECTION_CLIENTCONNECTION_H diff --git a/src/core/afv/connection/clientconnectiondata.cpp b/src/core/afv/connection/clientconnectiondata.cpp index f303f89288..9a3dda4498 100644 --- a/src/core/afv/connection/clientconnectiondata.cpp +++ b/src/core/afv/connection/clientconnectiondata.cpp @@ -3,8 +3,6 @@ #include "core/afv/connection/clientconnectiondata.h" -#include - #include "misc/logmessage.h" using namespace swift::misc; diff --git a/src/core/afv/connection/clientconnectiondata.h b/src/core/afv/connection/clientconnectiondata.h index 3a0a553072..35a5814b73 100644 --- a/src/core/afv/connection/clientconnectiondata.h +++ b/src/core/afv/connection/clientconnectiondata.h @@ -14,7 +14,6 @@ #include "core/afv/connection/apiserverconnection.h" #include "core/afv/crypto/cryptodtochannel.h" #include "core/afv/dto.h" -#include "misc/logcategories.h" namespace swift::core::afv::connection { @@ -114,4 +113,4 @@ namespace swift::core::afv::connection }; } // namespace swift::core::afv::connection -#endif // guard +#endif // SWIFT_CORE_AFV_CONNECTION_CLIENTCONNECTIONDATA_H diff --git a/src/core/afv/constants.h b/src/core/afv/constants.h index d83e6d2ca9..4477c21510 100644 --- a/src/core/afv/constants.h +++ b/src/core/afv/constants.h @@ -15,4 +15,4 @@ namespace swift::core::afv constexpr int c_sampleRate = 48000; } // namespace swift::core::afv -#endif // guard +#endif // SWIFT_CORE_AFV_CONSTANTS_H diff --git a/src/core/afv/crypto/cryptodtochannel.cpp b/src/core/afv/crypto/cryptodtochannel.cpp index ed9f9c456b..194cfaef81 100644 --- a/src/core/afv/crypto/cryptodtochannel.cpp +++ b/src/core/afv/crypto/cryptodtochannel.cpp @@ -3,6 +3,8 @@ #include "core/afv/crypto/cryptodtochannel.h" +#include + #include "sodium/crypto_aead_chacha20poly1305.h" #include "misc/verify.h" @@ -28,7 +30,7 @@ namespace swift::core::afv::crypto throw std::invalid_argument("wrong receive key size"); } - if (m_receiveSequenceSizeMaxSize < 1) { m_receiveSequenceSizeMaxSize = 1; } + m_receiveSequenceSizeMaxSize = std::max(m_receiveSequenceSizeMaxSize, 1); m_receiveSequenceHistory.fill(0, m_receiveSequenceSizeMaxSize); m_receiveSequenceHistoryDepth = 0; } @@ -95,7 +97,7 @@ namespace swift::core::afv::crypto } else { - int minIndex; + int minIndex {}; uint minValue = getMin(minIndex); if (sequenceReceived < minValue) { return false; } // Possible replay attack m_receiveSequenceHistory[minIndex] = sequenceReceived; diff --git a/src/core/afv/crypto/cryptodtochannel.h b/src/core/afv/crypto/cryptodtochannel.h index b60f99ad6d..099882d1a9 100644 --- a/src/core/afv/crypto/cryptodtochannel.h +++ b/src/core/afv/crypto/cryptodtochannel.h @@ -6,8 +6,6 @@ #ifndef SWIFT_CORE_AFV_CRYPTO_CRYPTODTOCHANNEL_H #define SWIFT_CORE_AFV_CRYPTO_CRYPTODTOCHANNEL_H -#include - #include #include #include @@ -58,4 +56,4 @@ namespace swift::core::afv::crypto }; } // namespace swift::core::afv::crypto -#endif // guard +#endif // SWIFT_CORE_AFV_CRYPTO_CRYPTODTOCHANNEL_H diff --git a/src/core/afv/crypto/cryptodtoheaderdto.h b/src/core/afv/crypto/cryptodtoheaderdto.h index abb705f5d9..0490f34b93 100644 --- a/src/core/afv/crypto/cryptodtoheaderdto.h +++ b/src/core/afv/crypto/cryptodtoheaderdto.h @@ -26,4 +26,4 @@ namespace swift::core::afv::crypto }; } // namespace swift::core::afv::crypto -#endif // gaurd +#endif // SWIFT_CORE_AFV_CRYPTO_CRYPTODTOHEADERDTO_H diff --git a/src/core/afv/crypto/cryptodtomode.h b/src/core/afv/crypto/cryptodtomode.h index f7324e3659..6b59e1ec21 100644 --- a/src/core/afv/crypto/cryptodtomode.h +++ b/src/core/afv/crypto/cryptodtomode.h @@ -23,4 +23,4 @@ namespace swift::core::afv::crypto //! \private MSGPACK_ADD_ENUM(swift::core::afv::crypto::CryptoDtoMode); -#endif // guard +#endif // SWIFT_CORE_AFV_CRYPTO_CRYPTODTOMODE_H diff --git a/src/core/afv/crypto/cryptodtoserializer.cpp b/src/core/afv/crypto/cryptodtoserializer.cpp index de946e6f19..b29f5a7b14 100644 --- a/src/core/afv/crypto/cryptodtoserializer.cpp +++ b/src/core/afv/crypto/cryptodtoserializer.cpp @@ -5,8 +5,6 @@ namespace swift::core::afv::crypto { - CryptoDtoSerializer::CryptoDtoSerializer() {} - CryptoDtoSerializer::Deserializer CryptoDtoSerializer::deserialize(CCryptoDtoChannel &channel, const QByteArray &bytes, bool loopback) { diff --git a/src/core/afv/crypto/cryptodtoserializer.h b/src/core/afv/crypto/cryptodtoserializer.h index ee7add2b5e..9219cd6945 100644 --- a/src/core/afv/crypto/cryptodtoserializer.h +++ b/src/core/afv/crypto/cryptodtoserializer.h @@ -30,7 +30,7 @@ namespace swift::core::afv::crypto class CryptoDtoSerializer { public: - CryptoDtoSerializer(); + CryptoDtoSerializer() = default; //! Serialize a DTO template @@ -44,16 +44,16 @@ namespace swift::core::afv::crypto headerBuffer.open(QIODevice::WriteOnly); msgpack::pack(headerBuffer, header); headerBuffer.close(); - const quint16 headerLength = static_cast(headerBuffer.buffer().size()); + const auto headerLength = static_cast(headerBuffer.buffer().size()); const QByteArray dtoShortName = T::getShortDtoName(); - const quint16 dtoNameLength = static_cast(dtoShortName.size()); + const auto dtoNameLength = static_cast(dtoShortName.size()); QBuffer dtoBuffer; dtoBuffer.open(QIODevice::WriteOnly); msgpack::pack(dtoBuffer, dto); dtoBuffer.close(); - const quint16 dtoLength = static_cast(dtoBuffer.buffer().size()); + const auto dtoLength = static_cast(dtoBuffer.buffer().size()); if (header.Mode == CryptoDtoMode::AEAD_ChaCha20Poly1305) { @@ -80,7 +80,7 @@ namespace swift::core::afv::crypto nonceBuffer.write(reinterpret_cast(&header.Sequence), sizeof(header.Sequence)); nonceBuffer.close(); - unsigned long long clen; + unsigned long long clen {}; QByteArray aeadPayload; aeadPayload.fill(0, static_cast(aePayloadBuffer.size() + crypto_aead_chacha20poly1305_IETF_ABYTES)); @@ -163,4 +163,4 @@ namespace swift::core::afv::crypto }; } // namespace swift::core::afv::crypto -#endif // guard +#endif // SWIFT_CORE_AFV_CRYPTO_CRYPTODTO_SERIALIZER_H diff --git a/src/core/afv/dto.h b/src/core/afv/dto.h index 87c3850409..02af7bf810 100644 --- a/src/core/afv/dto.h +++ b/src/core/afv/dto.h @@ -117,8 +117,8 @@ namespace swift::core::afv { //! @{ //! Properties - quint16 id; - quint32 frequencyHz; + quint16 id {}; + quint32 frequencyHz {}; double LatDeg = 0.0; double LonDeg = 0.0; double HeightMslM = 0.0; @@ -160,8 +160,8 @@ namespace swift::core::afv //! Properties QUuid id; QString name; - quint32 frequencyHz; - quint32 frequencyAliasHz; + quint32 frequencyHz {}; + quint32 frequencyAliasHz {}; //! @} //! From JSON @@ -219,15 +219,15 @@ namespace swift::core::afv struct TxTransceiverDto { //! Ctor - TxTransceiverDto() {} + TxTransceiverDto() = default; //! Ctor - TxTransceiverDto(const TransceiverDto &dto) { id = dto.id; } + TxTransceiverDto(const TransceiverDto &dto) : id(dto.id) {} //! Ctor - TxTransceiverDto(uint16_t value) { id = value; } + TxTransceiverDto(uint16_t value) : id(value) {} - uint16_t id; //!< id + uint16_t id {}; //!< id MSGPACK_DEFINE(id) }; @@ -281,4 +281,4 @@ namespace swift::core::afv }; } // namespace swift::core::afv -#endif // guard +#endif // SWIFT_CORE_AFV_DTO_H diff --git a/src/core/afv/model/afvmapreader.h b/src/core/afv/model/afvmapreader.h index 8d6e271eb0..ba78169f13 100644 --- a/src/core/afv/model/afvmapreader.h +++ b/src/core/afv/model/afvmapreader.h @@ -42,4 +42,4 @@ namespace swift::core::afv::model }; } // namespace swift::core::afv::model -#endif // guard +#endif // SWIFT_CORE_AFV_AFVMAPREADER_H diff --git a/src/core/afv/model/atcstationmodel.h b/src/core/afv/model/atcstationmodel.h index 59c1b744aa..f41b79b555 100644 --- a/src/core/afv/model/atcstationmodel.h +++ b/src/core/afv/model/atcstationmodel.h @@ -5,9 +5,6 @@ #define SWIFT_CORE_AFV_MODEL_ATCSTATIONMODEL_H #include -#include -#include -#include #include #include @@ -21,7 +18,7 @@ namespace swift::core::afv::model { public: //! Ctor - CSampleAtcStation() {} + CSampleAtcStation() = default; //! Ctor CSampleAtcStation(const QString &callsign, const swift::core::afv::TransceiverDto &transceiver); @@ -68,7 +65,7 @@ namespace swift::core::afv::model CSampleAtcStationModel(QObject *parent = nullptr); //! Dtor - virtual ~CSampleAtcStationModel() override; + ~CSampleAtcStationModel() override; //! Update the stations void updateAtcStations(const QVector &atcStations); @@ -91,4 +88,4 @@ namespace swift::core::afv::model }; } // namespace swift::core::afv::model -#endif // guard +#endif // SWIFT_CORE_AFV_MODEL_ATCSTATIONMODEL_H From 25ed9dd54cab2e61eda8e2dfb04f2f6252cb3f9e Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Tue, 19 Nov 2024 08:21:03 +0100 Subject: [PATCH 4/4] chore: Upgrade version to 0.15 --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index bc8c3870db..806be02260 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "version": { "major": 0, - "minor": 14 + "minor": 15 } }