swift
icaodatareader.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_ICAODATAREADER_H
7 #define SWIFT_CORE_ICAODATAREADER_H
8 
9 #include <atomic>
10 
11 #include <QObject>
12 #include <QString>
13 
14 #include "core/data/dbcaches.h"
15 #include "core/db/databasereader.h"
16 #include "core/swiftcoreexport.h"
19 #include "misc/country.h"
20 #include "misc/countrylist.h"
21 #include "misc/datacache.h"
23 #include "misc/network/url.h"
24 
25 class QDateTime;
26 class QNetworkReply;
27 
28 namespace swift::core::db
29 {
32  {
33  Q_OBJECT
34 
35  public:
37  explicit CIcaoDataReader(QObject *owner, const CDatabaseReaderConfigList &config);
38 
41  swift::misc::aviation::CAircraftIcaoCodeList getAircraftIcaoCodes() const;
42 
45  int getAircraftIcaoCodesCount() const;
46 
49  swift::misc::aviation::CAircraftIcaoCode getAircraftIcaoCodeForDesignator(const QString &designator) const;
50 
53  swift::misc::aviation::CAircraftIcaoCodeList getAircraftIcaoCodesForDesignator(const QString &designator) const;
54 
57  swift::misc::aviation::CAircraftIcaoCodeList getAircraftIcaoCodesForIataCode(const QString &iataCode) const;
58 
61  swift::misc::aviation::CAircraftIcaoCode getAircraftIcaoCodeForDbKey(int key) const;
62 
65  bool containsAircraftIcaoDesignator(const QString &designator) const;
66 
70  smartAircraftIcaoSelector(const swift::misc::aviation::CAircraftIcaoCode &icaoPattern) const;
71 
74  swift::misc::CCountryList getCountries() const;
75 
78  int getCountriesCount() const;
79 
82  swift::misc::CCountry getCountryForIsoCode(const QString &isoCode) const;
83 
86  swift::misc::CCountry getCountryForName(const QString &name) const;
87 
90  swift::misc::aviation::CAirlineIcaoCodeList getAirlineIcaoCodes() const;
91 
94  int getAirlineIcaoCodesCount() const;
95 
98  swift::misc::aviation::CAirlineIcaoCodeList getAirlineIcaoCodesForDesignator(const QString &designator) const;
99 
102  bool containsAirlineIcaoDesignator(const QString &designator) const;
103 
107  getAirlineIcaoCodeForUniqueDesignatorOrDefault(const QString &designator, bool preferOperatingAirlines) const;
108 
111  swift::misc::aviation::CAirlineIcaoCodeList getAirlineIcaoCodesForIataCode(const QString &iataCode) const;
112 
116  getAirlineIcaoCodeForUniqueIataCodeOrDefault(const QString &iataCode) const;
117 
120  swift::misc::aviation::CAirlineIcaoCode getAirlineIcaoCodeForDbKey(int key) const;
121 
124  swift::misc::aviation::CAirlineIcaoCode smartAirlineIcaoSelector(
125  const swift::misc::aviation::CAirlineIcaoCode &icaoPattern,
127 
130  swift::misc::aviation::CAircraftCategoryList getAircraftCategories() const;
131 
134  int getAircraftCategoryCount() const;
135 
138  bool areAllDataRead() const;
139 
141  bool writeToJsonFiles(const QString &dir);
142 
143  // data read from local data
144  swift::misc::CStatusMessageList readFromJsonFiles(const QString &dir,
145  swift::misc::network::CEntityFlags::Entity whatToRead,
146  bool overrideNewerOnly) override;
147  bool readFromJsonFilesInBackground(const QString &dir, swift::misc::network::CEntityFlags::Entity whatToRead,
148  bool overrideNewerOnly) override;
149 
150  // cache handling for base class
151  swift::misc::network::CEntityFlags::Entity getSupportedEntities() const override;
152  QDateTime getCacheTimestamp(swift::misc::network::CEntityFlags::Entity entity) const override;
153  int getCacheCount(swift::misc::network::CEntityFlags::Entity entity) const override;
154  swift::misc::network::CEntityFlags::Entity getEntitiesWithCacheCount() const override;
155  swift::misc::network::CEntityFlags::Entity
156  getEntitiesWithCacheTimestampNewerThan(const QDateTime &threshold) const override;
157  void synchronizeCaches(swift::misc::network::CEntityFlags::Entity entities) override;
158  void admitCaches(swift::misc::network::CEntityFlags::Entity entities) override;
159 
160  protected:
161  // cache handling for base class
162  void invalidateCaches(swift::misc::network::CEntityFlags::Entity entities) override;
163  bool hasChangedUrl(swift::misc::network::CEntityFlags::Entity entity, swift::misc::network::CUrl &oldUrlInfo,
164  swift::misc::network::CUrl &newUrlInfo) const override;
165  swift::misc::network::CUrl getDbServiceBaseUrl() const override;
166 
167  private:
169  this, &CIcaoDataReader::aircraftIcaoCacheChanged
170  };
172  this, &CIcaoDataReader::airlineIcaoCacheChanged
173  };
175  &CIcaoDataReader::countryCacheChanged };
177  this, &CIcaoDataReader::aircraftCategoryCacheChanged
178  };
179  std::atomic_bool m_syncedAircraftIcaoCache { false };
180  std::atomic_bool m_syncedAirlineIcaoCache { false };
181  std::atomic_bool m_syncedCountryCache { false };
182  std::atomic_bool m_syncedCategories { false };
183 
185  void read(swift::misc::network::CEntityFlags::Entity entities,
186  swift::misc::db::CDbFlags::DataRetrievalModeFlag mode, const QDateTime &newerThan) override;
187 
190  this, &CIcaoDataReader::baseUrlCacheChanged
191  };
192 
194  void parseAircraftIcaoData(QNetworkReply *nwReply);
195 
197  void parseAirlineIcaoData(QNetworkReply *nwReply);
198 
200  void parseCountryData(QNetworkReply *nwReply);
201 
203  void parseAircraftCategoryData(QNetworkReply *nwReplyPtr);
204 
206  void aircraftIcaoCacheChanged();
207 
209  void airlineIcaoCacheChanged();
210 
212  void countryCacheChanged();
213 
215  void aircraftCategoryCacheChanged();
216 
218  void baseUrlCacheChanged();
219 
221  void updateReaderUrl(const swift::misc::network::CUrl &url);
222 
225 
228 
231 
234  };
235 } // namespace swift::core::db
236 
237 #endif // SWIFT_CORE_ICAODATAREADER_H
Value object encapsulating a list of reader configs.
Specialized version of threaded reader for DB data.
Read ICAO data from Database.
Value object encapsulating a list of countries.
Definition: countrylist.h:32
Status messages, e.g. from Core -> GUI.
Value object encapsulating a list of ICAO codes.
Value object for ICAO classification.
Value object encapsulating a list of ICAO codes.
Value object for ICAO classification.
Value object encapsulating a list of ICAO codes.
Value object encapsulating information of a callsign.
Definition: callsign.h:30
DataRetrievalModeFlag
Which data to read, requires corresponding readers.
Definition: dbflags.h:25
Value object encapsulating information of a location, kind of simplified CValueObject compliant versi...
Definition: url.h:27
Classes interacting with the swift database (aka "datastore").
#define SWIFT_CORE_EXPORT
Export a class or function from the library.