Ref T709 Made settings provider non-static.

This commit is contained in:
Mat Sutcliffe
2019-08-12 22:41:28 +01:00
parent 349da3633b
commit 463ed4bfbd
4 changed files with 19 additions and 15 deletions

View File

@@ -9,18 +9,10 @@
#include "dbusobject.h"
#include <cassert>
XSwiftBus::CSettingsProvider *XSwiftBus::CDBusObject::s_settingsProvider = nullptr;
namespace XSwiftBus
{
CDBusObject::CDBusObject(CSettingsProvider *settingsProvider)
{
if (!CDBusObject::s_settingsProvider)
{
// we expect a single pointer
CDBusObject::s_settingsProvider = settingsProvider;
}
}
CDBusObject::CDBusObject(CSettingsProvider *settingsProvider) : m_settingsProvider(settingsProvider)
{}
CDBusObject::~CDBusObject()
{
@@ -83,13 +75,13 @@ namespace XSwiftBus
CSettings CDBusObject::getSettings() const
{
if (s_settingsProvider) { return s_settingsProvider->getSettings(); }
if (m_settingsProvider) { return m_settingsProvider->getSettings(); }
return CSettings();
}
bool CDBusObject::setSettings(const CSettings &s)
{
if (s_settingsProvider) { s_settingsProvider->setSettings(s); }
if (m_settingsProvider) { m_settingsProvider->setSettings(s); }
return false;
}

View File

@@ -86,7 +86,7 @@ namespace XSwiftBus
//! Set the settings
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:
static void dbusObjectPathUnregisterFunction(DBusConnection *connection, void *data);

View File

@@ -49,12 +49,16 @@ namespace XSwiftBus
surfaces.lights.timeOffset = static_cast<uint16_t>(std::rand() % 0xffff);
}
CTraffic *CTraffic::s_instance = nullptr;
// *INDENT-OFF*
CTraffic::CTraffic(CSettingsProvider *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(); })
{
assert(!s_instance);
s_instance = this;
XPLMRegisterDrawCallback(drawCallback, xplm_Phase_Airplanes, 1, this);
XPLMRegisterKeySniffer(spaceKeySniffer, 1, this);
@@ -67,6 +71,8 @@ namespace XSwiftBus
{
XPLMUnregisterDrawCallback(drawCallback, xplm_Phase_Airplanes, 1, this);
cleanup();
assert(s_instance == this);
s_instance = nullptr;
}
static bool s_legacyDataOK = true;
@@ -233,9 +239,11 @@ namespace XSwiftBus
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)
{
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)
{
@@ -248,9 +256,11 @@ namespace XSwiftBus
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)
{
return static_cast<float>(CTraffic::s_settingsProvider->getSettings().getMaxDrawDistanceNM()); // preferences
return static_cast<float>(s_instance->getSettings().getMaxDrawDistanceNM()); // preferences
}
return def;
}

View File

@@ -159,8 +159,10 @@ namespace XSwiftBus
void followPreviousPlane();
bool containsCallsign(const std::string &callsign) const;
static CTraffic *s_instance;
static int preferences(const char *section, const char *name, int def);
static float preferences(const char *section, const char *name, float def);
static int orbitOwnAircraftFunc(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);