swift
contextownaircraftimpl.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2013 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_CONTEXT_CONTEXTOWNAIRCRAFT_IMPL_H
7 #define SWIFT_CORE_CONTEXT_CONTEXTOWNAIRCRAFT_IMPL_H
8 
9 #include <atomic>
10 
11 #include <QObject>
12 #include <QReadWriteLock>
13 #include <QString>
14 #include <QTimer>
15 
16 #include "core/actionbind.h"
18 #include "core/corefacadeconfig.h"
19 #include "core/swiftcoreexport.h"
25 #include "misc/aviation/selcal.h"
27 #include "misc/icons.h"
28 #include "misc/identifiable.h"
29 #include "misc/identifier.h"
32 #include "misc/network/user.h"
33 #include "misc/pq/frequency.h"
34 #include "misc/pq/length.h"
35 #include "misc/settingscache.h"
40 
41 // clazy:excludeall=const-signal-or-slot
42 
43 namespace swift::misc
44 {
45  class CDBusServer;
46  namespace aviation
47  {
48  class CAircraftIcaoCode;
49  class CAircraftSituation;
50  class CAltitude;
51  class CCallsign;
52  class CTransponder;
53  } // namespace aviation
54 } // namespace swift::misc
55 namespace swift::core
56 {
57  class CCoreFacade;
58  namespace context
59  {
63  public IContextOwnAircraft,
66  {
67  Q_OBJECT
68  Q_CLASSINFO("D-Bus Interface", SWIFT_CORE_CONTEXTOWNAIRCRAFT_INTERFACENAME)
70  Q_INTERFACES(swift::misc::IProvider)
71  friend class swift::core::CCoreFacade;
72  friend class IContextOwnAircraft;
73 
74  public:
76  ~CContextOwnAircraft() override = default;
77 
78  // IOwnAircraftProvider overrides
81  swift::misc::aviation::CCallsign getOwnCallsign() const override;
82 
85  swift::misc::geo::CCoordinateGeodetic getOwnAircraftPosition() const override;
86 
89  swift::misc::aviation::CAircraftParts getOwnAircraftParts() const override;
90 
93  swift::misc::simulation::CAircraftModel getOwnAircraftModel() const override;
94 
98  getDistanceToOwnAircraft(const swift::misc::geo::ICoordinateGeodetic &position) const override;
99 
103  bool updateOwnModel(const swift::misc::simulation::CAircraftModel &model) override;
104 
107  bool updateOwnSituation(const swift::misc::aviation::CAircraftSituation &situation) override;
108 
111  bool updateOwnParts(const swift::misc::aviation::CAircraftParts &parts) override;
112 
115  bool updateOwnCG(const swift::misc::physical_quantities::CLength &cg) override;
116 
118  QObject *asQObject() override { return this; }
119 
120  signals:
124  void ps_changedModel(const swift::misc::simulation::CAircraftModel &model,
125  const swift::misc::CIdentifier &identifier);
126 
127  public slots:
130  swift::misc::simulation::CSimulatedAircraft getOwnAircraft() const override;
131 
135  getOwnComSystem(swift::misc::aviation::CComSystem::ComUnit unit) const override;
136 
139  swift::misc::aviation::CTransponder getOwnTransponder() const override;
140 
143  swift::misc::aviation::CAircraftSituation getOwnAircraftSituation() const override;
144 
147  bool updateOwnCallsign(const swift::misc::aviation::CCallsign &callsign) override;
148 
151  bool updateOwnIcaoCodes(const swift::misc::aviation::CAircraftIcaoCode &aircraftIcaoCode,
152  const swift::misc::aviation::CAirlineIcaoCode &airlineIcaoCode) override;
153 
155  bool updateOwnPosition(const swift::misc::geo::CCoordinateGeodetic &position,
156  const swift::misc::aviation::CAltitude &altitude,
157  const swift::misc::aviation::CAltitude &pressureAltitude) override;
158 
160  bool updateCockpit(const swift::misc::aviation::CComSystem &com1,
162  const swift::misc::aviation::CTransponder &transponder,
163  const swift::misc::CIdentifier &originator) override;
164 
166  bool updateTransponderMode(const swift::misc::aviation::CTransponder::TransponderMode &transponderMode,
167  const swift::misc::CIdentifier &originator) override;
168 
170  bool updateSelcal(const swift::misc::aviation::CSelcal &selcal,
171  const swift::misc::CIdentifier &originator) override;
172 
174  bool updateActiveComFrequency(const swift::misc::physical_quantities::CFrequency &frequency,
176  const swift::misc::CIdentifier &originator) override;
177 
179  bool updateStandbyComFrequency(const swift::misc::physical_quantities::CFrequency &frequency,
181  const swift::misc::CIdentifier &originator) override;
182 
184  bool updateOwnAircraftPilot(const swift::misc::network::CUser &pilot) override;
185 
187  void toggleTransponderMode() override;
188 
190  bool setTransponderMode(swift::misc::aviation::CTransponder::TransponderMode mode) override;
191 
200  bool parseCommandLine(const QString &commandLine, const swift::misc::CIdentifier &originator) override;
201 
203  static void registerHelp()
204  {
205  if (swift::misc::CSimpleCommandParser::registered("swift::core::context::CContextOwnAircraft"))
206  {
207  return;
208  }
209  swift::misc::CSimpleCommandParser::registerCommand({ ".x", "alias: .xpdr" });
210  swift::misc::CSimpleCommandParser::registerCommand({ ".x code|mode", "set XPDR code or mode" });
211  swift::misc::CSimpleCommandParser::registerCommand({ ".selcal code", "set SELCAL code" });
212  swift::misc::CSimpleCommandParser::registerCommand({ ".com1", "alias .c1" });
213  swift::misc::CSimpleCommandParser::registerCommand({ ".com1 frequency", "set COM1 frequency" });
214  swift::misc::CSimpleCommandParser::registerCommand({ ".com2 frequency", "set COM2 frequency" });
215  }
216 
217  protected:
220 
221  private:
223  mutable QReadWriteLock m_lockAircraft;
224 
225  CActionBind m_actionToggleXpdr { swift::misc::input::toggleXPDRStateHotkeyAction(),
226  swift::misc::input::toggleXPDRStateHotkeyIcon(), this,
227  &CContextOwnAircraft::actionToggleTransponder };
228  CActionBind m_actionIdent { swift::misc::input::toggleXPDRIdentHotkeyAction(),
229  swift::misc::input::toggleXPDRIdentHotkeyIcon(), this,
230  &CContextOwnAircraft::actionIdent };
231 
232  static constexpr qint64 MinHistoryDeltaMs = 1000;
233  static constexpr int MaxHistoryElements = 20;
234  QTimer m_historyTimer;
235  std::atomic_bool m_history { true };
237 
239  this
240  };
241 
244  void xCtxChangedSimulatorModel(const swift::misc::simulation::CAircraftModel &model,
245  const swift::misc::CIdentifier &identifier);
246 
249  void xCtxChangedSimulatorStatus(int status);
250 
253  void actionToggleTransponder(bool keydown);
254  void actionIdent(bool keydown);
256 
258  void allSwiftWebDataRead();
259 
261  void initOwnAircraft();
262 
264  void evaluateUpdateHistory();
265 
267  bool updateOwnModel(const swift::misc::simulation::CAircraftModel &model,
268  const swift::misc::CIdentifier &identifier);
269 
272  reverseLookupModel(const swift::misc::simulation::CAircraftModel &model);
273  };
274  } // namespace context
275 } // namespace swift::core
276 #endif // SWIFT_CORE_CONTEXT_CONTEXTOWNAIRCRAFT_IMPL_H
CActionBind binds a member function to an action.
Definition: actionbind.h:18
ContextMode
How to handle a given context.
The class providing facades (the contexts) for all DBus relevant operations.
Definition: corefacade.h:57
Own aircraft context implementation. Central instance of data for.
Base class with a member CIdentifier to be inherited by a class which has an identity in the environm...
Definition: identifiable.h:24
Value object encapsulating information identifying a component of a modular distributed swift process...
Definition: identifier.h:29
static void registerCommand(const CommandHtmlHelp &command)
Register a command.
static bool registered(const QString &helpContext)
Help already registered.
Base class for providers.
Definition: provider.h:19
Value object for ICAO classification.
Value object encapsulating information of aircraft's parts.
Definition: aircraftparts.h:26
Value object encapsulating information of an aircraft's situation.
Value object for ICAO classification.
Altitude as used in aviation, can be AGL or MSL altitude.
Definition: altitude.h:52
Value object encapsulating information of a callsign.
Definition: callsign.h:30
COM system (aka "radio")
Definition: comsystem.h:37
Value object for SELCAL.
Definition: selcal.h:31
Geodetic coordinate, a position in 3D space relative to the reference geoid.
Value object encapsulating information of a user.
Definition: user.h:28
Physical unit length (length)
Definition: length.h:18
Aircraft model (used by another pilot, my models on disk)
Definition: aircraftmodel.h:71
Comprehensive information of an aircraft.
Direct threadsafe in memory access to own aircraft.
#define SWIFT_CORE_CONTEXTOWNAIRCRAFT_INTERFACENAME
DBus interface for context.
Backend services of the swift project, like dealing with the network or the simulators.
Definition: actionbind.cpp:7
Free functions in swift::misc.
#define SWIFT_CORE_EXPORT
Export a class or function from the library.