swift
Loading...
Searching...
No Matches
modeldatareader.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_CORE_MODELDATAREADER_H
7#define SWIFT_CORE_MODELDATAREADER_H
8
9#include <QDateTime>
10#include <QList>
11#include <QObject>
12#include <QSet>
13#include <QString>
14#include <QStringList>
15
16#include "core/data/dbcaches.h"
23#include "misc/network/url.h"
26
27class QNetworkReply;
28
29namespace swift::core::db
30{
33 {
35
36 public:
39
43
47
52
56
60
64
68
72
76
79 bool containsModelString(const QString &modelString) const;
80
84
88
93
98 const QString &combinedCode);
99
102 int getLiveriesCount() const;
103
106 int getDistributorsCount() const;
107
112
117 const swift::misc::simulation::CAircraftModel &model) const;
118
121 int getModelsCount() const;
122
126
129 QStringList getModelStringList(bool sort = false) const;
130
133 bool areAllDataRead() const;
134
136 bool writeToJsonFiles(const QString &dir);
137
138 // Data read from local data
140 swift::misc::network::CEntityFlags::Entity whatToRead,
141 bool overrideNewerOnly) override;
142 bool readFromJsonFilesInBackground(const QString &dir, swift::misc::network::CEntityFlags::Entity whatToRead,
143 bool overrideNewerOnly) override;
144
145 // cache handling for base class
146 swift::misc::network::CEntityFlags::Entity getSupportedEntities() const override;
147 QDateTime getCacheTimestamp(swift::misc::network::CEntityFlags::Entity entity) const override;
148 int getCacheCount(swift::misc::network::CEntityFlags::Entity entity) const override;
149 swift::misc::network::CEntityFlags::Entity getEntitiesWithCacheCount() const override;
150 swift::misc::network::CEntityFlags::Entity
151 getEntitiesWithCacheTimestampNewerThan(const QDateTime &threshold) const override;
152 void synchronizeCaches(swift::misc::network::CEntityFlags::Entity entities) override;
153 void admitCaches(swift::misc::network::CEntityFlags::Entity entities) override;
154
155 protected:
156 // cache handling for base class
157 void invalidateCaches(swift::misc::network::CEntityFlags::Entity entities) override;
158 bool hasChangedUrl(swift::misc::network::CEntityFlags::Entity entity, swift::misc::network::CUrl &oldUrlInfo,
159 swift::misc::network::CUrl &newUrlInfo) const override;
161
162 private:
164 &CModelDataReader::liveryCacheChanged };
166 &CModelDataReader::modelCacheChanged };
168 this, &CModelDataReader::distributorCacheChanged
169 };
170 std::atomic_bool m_syncedLiveryCache { false };
171 std::atomic_bool m_syncedModelCache { false };
172 std::atomic_bool m_syncedDistributorCache { false };
173
175 void read(swift::misc::network::CEntityFlags::Entity entities =
178 const QDateTime &newerThan = QDateTime()) override;
179
182 this, &CModelDataReader::baseUrlCacheChanged
183 };
184
186 void parseLiveryData(QNetworkReply *nwReply);
187
189 void parseDistributorData(QNetworkReply *nwReply);
190
192 void parseModelData(QNetworkReply *nwReply);
193
195 void liveryCacheChanged();
196
198 void modelCacheChanged();
199
201 void distributorCacheChanged();
202
204 void baseUrlCacheChanged();
205
207 void updateReaderUrl(const swift::misc::network::CUrl &url);
208
211 swift::misc::aviation::CAircraftIcaoCodeList getAircraftAircraftIcaos() const;
212
215 swift::misc::aviation::CAircraftCategoryList getAircraftCategories() const;
216
219
222
225 };
226} // namespace swift::core::db
227
228#endif // SWIFT_CORE_MODELDATAREADER_H
Value object encapsulating a list of reader configs.
CDatabaseReader(QObject *owner, const CDatabaseReaderConfigList &config, const QString &name)
Constructor.
bool containsModelString(const QString &modelString) const
Contains modelstring?
swift::misc::simulation::CAircraftModel getModelForModelString(const QString &modelString) const
Get model for string.
swift::misc::simulation::CAircraftModel getModelForDbKey(int dbKey) const
Get model for DB key.
bool writeToJsonFiles(const QString &dir)
Write to JSON file.
swift::misc::aviation::CLivery getLiveryForCombinedCode(const QString &combinedCode) const
Get aircraft livery for code.
int getLiveriesCount() const
Get aircraft liveries count.
swift::misc::simulation::CDistributor getDistributorForDbKey(const QString &dbKey) const
Get distributor for id.
QSet< int > getModelDbKeys() const
Get model keys.
bool areAllDataRead() const
All data read?
QStringList getModelStringList(bool sort=false) const
Get model keys.
swift::misc::aviation::CLivery smartLiverySelector(const swift::misc::aviation::CLivery &livery) const
Best match specified by livery.
int getDistributorsCount() const
Get model distributors count.
swift::misc::network::CEntityFlags::Entity getEntitiesWithCacheCount() const
Entities already having data in cache.
void admitCaches(swift::misc::network::CEntityFlags::Entity entities)
Admit caches for given entities.
swift::misc::simulation::CDistributorList getDistributors() const
Get distributors (of models).
int getCacheCount(swift::misc::network::CEntityFlags::Entity entity) const
Cache`s number of entities.
swift::misc::simulation::CAircraftModelList getModelsForAircraftDesignatorAndLiveryCombinedCode(const QString &aircraftDesignator, const QString &combinedCode)
Get model for designator/combined code.
swift::misc::network::CUrl getDbServiceBaseUrl() const
Get the service URL, individual for each reader.
bool hasChangedUrl(swift::misc::network::CEntityFlags::Entity entity, swift::misc::network::CUrl &oldUrlInfo, swift::misc::network::CUrl &newUrlInfo) const
Changed URL, means the cache values have been read from elsewhere.
swift::misc::aviation::CAircraftIcaoCodeList getAicraftIcaoCodesForAirline(const swift::misc::aviation::CAirlineIcaoCode &code) const
Get aircraft ICAO designators (e.g. B737, ..) for given airline.
swift::misc::simulation::CDistributor smartDistributorSelector(const swift::misc::simulation::CDistributor &distributorPattern) const
Best match specified by distributor.
QDateTime getCacheTimestamp(swift::misc::network::CEntityFlags::Entity entity) const
Get cache timestamp.
swift::misc::network::CEntityFlags::Entity getSupportedEntities() const
Supported entities by this reader.
int getModelsCount() const
Get models count.
swift::misc::aviation::CLivery getStdLiveryForAirlineVDesignator(const swift::misc::aviation::CAirlineIcaoCode &icao) const
Get aircraft livery for ICAO code.
QSet< QString > getAircraftDesignatorsForAirline(const swift::misc::aviation::CAirlineIcaoCode &code) const
Get aircraft ICAO designators (e.g. B737, ..) for given airline.
void synchronizeCaches(swift::misc::network::CEntityFlags::Entity entities)
Admit caches for given entities.
swift::misc::aviation::CLivery getLiveryForDbKey(int id) const
Get aircraft livery for id.
swift::misc::simulation::CAircraftModelList getModels() const
Get models.
bool readFromJsonFilesInBackground(const QString &dir, swift::misc::network::CEntityFlags::Entity whatToRead, bool overrideNewerOnly)
Data read from local data.
swift::misc::aviation::CLiveryList getLiveries() const
Get aircraft liveries.
CModelDataReader(QObject *owner, const CDatabaseReaderConfigList &config)
Constructor.
swift::misc::network::CEntityFlags::Entity getEntitiesWithCacheTimestampNewerThan(const QDateTime &threshold) const
Entities already having data in cache (based on timestamp assumption).
void invalidateCaches(swift::misc::network::CEntityFlags::Entity entities)
Invalidate the caches for given entities.
swift::misc::CStatusMessageList readFromJsonFiles(const QString &dir, swift::misc::network::CEntityFlags::Entity whatToRead, bool overrideNewerOnly)
Data read from local data.
const QObject * owner() const
Owner of the worker.
Definition worker.h:352
Class template for accessing a specific value in the CDataCache.
Definition datacache.h:315
Status messages, e.g. from Core -> GUI.
Value object encapsulating a list of ICAO codes.
Value object encapsulating a list of ICAO codes.
Value object for ICAO classification.
Value object encapsulating information about an airpot.
Definition livery.h:29
Value object for a list of airports.
Definition liverylist.h:29
DataRetrievalModeFlag
Which data to read, requires corresponding readers.
Definition dbflags.h:25
@ DbReading
directly from DB
Definition dbflags.h:27
Value object encapsulating information of a location, kind of simplified CValueObject compliant versi...
Definition url.h:27
Aircraft model (used by another pilot, my models on disk).
Value object encapsulating a list of aircraft models.
Value object encapsulating information of software distributor.
Definition distributor.h:33
Value object encapsulating a list of distributors.
Classes interacting with the swift database (aka "datastore").
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
#define SWIFT_CORE_EXPORT
Export a class or function from the library.