swift
fgswiftbusserviceproxy.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_SIMPLUGIN_FLIGHTGEAR_SERVICE_PROXY_H
7 #define SWIFT_SIMPLUGIN_FLIGHTGEAR_SERVICE_PROXY_H
8 
9 #include <functional>
10 
11 #include <QDBusError>
12 #include <QDBusPendingReply>
13 #include <QList>
14 #include <QObject>
15 #include <QString>
16 #include <QStringList>
17 
19 
20 // clazy:excludeall=const-signal-or-slot
21 
22 class QDBusConnection;
23 class QDBusPendingCallWatcher;
24 
26 #define FGSWIFTBUS_SERVICE_INTERFACENAME "org.swift_project.fgswiftbus.service"
27 #define FGSWIFTBUS_SERVICE_OBJECTPATH "/fgswiftbus/service"
29 
30 namespace swift::simplugin::flightgear
31 {
32  struct FlightgearData;
33 
37  class CFGSwiftBusServiceProxy : public QObject
38  {
39  Q_OBJECT
40 
41  public:
43  static const QString &InterfaceName()
44  {
45  static const QString s(FGSWIFTBUS_SERVICE_INTERFACENAME);
46  return s;
47  }
48 
50  static const QString &ObjectPath()
51  {
52  static const QString s(FGSWIFTBUS_SERVICE_OBJECTPATH);
53  return s;
54  }
55 
57  CFGSwiftBusServiceProxy(QDBusConnection &connection, QObject *parent = nullptr, bool dummy = false);
58 
60  bool isValid() const { return m_dbusInterface->isValid(); }
61 
64 
65  private:
66  swift::misc::CGenericDBusInterface *m_dbusInterface = nullptr;
67 
68  // Returns a function object which can be passed to CGenericDBusInterface::callDBusAsync.
69  template <typename T>
70  std::function<void(QDBusPendingCallWatcher *)> setterCallback(T *obj)
71  {
72  return [this, obj](QDBusPendingCallWatcher *watcher) {
73  QDBusPendingReply<T> reply = *watcher;
74  if (reply.isError()) { emit this->asyncMethodError(reply.error()); }
75  else { *obj = reply; }
76  watcher->deleteLater();
77  };
78  }
79 
80  template <typename T>
81  std::function<void(QDBusPendingCallWatcher *)> setterCallbackWithDefault(T *obj, T defaultValue)
82  {
83  return [this, obj, defaultValue](QDBusPendingCallWatcher *watcher) {
84  QDBusPendingReply<T> reply = *watcher;
85  if (reply.isError())
86  {
87  if (reply.error().type() == QDBusError::UnknownMethod)
88  *obj = defaultValue;
89  else
90  emit this->asyncMethodError(reply.error());
91  }
92  else { *obj = reply; }
93  watcher->deleteLater();
94  };
95  }
96 
97  signals:
99  SWIFT_NO_RELAY void asyncMethodError(QDBusError error);
100 
102  void aircraftModelChanged(const QString &path, const QString &filename, const QString &livery,
103  const QString &icao, const QString &modelString, const QString &name,
104  const QString &description);
105 
106  public slots:
108  int getVersionNumber();
109 
111  void getOwnAircraftSituationData(FlightgearData *o_flightgearData);
112 
114  void getOwnAircraftVelocityData(FlightgearData *o_flightgearData);
115 
117  void addTextMessage(const QString &text);
118 
121  QString getAircraftModelPath() const;
122  void getAircraftModelPathAsync(QString *o_modelPath);
124 
127  QString getAircraftModelFilename() const;
128  void getAircraftModelFilenameAsync(QString *o_modelFilename);
130 
133  QString getAircraftLivery() const;
134  void getAircraftLiveryAsync(QString *o_modelLivery);
136 
139  QString getAircraftIcaoCode() const;
140  void getAircraftIcaoCodeAsync(QString *o_icaoCode);
142 
145  QString getAircraftDescription() const;
146  void getAircraftDescriptionAsync(QString *o_description);
148 
151  QString getAircraftModelString() const;
152  void getAircraftModelStringAsync(QString *o_modelString);
154 
157  QString getAircraftName() const;
158  void getAircraftNameAsync(QString *o_name);
160 
163  bool isPaused() const;
164  void isPausedAsync(bool *o_paused);
166 
169  double getLatitudeDeg() const;
170  void getLatitudeDegAsync(double *o_latitude);
172 
175  double getLongitudeDeg() const;
176  void getLongitudeDegAsync(double *o_longitude);
178 
181  double getAltitudeMslFt() const;
182  void getAltitudeMslFtAsync(double *o_altitude);
184 
187  double getHeightAglFt() const;
188  void getHeightAglFtAsync(double *o_height);
190 
193  double getGroundSpeedKts() const;
194  void getGroundSpeedKtsAsync(double *o_groundspeed);
196 
199  double getPitchDeg() const;
200  void getPitchDegAsync(double *o_pitch);
202 
205  double getRollDeg() const;
206  void getRollDegAsync(double *o_roll);
208 
211  bool getAllWheelsOnGround() const;
212  void getAllWheelsOnGroundAsync(bool *o_allWheels);
214 
217  int getCom1ActiveKhz() const;
218  void getCom1ActiveKhzAsync(int *o_com1Active);
220 
223  int getCom1StandbyKhz() const;
224  void getCom1StandbyKhzAsync(int *o_com1Standby);
226 
229  double getCom1Volume() const;
230  void getCom1VolumeAsync(double *o_com1Volume);
232 
235  double getCom2Volume() const;
236  void getCom2VolumeAsync(double *o_com2Volume);
238 
241  int getCom2ActiveKhz() const;
242  void getCom2ActiveKhzAsync(int *o_com2Active);
244 
247  int getCom2StandbyKhz() const;
248  void getCom2StandbyKhzAsync(int *o_com2Standby);
250 
253  int getTransponderCode() const;
254  void getTransponderCodeAsync(int *o_xpdrCode);
256 
259  int getTransponderMode() const;
260  void getTransponderModeAsync(int *o_xpdrMode);
262 
265  bool getTransponderIdent() const;
266  void getTransponderIdentAsync(bool *o_ident);
268 
271  bool getBeaconLightsOn() const;
272  void getBeaconLightsOnAsync(bool *o_beaconLightsOn);
274 
277  bool getLandingLightsOn() const;
278  void getLandingLightsOnAsync(bool *o_landingLightsOn);
280 
283  bool getNavLightsOn() const;
284  void getNavLightsOnAsync(bool *o_navLightsOn);
286 
289  bool getStrobeLightsOn() const;
290  void getStrobeLightsOnAsync(bool *o_strobeLightsOn);
292 
295  bool getTaxiLightsOn() const;
296  void getTaxiLightsOnAsync(bool *o_taxiLightsOn);
298 
301  double getPressureAltitudeFt() const;
302  void getPressureAltitudeFtAsync(double *o_qnh);
304 
306  void setCom1ActiveKhz(int freq);
307 
309  void setCom1StandbyKhz(int freq);
310 
312  void setCom2ActiveKhz(int freq);
313 
315  void setCom2StandbyKhz(int freq);
316 
318  void setTransponderCode(int code);
319 
321  void setTransponderMode(int mode);
322 
325  double getFlapsDeployRatio() const;
326  void getFlapsDeployRatioAsync(double *o_flapsDeployRatio);
328 
331  double getGearDeployRatio() const;
332  void getGearDeployRatioAsync(double *o_gearDeployRatio);
334 
337  QList<double> getEngineN1Percentage() const;
338  void getEngineN1PercentageAsync(QList<double> *o_engineN1Percentage);
340 
344  double getSpeedBrakeRatio() const;
345  void getSpeedBrakeRatioAsync(double *o_speedBrakeRatio);
347 
350  double getGroundElevation() const;
351  void getGroundElevationAsync(double *o_groundElevation);
353  };
354 } // namespace swift::simplugin::flightgear
355 
356 #endif // SWIFT_SIMPLUGIN_FLIGHTGEAR_SERVICE_PROXY_H
Used for hand written interface based on virtual methods.
void cancelAllPendingAsyncCalls()
Cancel all asynchronous DBus calls which are currently pending.
Proxy object connected to a real FGSwiftBus::CService object via DBus.
void getRollDegAsync(double *o_roll)
Get aircraft roll in degrees.
int getTransponderMode() const
Get the current transponder mode (depends on the aircraft, 0 and 1 usually mean standby,...
double getGroundElevation() const
Get ground elevation [m] for current airplane position.
void getOwnAircraftSituationData(FlightgearData *o_flightgearData)
Get own aircraft situation data.
QString getAircraftModelFilename() const
Get base filename of current aircraft model.
void getGroundElevationAsync(double *o_groundElevation)
Get ground elevation [m] for current airplane position.
bool getLandingLightsOn() const
Get whether landing lights are on.
void cancelAllPendingAsyncCalls()
Cancel all current async slot calls.
bool getTaxiLightsOn() const
Get whether taxi lights are on.
void getAircraftModelPathAsync(QString *o_modelPath)
Get full path to current aircraft model.
void setCom2StandbyKhz(int freq)
Set the current COM2 standby frequency in kHz.
double getFlapsDeployRatio() const
Get flaps deploy ratio, where 0.0 is flaps fully retracted, and 1.0 is flaps fully extended.
double getGroundSpeedKts() const
Get aircraft groundspeed in knots.
QString getAircraftModelString() const
Get canonical swift model string of current aircraft model.
void getAircraftModelStringAsync(QString *o_modelString)
Get canonical swift model string of current aircraft model.
QString getAircraftName() const
Get name of current aircraft model.
double getHeightAglFt() const
Get aircraft height in feet.
QString getAircraftIcaoCode() const
Get the ICAO code of the current aircraft model.
double getGearDeployRatio() const
Get gear deploy ratio, where 0 is up and 1 is down.
void getGroundSpeedKtsAsync(double *o_groundspeed)
Get aircraft groundspeed in knots.
double getLatitudeDeg() const
Get aircraft latitude in degrees.
void getCom2StandbyKhzAsync(int *o_com2Standby)
Get the current COM2 standby frequency in kHz.
void getCom2VolumeAsync(double *o_com2Volume)
Get Com2 volume [0..1].
bool getAllWheelsOnGround() const
Get whether all wheels are on the ground.
void setCom1StandbyKhz(int freq)
Set the current COM1 standby frequency in kHz.
SWIFT_NO_RELAY void asyncMethodError(QDBusError error)
Emitted if an asynchronous method call caused a DBus error.
void getStrobeLightsOnAsync(bool *o_strobeLightsOn)
Get whether strobe lights are on.
void getCom1VolumeAsync(double *o_com1Volume)
Get Com1 volume [0..1].
QString getAircraftLivery() const
Get current aircraft livery.
void getLandingLightsOnAsync(bool *o_landingLightsOn)
Get whether landing lights are on.
bool getNavLightsOn() const
Get whether nav lights are on.
void getLongitudeDegAsync(double *o_longitude)
Get aircraft longitude in degrees.
bool getBeaconLightsOn() const
Get whether beacon lights are on.
int getCom1ActiveKhz() const
Get the current COM1 active frequency in kHz.
void getAircraftDescriptionAsync(QString *o_description)
Get the description of the current aircraft model.
bool getStrobeLightsOn() const
Get whether strobe lights are on.
void getTaxiLightsOnAsync(bool *o_taxiLightsOn)
Get whether taxi lights are on.
void getPitchDegAsync(double *o_pitch)
Get aircraft pitch in degrees above horizon.
void getTransponderModeAsync(int *o_xpdrMode)
Get the current transponder mode (depends on the aircraft, 0 and 1 usually mean standby,...
void getAircraftNameAsync(QString *o_name)
Get name of current aircraft model.
void getNavLightsOnAsync(bool *o_navLightsOn)
Get whether nav lights are on.
void getAllWheelsOnGroundAsync(bool *o_allWheels)
Get whether all wheels are on the ground.
void getLatitudeDegAsync(double *o_latitude)
Get aircraft latitude in degrees.
int getCom2StandbyKhz() const
Get the current COM2 standby frequency in kHz.
QList< double > getEngineN1Percentage() const
Get the N1 speed as percent of max (per engine)
void getCom2ActiveKhzAsync(int *o_com2Active)
Get the current COM2 active frequency in kHz.
void getPressureAltitudeFtAsync(double *o_qnh)
Get pressure altitude in feet.
QString getAircraftDescription() const
Get the description of the current aircraft model.
void getCom1ActiveKhzAsync(int *o_com1Active)
Get the current COM1 active frequency in kHz.
void setCom2ActiveKhz(int freq)
Set the current COM2 active frequency in kHz.
double getSpeedBrakeRatio() const
Get the ratio how much the speedbrakes surfaces are extended (0.0 is fully retracted,...
void isPausedAsync(bool *o_paused)
True if sim is paused.
void getAircraftIcaoCodeAsync(QString *o_icaoCode)
Get the ICAO code of the current aircraft model.
void getTransponderIdentAsync(bool *o_ident)
Get whether we are currently squawking ident.
int getCom2ActiveKhz() const
Get the current COM2 active frequency in kHz.
bool getTransponderIdent() const
Get whether we are currently squawking ident.
void setTransponderCode(int code)
Set the current transponder code in decimal.
void getGearDeployRatioAsync(double *o_gearDeployRatio)
Get gear deploy ratio, where 0 is up and 1 is down.
void getSpeedBrakeRatioAsync(double *o_speedBrakeRatio)
Get the ratio how much the speedbrakes surfaces are extended (0.0 is fully retracted,...
void aircraftModelChanged(const QString &path, const QString &filename, const QString &livery, const QString &icao, const QString &modelString, const QString &name, const QString &description)
Own aircraft model changed.
double getAltitudeMslFt() const
Get aircraft altitude in feet.
void getBeaconLightsOnAsync(bool *o_beaconLightsOn)
Get whether beacon lights are on.
void getAltitudeMslFtAsync(double *o_altitude)
Get aircraft altitude in feet.
void getHeightAglFtAsync(double *o_height)
Get aircraft height in feet.
void getFlapsDeployRatioAsync(double *o_flapsDeployRatio)
Get flaps deploy ratio, where 0.0 is flaps fully retracted, and 1.0 is flaps fully extended.
void getAircraftModelFilenameAsync(QString *o_modelFilename)
Get base filename of current aircraft model.
double getPitchDeg() const
Get aircraft pitch in degrees above horizon.
void getTransponderCodeAsync(int *o_xpdrCode)
Get the current transponder code in decimal.
double getPressureAltitudeFt() const
Get pressure altitude in feet.
void getEngineN1PercentageAsync(QList< double > *o_engineN1Percentage)
Get the N1 speed as percent of max (per engine)
void getCom1StandbyKhzAsync(int *o_com1Standby)
Get the current COM1 standby frequency in kHz.
void setTransponderMode(int mode)
Set the current transponder mode (depends on the aircraft, 0 and 1 usually mean standby,...
void getAircraftLiveryAsync(QString *o_modelLivery)
Get current aircraft livery.
QString getAircraftModelPath() const
Get full path to current aircraft model.
int getCom1StandbyKhz() const
Get the current COM1 standby frequency in kHz.
CFGSwiftBusServiceProxy(QDBusConnection &connection, QObject *parent=nullptr, bool dummy=false)
Constructor.
void setCom1ActiveKhz(int freq)
Set the current COM1 active frequency in kHz.
double getRollDeg() const
Get aircraft roll in degrees.
bool isValid() const
Does the remote object exist?
int getTransponderCode() const
Get the current transponder code in decimal.
void getOwnAircraftVelocityData(FlightgearData *o_flightgearData)
Get own aircraft velocity data.
double getLongitudeDeg() const
Get aircraft longitude in degrees.
void addTextMessage(const QString &text)
Add a text message to the on-screen display.
#define SWIFT_NO_RELAY
Any signals tagged with this macro will be ignored by swift::misc::CGenericDBusInterface::relayParent...