Ref T709, send XSwiftBusSettings when driver is connected

* send from swift -> XPlane side
* also send if settings on swift side are updated
This commit is contained in:
Klaus Basan
2019-07-26 16:48:44 +02:00
committed by Mat Sutcliffe
parent d1db1943ae
commit cbd93da1c6
3 changed files with 43 additions and 9 deletions

View File

@@ -380,10 +380,17 @@ namespace BlackSimPlugin
connect(m_trafficProxy, &CXSwiftBusTrafficProxy::remoteAircraftAddingFailed, this, &CSimulatorXPlane::onRemoteAircraftAddingFailed); connect(m_trafficProxy, &CXSwiftBusTrafficProxy::remoteAircraftAddingFailed, this, &CSimulatorXPlane::onRemoteAircraftAddingFailed);
if (m_watcher) { m_watcher->setConnection(m_dBusConnection); } if (m_watcher) { m_watcher->setConnection(m_dBusConnection); }
m_trafficProxy->removeAllPlanes(); m_trafficProxy->removeAllPlanes();
// send the settings
this->sendXSwiftBusSettings();
// load CSL
this->loadCslPackages(); this->loadCslPackages();
// finish
this->initSimulatorInternals();
this->emitSimulatorCombinedStatus(); this->emitSimulatorCombinedStatus();
this->initSimulatorInternals();
return true; return true;
} }
@@ -1056,18 +1063,38 @@ namespace BlackSimPlugin
if (!m_serviceProxy) { return false; } if (!m_serviceProxy) { return false; }
const CXSwiftBusSettings s = m_xSwiftBusServerSettings.get(); const CXSwiftBusSettings s = m_xSwiftBusServerSettings.get();
m_serviceProxy->setSettings(s.toXSwiftBusJsonStringQt()); m_serviceProxy->setSettings(s.toXSwiftBusJsonStringQt());
CLogMessage(this).info(u"Send settings: %1") << s.toQString(true);
return true; return true;
} }
bool CSimulatorXPlane::receiveXSwiftBusSettings() CXSwiftBusSettings CSimulatorXPlane::receiveXSwiftBusSettings(bool &ok)
{ {
if (!this->isConnected()) { return false; } ok = false;
if (!m_serviceProxy) { return false; } CXSwiftBusSettings s;
if (!this->isConnected()) { return s; }
if (!m_serviceProxy) { return s; }
const QString json = m_serviceProxy->getSettings(); const QString json = m_serviceProxy->getSettings();
const CXSwiftBusSettings s(json); s.parseXSwiftBusStringQt(json);
Q_UNUSED(s); // DO SOMETHING WITH THE SETTINGS ok = true;
return true; return s;
}
void CSimulatorXPlane::onXSwiftBusSettingsChanged()
{
bool ok;
const CXSwiftBusSettings xPlaneSide = this->receiveXSwiftBusSettings(ok);
if (ok)
{
// we only send if DBus did not change
// DBus changes would require a restart
const CXSwiftBusSettings swiftSide = m_xSwiftBusServerSettings.get();
if (xPlaneSide.getDBusServerAddressQt() == swiftSide.getDBusServerAddressQt())
{
this->sendXSwiftBusSettings();
}
}
} }
void CSimulatorXPlane::updateAirportsInRange() void CSimulatorXPlane::updateAirportsInRange()

View File

@@ -225,11 +225,14 @@ namespace BlackSimPlugin
//! Send/receive settings @{ //! Send/receive settings @{
bool sendXSwiftBusSettings(); bool sendXSwiftBusSettings();
bool receiveXSwiftBusSettings(); BlackMisc::Simulation::Settings::CXSwiftBusSettings receiveXSwiftBusSettings(bool &ok);
//! @} //! @}
//! Settings have changed
void onXSwiftBusSettingsChanged();
DBusMode m_dbusMode; DBusMode m_dbusMode;
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TXSwiftBusSettings> m_xSwiftBusServerSettings { this }; BlackMisc::CSetting<BlackMisc::Simulation::Settings::TXSwiftBusSettings> m_xSwiftBusServerSettings { this, &CSimulatorXPlane::onXSwiftBusSettingsChanged };
static constexpr qint64 TimeoutAdding = 10000; static constexpr qint64 TimeoutAdding = 10000;
QDBusConnection m_dBusConnection { "default" }; QDBusConnection m_dBusConnection { "default" };
QDBusServiceWatcher *m_watcher { nullptr }; QDBusServiceWatcher *m_watcher { nullptr };

View File

@@ -165,6 +165,10 @@ namespace XSwiftBus
void CService::setSettings(const std::string &jsonString) void CService::setSettings(const std::string &jsonString)
{ {
m_pluginSettings.parseXSwiftBusString(jsonString); m_pluginSettings.parseXSwiftBusString(jsonString);
XPLMDebugString("Received settings ");
XPLMDebugString(m_pluginSettings.convertToString().c_str());
XPLMDebugString("\n");
} }
void CService::readAirportsDatabase() void CService::readAirportsDatabase()