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 updateOwnAircraftPilot(const swift::misc::network::CUser &pilot) override;
180 
182  void toggleTransponderMode() override;
183 
185  bool setTransponderMode(swift::misc::aviation::CTransponder::TransponderMode mode) override;
186 
195  bool parseCommandLine(const QString &commandLine, const swift::misc::CIdentifier &originator) override;
196 
198  static void registerHelp()
199  {
200  if (swift::misc::CSimpleCommandParser::registered("swift::core::context::CContextOwnAircraft"))
201  {
202  return;
203  }
204  swift::misc::CSimpleCommandParser::registerCommand({ ".x", "alias: .xpdr" });
205  swift::misc::CSimpleCommandParser::registerCommand({ ".x code|mode", "set XPDR code or mode" });
206  swift::misc::CSimpleCommandParser::registerCommand({ ".selcal code", "set SELCAL code" });
207  swift::misc::CSimpleCommandParser::registerCommand({ ".com1", "alias .c1" });
208  swift::misc::CSimpleCommandParser::registerCommand({ ".com1 frequency", "set COM1 frequency" });
209  swift::misc::CSimpleCommandParser::registerCommand({ ".com2 frequency", "set COM2 frequency" });
210  }
211 
212  protected:
215 
216  private:
218  mutable QReadWriteLock m_lockAircraft;
219 
220  CActionBind m_actionToggleXpdr { swift::misc::input::toggleXPDRStateHotkeyAction(),
221  swift::misc::input::toggleXPDRStateHotkeyIcon(), this,
222  &CContextOwnAircraft::actionToggleTransponder };
223  CActionBind m_actionIdent { swift::misc::input::toggleXPDRIdentHotkeyAction(),
224  swift::misc::input::toggleXPDRIdentHotkeyIcon(), this,
225  &CContextOwnAircraft::actionIdent };
226 
227  static constexpr qint64 MinHistoryDeltaMs = 1000;
228  static constexpr int MaxHistoryElements = 20;
229  QTimer m_historyTimer;
230  std::atomic_bool m_history { true };
232 
234  this
235  };
236 
239  void xCtxChangedSimulatorModel(const swift::misc::simulation::CAircraftModel &model,
240  const swift::misc::CIdentifier &identifier);
241 
244  void xCtxChangedSimulatorStatus(int status);
245 
248  void actionToggleTransponder(bool keydown);
249  void actionIdent(bool keydown);
251 
253  void allSwiftWebDataRead();
254 
256  void initOwnAircraft();
257 
259  void evaluateUpdateHistory();
260 
262  bool updateOwnModel(const swift::misc::simulation::CAircraftModel &model,
263  const swift::misc::CIdentifier &identifier);
264 
267  reverseLookupModel(const swift::misc::simulation::CAircraftModel &model);
268  };
269  } // namespace context
270 } // namespace swift::core
271 #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.