swift
Loading...
Searching...
No Matches
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
22class QDBusConnection;
24
26#define FGSWIFTBUS_SERVICE_INTERFACENAME "org.swift_project.fgswiftbus.service"
27#define FGSWIFTBUS_SERVICE_OBJECTPATH "/fgswiftbus/service"
29
30namespace swift::simplugin::flightgear
31{
32 struct FlightgearData;
33
38 {
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
63 void cancelAllPendingAsyncCalls() { m_dbusInterface->cancelAllPendingAsyncCalls(); }
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())
75 {
76 emit this->asyncMethodError(reply.error());
77 }
78 else
79 {
80 *obj = reply;
81 }
82 watcher->deleteLater();
83 };
84 }
85
86 template <typename T>
87 std::function<void(QDBusPendingCallWatcher *)> setterCallbackWithDefault(T *obj, T defaultValue)
88 {
89 return [this, obj, defaultValue](QDBusPendingCallWatcher *watcher) {
90 QDBusPendingReply<T> reply = *watcher;
91 if (reply.isError())
92 {
93 if (reply.error().type() == QDBusError::UnknownMethod)
94 *obj = defaultValue;
95 else
96 emit this->asyncMethodError(reply.error());
97 }
98 else
99 {
100 *obj = reply;
101 }
102 watcher->deleteLater();
103 };
104 }
105
106 signals:
109
111 void aircraftModelChanged(const QString &path, const QString &filename, const QString &livery,
112 const QString &icao, const QString &modelString, const QString &name,
113 const QString &description);
114
115 public slots:
117 int getVersionNumber();
118
120 void getOwnAircraftSituationData(FlightgearData *o_flightgearData);
121
123 void getOwnAircraftVelocityData(FlightgearData *o_flightgearData);
124
126 void addTextMessage(const QString &text);
127
131 void getAircraftModelPathAsync(QString *o_modelPath);
133
137 void getAircraftModelFilenameAsync(QString *o_modelFilename);
139
143 void getAircraftLiveryAsync(QString *o_modelLivery);
145
149 void getAircraftIcaoCodeAsync(QString *o_icaoCode);
151
155 void getAircraftDescriptionAsync(QString *o_description);
157
161 void getAircraftModelStringAsync(QString *o_modelString);
163
166 QString getAircraftName() const;
167 void getAircraftNameAsync(QString *o_name);
169
172 bool isPaused() const;
173 void isPausedAsync(bool *o_paused);
175
178 double getLatitudeDeg() const;
179 void getLatitudeDegAsync(double *o_latitude);
181
184 double getLongitudeDeg() const;
185 void getLongitudeDegAsync(double *o_longitude);
187
190 double getAltitudeMslFt() const;
191 void getAltitudeMslFtAsync(double *o_altitude);
193
196 double getHeightAglFt() const;
197 void getHeightAglFtAsync(double *o_height);
199
202 double getGroundSpeedKts() const;
203 void getGroundSpeedKtsAsync(double *o_groundspeed);
205
208 double getPitchDeg() const;
209 void getPitchDegAsync(double *o_pitch);
211
214 double getRollDeg() const;
215 void getRollDegAsync(double *o_roll);
217
220 bool getAllWheelsOnGround() const;
221 void getAllWheelsOnGroundAsync(bool *o_allWheels);
223
226 int getCom1ActiveKhz() const;
227 void getCom1ActiveKhzAsync(int *o_com1Active);
229
232 int getCom1StandbyKhz() const;
233 void getCom1StandbyKhzAsync(int *o_com1Standby);
235
238 double getCom1Volume() const;
239 void getCom1VolumeAsync(double *o_com1Volume);
241
244 double getCom2Volume() const;
245 void getCom2VolumeAsync(double *o_com2Volume);
247
250 int getCom2ActiveKhz() const;
251 void getCom2ActiveKhzAsync(int *o_com2Active);
253
256 int getCom2StandbyKhz() const;
257 void getCom2StandbyKhzAsync(int *o_com2Standby);
259
262 int getTransponderCode() const;
263 void getTransponderCodeAsync(int *o_xpdrCode);
265
268 int getTransponderMode() const;
269 void getTransponderModeAsync(int *o_xpdrMode);
271
274 bool getTransponderIdent() const;
275 void getTransponderIdentAsync(bool *o_ident);
277
280 bool getBeaconLightsOn() const;
281 void getBeaconLightsOnAsync(bool *o_beaconLightsOn);
283
286 bool getLandingLightsOn() const;
287 void getLandingLightsOnAsync(bool *o_landingLightsOn);
289
292 bool getNavLightsOn() const;
293 void getNavLightsOnAsync(bool *o_navLightsOn);
295
298 bool getStrobeLightsOn() const;
299 void getStrobeLightsOnAsync(bool *o_strobeLightsOn);
301
304 bool getTaxiLightsOn() const;
305 void getTaxiLightsOnAsync(bool *o_taxiLightsOn);
307
310 double getPressureAltitudeFt() const;
311 void getPressureAltitudeFtAsync(double *o_qnh);
313
315 void setCom1ActiveKhz(int freq);
316
318 void setCom1StandbyKhz(int freq);
319
321 void setCom2ActiveKhz(int freq);
322
324 void setCom2StandbyKhz(int freq);
325
327 void setTransponderCode(int code);
328
330 void setTransponderMode(int mode);
331
334 double getFlapsDeployRatio() const;
335 void getFlapsDeployRatioAsync(double *o_flapsDeployRatio);
337
340 double getGearDeployRatio() const;
341 void getGearDeployRatioAsync(double *o_gearDeployRatio);
343
347 void getEngineN1PercentageAsync(QList<double> *o_engineN1Percentage);
349
353 double getSpeedBrakeRatio() const;
354 void getSpeedBrakeRatioAsync(double *o_speedBrakeRatio);
356
359 double getGroundElevation() const;
360 void getGroundElevationAsync(double *o_groundElevation);
362 };
363} // namespace swift::simplugin::flightgear
364
365#endif // SWIFT_SIMPLUGIN_FLIGHTGEAR_SERVICE_PROXY_H
Used for hand written interface based on virtual methods.
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...
QDBusError::ErrorType type() const const
QDBusError error() const const
bool isError() const const
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
QObject * parent() const const