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:
Klaus Basan
2019-07-25 16:34:27 +02:00
committed by Mat Sutcliffe
parent 94f519961b
commit f6690136f2
10 changed files with 118 additions and 45 deletions

View File

@@ -505,5 +505,20 @@ namespace BlackSimPlugin
{ {
m_dbusInterface->callDBusAsync(QLatin1String("getSpeedBrakeRatio"), setterCallback(o_speedBrakeRatio)); 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
} // ns } // ns

View File

@@ -386,8 +386,17 @@ namespace BlackSimPlugin
double getSpeedBrakeRatio() const; double getSpeedBrakeRatio() const;
void getSpeedBrakeRatioAsync(double *o_speedBrakeRatio); 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 #endif // guard

View File

@@ -16,15 +16,16 @@
#include <functional> #include <functional>
#include <thread> #include <thread>
namespace { namespace
inline std::string xswiftbusServiceName() { {
inline std::string xswiftbusServiceName()
{
return std::string("org.swift-project.xswiftbus"); return std::string("org.swift-project.xswiftbus");
} }
} }
namespace XSwiftBus namespace XSwiftBus
{ {
CPlugin::CPlugin() CPlugin::CPlugin()
: m_dbusConnection(std::make_shared<CDBusConnection>()), m_menu(CMenu::mainMenu().subMenu("XSwiftBus")) : m_dbusConnection(std::make_shared<CDBusConnection>()), m_menu(CMenu::mainMenu().subMenu("XSwiftBus"))
{ {
@@ -50,7 +51,7 @@ namespace XSwiftBus
m_service->setDisappearMessageWindow(!checked); m_service->setDisappearMessageWindow(!checked);
}); });
m_planeViewSubMenu = m_menu.subMenu("Follow Plane View"); 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()); m_traffic->setFollowedAircraft(m_traffic->ownAircraftString());
}); });
@@ -96,9 +97,9 @@ namespace XSwiftBus
readConfig(); readConfig();
m_service = std::make_unique<CService>(); m_service = std::make_unique<CService>(m_pluginSettings);
m_traffic = std::make_unique<CTraffic>(); m_traffic = std::make_unique<CTraffic>(m_pluginSettings);
m_weather = std::make_unique<CWeather>(); m_weather = std::make_unique<CWeather>(m_pluginSettings);
m_traffic->setPlaneViewMenu(m_planeViewSubMenu); m_traffic->setPlaneViewMenu(m_planeViewSubMenu);

View File

@@ -24,9 +24,11 @@
#include "dbusdispatcher.h" #include "dbusdispatcher.h"
#include "dbusserver.h" #include "dbusserver.h"
#include "datarefs.h" #include "datarefs.h"
#include "XPLM/XPLMCamera.h"
#include "menus.h" #include "menus.h"
#include "config.h" #include "config.h"
#include "settings.h"
#include "XPLM/XPLMCamera.h"
#include <memory> #include <memory>
#include <thread> #include <thread>
@@ -57,6 +59,7 @@ namespace XSwiftBus
private: private:
CConfig m_pluginConfig; CConfig m_pluginConfig;
CDBusDispatcher m_dbusDispatcher; CDBusDispatcher m_dbusDispatcher;
CSettings m_pluginSettings;
std::unique_ptr<CDBusServer> m_dbusP2PServer; std::unique_ptr<CDBusServer> m_dbusP2PServer;
std::shared_ptr<CDBusConnection> m_dbusConnection; std::shared_ptr<CDBusConnection> m_dbusConnection;
std::unique_ptr<CService> m_service; std::unique_ptr<CService> m_service;
@@ -70,7 +73,7 @@ namespace XSwiftBus
CMenuItem m_popupMessageWindowMenuItem; CMenuItem m_popupMessageWindowMenuItem;
CMenuItem m_disappearMessageWindowMenuItem; CMenuItem m_disappearMessageWindowMenuItem;
CMenu m_planeViewSubMenu; CMenu m_planeViewSubMenu;
CMenuItem planeViewOwnAircraftMenuItem; CMenuItem m_planeViewOwnAircraftMenuItem;
DataRef<xplane::data::sim::atc::atis_enabled> m_atisEnabled; DataRef<xplane::data::sim::atc::atis_enabled> m_atisEnabled;
decltype(m_atisEnabled.get()) m_atisSaved = 0; decltype(m_atisEnabled.get()) m_atisSaved = 0;

View File

@@ -6,11 +6,14 @@
* or distributed except according to the terms contained in the LICENSE file. * or distributed except according to the terms contained in the LICENSE file.
*/ */
#include "service.h" #include "service.h"
#include "utils.h" #include "utils.h"
#include "blackmisc/simulation/xplane/qtfreeutils.h"
#include <XPLM/XPLMPlanes.h> #include <XPLM/XPLMPlanes.h>
#include <XPLM/XPLMUtilities.h> #include <XPLM/XPLMUtilities.h>
#include "blackmisc/simulation/xplane/qtfreeutils.h"
#include <algorithm> #include <algorithm>
// clazy:excludeall=reserve-candidates // clazy:excludeall=reserve-candidates
@@ -19,8 +22,7 @@ using namespace BlackMisc::Simulation::XPlane::QtFreeUtils;
namespace XSwiftBus namespace XSwiftBus
{ {
CService::CService(CSettings &settings) : CDBusObject(), m_pluginSettings(settings)
CService::CService() : CDBusObject()
{ {
updateAirportsInRange(); updateAirportsInRange();
} }
@@ -155,6 +157,16 @@ namespace XSwiftBus
return path; 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() void CService::readAirportsDatabase()
{ {
auto first = XPLMFindFirstNavAidOfType(xplm_Nav_Airport); auto first = XPLMFindFirstNavAidOfType(xplm_Nav_Airport);
@@ -652,6 +664,24 @@ namespace XSwiftBus
toggleMessageBoxVisibility(); 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 else
{ {
// Unknown message. Tell DBus that we cannot handle it // Unknown message. Tell DBus that we cannot handle it

View File

@@ -19,6 +19,7 @@
#include "datarefs.h" #include "datarefs.h"
#include "messages.h" #include "messages.h"
#include "navdatareference.h" #include "navdatareference.h"
#include "settings.h"
#include <XPLM/XPLMNavigation.h> #include <XPLM/XPLMNavigation.h>
#include <string> #include <string>
#include <chrono> #include <chrono>
@@ -37,7 +38,7 @@ namespace XSwiftBus
{ {
public: public:
//! Constructor //! Constructor
CService(); CService(CSettings &settings);
//! Destructor //! Destructor
~CService() override = default; ~CService() override = default;
@@ -234,6 +235,12 @@ namespace XSwiftBus
//! Enable/disable message window disappearing again after 5 seconds //! Enable/disable message window disappearing again after 5 seconds
void setDisappearMessageWindow(bool enabled) { m_disappearMessageWindow = enabled; } 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 //! Perform generic processing
int process(); int process();
@@ -253,8 +260,9 @@ namespace XSwiftBus
bool m_disappearMessageWindow = true; bool m_disappearMessageWindow = true;
std::chrono::system_clock::time_point m_disappearMessageWindowTime; std::chrono::system_clock::time_point m_disappearMessageWindowTime;
std::vector<CNavDataReference> m_airports; std::vector<CNavDataReference> m_airports;
void readAirportsDatabase(); CSettings &m_pluginSettings;
void readAirportsDatabase();
std::vector<CNavDataReference> findClosestAirports(int number, double latitude, double longitude); std::vector<CNavDataReference> findClosestAirports(int number, double latitude, double longitude);
StringDataRef<xplane::data::sim::aircraft::view::acf_livery_path> m_liveryPath; StringDataRef<xplane::data::sim::aircraft::view::acf_livery_path> m_liveryPath;

View File

@@ -45,14 +45,17 @@ namespace XSwiftBus
surfaces.lights.timeOffset = static_cast<uint16_t>(std::rand() % 0xffff); surfaces.lights.timeOffset = static_cast<uint16_t>(std::rand() % 0xffff);
} }
CTraffic::CTraffic() : // *INDENT-OFF*
CTraffic::CTraffic(CSettings &settings) :
CDBusObject(), 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_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(); }) 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); XPLMRegisterDrawCallback(drawCallback, xplm_Phase_Airplanes, 1, this);
XPLMRegisterKeySniffer(spaceKeySniffer, 1, this); XPLMRegisterKeySniffer(spaceKeySniffer, 1, this);
} }
// *INDENT-ON*
CTraffic::~CTraffic() CTraffic::~CTraffic()
{ {
@@ -394,7 +397,7 @@ namespace XSwiftBus
plane->surfaces.lights.bcnLights = beaconLights.at(i); plane->surfaces.lights.bcnLights = beaconLights.at(i);
plane->surfaces.lights.strbLights = strobeLights.at(i); plane->surfaces.lights.strbLights = strobeLights.at(i);
plane->surfaces.lights.navLights = navLights.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));
} }
} }

View File

@@ -16,6 +16,7 @@
#include "datarefs.h" #include "datarefs.h"
#include "terrainprobe.h" #include "terrainprobe.h"
#include "menus.h" #include "menus.h"
#include "settings.h"
#include "XPMPMultiplayer.h" #include "XPMPMultiplayer.h"
#include "XPLMCamera.h" #include "XPLMCamera.h"
#include <XPLM/XPLMDisplay.h> #include <XPLM/XPLMDisplay.h>
@@ -36,7 +37,7 @@ namespace XSwiftBus
{ {
public: public:
//! Constructor //! Constructor
CTraffic(); CTraffic(CSettings &settings);
//! Destructor //! Destructor
~CTraffic() override; ~CTraffic() override;
@@ -146,6 +147,7 @@ namespace XSwiftBus
bool m_initialized = false; bool m_initialized = false;
bool m_enabledMultiplayer = false; bool m_enabledMultiplayer = false;
CTerrainProbe m_terrainProbe; CTerrainProbe m_terrainProbe;
CSettings &m_pluginSettings;
void emitSimFrame(); void emitSimFrame();
void emitPlaneAdded(const std::string &callsign); void emitPlaneAdded(const std::string &callsign);
@@ -182,7 +184,6 @@ namespace XSwiftBus
const std::string &livery_, const std::string &modelName_); const std::string &livery_, const std::string &modelName_);
}; };
std::unordered_map<std::string, Plane *> m_planesByCallsign; std::unordered_map<std::string, Plane *> m_planesByCallsign;
std::unordered_map<void *, Plane *> m_planesById; std::unordered_map<void *, Plane *> m_planesById;
std::vector<std::string> m_followPlaneViewSequence; std::vector<std::string> m_followPlaneViewSequence;

View File

@@ -13,8 +13,9 @@
namespace XSwiftBus namespace XSwiftBus
{ {
CWeather::CWeather() CWeather::CWeather(CSettings &settings) : m_pluginSettings(settings)
{ {
// void
} }
//! Set cloud layer //! Set cloud layer

View File

@@ -16,6 +16,7 @@
#endif #endif
#include "dbusobject.h" #include "dbusobject.h"
#include "datarefs.h" #include "datarefs.h"
#include "settings.h"
//! \cond PRIVATE //! \cond PRIVATE
#define XSWIFTBUS_WEATHER_INTERFACENAME "org.swift_project.xswiftbus.weather" #define XSWIFTBUS_WEATHER_INTERFACENAME "org.swift_project.xswiftbus.weather"
@@ -24,7 +25,6 @@
namespace XSwiftBus namespace XSwiftBus
{ {
/*! /*!
* XSwiftBus weather object which is accessible through DBus * XSwiftBus weather object which is accessible through DBus
*/ */
@@ -32,7 +32,7 @@ namespace XSwiftBus
{ {
public: public:
//! Constructor //! Constructor
CWeather(); CWeather(CSettings &settings);
//! DBus interface name //! DBus interface name
static const std::string &InterfaceName() static const std::string &InterfaceName()
@@ -103,6 +103,8 @@ namespace XSwiftBus
virtual DBusHandlerResult dbusMessageHandler(const CDBusMessage &message) override; virtual DBusHandlerResult dbusMessageHandler(const CDBusMessage &message) override;
private: private:
CSettings &m_pluginSettings;
DataRef<xplane::data::sim::weather::use_real_weather_bool> m_useRealWeather; 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::visibility_reported_m> m_visibilityM;
DataRef<xplane::data::sim::weather::rain_percent> m_precipRatio; DataRef<xplane::data::sim::weather::rain_percent> m_precipRatio;