mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 18:25:37 +08:00
Ref T709 Made settings provider non-static.
This commit is contained in:
@@ -9,18 +9,10 @@
|
|||||||
#include "dbusobject.h"
|
#include "dbusobject.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
XSwiftBus::CSettingsProvider *XSwiftBus::CDBusObject::s_settingsProvider = nullptr;
|
|
||||||
|
|
||||||
namespace XSwiftBus
|
namespace XSwiftBus
|
||||||
{
|
{
|
||||||
CDBusObject::CDBusObject(CSettingsProvider *settingsProvider)
|
CDBusObject::CDBusObject(CSettingsProvider *settingsProvider) : m_settingsProvider(settingsProvider)
|
||||||
{
|
{}
|
||||||
if (!CDBusObject::s_settingsProvider)
|
|
||||||
{
|
|
||||||
// we expect a single pointer
|
|
||||||
CDBusObject::s_settingsProvider = settingsProvider;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CDBusObject::~CDBusObject()
|
CDBusObject::~CDBusObject()
|
||||||
{
|
{
|
||||||
@@ -83,13 +75,13 @@ namespace XSwiftBus
|
|||||||
|
|
||||||
CSettings CDBusObject::getSettings() const
|
CSettings CDBusObject::getSettings() const
|
||||||
{
|
{
|
||||||
if (s_settingsProvider) { return s_settingsProvider->getSettings(); }
|
if (m_settingsProvider) { return m_settingsProvider->getSettings(); }
|
||||||
return CSettings();
|
return CSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CDBusObject::setSettings(const CSettings &s)
|
bool CDBusObject::setSettings(const CSettings &s)
|
||||||
{
|
{
|
||||||
if (s_settingsProvider) { s_settingsProvider->setSettings(s); }
|
if (m_settingsProvider) { m_settingsProvider->setSettings(s); }
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ namespace XSwiftBus
|
|||||||
//! Set the settings
|
//! Set the settings
|
||||||
bool setSettings(const CSettings &s);
|
bool setSettings(const CSettings &s);
|
||||||
|
|
||||||
static CSettingsProvider *s_settingsProvider; //!< get the settings from here, still protected for the static functions
|
CSettingsProvider *m_settingsProvider; //!< get the settings from here
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void dbusObjectPathUnregisterFunction(DBusConnection *connection, void *data);
|
static void dbusObjectPathUnregisterFunction(DBusConnection *connection, void *data);
|
||||||
|
|||||||
@@ -49,12 +49,16 @@ namespace XSwiftBus
|
|||||||
surfaces.lights.timeOffset = static_cast<uint16_t>(std::rand() % 0xffff);
|
surfaces.lights.timeOffset = static_cast<uint16_t>(std::rand() % 0xffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CTraffic *CTraffic::s_instance = nullptr;
|
||||||
|
|
||||||
// *INDENT-OFF*
|
// *INDENT-OFF*
|
||||||
CTraffic::CTraffic(CSettingsProvider *settingsProvider) :
|
CTraffic::CTraffic(CSettingsProvider *settingsProvider) :
|
||||||
CDBusObject(settingsProvider),
|
CDBusObject(settingsProvider),
|
||||||
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(); })
|
||||||
{
|
{
|
||||||
|
assert(!s_instance);
|
||||||
|
s_instance = this;
|
||||||
XPLMRegisterDrawCallback(drawCallback, xplm_Phase_Airplanes, 1, this);
|
XPLMRegisterDrawCallback(drawCallback, xplm_Phase_Airplanes, 1, this);
|
||||||
XPLMRegisterKeySniffer(spaceKeySniffer, 1, this);
|
XPLMRegisterKeySniffer(spaceKeySniffer, 1, this);
|
||||||
|
|
||||||
@@ -67,6 +71,8 @@ namespace XSwiftBus
|
|||||||
{
|
{
|
||||||
XPLMUnregisterDrawCallback(drawCallback, xplm_Phase_Airplanes, 1, this);
|
XPLMUnregisterDrawCallback(drawCallback, xplm_Phase_Airplanes, 1, this);
|
||||||
cleanup();
|
cleanup();
|
||||||
|
assert(s_instance == this);
|
||||||
|
s_instance = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool s_legacyDataOK = true;
|
static bool s_legacyDataOK = true;
|
||||||
@@ -233,9 +239,11 @@ namespace XSwiftBus
|
|||||||
|
|
||||||
int CTraffic::preferences(const char *section, const char *name, int def)
|
int CTraffic::preferences(const char *section, const char *name, int def)
|
||||||
{
|
{
|
||||||
|
if (!s_instance) { return def; }
|
||||||
|
|
||||||
if (strcmp(section, "planes") == 0 && strcmp(name, "max_full_count") == 0)
|
if (strcmp(section, "planes") == 0 && strcmp(name, "max_full_count") == 0)
|
||||||
{
|
{
|
||||||
return CTraffic::s_settingsProvider->getSettings().getMaxPlanes(); // preferences
|
return s_instance->getSettings().getMaxPlanes(); // preferences
|
||||||
}
|
}
|
||||||
else if (strcmp(section, "debug") == 0 && strcmp(name, "allow_obj8_async_load") == 0)
|
else if (strcmp(section, "debug") == 0 && strcmp(name, "allow_obj8_async_load") == 0)
|
||||||
{
|
{
|
||||||
@@ -248,9 +256,11 @@ namespace XSwiftBus
|
|||||||
|
|
||||||
float CTraffic::preferences(const char *section, const char *name, float def)
|
float CTraffic::preferences(const char *section, const char *name, float def)
|
||||||
{
|
{
|
||||||
|
if (!s_instance) { return def; }
|
||||||
|
|
||||||
if (strcmp(section, "planes") == 0 && strcmp(name, "full_distance") == 0)
|
if (strcmp(section, "planes") == 0 && strcmp(name, "full_distance") == 0)
|
||||||
{
|
{
|
||||||
return static_cast<float>(CTraffic::s_settingsProvider->getSettings().getMaxDrawDistanceNM()); // preferences
|
return static_cast<float>(s_instance->getSettings().getMaxDrawDistanceNM()); // preferences
|
||||||
}
|
}
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,8 +159,10 @@ namespace XSwiftBus
|
|||||||
void followPreviousPlane();
|
void followPreviousPlane();
|
||||||
bool containsCallsign(const std::string &callsign) const;
|
bool containsCallsign(const std::string &callsign) const;
|
||||||
|
|
||||||
|
static CTraffic *s_instance;
|
||||||
static int preferences(const char *section, const char *name, int def);
|
static int preferences(const char *section, const char *name, int def);
|
||||||
static float preferences(const char *section, const char *name, float def);
|
static float preferences(const char *section, const char *name, float def);
|
||||||
|
|
||||||
static int orbitOwnAircraftFunc(XPLMCameraPosition_t *cameraPosition, int isLosingControl, void *refcon);
|
static int orbitOwnAircraftFunc(XPLMCameraPosition_t *cameraPosition, int isLosingControl, void *refcon);
|
||||||
static int orbitPlaneFunc(XPLMCameraPosition_t *cameraPosition, int isLosingControl, void *refcon);
|
static int orbitPlaneFunc(XPLMCameraPosition_t *cameraPosition, int isLosingControl, void *refcon);
|
||||||
static int drawCallback(XPLMDrawingPhase phase, int isBefore, void *refcon);
|
static int drawCallback(XPLMDrawingPhase phase, int isBefore, void *refcon);
|
||||||
|
|||||||
Reference in New Issue
Block a user