mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Ref T709, changed to settings provider
* CPlugin is the provider * it is "kept" in DBus object for traffic, service, weather
This commit is contained in:
committed by
Mat Sutcliffe
parent
97926eee26
commit
f9c87326fb
@@ -9,10 +9,18 @@
|
||||
#include "dbusobject.h"
|
||||
#include <cassert>
|
||||
|
||||
XSwiftBus::ISettingsProvider *XSwiftBus::CDBusObject::s_settingsProvider = nullptr;
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
CDBusObject::CDBusObject()
|
||||
{ }
|
||||
CDBusObject::CDBusObject(ISettingsProvider *settingsProvider)
|
||||
{
|
||||
if (!CDBusObject::s_settingsProvider)
|
||||
{
|
||||
// we expect a single pointer
|
||||
CDBusObject::s_settingsProvider = settingsProvider;
|
||||
}
|
||||
}
|
||||
|
||||
CDBusObject::~CDBusObject()
|
||||
{
|
||||
@@ -73,6 +81,18 @@ namespace XSwiftBus
|
||||
}
|
||||
}
|
||||
|
||||
CSettings CDBusObject::getSettings() const
|
||||
{
|
||||
if (s_settingsProvider) { return s_settingsProvider->getSettings(); }
|
||||
return CSettings();
|
||||
}
|
||||
|
||||
bool CDBusObject::setSettings(const CSettings &s)
|
||||
{
|
||||
if (s_settingsProvider) { s_settingsProvider->setSettings(s); }
|
||||
return false;
|
||||
}
|
||||
|
||||
void CDBusObject::dbusObjectPathUnregisterFunction(DBusConnection *connection, void *data)
|
||||
{
|
||||
(void)connection; // unused
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#define BLACKSIM_XSWIFTBUS_DBUSOBJECT_H
|
||||
|
||||
#include "dbusconnection.h"
|
||||
#include "settings.h"
|
||||
#include <XPLM/XPLMDisplay.h>
|
||||
#include <mutex>
|
||||
#include <deque>
|
||||
@@ -21,7 +22,7 @@ namespace XSwiftBus
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CDBusObject();
|
||||
CDBusObject(ISettingsProvider *settingsProvider);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CDBusObject();
|
||||
@@ -79,6 +80,14 @@ namespace XSwiftBus
|
||||
//! Invoke all pending DBus calls. They will be executed in the calling thread.
|
||||
void invokeQueuedDBusCalls();
|
||||
|
||||
//! Get the settings
|
||||
CSettings getSettings() const;
|
||||
|
||||
//! Set the settings
|
||||
bool setSettings(const CSettings &s);
|
||||
|
||||
static ISettingsProvider *s_settingsProvider; //!< get the settings from here, still protected for the static functions
|
||||
|
||||
private:
|
||||
static void dbusObjectPathUnregisterFunction(DBusConnection *connection, void *data);
|
||||
static DBusHandlerResult dbusObjectPathMessageFunction(DBusConnection *connection, DBusMessage *message, void *data);
|
||||
@@ -87,7 +96,7 @@ namespace XSwiftBus
|
||||
std::string m_interfaceName;
|
||||
std::string m_objectPath;
|
||||
|
||||
std::mutex m_mutex;
|
||||
std::mutex m_mutex; //!< DBus calls
|
||||
std::deque<std::function<void()>> m_qeuedDBusCalls;
|
||||
|
||||
const DBusObjectPathVTable m_dbusObjectPathVTable = { dbusObjectPathUnregisterFunction, dbusObjectPathMessageFunction, nullptr, nullptr, nullptr, nullptr };
|
||||
|
||||
@@ -26,8 +26,6 @@ namespace
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
CSettings CPlugin::s_pluginSettings = CSettings();
|
||||
|
||||
CPlugin::CPlugin()
|
||||
: m_dbusConnection(std::make_shared<CDBusConnection>()), m_menu(CMenu::mainMenu().subMenu("XSwiftBus"))
|
||||
{
|
||||
@@ -99,9 +97,9 @@ namespace XSwiftBus
|
||||
|
||||
readConfig();
|
||||
|
||||
m_service = std::make_unique<CService>(&CPlugin::s_pluginSettings);
|
||||
m_traffic = std::make_unique<CTraffic>(&CPlugin::s_pluginSettings);
|
||||
m_weather = std::make_unique<CWeather>(&CPlugin::s_pluginSettings);
|
||||
m_service = std::make_unique<CService>(this);
|
||||
m_traffic = std::make_unique<CTraffic>(this);
|
||||
m_weather = std::make_unique<CWeather>(this);
|
||||
|
||||
m_traffic->setPlaneViewMenu(m_planeViewSubMenu);
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace XSwiftBus
|
||||
/*!
|
||||
* Main plugin class
|
||||
*/
|
||||
class CPlugin
|
||||
class CPlugin : public ISettingsProvider
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
@@ -57,8 +57,6 @@ namespace XSwiftBus
|
||||
void onAircraftRepositioned();
|
||||
|
||||
private:
|
||||
static CSettings s_pluginSettings; //!< needs to used in static in static functions
|
||||
|
||||
CConfig m_pluginConfig;
|
||||
CDBusDispatcher m_dbusDispatcher;
|
||||
std::unique_ptr<CDBusServer> m_dbusP2PServer;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "plugin.h"
|
||||
#include "service.h"
|
||||
#include "utils.h"
|
||||
#include "blackmisc/simulation/xplane/qtfreeutils.h"
|
||||
@@ -21,11 +22,8 @@ using namespace BlackMisc::Simulation::XPlane::QtFreeUtils;
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
CSettings *CService::s_pluginSettings = nullptr;
|
||||
|
||||
CService::CService(CSettings *staticSettings) : CDBusObject()
|
||||
CService::CService(ISettingsProvider *settingsProvider) : CDBusObject(settingsProvider)
|
||||
{
|
||||
CService::s_pluginSettings = staticSettings;
|
||||
updateAirportsInRange();
|
||||
}
|
||||
|
||||
@@ -161,13 +159,14 @@ namespace XSwiftBus
|
||||
|
||||
std::string CService::getSettings() const
|
||||
{
|
||||
return CService::s_pluginSettings->toXSwiftBusJsonString();
|
||||
return s_settingsProvider->getSettings().toXSwiftBusJsonString();
|
||||
}
|
||||
|
||||
void CService::setSettings(const std::string &jsonString)
|
||||
{
|
||||
CService::s_pluginSettings->parseXSwiftBusString(jsonString);
|
||||
INFO_LOG("Received settings " + s_pluginSettings->convertToString());
|
||||
const CSettings s(jsonString);
|
||||
s_settingsProvider->setSettings(s);
|
||||
INFO_LOG("Received settings " + s.convertToString());
|
||||
}
|
||||
|
||||
void CService::readAirportsDatabase()
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#include "datarefs.h"
|
||||
#include "messages.h"
|
||||
#include "navdatareference.h"
|
||||
#include "settings.h"
|
||||
#include <XPLM/XPLMNavigation.h>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
@@ -38,7 +37,7 @@ namespace XSwiftBus
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CService(CSettings *staticSettings);
|
||||
CService(ISettingsProvider *settingsProvider);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CService() override = default;
|
||||
@@ -260,7 +259,6 @@ namespace XSwiftBus
|
||||
bool m_disappearMessageWindow = true;
|
||||
std::chrono::system_clock::time_point m_disappearMessageWindowTime;
|
||||
std::vector<CNavDataReference> m_airports;
|
||||
static CSettings *s_pluginSettings;
|
||||
|
||||
void readAirportsDatabase();
|
||||
std::vector<CNavDataReference> findClosestAirports(int number, double latitude, double longitude);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include "plugin.h"
|
||||
#include "traffic.h"
|
||||
#include "utils.h"
|
||||
#include "XPMPMultiplayer.h"
|
||||
@@ -31,8 +32,6 @@
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
CSettings *CTraffic::s_pluginSettings = nullptr;
|
||||
|
||||
CTraffic::Plane::Plane(void *id_, const std::string &callsign_, const std::string &aircraftIcao_, const std::string &airlineIcao_, const std::string &livery_, const std::string &modelName_)
|
||||
: id(id_), callsign(callsign_), aircraftIcao(aircraftIcao_), airlineIcao(airlineIcao_), livery(livery_), modelName(modelName_)
|
||||
{
|
||||
@@ -48,17 +47,16 @@ namespace XSwiftBus
|
||||
}
|
||||
|
||||
// *INDENT-OFF*
|
||||
CTraffic::CTraffic(CSettings *staticSettings) :
|
||||
CDBusObject(),
|
||||
CTraffic::CTraffic(ISettingsProvider *settingsProvider) :
|
||||
CDBusObject(settingsProvider),
|
||||
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(); })
|
||||
{
|
||||
CTraffic::s_pluginSettings = staticSettings;
|
||||
XPLMRegisterDrawCallback(drawCallback, xplm_Phase_Airplanes, 1, this);
|
||||
XPLMRegisterKeySniffer(spaceKeySniffer, 1, this);
|
||||
|
||||
// init labels
|
||||
this->setDrawingLabels(CTraffic::s_pluginSettings->isDrawingLabels());
|
||||
this->setDrawingLabels(this->getSettings().isDrawingLabels());
|
||||
}
|
||||
// *INDENT-ON*
|
||||
|
||||
@@ -84,6 +82,7 @@ namespace XSwiftBus
|
||||
std::string related = dir + "related.txt";
|
||||
std::string doc8643 = dir + "Doc8643.txt";
|
||||
std::string lights = dir + "lights.png";
|
||||
|
||||
auto err = XPMPMultiplayerInitLegacyData(csl.c_str(), related.c_str(), lights.c_str(), doc8643.c_str(),
|
||||
"C172", preferences, preferences);
|
||||
if (*err) { s_legacyDataOK = false; }
|
||||
@@ -217,7 +216,7 @@ namespace XSwiftBus
|
||||
{
|
||||
if (strcmp(section, "planes") == 0 && strcmp(name, "max_full_count") == 0)
|
||||
{
|
||||
return CTraffic::s_pluginSettings->getMaxPlanes();
|
||||
return s_settingsProvider->getSettings().getMaxPlanes();
|
||||
}
|
||||
else if (strcmp(section, "debug") == 0 && strcmp(name, "allow_obj8_async_load") == 0)
|
||||
{
|
||||
@@ -232,7 +231,7 @@ namespace XSwiftBus
|
||||
{
|
||||
if (strcmp(section, "planes") == 0 && strcmp(name, "full_distance") == 0)
|
||||
{
|
||||
return static_cast<float>(CTraffic::s_pluginSettings->getMaxDrawDistanceNM());
|
||||
return static_cast<float>(s_settingsProvider->getSettings().getMaxDrawDistanceNM());
|
||||
}
|
||||
return def;
|
||||
}
|
||||
@@ -256,7 +255,7 @@ namespace XSwiftBus
|
||||
|
||||
void CTraffic::setDrawingLabels(bool drawing)
|
||||
{
|
||||
CTraffic::s_pluginSettings->setDrawingLabels(drawing);
|
||||
s_settingsProvider->getSettings().setDrawingLabels(drawing);
|
||||
if (drawing)
|
||||
{
|
||||
XPMPEnableAircraftLabels();
|
||||
@@ -274,12 +273,12 @@ namespace XSwiftBus
|
||||
|
||||
void CTraffic::setMaxPlanes(int planes)
|
||||
{
|
||||
CTraffic::s_pluginSettings->setMaxPlanes(planes);
|
||||
s_settingsProvider->getSettings().setMaxPlanes(planes);
|
||||
}
|
||||
|
||||
void CTraffic::setMaxDrawDistance(double nauticalMiles)
|
||||
{
|
||||
CTraffic::s_pluginSettings->setMaxDrawDistanceNM(nauticalMiles);
|
||||
s_settingsProvider->getSettings().setMaxDrawDistanceNM(nauticalMiles);
|
||||
}
|
||||
|
||||
void CTraffic::addPlane(const std::string &callsign, const std::string &modelName, const std::string &aircraftIcao, const std::string &airlineIcao, const std::string &livery)
|
||||
@@ -898,7 +897,7 @@ namespace XSwiftBus
|
||||
// Now calculate where the camera should be positioned to be x
|
||||
// meters from the plane and pointing at the plane at the pitch and
|
||||
// heading we wanted above.
|
||||
const double distanceMeterM = static_cast<double>(std::max(10, CTraffic::s_pluginSettings->getFollowAircraftDistanceM()));
|
||||
const double distanceMeterM = static_cast<double>(std::max(10, s_settingsProvider->getSettings().getFollowAircraftDistanceM()));
|
||||
static const double PI = std::acos(-1);
|
||||
traffic->m_deltaCameraPosition.dx = -distanceMeterM * sin(traffic->m_deltaCameraPosition.heading * PI / 180.0);
|
||||
traffic->m_deltaCameraPosition.dz = distanceMeterM * cos(traffic->m_deltaCameraPosition.heading * PI / 180.0);
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
//! \file
|
||||
|
||||
#include "dbusobject.h"
|
||||
#include "settings.h"
|
||||
#include "command.h"
|
||||
#include "datarefs.h"
|
||||
#include "terrainprobe.h"
|
||||
#include "menus.h"
|
||||
#include "settings.h"
|
||||
#include "XPMPMultiplayer.h"
|
||||
#include "XPLMCamera.h"
|
||||
#include <XPLM/XPLMDisplay.h>
|
||||
@@ -37,7 +37,7 @@ namespace XSwiftBus
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CTraffic(CSettings *staticSettings);
|
||||
CTraffic(ISettingsProvider *settingsProvider);
|
||||
|
||||
//! Destructor
|
||||
~CTraffic() override;
|
||||
@@ -129,11 +129,14 @@ namespace XSwiftBus
|
||||
std::string ownAircraftString() const { return "ownAircraft"; }
|
||||
|
||||
protected:
|
||||
//! Handler
|
||||
virtual void dbusDisconnectedHandler() override;
|
||||
|
||||
//! Handler
|
||||
DBusHandlerResult dbusMessageHandler(const CDBusMessage &message) override;
|
||||
|
||||
private:
|
||||
//! Camera
|
||||
struct DeltaCameraPosition
|
||||
{
|
||||
double dx = 0.0;
|
||||
@@ -144,8 +147,6 @@ namespace XSwiftBus
|
||||
bool isInitialized = false;
|
||||
};
|
||||
|
||||
static CSettings *s_pluginSettings; //!< needs to be static for static functions
|
||||
|
||||
bool m_initialized = false;
|
||||
bool m_enabledMultiplayer = false;
|
||||
CTerrainProbe m_terrainProbe;
|
||||
|
||||
@@ -13,11 +13,9 @@
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
CSettings *CWeather::s_pluginSettings = nullptr;
|
||||
|
||||
CWeather::CWeather(CSettings *staticSettings)
|
||||
CWeather::CWeather(ISettingsProvider *settingsProvider) : CDBusObject(settingsProvider)
|
||||
{
|
||||
CWeather::s_pluginSettings = staticSettings;
|
||||
// void
|
||||
}
|
||||
|
||||
//! Set cloud layer
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#endif
|
||||
#include "dbusobject.h"
|
||||
#include "datarefs.h"
|
||||
#include "settings.h"
|
||||
|
||||
//! \cond PRIVATE
|
||||
#define XSWIFTBUS_WEATHER_INTERFACENAME "org.swift_project.xswiftbus.weather"
|
||||
@@ -32,7 +31,7 @@ namespace XSwiftBus
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CWeather(CSettings *staticSettings);
|
||||
CWeather(ISettingsProvider *settingsProvider);
|
||||
|
||||
//! DBus interface name
|
||||
static const std::string &InterfaceName()
|
||||
@@ -103,8 +102,6 @@ namespace XSwiftBus
|
||||
virtual DBusHandlerResult dbusMessageHandler(const CDBusMessage &message) override;
|
||||
|
||||
private:
|
||||
static CSettings *s_pluginSettings; //!< needs to be static for static functions;
|
||||
|
||||
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