swift
airspaceanalyzer.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_AIRSPACE_ANALYZER_H
7 #define SWIFT_CORE_AIRSPACE_ANALYZER_H
8 
9 #include <atomic>
10 #include <chrono>
11 
12 #include <QHash>
13 #include <QReadWriteLock>
14 #include <QtGlobal>
15 
16 #include "core/fsd/fsdclient.h"
17 #include "core/swiftcoreexport.h"
21 #include "misc/pq/frequency.h"
22 #include "misc/pq/length.h"
23 #include "misc/pq/units.h"
27 #include "misc/worker.h"
28 
29 namespace swift::misc::aviation
30 {
31  class CAircraftSituation;
32  class CCallsign;
33  class CTransponder;
34 } // namespace swift::misc::aviation
35 
36 namespace swift::core
37 {
38  class CAirspaceMonitor;
39 
53  {
54  Q_OBJECT
55 
56  public:
59 
62  fsd::CFSDClient *fsdClient, CAirspaceMonitor *airspaceMonitorParent);
63 
65  virtual ~CAirspaceAnalyzer() override;
66 
69  swift::misc::simulation::CAirspaceAircraftSnapshot getLatestAirspaceAircraftSnapshot() const;
70 
72  void
73  setSimulatorRenderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft,
74  const swift::misc::physical_quantities::CLength &maxRenderedDistance);
75 
78  void setEnabledWatchdog(bool enabled) { m_enabledWatchdog = enabled; }
79 
81  void clear();
82 
83  signals:
86 
89 
92 
93  private:
95  void watchdogRemoveAircraftCallsign(const swift::misc::aviation::CCallsign &callsign);
96 
98  void watchdogRemoveAtcCallsign(const swift::misc::aviation::CCallsign &callsign);
99 
101  void watchdogTouchAircraftCallsign(const swift::misc::aviation::CAircraftSituation &situation);
102 
104  void watchdogTouchAtcCallsign(const swift::misc::aviation::CCallsign &callsign,
108 
110  void onConnectionStatusChanged(swift::misc::network::CConnectionStatus oldStatus,
112 
114  void onNetworkPositionUpdate(const swift::misc::aviation::CAircraftSituation &situation,
115  const swift::misc::aviation::CTransponder &transponder);
116 
118  void onAtcStationDisconnected(const swift::misc::aviation::CAtcStation &station);
119 
121  void onTimeout();
122 
124  void watchdogCheckTimeouts();
125 
127  void analyzeAirspace();
128 
129  // watchdog
130  CCallsignTimestampSet m_aircraftCallsignTimestamps;
131  CCallsignTimestampSet m_atcCallsignTimestamps;
132  std::chrono::seconds m_timeoutAircraft { 15 };
133  std::chrono::seconds m_timeoutAtc { 50 };
134  qint64 m_lastWatchdogCallMsSinceEpoch;
135  qint64 m_doNotRunAgainBefore = -1;
136  std::atomic_bool m_enabledWatchdog { true };
137 
138  // snapshot
140  bool m_simulatorRenderedAircraftRestricted = false;
141  bool m_simulatorRenderingEnabled = true;
142  int m_simulatorMaxRenderedAircraft = -1;
143  swift::misc::physical_quantities::CLength m_simulatorMaxRenderedDistance { 0.0, nullptr };
144  mutable QReadWriteLock m_lockSnapshot;
145  mutable QReadWriteLock m_lockRestrictions;
146  };
147 } // namespace swift::core
148 
149 #endif // SWIFT_CORE_AIRSPACE_ANALYZER_H
Class monitoring and analyzing (closest aircraft, outdated aircraft / watchdog) airspace in backgroun...
void timeoutAircraft(const swift::misc::aviation::CCallsign &callsign)
Callsign has timed out.
void setEnabledWatchdog(bool enabled)
Enable/disable watchdog.
void timeoutAtc(const swift::misc::aviation::CCallsign &callsign)
Callsign has timed out.
void airspaceAircraftSnapshot(const swift::misc::simulation::CAirspaceAircraftSnapshot &snapshot)
New aircraft snapshot.
Keeps track of other entities in the airspace: aircraft, ATC stations, etc. Central instance of data ...
FSD client Todo: Send (interim) data updates automatically Todo Check ':' in FSD messages....
Definition: fsdclient.h:86
Base class for a long-lived worker object which lives in its own thread.
Definition: worker.h:275
Value object encapsulating information of an aircraft's situation.
Value object encapsulating information about an ATC station.
Definition: atcstation.h:38
Value object encapsulating information of a callsign.
Definition: callsign.h:30
Value object encapsulating information about a connection status.
Physical unit length (length)
Definition: length.h:18
Delegating class which can be directly used to access an.
Class which can be directly used to access an.
Direct threadsafe in memory access to own aircraft.
Backend services of the swift project, like dealing with the network or the simulators.
Definition: actionbind.cpp:7
#define SWIFT_CORE_EXPORT
Export a class or function from the library.