swift
vpilotrulesreader.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_MISC_SIMULATION_FSCOMMON_VPILOTRULESREADER_H
7 #define SWIFT_MISC_SIMULATION_FSCOMMON_VPILOTRULESREADER_H
8 
9 #include <QObject>
10 #include <QReadWriteLock>
11 #include <QString>
12 #include <QStringList>
13 
14 #include "misc/datacache.h"
18 #include "misc/swiftmiscexport.h"
19 
20 namespace swift::misc
21 {
22  class CWorker;
23 
24  namespace simulation::fscommon
25  {
28  class SWIFT_MISC_EXPORT CVPilotRulesReader : public QObject
29  {
30  Q_OBJECT
31 
32  public:
34  CVPilotRulesReader(bool standardDirectory = true, QObject *parent = nullptr);
35 
37  ~CVPilotRulesReader() override;
38 
41  QStringList getFiles() const;
42 
45  bool hasFiles() const;
46 
49  void addFilename(const QString &fileName);
50 
53  void addDirectory(const QString &directory);
54 
57  int countFilesLoaded() const;
58 
61  CVPilotModelRuleSet getRules() const;
62 
66 
69  swift::misc::simulation::CAircraftModelList getAsModelsFromCache() const;
70 
73  int getModelsCount() const;
74 
77  int countRulesLoaded() const;
78 
81  void gracefulShutdown();
82 
84  static const QString &standardMappingsDirectory();
85 
86  signals:
88  void readFinished(bool success);
89 
90  public slots:
93  bool read(bool convertToModels);
94 
97  swift::misc::CWorker *readInBackground(bool convertToModels);
98 
99  private slots:
102  void ps_readInBackgroundFinished();
103 
105  void ps_onVPilotCacheChanged();
106 
109  void ps_setCache(const swift::misc::simulation::CAircraftModelList &models);
110 
111  private:
112  QStringList m_fileList;
113  QStringList m_fileListWithProblems;
114  int m_loadedFiles = 0;
115  CVPilotModelRuleSet m_rules;
116  bool m_asyncLoadInProgress = false;
117  bool m_shutdown = false;
119  this, &CVPilotRulesReader::ps_onVPilotCacheChanged
120  };
121  mutable QReadWriteLock m_lockData;
122 
125  bool loadFile(const QString &fileName, CVPilotModelRuleSet &ruleSet);
126  };
127  } // namespace simulation::fscommon
128 } // namespace swift::misc
129 
130 #endif // SWIFT_MISC_SIMULATION_FSCOMMON_VPILOTRULESREADER_H
Class template for accessing a specific value in the CDataCache.
Definition: datacache.h:315
Class for doing some arbitrary parcel of work in its own thread.
Definition: worker.h:188
Value object encapsulating a list of aircraft models.
Value object reading a set of vPilot rules.
Free functions in swift::misc.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.