mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Ref T709, added DBus signatures and use CSettings class in service class
* CSettings objects will be shared among all services (traffic, weather, service) * It is "global" for plugin
This commit is contained in:
committed by
Mat Sutcliffe
parent
94f519961b
commit
f6690136f2
@@ -40,7 +40,7 @@ namespace BlackSimPlugin
|
||||
|
||||
QString CXSwiftBusServiceProxy::getVersionNumber()
|
||||
{
|
||||
return m_dbusInterface->callDBusRet<QString>(QLatin1String("getVersionNumber"));
|
||||
return m_dbusInterface->callDBusRet<QString>(QLatin1String("getVersionNumber"));
|
||||
}
|
||||
|
||||
void CXSwiftBusServiceProxy::getOwnAircraftSituationData(XPlaneData *o_xplaneData)
|
||||
@@ -505,5 +505,20 @@ namespace BlackSimPlugin
|
||||
{
|
||||
m_dbusInterface->callDBusAsync(QLatin1String("getSpeedBrakeRatio"), setterCallback(o_speedBrakeRatio));
|
||||
}
|
||||
|
||||
QString CXSwiftBusServiceProxy::getSettings() const
|
||||
{
|
||||
return m_dbusInterface->callDBusRet<QString>(QLatin1String("getSettings"));
|
||||
}
|
||||
|
||||
void CXSwiftBusServiceProxy::getSettingsAsync(QString *o_jsonSettings)
|
||||
{
|
||||
m_dbusInterface->callDBusAsync(QLatin1String("getSettings"), setterCallback(o_jsonSettings));
|
||||
}
|
||||
|
||||
void CXSwiftBusServiceProxy::setSettings(const QString &json)
|
||||
{
|
||||
m_dbusInterface->callDBus(QLatin1String("setSettings"), json);
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -386,8 +386,17 @@ namespace BlackSimPlugin
|
||||
double getSpeedBrakeRatio() const;
|
||||
void getSpeedBrakeRatioAsync(double *o_speedBrakeRatio);
|
||||
//! @}
|
||||
|
||||
//! \copydoc XSwiftBus::CService::getSettings
|
||||
//! @{
|
||||
QString getSettings() const;
|
||||
void getSettingsAsync(QString *o_jsonSettings);
|
||||
//! @}
|
||||
|
||||
//! \copydoc XSwiftBus::CService::setSettings
|
||||
void setSettings(const QString &json);
|
||||
};
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -16,15 +16,16 @@
|
||||
#include <functional>
|
||||
#include <thread>
|
||||
|
||||
namespace {
|
||||
inline std::string xswiftbusServiceName() {
|
||||
namespace
|
||||
{
|
||||
inline std::string xswiftbusServiceName()
|
||||
{
|
||||
return std::string("org.swift-project.xswiftbus");
|
||||
}
|
||||
}
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
|
||||
CPlugin::CPlugin()
|
||||
: m_dbusConnection(std::make_shared<CDBusConnection>()), m_menu(CMenu::mainMenu().subMenu("XSwiftBus"))
|
||||
{
|
||||
@@ -39,18 +40,18 @@ namespace XSwiftBus
|
||||
{
|
||||
m_service->toggleMessageBoxVisibility();
|
||||
});
|
||||
m_popupMessageWindowMenuItem = m_messageWindowSubMenu.checkableItem("Pop up Window on new Message", true, [this] (bool checked)
|
||||
m_popupMessageWindowMenuItem = m_messageWindowSubMenu.checkableItem("Pop up Window on new Message", true, [this](bool checked)
|
||||
{
|
||||
m_popupMessageWindowMenuItem.setChecked(!checked);
|
||||
m_service->setPopupMessageWindow(!checked);
|
||||
});
|
||||
m_disappearMessageWindowMenuItem = m_messageWindowSubMenu.checkableItem("Hide Message Window after 5s", true, [this] (bool checked)
|
||||
m_disappearMessageWindowMenuItem = m_messageWindowSubMenu.checkableItem("Hide Message Window after 5s", true, [this](bool checked)
|
||||
{
|
||||
m_disappearMessageWindowMenuItem.setChecked(!checked);
|
||||
m_service->setDisappearMessageWindow(!checked);
|
||||
});
|
||||
m_planeViewSubMenu = m_menu.subMenu("Follow Plane View");
|
||||
planeViewOwnAircraftMenuItem = m_planeViewSubMenu.item("Own Aircraft", [this]
|
||||
m_planeViewOwnAircraftMenuItem = m_planeViewSubMenu.item("Own Aircraft", [this]
|
||||
{
|
||||
m_traffic->setFollowedAircraft(m_traffic->ownAircraftString());
|
||||
});
|
||||
@@ -96,9 +97,9 @@ namespace XSwiftBus
|
||||
|
||||
readConfig();
|
||||
|
||||
m_service = std::make_unique<CService>();
|
||||
m_traffic = std::make_unique<CTraffic>();
|
||||
m_weather = std::make_unique<CWeather>();
|
||||
m_service = std::make_unique<CService>(m_pluginSettings);
|
||||
m_traffic = std::make_unique<CTraffic>(m_pluginSettings);
|
||||
m_weather = std::make_unique<CWeather>(m_pluginSettings);
|
||||
|
||||
m_traffic->setPlaneViewMenu(m_planeViewSubMenu);
|
||||
|
||||
|
||||
@@ -24,9 +24,11 @@
|
||||
#include "dbusdispatcher.h"
|
||||
#include "dbusserver.h"
|
||||
#include "datarefs.h"
|
||||
#include "XPLM/XPLMCamera.h"
|
||||
#include "menus.h"
|
||||
#include "config.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "XPLM/XPLMCamera.h"
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
||||
@@ -55,9 +57,10 @@ namespace XSwiftBus
|
||||
void onAircraftRepositioned();
|
||||
|
||||
private:
|
||||
CConfig m_pluginConfig;
|
||||
CConfig m_pluginConfig;
|
||||
CDBusDispatcher m_dbusDispatcher;
|
||||
std::unique_ptr<CDBusServer> m_dbusP2PServer;
|
||||
CSettings m_pluginSettings;
|
||||
std::unique_ptr<CDBusServer> m_dbusP2PServer;
|
||||
std::shared_ptr<CDBusConnection> m_dbusConnection;
|
||||
std::unique_ptr<CService> m_service;
|
||||
std::unique_ptr<CTraffic> m_traffic;
|
||||
@@ -65,12 +68,12 @@ namespace XSwiftBus
|
||||
CMenu m_menu;
|
||||
CMenuItem m_startServerMenuItem;
|
||||
CMenuItem m_showHideLabelsMenuItem;
|
||||
CMenu m_messageWindowSubMenu;
|
||||
CMenu m_messageWindowSubMenu;
|
||||
CMenuItem m_toggleMessageWindowMenuItem;
|
||||
CMenuItem m_popupMessageWindowMenuItem;
|
||||
CMenuItem m_disappearMessageWindowMenuItem;
|
||||
CMenu m_planeViewSubMenu;
|
||||
CMenuItem planeViewOwnAircraftMenuItem;
|
||||
CMenu m_planeViewSubMenu;
|
||||
CMenuItem m_planeViewOwnAircraftMenuItem;
|
||||
|
||||
DataRef<xplane::data::sim::atc::atis_enabled> m_atisEnabled;
|
||||
decltype(m_atisEnabled.get()) m_atisSaved = 0;
|
||||
|
||||
@@ -6,11 +6,14 @@
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#include "service.h"
|
||||
#include "utils.h"
|
||||
#include "blackmisc/simulation/xplane/qtfreeutils.h"
|
||||
|
||||
#include <XPLM/XPLMPlanes.h>
|
||||
#include <XPLM/XPLMUtilities.h>
|
||||
#include "blackmisc/simulation/xplane/qtfreeutils.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
// clazy:excludeall=reserve-candidates
|
||||
@@ -19,8 +22,7 @@ using namespace BlackMisc::Simulation::XPlane::QtFreeUtils;
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
|
||||
CService::CService() : CDBusObject()
|
||||
CService::CService(CSettings &settings) : CDBusObject(), m_pluginSettings(settings)
|
||||
{
|
||||
updateAirportsInRange();
|
||||
}
|
||||
@@ -155,10 +157,20 @@ namespace XSwiftBus
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string CService::getSettings() const
|
||||
{
|
||||
return m_pluginSettings.toXSwiftBusJsonString();
|
||||
}
|
||||
|
||||
void CService::setSettings(const std::string &jsonString)
|
||||
{
|
||||
m_pluginSettings.parseXSwiftBusString(jsonString);
|
||||
}
|
||||
|
||||
void CService::readAirportsDatabase()
|
||||
{
|
||||
auto first = XPLMFindFirstNavAidOfType(xplm_Nav_Airport);
|
||||
auto last = XPLMFindLastNavAidOfType(xplm_Nav_Airport);
|
||||
auto last = XPLMFindLastNavAidOfType(xplm_Nav_Airport);
|
||||
if (first != XPLM_NAV_NOT_FOUND)
|
||||
{
|
||||
for (auto i = first; i <= last; ++i)
|
||||
@@ -652,6 +664,24 @@ namespace XSwiftBus
|
||||
toggleMessageBoxVisibility();
|
||||
});
|
||||
}
|
||||
else if (message.getMethodName() == "getSettings")
|
||||
{
|
||||
queueDBusCall([ = ]()
|
||||
{
|
||||
sendDBusReply(sender, serial, getSettings());
|
||||
});
|
||||
}
|
||||
else if (message.getMethodName() == "setSettings")
|
||||
{
|
||||
maybeSendEmptyDBusReply(wantsReply, sender, serial);
|
||||
std::string json;
|
||||
message.beginArgumentRead();
|
||||
message.getArgument(json);
|
||||
queueDBusCall([ = ]()
|
||||
{
|
||||
setSettings(json);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unknown message. Tell DBus that we cannot handle it
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "datarefs.h"
|
||||
#include "messages.h"
|
||||
#include "navdatareference.h"
|
||||
#include "settings.h"
|
||||
#include <XPLM/XPLMNavigation.h>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
@@ -37,7 +38,7 @@ namespace XSwiftBus
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CService();
|
||||
CService(CSettings &settings);
|
||||
|
||||
//! Destructor
|
||||
~CService() override = default;
|
||||
@@ -234,6 +235,12 @@ namespace XSwiftBus
|
||||
//! Enable/disable message window disappearing again after 5 seconds
|
||||
void setDisappearMessageWindow(bool enabled) { m_disappearMessageWindow = enabled; }
|
||||
|
||||
//! Get settings in JSON format
|
||||
std::string getSettings() const;
|
||||
|
||||
//! Set settings
|
||||
void setSettings(const std::string &jsonString);
|
||||
|
||||
//! Perform generic processing
|
||||
int process();
|
||||
|
||||
@@ -249,12 +256,13 @@ namespace XSwiftBus
|
||||
const std::vector<double> &lats, const std::vector<double> &lons, const std::vector<double> &alts);
|
||||
|
||||
CMessageBoxControl m_messages { 16, 16, 16 };
|
||||
bool m_popupMessageWindow = true;
|
||||
bool m_popupMessageWindow = true;
|
||||
bool m_disappearMessageWindow = true;
|
||||
std::chrono::system_clock::time_point m_disappearMessageWindowTime;
|
||||
std::vector<CNavDataReference> m_airports;
|
||||
void readAirportsDatabase();
|
||||
CSettings &m_pluginSettings;
|
||||
|
||||
void readAirportsDatabase();
|
||||
std::vector<CNavDataReference> findClosestAirports(int number, double latitude, double longitude);
|
||||
|
||||
StringDataRef<xplane::data::sim::aircraft::view::acf_livery_path> m_liveryPath;
|
||||
|
||||
@@ -45,14 +45,17 @@ namespace XSwiftBus
|
||||
surfaces.lights.timeOffset = static_cast<uint16_t>(std::rand() % 0xffff);
|
||||
}
|
||||
|
||||
CTraffic::CTraffic() :
|
||||
// *INDENT-OFF*
|
||||
CTraffic::CTraffic(CSettings &settings) :
|
||||
CDBusObject(),
|
||||
m_pluginSettings(settings),
|
||||
m_followPlaneViewNextCommand("org/swift-project/xswiftbus/follow_next_plane", "Changes plane view to follow next plane in sequence", [this] { followNextPlane(); }),
|
||||
m_followPlaneViewPreviousCommand("org/swift-project/xswiftbus/follow_previous_plane", "Changes plane view to follow previous plane in sequence", [this] { followPreviousPlane(); })
|
||||
{
|
||||
XPLMRegisterDrawCallback(drawCallback, xplm_Phase_Airplanes, 1, this);
|
||||
XPLMRegisterKeySniffer(spaceKeySniffer, 1, this);
|
||||
}
|
||||
// *INDENT-ON*
|
||||
|
||||
CTraffic::~CTraffic()
|
||||
{
|
||||
@@ -394,7 +397,7 @@ namespace XSwiftBus
|
||||
plane->surfaces.lights.bcnLights = beaconLights.at(i);
|
||||
plane->surfaces.lights.strbLights = strobeLights.at(i);
|
||||
plane->surfaces.lights.navLights = navLights.at(i);
|
||||
plane->surfaces.lights.flashPattern = lightPatterns.at(i);
|
||||
plane->surfaces.lights.flashPattern = static_cast<unsigned int>(lightPatterns.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "datarefs.h"
|
||||
#include "terrainprobe.h"
|
||||
#include "menus.h"
|
||||
#include "settings.h"
|
||||
#include "XPMPMultiplayer.h"
|
||||
#include "XPLMCamera.h"
|
||||
#include <XPLM/XPLMDisplay.h>
|
||||
@@ -36,7 +37,7 @@ namespace XSwiftBus
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CTraffic();
|
||||
CTraffic(CSettings &settings);
|
||||
|
||||
//! Destructor
|
||||
~CTraffic() override;
|
||||
@@ -146,6 +147,7 @@ namespace XSwiftBus
|
||||
bool m_initialized = false;
|
||||
bool m_enabledMultiplayer = false;
|
||||
CTerrainProbe m_terrainProbe;
|
||||
CSettings &m_pluginSettings;
|
||||
|
||||
void emitSimFrame();
|
||||
void emitPlaneAdded(const std::string &callsign);
|
||||
@@ -182,7 +184,6 @@ namespace XSwiftBus
|
||||
const std::string &livery_, const std::string &modelName_);
|
||||
};
|
||||
|
||||
|
||||
std::unordered_map<std::string, Plane *> m_planesByCallsign;
|
||||
std::unordered_map<void *, Plane *> m_planesById;
|
||||
std::vector<std::string> m_followPlaneViewSequence;
|
||||
|
||||
@@ -13,8 +13,9 @@
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
CWeather::CWeather()
|
||||
CWeather::CWeather(CSettings &settings) : m_pluginSettings(settings)
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
//! Set cloud layer
|
||||
@@ -63,7 +64,7 @@ namespace XSwiftBus
|
||||
|
||||
const char *introspection_weather =
|
||||
DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
|
||||
#include "org.swift_project.xswiftbus.weather.xml"
|
||||
#include "org.swift_project.xswiftbus.weather.xml"
|
||||
;
|
||||
|
||||
DBusHandlerResult CWeather::dbusMessageHandler(const CDBusMessage &message_)
|
||||
@@ -84,7 +85,7 @@ namespace XSwiftBus
|
||||
{
|
||||
if (message.getMethodName() == "isUsingRealWeather")
|
||||
{
|
||||
queueDBusCall([=]()
|
||||
queueDBusCall([ = ]()
|
||||
{
|
||||
sendDBusReply(sender, serial, isUsingRealWeather());
|
||||
});
|
||||
@@ -95,7 +96,7 @@ namespace XSwiftBus
|
||||
bool enable = false;
|
||||
message.beginArgumentRead();
|
||||
message.getArgument(enable);
|
||||
queueDBusCall([=]()
|
||||
queueDBusCall([ = ]()
|
||||
{
|
||||
setUseRealWeather(enable);
|
||||
});
|
||||
@@ -106,7 +107,7 @@ namespace XSwiftBus
|
||||
double visibilityM = 10.0;
|
||||
message.beginArgumentRead();
|
||||
message.getArgument(visibilityM);
|
||||
queueDBusCall([=]()
|
||||
queueDBusCall([ = ]()
|
||||
{
|
||||
setVisibility(visibilityM);
|
||||
});
|
||||
@@ -117,7 +118,7 @@ namespace XSwiftBus
|
||||
int degreesC = 10;
|
||||
message.beginArgumentRead();
|
||||
message.getArgument(degreesC);
|
||||
queueDBusCall([=]()
|
||||
queueDBusCall([ = ]()
|
||||
{
|
||||
setTemperature(degreesC);
|
||||
});
|
||||
@@ -128,7 +129,7 @@ namespace XSwiftBus
|
||||
int degreesC = 10;
|
||||
message.beginArgumentRead();
|
||||
message.getArgument(degreesC);
|
||||
queueDBusCall([=]()
|
||||
queueDBusCall([ = ]()
|
||||
{
|
||||
setDewPoint(degreesC);
|
||||
});
|
||||
@@ -139,7 +140,7 @@ namespace XSwiftBus
|
||||
double inHg = 29.92;
|
||||
message.beginArgumentRead();
|
||||
message.getArgument(inHg);
|
||||
queueDBusCall([=]()
|
||||
queueDBusCall([ = ]()
|
||||
{
|
||||
setQNH(inHg);
|
||||
});
|
||||
@@ -150,7 +151,7 @@ namespace XSwiftBus
|
||||
double precipRatio = 0.0;
|
||||
message.beginArgumentRead();
|
||||
message.getArgument(precipRatio);
|
||||
queueDBusCall([=]()
|
||||
queueDBusCall([ = ]()
|
||||
{
|
||||
setPrecipitationRatio(precipRatio);
|
||||
});
|
||||
@@ -161,7 +162,7 @@ namespace XSwiftBus
|
||||
double cbRatio = 0.0;
|
||||
message.beginArgumentRead();
|
||||
message.getArgument(cbRatio);
|
||||
queueDBusCall([=]()
|
||||
queueDBusCall([ = ]()
|
||||
{
|
||||
setThunderstormRatio(cbRatio);
|
||||
});
|
||||
@@ -173,7 +174,7 @@ namespace XSwiftBus
|
||||
double turbulenceRatio = 0.0;
|
||||
message.beginArgumentRead();
|
||||
message.getArgument(turbulenceRatio);
|
||||
queueDBusCall([=]()
|
||||
queueDBusCall([ = ]()
|
||||
{
|
||||
setTurbulenceRatio(turbulenceRatio);
|
||||
});
|
||||
@@ -184,7 +185,7 @@ namespace XSwiftBus
|
||||
int friction = 10;
|
||||
message.beginArgumentRead();
|
||||
message.getArgument(friction);
|
||||
queueDBusCall([=]()
|
||||
queueDBusCall([ = ]()
|
||||
{
|
||||
setRunwayFriction(friction);
|
||||
});
|
||||
@@ -203,7 +204,7 @@ namespace XSwiftBus
|
||||
message.getArgument(tops);
|
||||
message.getArgument(type);
|
||||
message.getArgument(coverage);
|
||||
queueDBusCall([=]()
|
||||
queueDBusCall([ = ]()
|
||||
{
|
||||
setCloudLayer(layer, base, tops, type, coverage);
|
||||
});
|
||||
@@ -226,7 +227,7 @@ namespace XSwiftBus
|
||||
message.getArgument(shearDirectionDeg);
|
||||
message.getArgument(shearSpeedKt);
|
||||
message.getArgument(turbulence);
|
||||
queueDBusCall([=]()
|
||||
queueDBusCall([ = ]()
|
||||
{
|
||||
setWindLayer(layer, altitudeM, directionDeg, speedKt, shearDirectionDeg, shearSpeedKt, turbulence);
|
||||
});
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#endif
|
||||
#include "dbusobject.h"
|
||||
#include "datarefs.h"
|
||||
#include "settings.h"
|
||||
|
||||
//! \cond PRIVATE
|
||||
#define XSWIFTBUS_WEATHER_INTERFACENAME "org.swift_project.xswiftbus.weather"
|
||||
@@ -24,7 +25,6 @@
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
|
||||
/*!
|
||||
* XSwiftBus weather object which is accessible through DBus
|
||||
*/
|
||||
@@ -32,7 +32,7 @@ namespace XSwiftBus
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CWeather();
|
||||
CWeather(CSettings &settings);
|
||||
|
||||
//! DBus interface name
|
||||
static const std::string &InterfaceName()
|
||||
@@ -103,6 +103,8 @@ namespace XSwiftBus
|
||||
virtual DBusHandlerResult dbusMessageHandler(const CDBusMessage &message) override;
|
||||
|
||||
private:
|
||||
CSettings &m_pluginSettings;
|
||||
|
||||
DataRef<xplane::data::sim::weather::use_real_weather_bool> m_useRealWeather;
|
||||
DataRef<xplane::data::sim::weather::visibility_reported_m> m_visibilityM;
|
||||
DataRef<xplane::data::sim::weather::rain_percent> m_precipRatio;
|
||||
|
||||
Reference in New Issue
Block a user