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/threadedtimer.h"
28 #include "misc/worker.h"
29 
30 namespace swift::misc::aviation
31 {
32  class CAircraftSituation;
33  class CCallsign;
34  class CTransponder;
35 } // namespace swift::misc::aviation
36 
37 namespace swift::core
38 {
39  class CAirspaceMonitor;
40 
54  {
55  Q_OBJECT
56 
57  public:
60 
63  fsd::CFSDClient *fsdClient, CAirspaceMonitor *airspaceMonitorParent);
64 
66  ~CAirspaceAnalyzer() override = default;
67 
70 
73 
76 
79 
82  swift::misc::simulation::CAirspaceAircraftSnapshot getLatestAirspaceAircraftSnapshot() const;
83 
85  void
86  setSimulatorRenderRestrictionsChanged(bool restricted, bool enabled, int maxAircraft,
87  const swift::misc::physical_quantities::CLength &maxRenderedDistance);
88 
91  void setEnabledWatchdog(bool enabled) { m_enabledWatchdog = enabled; }
92 
94  void clear();
95 
96  signals:
99 
102 
105 
106  private:
108  void watchdogRemoveAircraftCallsign(const swift::misc::aviation::CCallsign &callsign);
109 
111  void watchdogRemoveAtcCallsign(const swift::misc::aviation::CCallsign &callsign);
112 
114  void watchdogTouchAircraftCallsign(const swift::misc::aviation::CAircraftSituation &situation);
115 
117  void watchdogTouchAtcCallsign(const swift::misc::aviation::CCallsign &callsign,
121 
123  void onConnectionStatusChanged(swift::misc::network::CConnectionStatus oldStatus,
125 
127  void onNetworkPositionUpdate(const swift::misc::aviation::CAircraftSituation &situation,
128  const swift::misc::aviation::CTransponder &transponder);
129 
131  void onAtcStationDisconnected(const swift::misc::aviation::CAtcStation &station);
132 
134  void onTimeout();
135 
137  void watchdogCheckTimeouts();
138 
140  void analyzeAirspace();
141 
142  // watchdog
143  CCallsignTimestampSet m_aircraftCallsignTimestamps;
144  CCallsignTimestampSet m_atcCallsignTimestamps;
145  std::chrono::seconds m_timeoutAircraft { 15 };
146  std::chrono::seconds m_timeoutAtc { 50 };
147  qint64 m_lastWatchdogCallMsSinceEpoch;
148  qint64 m_doNotRunAgainBefore = -1;
149  std::atomic_bool m_enabledWatchdog { true };
150  misc::CThreadedTimer m_updateTimer;
151 
152  // snapshot
154  bool m_simulatorRenderedAircraftRestricted = false;
155  bool m_simulatorRenderingEnabled = true;
156  int m_simulatorMaxRenderedAircraft = -1;
157  swift::misc::physical_quantities::CLength m_simulatorMaxRenderedDistance { 0.0, nullptr };
158  mutable QReadWriteLock m_lockSnapshot;
159  mutable QReadWriteLock m_lockRestrictions;
160  };
161 } // namespace swift::core
162 
163 #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.
~CAirspaceAnalyzer()=default
Destructor.
void airspaceAircraftSnapshot(const swift::misc::simulation::CAirspaceAircraftSnapshot &snapshot)
New aircraft snapshot.
CAirspaceAnalyzer & operator=(CAirspaceAnalyzer &&)=delete
Move assignment.
CAirspaceAnalyzer & operator=(const CAirspaceAnalyzer &)=delete
Copy assignment.
CAirspaceAnalyzer(CAirspaceAnalyzer &&)=delete
Move constructor.
CAirspaceAnalyzer(const CAirspaceAnalyzer &)=delete
Copy constructor.
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:85
Base class for a long-lived worker object which lives in its own thread.
Definition: worker.h:299
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.