diff --git a/.clang-tidy b/.clang-tidy index 3b31cbcaa..c5306d66b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -19,6 +19,7 @@ Checks: - '-readability-math-missing-parentheses' - '-readability-avoid-unconditional-preprocessor-if' - '-readability-magic-numbers' + - '-readability-container-size-empty' - 'cppcoreguidelines-*' - '-cppcoreguidelines-avoid-magic-numbers' - '-cppcoreguidelines-non-private-member-variables-in-classes' diff --git a/src/core/afv/clients/afvclient.cpp b/src/core/afv/clients/afvclient.cpp index b829c4b3f..535cddd8e 100644 --- a/src/core/afv/clients/afvclient.cpp +++ b/src/core/afv/clients/afvclient.cpp @@ -97,7 +97,7 @@ namespace swift::core::afv::clients if (!hasContexts()) { return; } // Disconnect all previously connect signals between the AfvClient and the required contexts - for (auto context : QVector { sApp->getIContextOwnAircraft(), sApp->getIContextNetwork() }) + for (auto *context : QVector { sApp->getIContextOwnAircraft(), sApp->getIContextNetwork() }) { this->disconnect(context); context->disconnect(this); @@ -465,11 +465,8 @@ namespace swift::core::afv::clients if (!enabledTransceivers.contains(id)) { return false; } const auto transceivers = this->getTransceivers(); // threadsafe - for (const TransceiverDto &dto : transceivers) - { - if (dto.id == id) { return true; } - } - return false; + return std::any_of(transceivers.cbegin(), transceivers.cend(), + [&id](const TransceiverDto &dto) { return dto.id == id; }); } bool CAfvClient::isEnabledComUnit(CComSystem::ComUnit comUnit) const @@ -507,7 +504,7 @@ namespace swift::core::afv::clients void CAfvClient::updateComFrequency(CComSystem::ComUnit comUnit, const CFrequency &comFrequency) { - const quint32 freqHz = static_cast(comFrequency.valueInteger(CFrequencyUnit::Hz())); + const auto freqHz = static_cast(comFrequency.valueInteger(CFrequencyUnit::Hz())); this->updateComFrequency(comUnitToTransceiverId(comUnit), freqHz); } @@ -592,11 +589,8 @@ namespace swift::core::afv::clients bool CAfvClient::isTransmittingTransceiver(quint16 id) const { QMutexLocker lock(&m_mutexTransceivers); - for (const TxTransceiverDto &dto : m_transmittingTransceivers) - { - if (dto.id == id) { return true; } - } - return false; + return std::any_of(m_transmittingTransceivers.cbegin(), m_transmittingTransceivers.cend(), + [&id](const TxTransceiverDto &dto) { return dto.id == id; }); } bool CAfvClient::isTransmittingComUnit(CComSystem::ComUnit comUnit) const @@ -747,10 +741,8 @@ namespace swift::core::afv::clients double CAfvClient::getComOutputVolumeDb(CComSystem::ComUnit comUnit) const { QMutexLocker lock(&m_mutexVolume); - if (comUnit == CComSystem::Com1) - return m_outputVolumeDbCom1; - else if (comUnit == CComSystem::Com2) - return m_outputVolumeDbCom2; + if (comUnit == CComSystem::Com1) return m_outputVolumeDbCom1; + if (comUnit == CComSystem::Com2) return m_outputVolumeDbCom2; qFatal("Invalid COM unit"); return 0; } @@ -758,10 +750,8 @@ namespace swift::core::afv::clients double CAfvClient::getOutputGainRatio(CComSystem::ComUnit comUnit) const { QMutexLocker lock(&m_mutexVolume); - if (comUnit == CComSystem::Com1) - return m_outputGainRatioCom1; - else if (comUnit == CComSystem::Com2) - return m_outputGainRatioCom2; + if (comUnit == CComSystem::Com1) return m_outputGainRatioCom1; + if (comUnit == CComSystem::Com2) return m_outputGainRatioCom2; qFatal("Invalid COM unit"); return 0; } @@ -784,7 +774,7 @@ namespace swift::core::afv::clients { QMutexLocker lock(&m_mutexVolume); if (comUnit == CComSystem::Com1) { return m_outputVolumeCom1Normalized; } - else if (comUnit == CComSystem::Com2) { return m_outputVolumeCom2Normalized; } + if (comUnit == CComSystem::Com2) { return m_outputVolumeCom2Normalized; } qFatal("Invalid ComUnit"); return 0; } @@ -1069,7 +1059,10 @@ namespace swift::core::afv::clients const int failures = ++m_heartBeatFailures; if (failures < 2) { return; } - QString un, pw, cs, client; + QString un; + QString pw; + QString cs; + QString client; { QMutexLocker lock(&m_mutexConnection); un = m_connection->getUserName(); @@ -1331,17 +1324,17 @@ namespace swift::core::afv::clients { QMutexLocker lock(&m_mutex); CFrequency roundedFrequency(static_cast(roundedFrequencyHz), CFrequencyUnit::Hz()); - const auto it = std::find_if( - m_aliasedStations.constBegin(), m_aliasedStations.constEnd(), [roundedFrequency](const StationDto &d) { - if (d.frequencyAliasHz > 100000000 && - roundedFrequency.value(CFrequencyUnit::Hz()) > 100000000) // both VHF - { - const int aliasedFreqHz = static_cast(qRound(d.frequencyAliasHz / 1000.0)) * 1000; - return CComSystem::isSameFrequency(CFrequency(aliasedFreqHz, CFrequencyUnit::Hz()), - roundedFrequency); - } - return d.frequencyAliasHz == roundedFrequency.value(CFrequencyUnit::Hz()); - }); + const auto it = std::find_if(m_aliasedStations.constBegin(), m_aliasedStations.constEnd(), + [roundedFrequency](const StationDto &d) { + if (d.frequencyAliasHz > 100000000 && + roundedFrequency.value(CFrequencyUnit::Hz()) > 100000000) // both VHF + { + const int aliasedFreqHz = qRound(d.frequencyAliasHz / 1000.0) * 1000; + return CComSystem::isSameFrequency( + CFrequency(aliasedFreqHz, CFrequencyUnit::Hz()), roundedFrequency); + } + return d.frequencyAliasHz == roundedFrequency.value(CFrequencyUnit::Hz()); + }); if (it != m_aliasedStations.constEnd()) { diff --git a/src/core/airspaceanalyzer.cpp b/src/core/airspaceanalyzer.cpp index 2758b70ee..5b62f13cc 100644 --- a/src/core/airspaceanalyzer.cpp +++ b/src/core/airspaceanalyzer.cpp @@ -99,8 +99,6 @@ namespace swift::core m_simulatorMaxRenderedDistance = maxRenderedDistance; } - CAirspaceAnalyzer::~CAirspaceAnalyzer() {} - void CAirspaceAnalyzer::onNetworkPositionUpdate(const CAircraftSituation &situation, const CTransponder &transponder) { @@ -172,7 +170,7 @@ namespace swift::core // this is a trick to not remove everything while debugging const qint64 currentTimeMsEpoch = QDateTime::currentMSecsSinceEpoch(); const qint64 callDiffMs = currentTimeMsEpoch - m_lastWatchdogCallMsSinceEpoch; - const qint64 callThresholdMs = static_cast(updateInterval.count() * 1.5); + constexpr auto callThresholdMs = static_cast(updateInterval.count() * 1.5); m_lastWatchdogCallMsSinceEpoch = currentTimeMsEpoch; if (callDiffMs > callThresholdMs) { @@ -228,8 +226,9 @@ namespace swift::core Q_ASSERT_X(!CThreadUtils::thisIsMainThread(), Q_FUNC_INFO, "Expect to run in background thread"); Q_ASSERT_X(thread() != qApp->thread(), Q_FUNC_INFO, "Expect to run in background thread affinity"); - bool restricted, enabled; - int maxAircraft; + bool restricted {}; + bool enabled {}; + int maxAircraft {}; CLength maxRenderedDistance; { QReadLocker l(&m_lockRestrictions); diff --git a/src/core/airspaceanalyzer.h b/src/core/airspaceanalyzer.h index a4b88a2ac..c037bfd2f 100644 --- a/src/core/airspaceanalyzer.h +++ b/src/core/airspaceanalyzer.h @@ -63,7 +63,19 @@ namespace swift::core fsd::CFSDClient *fsdClient, CAirspaceMonitor *airspaceMonitorParent); //! Destructor - virtual ~CAirspaceAnalyzer() override; + ~CAirspaceAnalyzer() override = default; + + //! Copy constructor + CAirspaceAnalyzer(const CAirspaceAnalyzer &) = delete; + + //! Copy assignment + CAirspaceAnalyzer &operator=(const CAirspaceAnalyzer &) = delete; + + //! Move constructor + CAirspaceAnalyzer(CAirspaceAnalyzer &&) = delete; + + //! Move assignment + CAirspaceAnalyzer &operator=(CAirspaceAnalyzer &&) = delete; //! Get the latest snapshot //! \threadsafe diff --git a/src/core/airspacemonitor.cpp b/src/core/airspacemonitor.cpp index 15ac46287..b4bdc515d 100644 --- a/src/core/airspacemonitor.cpp +++ b/src/core/airspacemonitor.cpp @@ -176,7 +176,7 @@ namespace swift::core { if (!myself || !sApp || sApp->isShuttingDown()) // cppcheck-suppress knownConditionTrueFalse { - return CFlightPlan(); + return {}; } if (m_flightPlanCache.contains(callsign)) { plan = m_flightPlanCache[callsign]; } } @@ -186,7 +186,7 @@ namespace swift::core CFlightPlanRemarks CAirspaceMonitor::tryToGetFlightPlanRemarks(const CCallsign &callsign) const { - if (callsign.isEmpty()) { return CFlightPlanRemarks(); } + if (callsign.isEmpty()) { return {}; } // full flight plan's remarks if (m_flightPlanCache.contains(callsign)) { return m_flightPlanCache[callsign].getFlightPlanRemarks(); } @@ -198,7 +198,7 @@ namespace swift::core } // unsupported - return CFlightPlanRemarks(); + return {}; } CAtcStationList CAirspaceMonitor::getAtcStationsOnlineRecalculated() @@ -524,14 +524,14 @@ namespace swift::core if (!sApp || sApp->isShuttingDown() || !sApp->getWebDataServices()) { return; } CClientList clients(this->getClients()); // copy bool changed = false; - for (auto client = clients.begin(); client != clients.end(); ++client) + for (auto &client : clients) { - if (client->hasSpecifiedVoiceCapabilities()) { continue; } // we already have voice caps + if (client.hasSpecifiedVoiceCapabilities()) { continue; } // we already have voice caps const CVoiceCapabilities vc = - sApp->getWebDataServices()->getVoiceCapabilityForCallsign(client->getCallsign()); + sApp->getWebDataServices()->getVoiceCapabilityForCallsign(client.getCallsign()); if (vc.isUnknown()) { continue; } changed = true; - client->setVoiceCapabilities(vc); + client.setVoiceCapabilities(vc); } if (!changed) { return; } this->setClients(clients); @@ -756,7 +756,7 @@ namespace swift::core // TODO Replace with Qt 6.0 QStringView::slice() zuluTimeView.chop(1); // Remove z - bool ok; + bool ok {}; const int h = zuluTimeView.left(2).toInt(&ok); if (!ok) { return; } const int m = zuluTimeView.right(2).toInt(&ok); @@ -1063,13 +1063,10 @@ namespace swift::core callsign, rv.model.getAircraftIcaoCodeDesignator(), rv.model.getAirlineIcaoCodeVDesignator(), rv.model.getLivery().getCombinedCode(), modelString, type, log, false); } - else - { - lookupModel = rv.model; - CCallsign::addLogDetailsToList(log, callsign, - QStringLiteral("Matching script: Using model from matching script"), - CAirspaceMonitor::getLogCategories()); - } + lookupModel = rv.model; + CCallsign::addLogDetailsToList(log, callsign, + QStringLiteral("Matching script: Using model from matching script"), + CAirspaceMonitor::getLogCategories()); } } else { CCallsign::addLogDetailsToList(log, callsign, QStringLiteral("No reverse lookup script used")); } @@ -1451,19 +1448,19 @@ namespace swift::core if (callsign.isEmpty()) { return; } unsigned long pp = 0; - bool ok; + bool ok {}; pp = config.toULong(&ok, 10); - bool gear = (pp & 1u); - bool landLight = (pp & 2u); - bool navLight = (pp & 4u); - bool strobeLight = (pp & 8u); - bool beaconLight = (pp & 16u); - bool taxiLight = (pp & 32u); - bool engine1Running = (pp & 64u); - bool engine2Running = (pp & 128u); - bool engine3Running = (pp & 256u); - bool engine4Running = (pp & 512u); + bool gear = (pp & 1U); + bool landLight = (pp & 2U); + bool navLight = (pp & 4U); + bool strobeLight = (pp & 8U); + bool beaconLight = (pp & 16U); + bool taxiLight = (pp & 32U); + bool engine1Running = (pp & 64U); + bool engine2Running = (pp & 128U); + bool engine3Running = (pp & 256U); + bool engine4Running = (pp & 512U); // CLogMessage(this).info(u"taxiLight %1 landLight %2 beaconLight %3 strobeLight %4 gear %5") << taxiLight << // landLight << beaconLight << strobeLight << gear; CLogMessage(this).info(u"engine1Running %1 engine2Running %2 diff --git a/src/core/airspacemonitor.h b/src/core/airspacemonitor.h index 0b9894cf7..94b2e558e 100644 --- a/src/core/airspacemonitor.h +++ b/src/core/airspacemonitor.h @@ -53,7 +53,7 @@ namespace swift::core //! Keeps track of other entities in the airspace: aircraft, ATC stations, etc. //! Central instance of data for \sa IRemoteAircraftProvider. - class SWIFT_CORE_EXPORT CAirspaceMonitor : + class SWIFT_CORE_EXPORT CAirspaceMonitor final : public swift::misc::simulation::CRemoteAircraftProvider, // those data will be provided from the class // CAirspaceMonitor public swift::misc::network::CClientProvider, // those data will be provided from the class CAirspaceMonitor @@ -198,7 +198,7 @@ namespace swift::core FsInnPacket() {} //! Constructor - FsInnPacket(const QString &aircraftIcaoDesignator, const QString &airlineDesignator, + FsInnPacket(const QString &aircraftIcaoDesignator, const QString &airlineIcaoDesignator, const QString &combinedCode, const QString &modelString); QString aircraftIcaoDesignator; @@ -444,7 +444,7 @@ namespace swift::core //! Receive FSInn packet //! \remark This can happen even without a query before void onCustomFSInnPacketReceived(const swift::misc::aviation::CCallsign &callsign, - const QString &airlineIcaoDesignator, const QString &aircraftDesignator, + const QString &airlineIcaoDesignator, const QString &aircraftIcaoDesignator, const QString &combinedAircraftType, const QString &modelString); void onRealNameReplyReceived(const swift::misc::aviation::CCallsign &callsign, const QString &realname); diff --git a/src/core/db/backgrounddataupdater.cpp b/src/core/db/backgrounddataupdater.cpp index 2e35aa517..ed02b77d2 100644 --- a/src/core/db/backgrounddataupdater.cpp +++ b/src/core/db/backgrounddataupdater.cpp @@ -141,7 +141,7 @@ namespace swift::core::db if (c > 0) { const CStatusMessage m = modelCaches.setCachedModels(simulatorModels, singleSimulator); - const int msElapsed = time.elapsed(); + const qint64 msElapsed = time.elapsed(); this->addHistory(CLogMessage(this).info(u"Consolidated %1 models (%2) for '%3' in %4ms") << c << description << singleSimulator.convertToQString() << msElapsed); CLogMessage::preformatted(m); diff --git a/src/core/threadedreader.h b/src/core/threadedreader.h index 39b231413..9823e0730 100644 --- a/src/core/threadedreader.h +++ b/src/core/threadedreader.h @@ -17,7 +17,6 @@ #include "core/swiftcoreexport.h" #include "core/vatsim/vatsimsettings.h" -#include "misc/logcategories.h" #include "misc/network/urlloglist.h" #include "misc/worker.h" @@ -39,7 +38,19 @@ namespace swift::core static const QStringList &getLogCategories(); //! Destructor - virtual ~CThreadedReader() = default; + ~CThreadedReader() override = default; + + //! Copy constructor + CThreadedReader(const CThreadedReader &) = delete; + + //! Copy assignment + CThreadedReader &operator=(const CThreadedReader &) = delete; + + //! Move constructor + CThreadedReader(CThreadedReader &&) = delete; + + //! Move assignment + CThreadedReader &operator=(CThreadedReader &&) = delete; //! Thread safe, get update timestamp //! \threadsafe diff --git a/src/core/webdataservices.cpp b/src/core/webdataservices.cpp index e82ed88ab..7bee55cd9 100644 --- a/src/core/webdataservices.cpp +++ b/src/core/webdataservices.cpp @@ -47,7 +47,7 @@ using namespace swift::misc::weather; namespace swift::core { - CWebDataServices::CWebDataServices(CWebReaderFlags::WebReader readers, + CWebDataServices::CWebDataServices(CWebReaderFlags::WebReader readerFlags, const CDatabaseReaderConfigList &dbReaderConfig, QObject *parent) : QObject(parent), m_dbReaderConfig(dbReaderConfig) { @@ -65,22 +65,23 @@ namespace swift::core // check if I need info objects const bool readFromSwiftDb = dbReaderConfig.possiblyReadsFromSwiftDb(); // DB read access const bool writeToSwiftDb = dbReaderConfig.possiblyWritesToSwiftDb(); // DB write access - if (!readFromSwiftDb && readers.testFlag(CWebReaderFlags::DbInfoDataReader)) + if (!readFromSwiftDb && readerFlags.testFlag(CWebReaderFlags::DbInfoDataReader)) { // will remove info reader because not needed - readers &= ~CWebReaderFlags::DbInfoDataReader; + readerFlags &= ~CWebReaderFlags::DbInfoDataReader; CLogMessage(this).info(u"Remove info object reader because not needed"); } // get entities to be read - CEntityFlags::Entity entities = CWebReaderFlags::allEntitiesForReaders(readers); + CEntityFlags::Entity entities = CWebReaderFlags::allEntitiesForReaders(readerFlags); if (entities.testFlag(CEntityFlags::DbInfoObjectEntity)) { - Q_ASSERT_X(readers.testFlag(CWebReaderFlags::DbInfoDataReader), Q_FUNC_INFO, "info object but no reader"); + Q_ASSERT_X(readerFlags.testFlag(CWebReaderFlags::DbInfoDataReader), Q_FUNC_INFO, + "info object but no reader"); CLogMessage(this).info(u"Using info objects for swift DB entities"); } - this->initReaders(readers, entities); // reads info objects if required + this->initReaders(readerFlags, entities); // reads info objects if required if (writeToSwiftDb) { this->initWriters(); } // make sure this is called in event queue, so pending tasks cam be performed @@ -98,7 +99,7 @@ namespace swift::core CServerList CWebDataServices::getVatsimFsdServers() const { if (m_vatsimServerFileReader) { return m_vatsimServerFileReader->getFsdServers(); } - return CServerList(); + return {}; } CUrl CWebDataServices::getVatsimMetarUrl() const @@ -116,19 +117,19 @@ namespace swift::core CUserList CWebDataServices::getUsersForCallsign(const CCallsign &callsign) const { if (m_vatsimDataFileReader) { return m_vatsimDataFileReader->getUsersForCallsign(callsign); } - return CUserList(); + return {}; } CAtcStationList CWebDataServices::getAtcStationsForCallsign(const CCallsign &callsign) const { if (m_vatsimDataFileReader) { return m_vatsimDataFileReader->getAtcStationsForCallsign(callsign); } - return CAtcStationList(); + return {}; } CVoiceCapabilities CWebDataServices::getVoiceCapabilityForCallsign(const CCallsign &callsign) const { if (m_vatsimDataFileReader) { return m_vatsimDataFileReader->getVoiceCapabilityForCallsign(callsign); } - return CVoiceCapabilities(); + return {}; } void CWebDataServices::updateWithVatsimDataFileData(CSimulatedAircraft &aircraftToBeUdpated) const @@ -139,13 +140,13 @@ namespace swift::core CStatusMessageList CWebDataServices::asyncPublishModels(const CAircraftModelList &modelsToBePublished) const { if (m_databaseWriter) { return m_databaseWriter->asyncPublishModels(modelsToBePublished, ""); } - return CStatusMessageList(); + return {}; } CStatusMessageList CWebDataServices::asyncAutoPublish(const CAutoPublishData &data) const { if (m_databaseWriter) { return m_databaseWriter->asyncAutoPublish(data); } - return CStatusMessageList(); + return {}; } void CWebDataServices::triggerReadOfDbInfoObjects() { initDbInfoObjectReaderAndTriggerRead(); } @@ -340,25 +341,25 @@ namespace swift::core QDateTime CWebDataServices::getCacheTimestamp(CEntityFlags::Entity entity) const { Q_ASSERT_X(CEntityFlags::isSingleEntity(entity), Q_FUNC_INFO, "Need single entity"); - if (!CEntityFlags::anySwiftDbEntity(entity)) { return QDateTime(); } + if (!CEntityFlags::anySwiftDbEntity(entity)) { return {}; } const CDatabaseReader *dr = this->getDbReader(entity); - if (!dr) { return QDateTime(); } + if (!dr) { return {}; } return dr->getCacheTimestamp(entity); } QDateTime CWebDataServices::getLatestDbEntityTimestamp(CEntityFlags::Entity entity) const { Q_ASSERT_X(CEntityFlags::isSingleEntity(entity), Q_FUNC_INFO, "Need single entity"); - if (!CEntityFlags::anySwiftDbEntity(entity)) { return QDateTime(); } + if (!CEntityFlags::anySwiftDbEntity(entity)) { return {}; } const CInfoDataReader *ir = this->getDbInfoDataReader(); - if (!ir) { return QDateTime(); } + if (!ir) { return {}; } return ir->getLatestEntityTimestampFromDbInfoObjects(entity); } QDateTime CWebDataServices::getLatestSharedInfoObjectTimestamp(CEntityFlags::Entity entity) const { const CDatabaseReader *reader = this->getDbReader(entity); - if (!reader) { return QDateTime(); } + if (!reader) { return {}; } Q_ASSERT_X(CEntityFlags::isSingleEntity(entity), Q_FUNC_INFO, "need single entity"); return reader->getLatestEntityTimestampFromSharedInfoObjects(entity); } @@ -427,11 +428,8 @@ namespace swift::core if (!dr) { return -1; } return dr->getCacheCount(entity); } - else - { - // non DB/shared entities would go here - return -1; - } + // non DB/shared entities would go here + return -1; } int CWebDataServices::getDbInfoObjectCount(CEntityFlags::Entity entity) const @@ -510,7 +508,7 @@ namespace swift::core CDistributorList CWebDataServices::getDistributors() const { if (m_modelDataReader) { return m_modelDataReader->getDistributors(); } - return CDistributorList(); + return {}; } int CWebDataServices::getDistributorsCount() const @@ -522,26 +520,26 @@ namespace swift::core CDistributor CWebDataServices::getDistributorForDbKey(const QString &key) const { if (m_modelDataReader) { return m_modelDataReader->getDistributorForDbKey(key); } - return CDistributor(); + return {}; } CDistributor CWebDataServices::smartDistributorSelector(const CDistributor &distributor) const { if (m_modelDataReader) { return m_modelDataReader->smartDistributorSelector(distributor); } - return CDistributor(); + return {}; } CDistributor CWebDataServices::smartDistributorSelector(const CDistributor &distributor, const CAircraftModel &model) const { if (m_modelDataReader) { return m_modelDataReader->smartDistributorSelector(distributor, model); } - return CDistributor(); + return {}; } CLiveryList CWebDataServices::getLiveries() const { if (m_modelDataReader) { return m_modelDataReader->getLiveries(); } - return CLiveryList(); + return {}; } int CWebDataServices::getLiveriesCount() const @@ -553,25 +551,25 @@ namespace swift::core CLivery CWebDataServices::getLiveryForCombinedCode(const QString &combinedCode) const { if (m_modelDataReader) { return m_modelDataReader->getLiveryForCombinedCode(combinedCode); } - return CLivery(); + return {}; } CLivery CWebDataServices::getTempLiveryOrDefault() const { if (m_modelDataReader) { return m_modelDataReader->getLiveryForCombinedCode(CLivery::tempLiveryCode()); } - return CLivery(); + return {}; } CLivery CWebDataServices::getStdLiveryForAirlineCode(const CAirlineIcaoCode &icao) const { if (m_modelDataReader) { return m_modelDataReader->getStdLiveryForAirlineVDesignator(icao); } - return CLivery(); + return {}; } CLivery CWebDataServices::getLiveryForDbKey(int id) const { if (m_modelDataReader) { return m_modelDataReader->getLiveryForDbKey(id); } - return CLivery(); + return {}; } CLivery CWebDataServices::smartLiverySelector(const CLivery &livery) const @@ -583,7 +581,7 @@ namespace swift::core CAircraftModelList CWebDataServices::getModels() const { if (m_modelDataReader) { return m_modelDataReader->getModels(); } - return CAircraftModelList(); + return {}; } int CWebDataServices::getModelsCount() const @@ -595,19 +593,19 @@ namespace swift::core QSet CWebDataServices::getModelDbKeys() const { if (m_modelDataReader) { return m_modelDataReader->getModelDbKeys(); } - return QSet(); + return {}; } QStringList CWebDataServices::getModelStrings(bool sort) const { if (m_modelDataReader) { return m_modelDataReader->getModelStringList(sort); } - return QStringList(); + return {}; } QStringList CWebDataServices::getModelCompleterStrings(bool sorted, const CSimulatorInfo &simulator) const { if (m_modelDataReader) { return m_modelDataReader->getModels().toCompleterStrings(sorted, simulator); } - return QStringList(); + return {}; } CAircraftModelList @@ -619,13 +617,13 @@ namespace swift::core return m_modelDataReader->getModelsForAircraftDesignatorAndLiveryCombinedCode(aircraftDesignator, combinedCode); } - return CAircraftModelList(); + return {}; } CAircraftModel CWebDataServices::getModelForModelString(const QString &modelString) const { if (m_modelDataReader) { return m_modelDataReader->getModelForModelString(modelString); } - return CAircraftModel(); + return {}; } bool CWebDataServices::containsModelString(const QString &modelString) const @@ -637,13 +635,13 @@ namespace swift::core CAircraftModel CWebDataServices::getModelForDbKey(int dbKey) const { if (m_modelDataReader) { return m_modelDataReader->getModelForDbKey(dbKey); } - return CAircraftModel(); + return {}; } CAircraftIcaoCodeList CWebDataServices::getAircraftIcaoCodes() const { if (m_icaoDataReader) { return m_icaoDataReader->getAircraftIcaoCodes(); } - return CAircraftIcaoCodeList(); + return {}; } int CWebDataServices::getAircraftIcaoCodesCount() const @@ -655,7 +653,7 @@ namespace swift::core CAircraftIcaoCode CWebDataServices::getAircraftIcaoCodeForDesignator(const QString &designator) const { if (m_icaoDataReader) { return m_icaoDataReader->getAircraftIcaoCodeForDesignator(designator); } - return CAircraftIcaoCode(); + return {}; } int CWebDataServices::getAircraftIcaoCodesForDesignatorCount(const QString &designator) const @@ -665,22 +663,22 @@ namespace swift::core QSet CWebDataServices::getAircraftDesignatorsForAirline(const CAirlineIcaoCode &airline) const { - if (!airline.hasValidDesignator()) { return QSet(); } + if (!airline.hasValidDesignator()) { return {}; } if (m_modelDataReader) { return m_modelDataReader->getAircraftDesignatorsForAirline(airline); } - return QSet(); + return {}; } CAircraftIcaoCodeList CWebDataServices::getAircraftIcaoCodesForAirline(const CAirlineIcaoCode &airline) const { - if (!airline.hasValidDesignator()) { return CAircraftIcaoCodeList(); } + if (!airline.hasValidDesignator()) { return {}; } if (m_modelDataReader) { return m_modelDataReader->getAicraftIcaoCodesForAirline(airline); } - return CAircraftIcaoCodeList(); + return {}; } CAircraftCategoryList CWebDataServices::getAircraftCategories() const { if (m_icaoDataReader) { return m_icaoDataReader->getAircraftCategories(); } - return CAircraftCategoryList(); + return {}; } int CWebDataServices::getAircraftCategoriesCount() const @@ -699,13 +697,13 @@ namespace swift::core CAircraftIcaoCodeList CWebDataServices::getAircraftIcaoCodesForDesignator(const QString &designator) const { if (m_icaoDataReader) { return m_icaoDataReader->getAircraftIcaoCodesForDesignator(designator); } - return CAircraftIcaoCodeList(); + return {}; } CAircraftIcaoCode CWebDataServices::getAircraftIcaoCodeForDbKey(int key) const { if (m_icaoDataReader) { return m_icaoDataReader->getAircraftIcaoCodeForDbKey(key); } - return CAircraftIcaoCode(); + return {}; } CAircraftIcaoCode CWebDataServices::smartAircraftIcaoSelector(const CAircraftIcaoCode &icao) const @@ -717,7 +715,7 @@ namespace swift::core CAirlineIcaoCodeList CWebDataServices::getAirlineIcaoCodes() const { if (m_icaoDataReader) { return m_icaoDataReader->getAirlineIcaoCodes(); } - return CAirlineIcaoCodeList(); + return {}; } bool CWebDataServices::containsAirlineIcaoDesignator(const QString &designator) const @@ -731,20 +729,20 @@ namespace swift::core CWebDataServices::getAirlineIcaoCodeForUniqueDesignatorOrDefault(const QString &designator, bool preferOperatingAirlines) const { - if (designator.isEmpty()) { return CAirlineIcaoCode(); } + if (designator.isEmpty()) { return {}; } if (m_icaoDataReader) { return m_icaoDataReader->getAirlineIcaoCodeForUniqueDesignatorOrDefault(designator, preferOperatingAirlines); } - return CAirlineIcaoCode(); + return {}; } CAirlineIcaoCode CWebDataServices::getAirlineIcaoCodeForUniqueIataCodeOrDefault(const QString &iataCode) const { - if (iataCode.isEmpty()) { return CAirlineIcaoCode(); } + if (iataCode.isEmpty()) { return {}; } if (m_icaoDataReader) { return m_icaoDataReader->getAirlineIcaoCodeForUniqueIataCodeOrDefault(iataCode); } - return CAirlineIcaoCode(); + return {}; } int CWebDataServices::getAirlineIcaoCodesCount() const @@ -779,12 +777,12 @@ namespace swift::core const CCallsign &callsign) const { if (m_icaoDataReader) { return m_icaoDataReader->smartAirlineIcaoSelector(icaoPattern, callsign); } - return CAirlineIcaoCode(); + return {}; } CAirlineIcaoCode CWebDataServices::findBestMatchByCallsign(const CCallsign &callsign) const { - if (callsign.isEmpty()) { return CAirlineIcaoCode(); } + if (callsign.isEmpty()) { return {}; } const CAirlineIcaoCodeList icaos(this->getAirlineIcaoCodes()); return icaos.findBestMatchByCallsign(callsign); } @@ -792,13 +790,13 @@ namespace swift::core CAirlineIcaoCode CWebDataServices::getAirlineIcaoCodeForDbKey(int key) const { if (m_icaoDataReader) { return m_icaoDataReader->getAirlineIcaoCodeForDbKey(key); } - return CAirlineIcaoCode(); + return {}; } CCountryList CWebDataServices::getCountries() const { if (m_icaoDataReader) { return m_icaoDataReader->getCountries(); } - return CCountryList(); + return {}; } int CWebDataServices::getCountriesCount() const @@ -810,13 +808,13 @@ namespace swift::core CCountry CWebDataServices::getCountryForName(const QString &name) const { if (m_icaoDataReader) { return m_icaoDataReader->getCountryForName(name); } - return CCountry(); + return {}; } CAirportList CWebDataServices::getAirports() const { if (m_airportDataReader) { return m_airportDataReader->getAirports(); } - return CAirportList(); + return {}; } int CWebDataServices::getAirportsCount() const @@ -828,19 +826,19 @@ namespace swift::core CAirport CWebDataServices::getAirportForIcaoDesignator(const QString &icao) const { if (m_airportDataReader) { return m_airportDataReader->getAirportForIcaoDesignator(icao); } - return CAirport(); + return {}; } CAirport CWebDataServices::getAirportForNameOrLocation(const QString &nameOrLocation) const { if (m_airportDataReader) { return m_airportDataReader->getAirportForNameOrLocation(nameOrLocation); } - return CAirport(); + return {}; } CCountry CWebDataServices::getCountryForIsoCode(const QString &iso) const { if (m_icaoDataReader) { return m_icaoDataReader->getCountryForIsoCode(iso); } - return CCountry(); + return {}; } CMetarList CWebDataServices::getMetars() const @@ -852,7 +850,7 @@ namespace swift::core CMetar CWebDataServices::getMetarForAirport(const CAirportIcaoCode &icao) const { if (m_vatsimMetarReader) { return m_vatsimMetarReader->getMetarForAirport(icao); } - return CMetar(); + return {}; } CStatusMessageList CWebDataServices::validateForPublishing(const CAircraftModelList &modelsToBePublished, @@ -913,7 +911,7 @@ namespace swift::core CAirlineIcaoCodeList CWebDataServices::getAirlineIcaoCodesForDesignator(const QString &designator) const { if (m_icaoDataReader) { return m_icaoDataReader->getAirlineIcaoCodesForDesignator(designator); } - return CAirlineIcaoCodeList(); + return {}; } int CWebDataServices::getAirlineIcaoCodesForDesignatorCount(const QString &designator) const @@ -1311,11 +1309,8 @@ namespace swift::core const CDbInfo info = reader->getInfoObjects().findFirstByEntityOrDefault(entity); return info.getEntries(); } - else - { - // non DB entities would go here - return -1; - } + // non DB entities would go here + return -1; } CEntityFlags::Entity CWebDataServices::getDbEntitiesWithCachedData() const @@ -1552,26 +1547,22 @@ namespace swift::core emit this->databaseReaderMessages(m); return false; // wait } - else - { - // we have a response, but a failure, means server is alive, but responded with error - // such an error (access, ...) normally will not go away - const CStatusMessage m = - CLogMessage(this).error(u"Info objects (%1) loading for '%2' failed from '%3', '%4'") - << info << CEntityFlags::entitiesToString(entities) << infoReader->getInfoObjectsUrl().toQString() - << infoReader->getStatusMessage(); - infoReader->setMarkedAsFailed(true); - emit this->databaseReaderMessages(m); - return true; // carry on, regardless of situation - } - } - else - { - // wait for 1st reply - // we call read again in some time - this->readDeferredInBackground(entities); - return false; // wait + + // we have a response, but a failure, means server is alive, but responded with error + // such an error (access, ...) normally will not go away + const CStatusMessage m = + CLogMessage(this).error(u"Info objects (%1) loading for '%2' failed from '%3', '%4'") + << info << CEntityFlags::entitiesToString(entities) << infoReader->getInfoObjectsUrl().toQString() + << infoReader->getStatusMessage(); + infoReader->setMarkedAsFailed(true); + emit this->databaseReaderMessages(m); + return true; // carry on, regardless of situation } + + // wait for 1st reply + // we call read again in some time + this->readDeferredInBackground(entities); + return false; // wait } bool CWebDataServices::writeDbDataToDisk(const QString &dir) diff --git a/src/core/webdataservices.h b/src/core/webdataservices.h index 746570bf2..94e95dbc8 100644 --- a/src/core/webdataservices.h +++ b/src/core/webdataservices.h @@ -281,7 +281,7 @@ namespace swift::core //! ICAO code for id //! \threadsafe - swift::misc::aviation::CAircraftIcaoCode getAircraftIcaoCodeForDbKey(int id) const; + swift::misc::aviation::CAircraftIcaoCode getAircraftIcaoCodeForDbKey(int key) const; //! Use an ICAO object to select the best complete ICAO object from DB for it //! \threadsafe @@ -328,12 +328,12 @@ namespace swift::core //! ICAO code for id //! \threadsafe - swift::misc::aviation::CAirlineIcaoCode getAirlineIcaoCodeForDbKey(int id) const; + swift::misc::aviation::CAirlineIcaoCode getAirlineIcaoCodeForDbKey(int key) const; //! Smart airline selector //! \threadsafe swift::misc::aviation::CAirlineIcaoCode smartAirlineIcaoSelector( - const swift::misc::aviation::CAirlineIcaoCode &code, + const swift::misc::aviation::CAirlineIcaoCode &icaoPattern, const swift::misc::aviation::CCallsign &callsign = swift::misc::aviation::CCallsign()) const; //! ICAO code for callsign (e.g. DLH123 -> DLH) diff --git a/src/misc/worker.cpp b/src/misc/worker.cpp index 54a71ee54..2b7463dc4 100644 --- a/src/misc/worker.cpp +++ b/src/misc/worker.cpp @@ -218,9 +218,7 @@ namespace swift::misc const unsigned long waitTimeoutMs = this->waitTimeoutMs(); const QString name(this->getName()); qint64 waitTime = QDateTime::currentMSecsSinceEpoch(); - const bool ok = - workerThread->wait(waitTimeoutMs); //! \todo KB 2017-10 temp workaround: in T145 this will be fixed, - //! sometimes (very rarely) hanging here during shutdown + const bool ok = workerThread->wait(waitTimeoutMs); waitTime = QDateTime::currentMSecsSinceEpoch() - waitTime; const QString msg = QStringLiteral("Waiting for quitAndWait of '%1' for %2ms").arg(name).arg(waitTime); const QByteArray msgBA = msg.toLatin1(); diff --git a/src/misc/worker.h b/src/misc/worker.h index 162ca55ee..b1dd78477 100644 --- a/src/misc/worker.h +++ b/src/misc/worker.h @@ -34,17 +34,29 @@ namespace swift::misc /*! * Just a subclass of QThread whose destructor waits for the thread to finish. */ - class SWIFT_MISC_EXPORT CRegularThread : public QThread + class SWIFT_MISC_EXPORT CRegularThread final : public QThread { Q_OBJECT public: //! Constructor - CRegularThread(QObject *parent = nullptr) : QThread(parent) {} + explicit CRegularThread(QObject *parent = nullptr) : QThread(parent) {} //! Destructor ~CRegularThread() override; + //! Copy constructor + CRegularThread(const CRegularThread &) = delete; + + //! Copy assignment + CRegularThread &operator=(const CRegularThread &) = delete; + + //! Move constructor + CRegularThread(CRegularThread &&) = delete; + + //! Move assignment + CRegularThread &operator=(CRegularThread &&) = delete; + protected: //! \copydoc QThread::run void run() override; @@ -61,6 +73,21 @@ namespace swift::misc Q_OBJECT public: + //! Destructor. + ~CWorkerBase() override; + + //! Copy constructor + CWorkerBase(const CWorkerBase &) = delete; + + //! Copy assignment + CWorkerBase &operator=(const CWorkerBase &) = delete; + + //! Move constructor + CWorkerBase(CWorkerBase &&) = delete; + + //! Move assignment + CWorkerBase &operator=(CWorkerBase &&) = delete; + //! Log categories static const QStringList &getLogCategories(); @@ -147,9 +174,6 @@ namespace swift::misc //! Constructor. CWorkerBase(); - //! Destructor. - ~CWorkerBase() override; - //! For the task to check whether it can finish early. //! \threadsafe bool isAbandoned() const;