swift
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"
17 #include "core/db/databasereader.h"
18 #include "core/swiftcoreexport.h"
23 #include "misc/network/url.h"
26 
27 class QNetworkReply;
28 
29 namespace swift::core::db
30 {
33  {
34  Q_OBJECT
35 
36  public:
38  explicit CModelDataReader(QObject *owner, const CDatabaseReaderConfigList &config);
39 
42  swift::misc::aviation::CLiveryList getLiveries() const;
43 
46  swift::misc::aviation::CLivery getLiveryForCombinedCode(const QString &combinedCode) const;
47 
51  getStdLiveryForAirlineVDesignator(const swift::misc::aviation::CAirlineIcaoCode &icao) const;
52 
55  swift::misc::aviation::CLivery getLiveryForDbKey(int id) const;
56 
59  swift::misc::aviation::CLivery smartLiverySelector(const swift::misc::aviation::CLivery &livery) const;
60 
63  swift::misc::simulation::CDistributorList getDistributors() const;
64 
67  swift::misc::simulation::CDistributor getDistributorForDbKey(const QString &dbKey) const;
68 
72 
75  swift::misc::simulation::CAircraftModel getModelForModelString(const QString &modelString) const;
76 
79  bool containsModelString(const QString &modelString) const;
80 
83  swift::misc::simulation::CAircraftModel getModelForDbKey(int dbKey) const;
84 
87  QSet<QString> getAircraftDesignatorsForAirline(const swift::misc::aviation::CAirlineIcaoCode &code) const;
88 
92  getAicraftIcaoCodesForAirline(const swift::misc::aviation::CAirlineIcaoCode &code) const;
93 
97  getModelsForAircraftDesignatorAndLiveryCombinedCode(const QString &aircraftDesignator,
98  const QString &combinedCode);
99 
102  int getLiveriesCount() const;
103 
106  int getDistributorsCount() const;
107 
111  smartDistributorSelector(const swift::misc::simulation::CDistributor &distributorPattern) const;
112 
116  smartDistributorSelector(const swift::misc::simulation::CDistributor &distributorPattern,
117  const swift::misc::simulation::CAircraftModel &model) const;
118 
121  int getModelsCount() const;
122 
125  QSet<int> getModelDbKeys() const;
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
139  swift::misc::CStatusMessageList readFromJsonFiles(const QString &dir,
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;
160  swift::misc::network::CUrl getDbServiceBaseUrl() 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.
Specialized version of threaded reader for DB data.
Read model related data from Database.
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)
Definition: aircraftmodel.h:71
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").
#define SWIFT_CORE_EXPORT
Export a class or function from the library.