From 14c045e7b4d6b2e24903df80051b5ceac7855d12 Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Fri, 9 Feb 2024 16:32:45 +0100 Subject: [PATCH] refactor: Remove CUrlList Nowadays most of the loadbalancing is done on the server-side and hence there is only a single datafile URL (and other URLs) inside the boostrap.json. The features of the CUrlList are hence not really used. This is also a step into removing CUrl and using QUrl instead, to avoid maintaining a separate URL class. --- .../share/shared/bootstrap/bootstrap.json | 42 +--- scripts/swift.imp | 2 - src/blackcore/application.cpp | 24 +- src/blackcore/application.h | 8 +- src/blackcore/data/globalsetup.cpp | 25 +- src/blackcore/data/globalsetup.h | 40 ++- src/blackcore/data/vatsimsetup.cpp | 16 +- src/blackcore/data/vatsimsetup.h | 40 +-- src/blackcore/setupreader.h | 1 - src/blackcore/vatsim/vatsimdatafilereader.cpp | 7 +- src/blackcore/vatsim/vatsimmetarreader.cpp | 5 +- .../vatsim/vatsimstatusfilereader.cpp | 47 ++-- src/blackcore/vatsim/vatsimstatusfilereader.h | 10 +- src/blackcore/webdataservices.cpp | 12 +- src/blackcore/webdataservices.h | 10 +- .../components/dbloadoverviewcomponent.cpp | 28 +-- src/blackgui/components/updateinfodialog.cpp | 2 +- src/blackmisc/CMakeLists.txt | 2 - src/blackmisc/db/artifact.cpp | 2 +- src/blackmisc/db/distribution.cpp | 18 +- src/blackmisc/db/distribution.h | 20 +- src/blackmisc/db/updateinfo.cpp | 4 +- .../network/registermetadatanetwork.cpp | 3 - src/blackmisc/network/urllist.cpp | 232 ------------------ src/blackmisc/network/urllist.h | 136 ---------- src/swiftguistandard/swiftguistdmenus.cpp | 1 - 26 files changed, 153 insertions(+), 584 deletions(-) delete mode 100644 src/blackmisc/network/urllist.cpp delete mode 100644 src/blackmisc/network/urllist.h diff --git a/resources/share/shared/bootstrap/bootstrap.json b/resources/share/shared/bootstrap/bootstrap.json index 5df235745..97ede2dc7 100644 --- a/resources/share/shared/bootstrap/bootstrap.json +++ b/resources/share/shared/bootstrap/bootstrap.json @@ -9,50 +9,30 @@ "ncepGlobalForecastSystemUrl25": { "url": "http://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p25.pl" }, - "onlineHelpUrls": { - "containerbase": [ - { - "url": "https://datastore.swift-project.org/page/swifthelpdispatcher.html" - } - ] + "onlineHelpUrl": { + "url": "https://datastore.swift-project.org/page/swifthelpdispatcher.html" }, "predefinedServers": { "containerbase": [ ] }, - "sharedUrls": { - "containerbase": [ - { - "url": "http://download.swift-project.org/shared/" - } - ] + "sharedUrl": { + "url": "http://download.swift-project.org/shared/" }, - "vatsimDataFileUrls": { - "containerbase": [ - { - "url": "https://data.vatsim.net/v3/vatsim-data.json" - } - ] + "vatsimDataFileUrl": { + "url": "https://data.vatsim.net/v3/vatsim-data.json" }, "vatsimServerFileUrl": { - "url": "https://data.vatsim.net/v3/vatsim-servers.json" + "url": "https://data.vatsim.net/v3/vatsim-servers.json" }, "vatsimFsdHttpUrl": { "url": "http://fsd.vatsim.net" }, - "vatsimMetarsUrls": { - "containerbase": [ - { - "url": "http://metar.vatsim.net/metar.php" - } - ] + "vatsimMetarsUrl": { + "url": "http://metar.vatsim.net/metar.php" }, - "vatsimStatusFileUrls": { - "containerbase": [ - { - "url": "https://status.vatsim.net" - } - ] + "vatsimStatusFileUrl": { + "url": "https://status.vatsim.net" }, "comNavEquipmentHelpUrl": { "url": "https://en.wikipedia.org/wiki/Equipment_codes#Radio_communication,_navigation_and_approach_aid_equipment_and_capabilities" diff --git a/scripts/swift.imp b/scripts/swift.imp index fb6ffd167..c72bb65c1 100644 --- a/scripts/swift.imp +++ b/scripts/swift.imp @@ -87,8 +87,6 @@ { include: [ "\"fileutils.h\"", "private", "\"blackmisc/fileutils.h\"", "public" ] }, { include: [ "\"network/serverlist.h\"", "private", "\"blackmisc/network/serverlist.h\"", "public" ] }, { include: [ "\"serverlist.h\"", "private", "\"blackmisc/network/serverlist.h\"", "public" ] }, - { include: [ "\"network/urllist.h\"", "private", "\"blackmisc/network/urllist.h\"", "public" ] }, - { include: [ "\"urllist.h\"", "private", "\"blackmisc/network/urllist.h\"", "public" ] }, { include: [ "\"network/server.h\"", "private", "\"blackmisc/network/server.h\"", "public" ] }, { include: [ "\"server.h\"", "private", "\"blackmisc/network/server.h\"", "public" ] }, { include: [ "\"network/user.h\"", "private", "\"blackmisc/network/user.h\"", "public" ] }, diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index 0fcc86849..cfc05b3f6 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -1337,34 +1337,34 @@ namespace BlackCore return requestMsgs; } - CUrlList CApplication::getVatsimMetarUrls() const + CUrl CApplication::getVatsimMetarUrl() const { - if (m_shutdown) { return CUrlList(); } + if (m_shutdown) { return {}; } if (m_webDataServices) { - const CUrlList urls(m_webDataServices->getVatsimMetarUrls()); - if (!urls.isEmpty()) { return urls; } + const CUrl url(m_webDataServices->getVatsimMetarUrl()); + if (!url.isEmpty()) { return url; } } if (m_setupReader) { - return m_setupReader->getSetup().getVatsimMetarsUrls(); + return m_setupReader->getSetup().getVatsimMetarsUrl(); } - return CUrlList(); + return {}; } - CUrlList CApplication::getVatsimDataFileUrls() const + CUrl CApplication::getVatsimDataFileUrl() const { - if (m_shutdown) { return CUrlList(); } + if (m_shutdown) { return {}; } if (m_webDataServices) { - const CUrlList urls(m_webDataServices->getVatsimDataFileUrls()); - if (!urls.isEmpty()) { return urls; } + const CUrl url(m_webDataServices->getVatsimDataFileUrl()); + if (!url.isEmpty()) { return url; } } if (m_setupReader) { - return m_setupReader->getSetup().getVatsimDataFileUrls(); + return m_setupReader->getSetup().getVatsimDataFileUrl(); } - return CUrlList(); + return {}; } CUrl CApplication::getVatsimServerFileUrl() const diff --git a/src/blackcore/application.h b/src/blackcore/application.h index 81739d636..f218a2a97 100644 --- a/src/blackcore/application.h +++ b/src/blackcore/application.h @@ -15,7 +15,7 @@ #include "blackcore/inputmanager.h" #include "blackcore/webreaderflags.h" #include "blackmisc/db/updateinfo.h" -#include "blackmisc/network/urllist.h" +#include "blackmisc/network/url.h" #include "blackmisc/network/networkutils.h" #include "blackmisc/identifiable.h" #include "blackmisc/slot.h" @@ -395,11 +395,11 @@ namespace BlackCore //! Consolidated version of METAR URLs, either from CGlobalSetup or CVatsimSetup //! \threadsafe - BlackMisc::Network::CUrlList getVatsimMetarUrls() const; + BlackMisc::Network::CUrl getVatsimMetarUrl() const; - //! Consolidated version of data file URLs, either from CGlobalSetup or CVatsimSetup + //! Consolidated version of data file URL, either from CGlobalSetup or CVatsimSetup //! \threadsafe - BlackMisc::Network::CUrlList getVatsimDataFileUrls() const; + BlackMisc::Network::CUrl getVatsimDataFileUrl() const; //! Get URL to file which contains the list of VATSIM servers BlackMisc::Network::CUrl getVatsimServerFileUrl() const; diff --git a/src/blackcore/data/globalsetup.cpp b/src/blackcore/data/globalsetup.cpp index 0197bc43b..ad5d9b879 100644 --- a/src/blackcore/data/globalsetup.cpp +++ b/src/blackcore/data/globalsetup.cpp @@ -50,11 +50,10 @@ namespace BlackCore::Data return getDbRootDirectoryUrl(); } - const CUrlList &CGlobalSetup::getSwiftSharedUrls() const + const CUrl &CGlobalSetup::getSwiftSharedUrl() const { - return m_sharedUrls; + return m_sharedUrl; } - CUrl CGlobalSetup::getDbHomePageUrl() const { return getDbRootDirectoryUrl().withAppendedPath("/page/index.php"); @@ -62,11 +61,9 @@ namespace BlackCore::Data CUrl CGlobalSetup::getHelpPageUrl(const QString &context) const { - const CUrlList urls(m_onlineHelpUrls); - // we display in the standard browser, // so the user will realize if the URL does not work - CUrl url = (urls.size() < 2) ? urls.frontOrDefault() : urls.getRandomUrl(); + CUrl url = m_onlineHelpUrl; if (url.isEmpty()) { return url; } // context string something like "application.moreSpecific.evenMoreSpecific" @@ -148,11 +145,11 @@ namespace BlackCore::Data QString s = u"Global setup loaded: " % separator % u"Mapping min.version: " % this->getMappingMinimumVersionString() % separator - % u"Help URLs: " % m_onlineHelpUrls.toQString(i18n) % separator; + % u"Help URL: " % m_onlineHelpUrl.toQString(i18n) % separator; s += u"DB root directory: " % getDbRootDirectoryUrl().toQString(i18n) % separator % u"ICAO DB reader: " % getDbIcaoReaderUrl().toQString(i18n) % separator % u"Model DB reader: " % getDbModelReaderUrl().toQString(i18n) % separator % u"Airport DB reader: " % getDbAirportReaderUrl().toQString(i18n) % separator % u"DB home page: " % getDbHomePageUrl().toQString(i18n) % separator % u"DB login service: " % getDbLoginServiceUrl().toQString(i18n) % separator; s += - u"VATSIM METARs: " % getVatsimMetarsUrls().toQString(i18n) % separator % u"VATSIM data file: " % getVatsimDataFileUrls().toQString(i18n) % separator % u"VATSIM server file: " % getVatsimServerFileUrl().toQString(i18n) % separator + u"VATSIM METARs: " % getVatsimMetarsUrl().toQString(i18n) % separator % u"VATSIM data file: " % getVatsimDataFileUrl().toQString(i18n) % separator % u"VATSIM server file: " % getVatsimServerFileUrl().toQString(i18n) % separator % u"Predefined servers: " % getPredefinedServers().toQString(i18n) % separator @@ -174,8 +171,8 @@ namespace BlackCore::Data case IndexDbHttpPort: return QVariant::fromValue(m_dbHttpPort); case IndexDbHttpsPort: return QVariant::fromValue(m_dbHttpsPort); case IndexDbLoginService: return QVariant::fromValue(this->getDbLoginServiceUrl()); - case IndexVatsimStatus: return QVariant::fromValue(m_vatsimStatusFileUrls); - case IndexVatsimData: return QVariant::fromValue(m_vatsimDataFileUrls); + case IndexVatsimStatus: return QVariant::fromValue(m_vatsimStatusFileUrl); + case IndexVatsimData: return QVariant::fromValue(m_vatsimDataFileUrl); case IndexVatsimServer: return QVariant::fromValue(m_vatsimServerFileUrl); case IndexVatsimHttpFsd: return QVariant::fromValue(m_vatsimFsdHttpUrl); case IndexVatsimMetars: return QVariant::fromValue(m_vatsimMetarsUrl); @@ -204,12 +201,12 @@ namespace BlackCore::Data case IndexDbHttpPort: m_dbHttpPort = variant.toInt(); break; case IndexDbHttpsPort: m_dbHttpsPort = variant.toInt(); break; case IndexDbLoginService: break; // cannot be changed - case IndexVatsimData: m_vatsimDataFileUrls = variant.value(); break; + case IndexVatsimData: m_vatsimDataFileUrl = variant.value(); break; case IndexVatsimServer: m_vatsimServerFileUrl = variant.value(); break; case IndexVatsimHttpFsd: m_vatsimFsdHttpUrl = variant.value(); break; - case IndexVatsimMetars: m_vatsimMetarsUrls = variant.value(); break; - case IndexSharedUrls: m_sharedUrls = variant.value(); break; - case IndexOnlineHelpUrls: m_onlineHelpUrls = variant.value(); break; + case IndexVatsimMetars: m_vatsimMetarsUrl = variant.value(); break; + case IndexSharedUrl: m_sharedUrl = variant.value(); break; + case IndexOnlineHelpUrl: m_onlineHelpUrl = variant.value(); break; case IndexMappingMinimumVersion: m_mappingMinimumVersion = variant.toString(); break; case IndexPredefinedServers: m_predefinedServers = variant.value(); break; case IndexAfvApiServerUrl: m_afvApiServerUrl = variant.value(); break; diff --git a/src/blackcore/data/globalsetup.h b/src/blackcore/data/globalsetup.h index d04c2fb94..3e830c0be 100644 --- a/src/blackcore/data/globalsetup.h +++ b/src/blackcore/data/globalsetup.h @@ -9,7 +9,6 @@ #include "blackcore/blackcoreexport.h" #include "blackmisc/network/serverlist.h" #include "blackmisc/network/url.h" -#include "blackmisc/network/urllist.h" #include "blackmisc/identifiable.h" #include "blackmisc/datacache.h" #include "blackmisc/metaclass.h" @@ -43,8 +42,8 @@ namespace BlackCore::Data IndexVatsimData, IndexVatsimServer, IndexVatsimHttpFsd, - IndexOnlineHelpUrls, - IndexSharedUrls, + IndexOnlineHelpUrl, + IndexSharedUrl, IndexMappingMinimumVersion, IndexPredefinedServers, IndexAfvApiServerUrl, @@ -97,17 +96,17 @@ namespace BlackCore::Data //! \remark based on getDbRootDirectoryUrl BlackMisc::Network::CUrl getDbLoginServiceUrl() const; - //! Shared URLs - const BlackMisc::Network::CUrlList &getSwiftSharedUrls() const; + //! Shared URL + const BlackMisc::Network::CUrl &getSwiftSharedUrl() const; //! VATSIM METAR URL - const BlackMisc::Network::CUrlList &getVatsimMetarsUrls() const { return m_vatsimMetarsUrls; } + const BlackMisc::Network::CUrl &getVatsimMetarsUrl() const { return m_vatsimMetarsUrl; } - //! VATSIM status file URLs - const BlackMisc::Network::CUrlList &getVatsimStatusFileUrls() const { return m_vatsimStatusFileUrls; } + //! VATSIM status file URL + const BlackMisc::Network::CUrl &getVatsimStatusFileUrl() const { return m_vatsimStatusFileUrl; } - //! VATSIM data file URLs - const BlackMisc::Network::CUrlList &getVatsimDataFileUrls() const { return m_vatsimDataFileUrls; } + //! VATSIM data file URL + const BlackMisc::Network::CUrl &getVatsimDataFileUrl() const { return m_vatsimDataFileUrl; } //! VATSIM server file URL BlackMisc::Network::CUrl getVatsimServerFileUrl() const { return m_vatsimServerFileUrl; } @@ -116,7 +115,6 @@ namespace BlackCore::Data BlackMisc::Network::CUrl getVatsimFsdHttpUrl() const { return m_vatsimFsdHttpUrl; } //! Help page URL - //! \remark working URL evaluated at runtime, based on getOnlineHelpUrls BlackMisc::Network::CUrl getHelpPageUrl(const QString &context = {}) const; //! Predefined servers @@ -171,13 +169,13 @@ namespace BlackCore::Data int m_dbHttpsPort = 443; //!< SSL port QString m_mappingMinimumVersion; //!< minimum version BlackMisc::Network::CUrl m_dbRootDirectoryUrl; //!< Root directory of DB - BlackMisc::Network::CUrlList m_vatsimMetarsUrls; //!< METAR data - BlackMisc::Network::CUrlList m_vatsimStatusFileUrls; //!< Status file, where to find the VATSIM files (METAR, data, ATIS, other status files) - BlackMisc::Network::CUrlList m_vatsimDataFileUrls; //!< Overall VATSIM data file / merely for bootstrapping the first time + BlackMisc::Network::CUrl m_vatsimMetarsUrl; //!< METAR data + BlackMisc::Network::CUrl m_vatsimStatusFileUrl; //!< Status file, where to find the VATSIM files (METAR, data, ATIS, other status files) + BlackMisc::Network::CUrl m_vatsimDataFileUrl; //!< Overall VATSIM data file / merely for bootstrapping the first time BlackMisc::Network::CUrl m_vatsimServerFileUrl; //!< URL to list of VATSIM servers BlackMisc::Network::CUrl m_vatsimFsdHttpUrl; //!< URL to HTTP FSD server (for load-balancing and automatic server selection) - BlackMisc::Network::CUrlList m_sharedUrls; //!< where we can obtain shared info files such as bootstrap, .. - BlackMisc::Network::CUrlList m_onlineHelpUrls; //!< online help URLs + BlackMisc::Network::CUrl m_sharedUrl; //!< where we can obtain shared info files such as bootstrap, .. + BlackMisc::Network::CUrl m_onlineHelpUrl; //!< online help URL BlackMisc::Network::CServerList m_predefinedServers; //!< Predefined servers loaded from setup file BlackMisc::Network::CUrl m_ncepGlobalForecastSystemUrl25; //!< NCEP GFS url 0.25 degree resolution BlackMisc::Network::CUrl m_comNavEquipmentHelpUrl; //!< Help URL for COM/NAV equipment codes @@ -191,13 +189,13 @@ namespace BlackCore::Data BLACK_METAMEMBER(dbRootDirectoryUrl, 0, RequiredForJson), BLACK_METAMEMBER(dbHttpPort, 0, RequiredForJson), BLACK_METAMEMBER(dbHttpsPort, 0, RequiredForJson), - BLACK_METAMEMBER(vatsimStatusFileUrls, 0, RequiredForJson), - BLACK_METAMEMBER(vatsimDataFileUrls, 0, RequiredForJson), + BLACK_METAMEMBER(vatsimStatusFileUrl, 0, RequiredForJson), + BLACK_METAMEMBER(vatsimDataFileUrl, 0, RequiredForJson), BLACK_METAMEMBER(vatsimServerFileUrl, 0, RequiredForJson), BLACK_METAMEMBER(vatsimFsdHttpUrl, 0, RequiredForJson), - BLACK_METAMEMBER(vatsimMetarsUrls, 0, RequiredForJson), - BLACK_METAMEMBER(sharedUrls, 0, RequiredForJson), - BLACK_METAMEMBER(onlineHelpUrls, 0, RequiredForJson), + BLACK_METAMEMBER(vatsimMetarsUrl, 0, RequiredForJson), + BLACK_METAMEMBER(sharedUrl, 0, RequiredForJson), + BLACK_METAMEMBER(onlineHelpUrl, 0, RequiredForJson), BLACK_METAMEMBER(predefinedServers, 0, RequiredForJson), BLACK_METAMEMBER(mappingMinimumVersion, 0, RequiredForJson), BLACK_METAMEMBER(ncepGlobalForecastSystemUrl25, 0, RequiredForJson), diff --git a/src/blackcore/data/vatsimsetup.cpp b/src/blackcore/data/vatsimsetup.cpp index 266d53348..e0949558c 100644 --- a/src/blackcore/data/vatsimsetup.cpp +++ b/src/blackcore/data/vatsimsetup.cpp @@ -14,12 +14,12 @@ namespace BlackCore::Data CVatsimSetup::CVatsimSetup() : ITimestampBased(0) {} - bool CVatsimSetup::setUrls(const CUrlList &dataFileUrls, const CUrlList &serverFileUrls, const CUrlList &metarFileUrls) + bool CVatsimSetup::setUrls(const CUrl &dataFileUrl, const CUrl &serverFileUrl, const CUrl &metarFileUrl) { - const bool changed = (dataFileUrls != getDataFileUrls() || serverFileUrls != getServerFileUrls() || metarFileUrls != getMetarFileUrls()); - this->setServerFileUrls(serverFileUrls); - this->setMetarFileUrls(metarFileUrls); - this->setDataFileUrls(dataFileUrls); + const bool changed = (dataFileUrl != getDataFileUrl() || serverFileUrl != getServerFileUrl() || metarFileUrl != getMetarFileUrl()); + this->setServerFileUrl(serverFileUrl); + this->setMetarFileUrl(metarFileUrl); + this->setDataFileUrl(dataFileUrl); return changed; } @@ -43,7 +43,7 @@ namespace BlackCore::Data s.append(separator); s.append("VATSIM data file: "); - s.append(getDataFileUrls().toQString(i18n)); + s.append(getDataFileUrl().toQString(i18n)); s.append(separator); s.append("FSD servers: "); @@ -60,7 +60,7 @@ namespace BlackCore::Data switch (i) { case IndexFsdServers: return QVariant::fromValue(this->m_fsdServers); - case IndexDataFiles: return QVariant::fromValue(this->m_dataFileUrls); + case IndexDataFiles: return QVariant::fromValue(this->m_dataFileUrl); default: return CValueObject::propertyByIndex(index); } } @@ -82,7 +82,7 @@ namespace BlackCore::Data switch (i) { case IndexFsdServers: this->m_fsdServers = variant.value(); break; - case IndexDataFiles: this->m_dataFileUrls = variant.value(); break; + case IndexDataFiles: this->m_dataFileUrl = variant.value(); break; default: CValueObject::setPropertyByIndex(index, variant); break; } } diff --git a/src/blackcore/data/vatsimsetup.h b/src/blackcore/data/vatsimsetup.h index f89b16a53..90842b639 100644 --- a/src/blackcore/data/vatsimsetup.h +++ b/src/blackcore/data/vatsimsetup.h @@ -10,7 +10,7 @@ #include "blackmisc/datacache.h" #include "blackmisc/metaclass.h" #include "blackmisc/network/serverlist.h" -#include "blackmisc/network/urllist.h" +#include "blackmisc/network/url.h" #include "blackmisc/network/user.h" #include "blackmisc/propertyindex.h" #include "blackmisc/timestampbased.h" @@ -43,26 +43,26 @@ namespace BlackCore::Data //! Default constructor CVatsimSetup(); - //! VATSIM data file URLs - const BlackMisc::Network::CUrlList &getDataFileUrls() const { return m_dataFileUrls; } + //! VATSIM data file URL + const BlackMisc::Network::CUrl &getDataFileUrl() const { return m_dataFileUrl; } - //! Set VATSIM data file URLs - void setDataFileUrls(const BlackMisc::Network::CUrlList &urls) { m_dataFileUrls = urls; } + //! Set VATSIM data file URL + void setDataFileUrl(const BlackMisc::Network::CUrl &url) { m_dataFileUrl = url; } - //! Server file URLs (like data file, only servers) - const BlackMisc::Network::CUrlList &getServerFileUrls() const { return m_serverFileUrls; } + //! Server file URL + const BlackMisc::Network::CUrl &getServerFileUrl() const { return m_serverFileUrl; } - //! Set server file URLs (like data file, only servers) - void setServerFileUrls(const BlackMisc::Network::CUrlList &urls) { m_serverFileUrls = urls; } + //! Set server file URL + void setServerFileUrl(const BlackMisc::Network::CUrl &url) { m_serverFileUrl = url; } - //! METAR file URLs - const BlackMisc::Network::CUrlList &getMetarFileUrls() const { return m_metarFileUrls; } + //! METAR file URL + const BlackMisc::Network::CUrl &getMetarFileUrl() const { return m_metarFileUrl; } - //! METAR file URLs - void setMetarFileUrls(const BlackMisc::Network::CUrlList &urls) { m_metarFileUrls = urls; } + //! METAR file URL + void setMetarFileUrl(const BlackMisc::Network::CUrl &url) { m_metarFileUrl = url; } //! Set all URLs and indicate if something has changed - bool setUrls(const BlackMisc::Network::CUrlList &dataFileUrls, const BlackMisc::Network::CUrlList &serverFileUrls, const BlackMisc::Network::CUrlList &metarFileUrls); + bool setUrls(const BlackMisc::Network::CUrl &dataFileUrl, const BlackMisc::Network::CUrl &serverFileUrl, const BlackMisc::Network::CUrl &metarFileUrl); //! FSD servers const BlackMisc::Network::CServerList &getFsdServers() const { return m_fsdServers; } @@ -92,17 +92,17 @@ namespace BlackCore::Data void setPropertyByIndex(BlackMisc::CPropertyIndexRef index, const QVariant &variant); private: - BlackMisc::Network::CUrlList m_serverFileUrls; //!< only the FSD servers - BlackMisc::Network::CUrlList m_dataFileUrls; //!< Full VATSIM files - BlackMisc::Network::CUrlList m_metarFileUrls; //!< METAR files + BlackMisc::Network::CUrl m_serverFileUrl; //!< only the FSD servers + BlackMisc::Network::CUrl m_dataFileUrl; //!< Full VATSIM file + BlackMisc::Network::CUrl m_metarFileUrl; //!< METAR file BlackMisc::Network::CServerList m_fsdServers; //!< FSD test servers BlackMisc::Network::CServerList m_voiceServers; //!< voice servers BLACK_METACLASS( CVatsimSetup, - BLACK_METAMEMBER(serverFileUrls), - BLACK_METAMEMBER(dataFileUrls), - BLACK_METAMEMBER(metarFileUrls), + BLACK_METAMEMBER(serverFileUrl), + BLACK_METAMEMBER(dataFileUrl), + BLACK_METAMEMBER(metarFileUrl), BLACK_METAMEMBER(fsdServers), BLACK_METAMEMBER(voiceServers), BLACK_METAMEMBER(timestampMSecsSinceEpoch) diff --git a/src/blackcore/setupreader.h b/src/blackcore/setupreader.h index fbb708c60..f9d1c8655 100644 --- a/src/blackcore/setupreader.h +++ b/src/blackcore/setupreader.h @@ -10,7 +10,6 @@ #include "blackcore/data/globalsetup.h" #include "blackmisc/db/updateinfo.h" #include "blackmisc/datacache.h" -#include "blackmisc/network/urllist.h" #include "blackmisc/statusmessagelist.h" #include diff --git a/src/blackcore/vatsim/vatsimdatafilereader.cpp b/src/blackcore/vatsim/vatsimdatafilereader.cpp index c6f457826..e65355762 100644 --- a/src/blackcore/vatsim/vatsimdatafilereader.cpp +++ b/src/blackcore/vatsim/vatsimdatafilereader.cpp @@ -10,7 +10,6 @@ #include "blackmisc/network/entityflags.h" #include "blackmisc/network/server.h" #include "blackmisc/network/url.h" -#include "blackmisc/network/urllist.h" #include "blackmisc/network/user.h" #include "blackmisc/pq/frequency.h" #include "blackmisc/pq/length.h" @@ -168,12 +167,8 @@ namespace BlackCore::Vatsim this->threadAssertCheck(); if (!this->doWorkCheck()) { return; } - // round robin for load balancing - // remark: Don't use QThread to run network operations in the background - // see http://qt-project.org/doc/qt-4.7/qnetworkaccessmanager.html Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing application"); - CFailoverUrlList urls(sApp->getVatsimDataFileUrls()); - const QUrl url(urls.obtainNextWorkingUrl(true)); + const QUrl url(sApp->getVatsimDataFileUrl()); if (url.isEmpty()) { return; } this->getFromNetworkAndLog(url, { this, &CVatsimDataFileReader::parseVatsimFile }); } diff --git a/src/blackcore/vatsim/vatsimmetarreader.cpp b/src/blackcore/vatsim/vatsimmetarreader.cpp index de9f552b9..01cfe1b92 100644 --- a/src/blackcore/vatsim/vatsimmetarreader.cpp +++ b/src/blackcore/vatsim/vatsimmetarreader.cpp @@ -7,8 +7,6 @@ #include "blackmisc/logmessage.h" #include "blackmisc/network/entityflags.h" #include "blackmisc/network/url.h" -#include "blackmisc/network/urllist.h" -#include "blackmisc/statusmessage.h" #include #include @@ -67,8 +65,7 @@ namespace BlackCore::Vatsim this->threadAssertCheck(); if (!this->doWorkCheck()) { return; } - CFailoverUrlList urls(sApp->getVatsimMetarUrls()); - const CUrl url(urls.obtainNextWorkingUrl(true)); + const CUrl url(sApp->getVatsimMetarUrl()); if (url.isEmpty()) { return; } Q_ASSERT_X(sApp, Q_FUNC_INFO, "No Application"); this->getFromNetworkAndLog(url.withAppendedQuery("id=all"), { this, &CVatsimMetarReader::decodeMetars }); diff --git a/src/blackcore/vatsim/vatsimstatusfilereader.cpp b/src/blackcore/vatsim/vatsimstatusfilereader.cpp index f81a8f116..c2e0b5352 100644 --- a/src/blackcore/vatsim/vatsimstatusfilereader.cpp +++ b/src/blackcore/vatsim/vatsimstatusfilereader.cpp @@ -6,7 +6,6 @@ #include "blackcore/data/globalsetup.h" #include "blackmisc/logmessage.h" #include "blackmisc/network/url.h" -#include "blackmisc/network/urllist.h" #include "blackmisc/statusmessage.h" #include @@ -45,14 +44,14 @@ namespace BlackCore::Vatsim }); } - CUrlList CVatsimStatusFileReader::getMetarFileUrls() const + CUrl CVatsimStatusFileReader::getMetarFileUrl() const { - return m_lastGoodSetup.get().getMetarFileUrls(); + return m_lastGoodSetup.get().getMetarFileUrl(); } - CUrlList CVatsimStatusFileReader::getDataFileUrls() const + CUrl CVatsimStatusFileReader::getDataFileUrl() const { - return m_lastGoodSetup.get().getDataFileUrls(); + return m_lastGoodSetup.get().getDataFileUrl(); } void CVatsimStatusFileReader::read() @@ -61,27 +60,10 @@ namespace BlackCore::Vatsim if (!this->doWorkCheck()) { return; } Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing application"); - const CUrlList urls(sApp->getGlobalSetup().getVatsimStatusFileUrls()); - const CUrl url = urls.getRandomUrl(); + const CUrl url(sApp->getGlobalSetup().getVatsimStatusFileUrl()); if (url.isEmpty()) { return; } CLogMessage(this).info(u"Trigger read of VATSIM status file from '%1'") << url.toQString(true); this->getFromNetworkAndLog(url, { this, &CVatsimStatusFileReader::parseVatsimFile }); - - if (urls.size() < 2) { return; } - const CUrl secondary = urls.getRandomWithout(url); - if (secondary.isEmpty()) { return; } - - constexpr int DelayMs = 5000; - const QPointer myself(this); - QTimer::singleShot(DelayMs, this, [=] { - if (!myself) { return; } - const CVatsimSetup vs(m_lastGoodSetup.get()); - if (vs.getTimeDifferenceToNowMs() > 2 * DelayMs) - { - // not yet read - this->getFromNetworkAndLog(url, { this, &CVatsimStatusFileReader::parseVatsimFile }); - } - }); } void CVatsimStatusFileReader::parseVatsimFile(QNetworkReply *nwReplyPtr) @@ -111,9 +93,9 @@ namespace BlackCore::Vatsim const QList lines = splitLinesRefs(dataFileData); if (lines.isEmpty()) { return; } - CUrlList dataFileUrls; - CUrlList serverFileUrls; - CUrlList metarFileUrls; + CUrl dataFileUrl; + CUrl serverFileUrl; + CUrl metarFileUrl; QString currentLine; // declared outside of the for loop, to amortize the cost of allocation for (const QStringRef &clRef : lines) @@ -136,17 +118,18 @@ namespace BlackCore::Vatsim const QString key(parts[0].trimmed().toLower()); const QString value(parts[1].trimmed()); const CUrl url(value); + // Always taking last in the file (at the time of writing, the status file also only contains a single URL for each type either) if (key.startsWith("json3")) { - dataFileUrls.push_back(url); + dataFileUrl = url; } else if (key.startsWith("url1")) { - serverFileUrls.push_back(url); + serverFileUrl = url; } else if (key.startsWith("metar")) { - metarFileUrls.push_back(url); + metarFileUrl = url; } else if (key.startsWith("atis")) { @@ -156,14 +139,14 @@ namespace BlackCore::Vatsim // cache itself is thread safe, avoid writing with unchanged data CVatsimSetup vs(m_lastGoodSetup.get()); - const bool changed = vs.setUrls(dataFileUrls, serverFileUrls, metarFileUrls); + const bool changed = vs.setUrls(dataFileUrl, serverFileUrl, metarFileUrl); vs.setUtcTimestamp(QDateTime::currentDateTime()); const CStatusMessage cacheMsg = m_lastGoodSetup.set(vs); if (cacheMsg.isFailure()) { CLogMessage::preformatted(cacheMsg); } else { - CLogMessage(this).info(u"Read VATSIM status file from '%1', %2 data file URLs, %3 server file URLs, %4 METAR file URLs") - << urlString << dataFileUrls.size() << serverFileUrls.size() << metarFileUrls.size(); + CLogMessage(this).info(u"Read VATSIM status file from '%1'") + << urlString; } Q_UNUSED(changed); diff --git a/src/blackcore/vatsim/vatsimstatusfilereader.h b/src/blackcore/vatsim/vatsimstatusfilereader.h index d0f7f82cc..ba1ad3cfe 100644 --- a/src/blackcore/vatsim/vatsimstatusfilereader.h +++ b/src/blackcore/vatsim/vatsimstatusfilereader.h @@ -10,7 +10,7 @@ #include "blackcore/data/vatsimsetup.h" #include "blackmisc/datacache.h" #include "blackmisc/network/entityflags.h" -#include "blackmisc/network/urllist.h" +#include "blackmisc/network/url.h" #include "blackcore/threadedreader.h" #include @@ -29,13 +29,13 @@ namespace BlackCore::Vatsim //! Constructor explicit CVatsimStatusFileReader(QObject *owner); - //! METAR URLs + //! METAR URL //! \threadsafe - BlackMisc::Network::CUrlList getMetarFileUrls() const; + BlackMisc::Network::CUrl getMetarFileUrl() const; - //! Data file URLs + //! Data file URL //! \threadsafe - BlackMisc::Network::CUrlList getDataFileUrls() const; + BlackMisc::Network::CUrl getDataFileUrl() const; //! Start reading in own thread void readInBackgroundThread(); diff --git a/src/blackcore/webdataservices.cpp b/src/blackcore/webdataservices.cpp index 2dd643685..d69ba354e 100644 --- a/src/blackcore/webdataservices.cpp +++ b/src/blackcore/webdataservices.cpp @@ -109,16 +109,16 @@ namespace BlackCore return CServerList(); } - CUrlList CWebDataServices::getVatsimMetarUrls() const + CUrl CWebDataServices::getVatsimMetarUrl() const { - if (m_vatsimStatusReader) { return m_vatsimStatusReader->getMetarFileUrls(); } - return CUrlList(); + if (m_vatsimStatusReader) { return m_vatsimStatusReader->getMetarFileUrl(); } + return {}; } - CUrlList CWebDataServices::getVatsimDataFileUrls() const + CUrl CWebDataServices::getVatsimDataFileUrl() const { - if (m_vatsimStatusReader) { return m_vatsimStatusReader->getDataFileUrls(); } - return CUrlList(); + if (m_vatsimStatusReader) { return m_vatsimStatusReader->getDataFileUrl(); } + return {}; } CUserList CWebDataServices::getUsersForCallsign(const CCallsign &callsign) const diff --git a/src/blackcore/webdataservices.h b/src/blackcore/webdataservices.h index f719e92b3..29019078b 100644 --- a/src/blackcore/webdataservices.h +++ b/src/blackcore/webdataservices.h @@ -20,7 +20,7 @@ #include "blackmisc/aviation/atcstationlist.h" #include "blackmisc/aviation/liverylist.h" #include "blackmisc/network/serverlist.h" -#include "blackmisc/network/urllist.h" +#include "blackmisc/network/url.h" #include "blackmisc/network/userlist.h" #include "blackmisc/network/entityflags.h" #include "blackmisc/network/voicecapabilities.h" @@ -118,13 +118,13 @@ namespace BlackCore //! \threadsafe BlackMisc::Network::CServerList getVatsimFsdServers() const; - //! METAR URLs (from status file) + //! METAR URL (from status file) //! \threadsafe - BlackMisc::Network::CUrlList getVatsimMetarUrls() const; + BlackMisc::Network::CUrl getVatsimMetarUrl() const; - //! Data file locations (from status file) + //! Data file location (from status file) //! \threadsafe - BlackMisc::Network::CUrlList getVatsimDataFileUrls() const; + BlackMisc::Network::CUrl getVatsimDataFileUrl() const; //! Users by callsign //! \threadsafe diff --git a/src/blackgui/components/dbloadoverviewcomponent.cpp b/src/blackgui/components/dbloadoverviewcomponent.cpp index 233968b52..15aeff97a 100644 --- a/src/blackgui/components/dbloadoverviewcomponent.cpp +++ b/src/blackgui/components/dbloadoverviewcomponent.cpp @@ -224,32 +224,28 @@ namespace BlackGui::Components m_sharedValueCheckInProgress = true; // avoid processEvent (canConnect) calling this again before done - const CUrlList sharedUrls(sGui->getGlobalSetup().getSwiftSharedUrls()); + const CUrl sharedUrl(sGui->getGlobalSetup().getSwiftSharedUrl()); const QString valueHtml(" %2"); const QString urlLinkHtml("%2"); QStringList values; - for (const CUrl &sharedUrl : sharedUrls) + + if (!sGui || sGui->isShuttingDown()) { - if (!sGui || sGui->isShuttingDown()) - { - // shutdown during connect test - m_sharedValueCheckInProgress = false; - return; - } - const bool canConnect = CNetworkUtils::canConnect(sharedUrl); - values.push_back( - valueHtml.arg(canConnect ? m_imgOk : m_imgFailed, urlLinkHtml.arg(sharedUrl.getFullUrl(), sharedUrl.getHost()))); + // shutdown during connect test + m_sharedValueCheckInProgress = false; + return; } + const bool canConnect = CNetworkUtils::canConnect(sharedUrl); + values.push_back( + valueHtml.arg(canConnect ? m_imgOk : m_imgFailed, urlLinkHtml.arg(sharedUrl.getFullUrl(), sharedUrl.getHost()))); const QString sharedUrlTable = toHtmTable(values, 2); ui->lbl_SharedUrls->setText(sharedUrlTable); - ui->lbl_SharedUrls->setMinimumHeight(10 + (18 * sharedUrls.size())); - - const CUrlList urls = sGui->getGlobalSetup().getSwiftSharedUrls(); - Q_ASSERT_X(!urls.empty(), Q_FUNC_INFO, "Need at least one shared URL"); + ui->lbl_SharedUrls->setMinimumHeight(28); + const QString currentlyUsedSharedUrl = sGui->getGlobalSetup().getSwiftSharedUrl().toQString(); ui->lbl_SharedUrls->setToolTip( - urls[0].isEmpty() ? "No shared URL" : "currently used: " + urls[0].toQString()); + currentlyUsedSharedUrl.isEmpty() ? "No shared URL" : "currently used: " + currentlyUsedSharedUrl); m_sharedLastCheck = QDateTime::currentMSecsSinceEpoch(); m_sharedValueCheckInProgress = false; diff --git a/src/blackgui/components/updateinfodialog.cpp b/src/blackgui/components/updateinfodialog.cpp index d807ee149..783633e24 100644 --- a/src/blackgui/components/updateinfodialog.cpp +++ b/src/blackgui/components/updateinfodialog.cpp @@ -37,7 +37,7 @@ namespace BlackGui::Components if (r != QDialog::Accepted) { return r; } if (!ui->comp_UpdateInfo->isNewPilotClientVersionAvailable()) { return QDialog::Rejected; } const CDistribution distribution = ui->comp_UpdateInfo->getCurrentDistribution(); - if (!distribution.hasDownloadUrls()) { return QDialog::Rejected; } + if (!distribution.hasDownloadUrl()) { return QDialog::Rejected; } ui->comp_UpdateInfo->triggerDownload(); return r; diff --git a/src/blackmisc/CMakeLists.txt b/src/blackmisc/CMakeLists.txt index f911fa50f..b3e28e71b 100644 --- a/src/blackmisc/CMakeLists.txt +++ b/src/blackmisc/CMakeLists.txt @@ -423,8 +423,6 @@ add_library(misc SHARED network/textmessagelist.h network/url.cpp network/url.h - network/urllist.cpp - network/urllist.h network/urllog.cpp network/urllog.h network/urlloglist.cpp diff --git a/src/blackmisc/db/artifact.cpp b/src/blackmisc/db/artifact.cpp index 90d47c0a7..9bcb6bbad 100644 --- a/src/blackmisc/db/artifact.cpp +++ b/src/blackmisc/db/artifact.cpp @@ -71,7 +71,7 @@ namespace BlackMisc::Db if (!this->hasDistributions()) { return CRemoteFile(); } CRemoteFile rf(this->getName(), this->getFileSize()); const CDistribution d = this->getMostStableDistribution(); - const CUrl url = d.getDownloadUrls().getRandomUrl(); + const CUrl url = d.getDownloadUrl(); if (url.isEmpty()) { return CRemoteFile(); } rf.setUtcTimestamp(this->getUtcTimestamp()); rf.setUrl(url); diff --git a/src/blackmisc/db/distribution.cpp b/src/blackmisc/db/distribution.cpp index 3a8edc97c..53cb98479 100644 --- a/src/blackmisc/db/distribution.cpp +++ b/src/blackmisc/db/distribution.cpp @@ -24,15 +24,15 @@ namespace BlackMisc::Db m_channel = channel.trimmed().toUpper(); } - void CDistribution::addDownloadUrl(const CUrl &url) + void CDistribution::setDownloadUrl(const CUrl &url) { if (url.isEmpty()) { return; } - m_downloadUrls.push_back(url); + m_downloadUrl = url; } - bool CDistribution::hasDownloadUrls() const + bool CDistribution::hasDownloadUrl() const { - return !m_downloadUrls.isEmpty(); + return !m_downloadUrl.isEmpty(); } CIcons::IconIndex CDistribution::getRestrictionIcon() const @@ -61,8 +61,8 @@ namespace BlackMisc::Db return u"channel: " % this->getChannel() % separator % - u"download URLs: " % - getDownloadUrls().toQString(i18n) % + u"download URL: " % + getDownloadUrl().toQString(i18n) % separator % u"timestamp: " % this->getFormattedUtcTimestampYmdhms(); @@ -83,7 +83,7 @@ namespace BlackMisc::Db { case IndexChannel: return QVariant::fromValue(m_channel); case IndexStability: return QVariant::fromValue(m_stability); - case IndexDownloadUrls: return QVariant::fromValue(m_downloadUrls); + case IndexDownloadUrl: return QVariant::fromValue(m_downloadUrl); case IndexRestricted: return QVariant::fromValue(m_restricted); default: return CValueObject::propertyByIndex(index); } @@ -107,7 +107,7 @@ namespace BlackMisc::Db { case IndexChannel: this->setChannel(variant.value()); break; case IndexStability: m_stability = variant.toInt(); break; - case IndexDownloadUrls: m_downloadUrls = variant.value(); break; + case IndexDownloadUrl: m_downloadUrl = variant.value(); break; case IndexRestricted: m_restricted = variant.toBool(); break; default: CValueObject::setPropertyByIndex(index, variant); break; } @@ -139,7 +139,7 @@ namespace BlackMisc::Db const QString key = "url" + QString::number(i); const QString url = json.value(key).toString(); if (url.isEmpty()) { continue; } - distribution.addDownloadUrl(CUrl(url)); + distribution.setDownloadUrl(CUrl(url)); } return distribution; } diff --git a/src/blackmisc/db/distribution.h b/src/blackmisc/db/distribution.h index 0c422f2a5..97e6a124f 100644 --- a/src/blackmisc/db/distribution.h +++ b/src/blackmisc/db/distribution.h @@ -8,7 +8,7 @@ #include "blackconfig/buildconfig.h" #include "blackmisc/blackmiscexport.h" -#include "blackmisc/network/urllist.h" +#include "blackmisc/network/url.h" #include "blackmisc/db/datastore.h" #include "blackmisc/settingscache.h" #include "blackmisc/dictionary.h" @@ -34,7 +34,7 @@ namespace BlackMisc::Db IndexChannel = CPropertyIndexRef::GlobalIndexCDistribution, IndexStability, IndexRestricted, - IndexDownloadUrls + IndexDownloadUrl }; //! Default constructor @@ -55,14 +55,14 @@ namespace BlackMisc::Db //! Order void setStability(int stability) { m_stability = stability; } - //! Download URLs, i.e. here one can download installer - const Network::CUrlList &getDownloadUrls() const { return m_downloadUrls; } + //! Download URL, i.e. here one can download installer + const Network::CUrl &getDownloadUrl() const { return m_downloadUrl; } - //! Add URL, ignored if empty - void addDownloadUrl(const Network::CUrl &url); + //! Set URL, ignored if empty + void setDownloadUrl(const BlackMisc::Network::CUrl &url); - //! At least one download URL? - bool hasDownloadUrls() const; + //! Has a download URL? + bool hasDownloadUrl() const; //! Restricted channel? bool isRestricted() const { return m_restricted; } @@ -107,7 +107,7 @@ namespace BlackMisc::Db QString m_channel; //!< channel the files belong to int m_stability; //!< stability bool m_restricted = false; //!< restricted access (i.e. password for download needed) - Network::CUrlList m_downloadUrls; //!< download URLs, here I get the installer + Network::CUrl m_downloadUrl; //!< download URL, here I get the installer BLACK_METACLASS( CDistribution, @@ -115,7 +115,7 @@ namespace BlackMisc::Db BLACK_METAMEMBER(timestampMSecsSinceEpoch), BLACK_METAMEMBER(channel), BLACK_METAMEMBER(stability), - BLACK_METAMEMBER(downloadUrls) + BLACK_METAMEMBER(downloadUrl) ); }; } // ns diff --git a/src/blackmisc/db/updateinfo.cpp b/src/blackmisc/db/updateinfo.cpp index 09b58eab5..14f570a4e 100644 --- a/src/blackmisc/db/updateinfo.cpp +++ b/src/blackmisc/db/updateinfo.cpp @@ -158,8 +158,8 @@ namespace BlackMisc::Db const QString url = CBuildConfig::gitHubRepoUrl() + QStringLiteral("releases/download"); CDistribution alphaDistribution("ALPHA", 5, false); CDistribution betaDistribution("BETA", 10, false); - alphaDistribution.addDownloadUrl(url); - betaDistribution.addDownloadUrl(url); + alphaDistribution.setDownloadUrl(url); + betaDistribution.setDownloadUrl(url); CUpdateInfo result; result.m_distributions = { alphaDistribution, betaDistribution }; diff --git a/src/blackmisc/network/registermetadatanetwork.cpp b/src/blackmisc/network/registermetadatanetwork.cpp index 9779ea6b1..cabf52a9c 100644 --- a/src/blackmisc/network/registermetadatanetwork.cpp +++ b/src/blackmisc/network/registermetadatanetwork.cpp @@ -25,7 +25,6 @@ #include "blackmisc/network/textmessage.h" #include "blackmisc/network/textmessagelist.h" #include "blackmisc/network/url.h" -#include "blackmisc/network/urllist.h" #include "blackmisc/network/urllog.h" #include "blackmisc/network/urlloglist.h" #include "blackmisc/network/user.h" @@ -63,8 +62,6 @@ namespace BlackMisc CTextMessage::registerMetadata(); CTextMessageList::registerMetadata(); CUrl::registerMetadata(); - CUrlList::registerMetadata(); - CFailoverUrlList::registerMetadata(); CUrlLog::registerMetadata(); CUrlLogList::registerMetadata(); CUser::registerMetadata(); diff --git a/src/blackmisc/network/urllist.cpp b/src/blackmisc/network/urllist.cpp deleted file mode 100644 index 12ad44a92..000000000 --- a/src/blackmisc/network/urllist.cpp +++ /dev/null @@ -1,232 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#include "blackmisc/network/urllist.h" -#include "blackmisc/network/networkutils.h" -#include "blackmisc/math/mathutils.h" -#include "blackmisc/stringutils.h" - -#include - -using namespace BlackMisc::Math; - -BLACK_DEFINE_SEQUENCE_MIXINS(BlackMisc::Network, CUrl, CUrlList) - -namespace BlackMisc::Network -{ - CUrlList::CUrlList() {} - - CUrlList::CUrlList(const CSequence &other) : CSequence(other) - {} - - CUrlList::CUrlList(const QStringList &listOfUrls, bool removeDuplicates) - { - QStringList urlList(listOfUrls); - if (removeDuplicates) { urlList.removeDuplicates(); } - for (const QString &url : urlList) - { - this->push_back(CUrl(url)); - } - } - - CUrl CUrlList::getRandomUrl() const - { - if (this->isEmpty()) { return CUrl(); } - if (this->size() == 1) { return this->front(); } - const int i = CMathUtils::randomInteger(0, this->size() - 1); - return (*this)[i]; - } - - CUrl CUrlList::getRandomWorkingUrl(int maxTrials, int timeoutMs) const - { - if (this->isEmpty()) { return CUrl(); } - if (maxTrials < 1) { return CUrl(); } - CUrlList trials; - - if (timeoutMs < 0) { timeoutMs = CNetworkUtils::getTimeoutMs(); } - for (int t = 0; t < maxTrials && t < this->size(); t++) - { - const CUrl url(this->getRandomWithout(trials)); - trials.push_back(url); - QString message; - if (CNetworkUtils::canConnect(url, message, timeoutMs)) { return url; } - } - return CUrl(); - } - - CUrl CUrlList::getRandomWithout(const CUrl &exclude) const - { - const CUrlList excludes({ exclude }); - return this->getRandomWithout(excludes); - } - - CUrl CUrlList::getRandomWithout(const CUrlList &exclude) const - { - CUrlList copy(*this); - copy.removeIfIn(exclude); - if (copy.isEmpty()) { return CUrl(); } - return copy.getRandomUrl(); - } - - CUrlList CUrlList::withAppendedPath(const QString &path) const - { - if (path.isEmpty() || this->isEmpty()) { return (*this); } - CUrlList urls; - for (const CUrl &url : (*this)) - { - urls.push_back(url.withAppendedPath(path)); - } - return urls; - } - - CUrlList CUrlList::findByHost(const QString &host, Qt::CaseSensitivity cs) const - { - CUrlList result; - if (host.isEmpty() || this->isEmpty()) { return result; } - for (const CUrl &url : *this) - { - if (stringCompare(url.getHost(), host, cs)) - { - result.push_back(url); - } - } - return result; - } - - QString CUrlList::convertToQString(const QString &separator, bool i18n) const - { - const QStringList sl(toStringList(i18n)); - return sl.join(separator); - } - - CUrlList CUrlList::getWithoutDuplicates() const - { - if (this->size() < 2) { return (*this); } - CUrlList withoutDuplicates; - for (const CUrl &url : (*this)) - { - withoutDuplicates.replaceOrAdd(url); - } - return withoutDuplicates; - } - - int CUrlList::removeDuplicates() - { - if (this->size() < 2) { return 0; } - const CUrlList withoutDuplicates(getWithoutDuplicates()); - if (this->size() == withoutDuplicates.size()) { return 0; } - int r = this->size() - withoutDuplicates.size(); - (*this) = withoutDuplicates; - return r; - } - - CFailoverUrlList::CFailoverUrlList(int maxTrials) : m_maxTrials(maxTrials) - {} - - CFailoverUrlList::CFailoverUrlList(const QStringList &listOfUrls, int maxTrials) : CUrlList(listOfUrls), m_maxTrials(maxTrials) - {} - - CFailoverUrlList::CFailoverUrlList(const CUrlList &urlIst, int maxTrials) : CUrlList(urlIst), m_maxTrials(maxTrials) - {} - - CUrlList CFailoverUrlList::getWithoutFailed() const - { - CUrlList urls(*this); - urls.removeIfIn(m_failedUrls); - return urls; - } - - bool CFailoverUrlList::addFailedUrl(const CUrl &failedUrl) - { - Q_ASSERT_X(!failedUrl.isEmpty(), Q_FUNC_INFO, "empty URL as failed"); - m_failedUrls.push_back(failedUrl); - return hasMoreUrlsToTry(); - } - - bool CFailoverUrlList::addFailedUrls(const CUrlList &failedUrls) - { - m_failedUrls.push_back(failedUrls); - return hasMoreUrlsToTry(); - } - - bool CFailoverUrlList::addFailedHost(const CUrl &failedUrl) - { - Q_ASSERT_X(!failedUrl.isEmpty(), Q_FUNC_INFO, "empty URL as failed"); - const QString host = failedUrl.getHost(); - return CFailoverUrlList::addFailedHost(host); - } - - bool CFailoverUrlList::addFailedHost(const QString &host, Qt::CaseSensitivity cs) - { - if (host.isEmpty()) { return this->hasMoreUrlsToTry(); } - const CUrlList failedUrls = this->findByHost(host, cs); - return addFailedUrls(failedUrls); - } - - bool CFailoverUrlList::hasMoreUrlsToTry() const - { - return this->numberOfStillValidUrls() > 0; - } - - int CFailoverUrlList::numberOfStillValidUrls() const - { - if (this->isEmpty()) { return 0; } - if (m_failedUrls.size() >= m_maxTrials) { return 0; } - const int trailsLeft1 = qMax(m_maxTrials - m_failedUrls.size(), 0); - const int trailsLeft2 = qMax(this->size() - m_failedUrls.size(), 0); - return qMin(trailsLeft1, trailsLeft2); - } - - CUrl CFailoverUrlList::obtainNextWorkingUrl(bool random, int connectTimeoutMs) - { - if (!hasMoreUrlsToTry()) { return CUrl(); } - const CUrl url(this->obtainNextUrlWithout(random, m_failedUrls)); - QString msg; - if (CNetworkUtils::canConnect(url, msg, connectTimeoutMs)) { return url; } - if (addFailedUrl(url)) - { - if (!msg.isEmpty()) - { - m_errorMsgs.append(QStringLiteral("URL: %1 error: %2").arg(url.toQString(), msg)); - } - return obtainNextWorkingUrl(random, connectTimeoutMs); - } - return CUrl(); - } - - CUrl CFailoverUrlList::obtainNextUrl(bool randomStart) - { - if (this->isEmpty()) { return CUrl(); } - if (this->size() == 1) { return this->front(); } - if (m_currentIndexDistributedLoad < 0) - { - // random start point - m_currentIndexDistributedLoad = randomStart ? - CMathUtils::randomInteger(0, this->size() - 1) : - 0; - } - else - { - m_currentIndexDistributedLoad++; - if (m_currentIndexDistributedLoad >= this->size()) - { - m_currentIndexDistributedLoad = 0; - } - } - return (*this)[m_currentIndexDistributedLoad]; - } - - CUrl CFailoverUrlList::obtainNextUrlWithout(bool randomStart, const CUrlList &exclude) const - { - CFailoverUrlList copy(*this); - copy.removeIfIn(exclude); - if (copy.isEmpty()) { return CUrl(); } - return copy.obtainNextUrl(randomStart); - } - - void CFailoverUrlList::reset(int maxTrials) - { - m_failedUrls.clear(); - if (maxTrials >= 0) { m_maxTrials = maxTrials; } - } -} // namespace diff --git a/src/blackmisc/network/urllist.h b/src/blackmisc/network/urllist.h deleted file mode 100644 index e97c170cc..000000000 --- a/src/blackmisc/network/urllist.h +++ /dev/null @@ -1,136 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKMISC_NETWORK_URLLIST_H -#define BLACKMISC_NETWORK_URLLIST_H - -#include "blackmisc/blackmiscexport.h" -#include "blackmisc/collection.h" -#include "blackmisc/network/url.h" -#include "blackmisc/sequence.h" - -#include -#include -#include - -BLACK_DECLARE_SEQUENCE_MIXINS(BlackMisc::Network, CUrl, CUrlList) - -namespace BlackMisc::Network -{ - //! Value object encapsulating a list of URLs. - class BLACKMISC_EXPORT CUrlList : - public CSequence, - public BlackMisc::Mixin::MetaType - { - public: - BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CUrlList) - using CSequence::CSequence; - - //! Default constructor. - CUrlList(); - - //! Construct from a base class object. - CUrlList(const CSequence &other); - - //! By list of URLs - explicit CUrlList(const QStringList &listOfUrls, bool removeDuplicates = true); - - //! Random location for distributed load - CUrl getRandomUrl() const; - - //! Random location for distributed load, tested - CUrl getRandomWorkingUrl(int maxTrials = 2, int timeoutMs = -1) const; - - //! Random location for distributed load - CUrl getRandomWithout(const CUrl &exclude) const; - - //! Random location for distributed load - CUrl getRandomWithout(const CUrlList &exclude) const; - - //! Append path to all URLs - CUrlList withAppendedPath(const QString &path) const; - - //! Find by host - CUrlList findByHost(const QString &host, Qt::CaseSensitivity cs = Qt::CaseInsensitive) const; - - //! To formatted String - QString convertToQString(const QString &separator, bool i18n = false) const; - - //! URLs without duplicates - CUrlList getWithoutDuplicates() const; - - //! Remove duplicated URL and return number of removed elements - int removeDuplicates(); - }; - - //! URL list with fail support - class BLACKMISC_EXPORT CFailoverUrlList : public CUrlList - { - public: - //! Default constructor. - CFailoverUrlList(int maxTrials = 2); - - //! By list of URLs - explicit CFailoverUrlList(const QStringList &listOfUrls, int maxTrials = 2); - - //! From url list - CFailoverUrlList(const CUrlList &urlIst, int maxTrials = 2); - - //! All failed URLs - const CUrlList &getFailedUrls() const { return m_failedUrls; } - - //! Size of failed URLs - int getFailedUrlsSize() const { return m_failedUrls.size(); } - - //! Get without the failed URLs - CUrlList getWithoutFailed() const; - - //! Failed URL - bool addFailedUrl(const CUrl &failedUrl); - - //! Failed URLs - bool addFailedUrls(const CUrlList &failedUrls); - - //! Failed host - bool addFailedHost(const CUrl &failedUrl); - - //! Failed host - bool addFailedHost(const QString &host, Qt::CaseSensitivity cs = Qt::CaseInsensitive); - - //! More URLs to try - bool hasMoreUrlsToTry() const; - - //! Number of URLs which can be used for a retry - int numberOfStillValidUrls() const; - - //! Next utl from this list - CUrl obtainNextUrl(bool randomStart = false); - - //! Round robin with random start point - CUrl obtainNextUrlWithout(bool randomStart = false, const CUrlList &exclude = CUrlList()) const; - - //! Next working URL, test if it can be connected - CUrl obtainNextWorkingUrl(bool random = false, int connectTimeoutMs = -1); - - //! Get the error messages - const QStringList &getErrorMessages() const { return m_errorMsgs; } - - //! Reset failed URL, allows to set an optional new number of max.trials - void reset(int maxTrials = -1); - - private: - int m_currentIndexDistributedLoad = -1; //!< index for random access - int m_maxTrials = 2; //!< number of max trials - CUrlList m_failedUrls; //!< failed tested URLs - QStringList m_errorMsgs; //!< error messages while testing; - }; - -} // namespace - -Q_DECLARE_METATYPE(BlackMisc::Network::CUrlList) -Q_DECLARE_METATYPE(BlackMisc::Network::CFailoverUrlList) -Q_DECLARE_METATYPE(BlackMisc::CCollection) - -#endif // guard diff --git a/src/swiftguistandard/swiftguistdmenus.cpp b/src/swiftguistandard/swiftguistdmenus.cpp index 497b4ed08..56b4f05ce 100644 --- a/src/swiftguistandard/swiftguistdmenus.cpp +++ b/src/swiftguistandard/swiftguistdmenus.cpp @@ -9,7 +9,6 @@ #include "blackgui/foreignwindows.h" #include "blackgui/copyxswiftbusdialog.h" #include "blackmisc/aviation/altitude.h" -#include "blackmisc/network/urllist.h" #include "blackmisc/pq/units.h" #include "blackmisc/logmessage.h" #include "blackconfig/buildconfig.h"