mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-09 13:35:34 +08:00
Ref T709, change XPlane driver to TXSwiftBusSettings, send/receive functions
This commit is contained in:
committed by
Mat Sutcliffe
parent
81577d29c5
commit
dab3e03d0b
@@ -68,9 +68,9 @@ using namespace BlackMisc;
|
|||||||
using namespace BlackMisc::Aviation;
|
using namespace BlackMisc::Aviation;
|
||||||
using namespace BlackMisc::Network;
|
using namespace BlackMisc::Network;
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
using namespace BlackMisc::Simulation;
|
|
||||||
using namespace BlackMisc::Geo;
|
using namespace BlackMisc::Geo;
|
||||||
using namespace BlackMisc::Simulation;
|
using namespace BlackMisc::Simulation;
|
||||||
|
using namespace BlackMisc::Simulation::Settings;
|
||||||
using namespace BlackMisc::Weather;
|
using namespace BlackMisc::Weather;
|
||||||
using namespace BlackCore;
|
using namespace BlackCore;
|
||||||
|
|
||||||
@@ -341,16 +341,16 @@ namespace BlackSimPlugin
|
|||||||
bool CSimulatorXPlane::connectTo()
|
bool CSimulatorXPlane::connectTo()
|
||||||
{
|
{
|
||||||
if (isConnected()) { return true; }
|
if (isConnected()) { return true; }
|
||||||
QString dbusAddress = m_xswiftbusServerSetting.getThreadLocal();
|
const QString dBusServerAddress = m_xSwiftBusServerSettings.getThreadLocal().getDBusServerAddressQt();
|
||||||
|
|
||||||
if (CDBusServer::isSessionOrSystemAddress(dbusAddress))
|
if (CDBusServer::isSessionOrSystemAddress(dBusServerAddress))
|
||||||
{
|
{
|
||||||
m_dBusConnection = connectionFromString(dbusAddress);
|
m_dBusConnection = connectionFromString(dBusServerAddress);
|
||||||
m_dbusMode = Session;
|
m_dbusMode = Session;
|
||||||
}
|
}
|
||||||
else if (CDBusServer::isQtDBusAddress(dbusAddress))
|
else if (CDBusServer::isQtDBusAddress(dBusServerAddress))
|
||||||
{
|
{
|
||||||
m_dBusConnection = QDBusConnection::connectToPeer(dbusAddress, "xswiftbus");
|
m_dBusConnection = QDBusConnection::connectToPeer(dBusServerAddress, "xswiftbus");
|
||||||
if (! m_dBusConnection.isConnected()) { return false; }
|
if (! m_dBusConnection.isConnected()) { return false; }
|
||||||
m_dbusMode = P2P;
|
m_dbusMode = P2P;
|
||||||
}
|
}
|
||||||
@@ -1050,6 +1050,26 @@ namespace BlackSimPlugin
|
|||||||
m_dBusConnection = QDBusConnection { "default" };
|
m_dBusConnection = QDBusConnection { "default" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CSimulatorXPlane::sendXSwiftBusSettings()
|
||||||
|
{
|
||||||
|
if (!this->isConnected()) { return false; }
|
||||||
|
if (!m_serviceProxy) { return false; }
|
||||||
|
const CXSwiftBusSettings s = m_xSwiftBusServerSettings.get();
|
||||||
|
m_serviceProxy->setSettings(s.toXSwiftBusJsonStringQt());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CSimulatorXPlane::receiveXSwiftBusSettings()
|
||||||
|
{
|
||||||
|
if (!this->isConnected()) { return false; }
|
||||||
|
if (!m_serviceProxy) { return false; }
|
||||||
|
|
||||||
|
const QString json = m_serviceProxy->getSettings();
|
||||||
|
const CXSwiftBusSettings s(json);
|
||||||
|
Q_UNUSED(s); // DO SOMETHING WITH THE SETTINGS
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void CSimulatorXPlane::updateAirportsInRange()
|
void CSimulatorXPlane::updateAirportsInRange()
|
||||||
{
|
{
|
||||||
if (this->isConnected()) { m_serviceProxy->updateAirportsInRange(); }
|
if (this->isConnected()) { m_serviceProxy->updateAirportsInRange(); }
|
||||||
@@ -1254,7 +1274,7 @@ namespace BlackSimPlugin
|
|||||||
if (this->isShuttingDown()) { return; }
|
if (this->isShuttingDown()) { return; }
|
||||||
Q_ASSERT_X(!CThreadUtils::isCurrentThreadApplicationThread(), Q_FUNC_INFO, "Expect to run in background");
|
Q_ASSERT_X(!CThreadUtils::isCurrentThreadApplicationThread(), Q_FUNC_INFO, "Expect to run in background");
|
||||||
|
|
||||||
QString dbusAddress = m_xswiftbusServerSetting.getThreadLocal();
|
const QString dbusAddress = m_xSwiftBusServerSettings.getThreadLocal().getDBusServerAddressQt();
|
||||||
if (CDBusServer::isSessionOrSystemAddress(dbusAddress))
|
if (CDBusServer::isSessionOrSystemAddress(dbusAddress))
|
||||||
{
|
{
|
||||||
checkConnectionViaBus(dbusAddress);
|
checkConnectionViaBus(dbusAddress);
|
||||||
@@ -1267,34 +1287,34 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
void CSimulatorXPlaneListener::checkConnectionViaBus(const QString &address)
|
void CSimulatorXPlaneListener::checkConnectionViaBus(const QString &address)
|
||||||
{
|
{
|
||||||
m_conn = CSimulatorXPlane::connectionFromString(address);
|
m_DBusConnection = CSimulatorXPlane::connectionFromString(address);
|
||||||
if (!m_conn.isConnected())
|
if (!m_DBusConnection.isConnected())
|
||||||
{
|
{
|
||||||
m_conn.disconnectFromBus(m_conn.name());
|
m_DBusConnection.disconnectFromBus(m_DBusConnection.name());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
checkConnectionCommon();
|
checkConnectionCommon();
|
||||||
m_conn.disconnectFromBus(m_conn.name());
|
m_DBusConnection.disconnectFromBus(m_DBusConnection.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimulatorXPlaneListener::checkConnectionViaPeer(const QString &address)
|
void CSimulatorXPlaneListener::checkConnectionViaPeer(const QString &address)
|
||||||
{
|
{
|
||||||
m_conn = QDBusConnection::connectToPeer(address, "xswiftbus");
|
m_DBusConnection = QDBusConnection::connectToPeer(address, "xswiftbus");
|
||||||
if (!m_conn.isConnected())
|
if (!m_DBusConnection.isConnected())
|
||||||
{
|
{
|
||||||
// This is required to cleanup the connection in QtDBus
|
// This is required to cleanup the connection in QtDBus
|
||||||
m_conn.disconnectFromPeer(m_conn.name());
|
m_DBusConnection.disconnectFromPeer(m_DBusConnection.name());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
checkConnectionCommon();
|
checkConnectionCommon();
|
||||||
m_conn.disconnectFromPeer(m_conn.name());
|
m_DBusConnection.disconnectFromPeer(m_DBusConnection.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimulatorXPlaneListener::checkConnectionCommon()
|
void CSimulatorXPlaneListener::checkConnectionCommon()
|
||||||
{
|
{
|
||||||
CXSwiftBusServiceProxy service(m_conn);
|
CXSwiftBusServiceProxy service(m_DBusConnection);
|
||||||
CXSwiftBusTrafficProxy traffic(m_conn);
|
CXSwiftBusTrafficProxy traffic(m_DBusConnection);
|
||||||
CXSwiftBusWeatherProxy weather(m_conn);
|
CXSwiftBusWeatherProxy weather(m_DBusConnection);
|
||||||
|
|
||||||
bool result = service.isValid() && traffic.isValid() && weather.isValid();
|
bool result = service.isValid() && traffic.isValid() && weather.isValid();
|
||||||
if (! result) { return; }
|
if (! result) { return; }
|
||||||
@@ -1332,13 +1352,18 @@ namespace BlackSimPlugin
|
|||||||
{
|
{
|
||||||
emit simulatorStarted(getPluginInfo());
|
emit simulatorStarted(getPluginInfo());
|
||||||
}
|
}
|
||||||
m_conn.disconnectFromBus(m_conn.name());
|
m_DBusConnection.disconnectFromBus(m_DBusConnection.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimulatorXPlaneListener::xSwiftBusServerSettingChanged()
|
void CSimulatorXPlaneListener::onXSwiftBusServerSettingChanged()
|
||||||
{
|
{
|
||||||
this->stop();
|
const CXSwiftBusSettings s = m_xSwiftBusServerSettings.get();
|
||||||
this->start();
|
if (m_dBusServerAddress != s.getDBusServerAddressQt())
|
||||||
|
{
|
||||||
|
this->stop();
|
||||||
|
this->start();
|
||||||
|
m_dBusServerAddress = s.getDBusServerAddressQt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -165,6 +165,7 @@ namespace BlackSimPlugin
|
|||||||
void serviceUnregistered();
|
void serviceUnregistered();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
//! Mode
|
||||||
enum DBusMode
|
enum DBusMode
|
||||||
{
|
{
|
||||||
Session,
|
Session,
|
||||||
@@ -219,14 +220,19 @@ namespace BlackSimPlugin
|
|||||||
const QDoubleList &elevationsMeters, const QDoubleList &verticalOffsetsMeters);
|
const QDoubleList &elevationsMeters, const QDoubleList &verticalOffsetsMeters);
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
//! Dsiconnect from DBus
|
//! Disconnect from DBus
|
||||||
void disconnectFromDBus();
|
void disconnectFromDBus();
|
||||||
|
|
||||||
|
//! Send/receive settings @{
|
||||||
|
bool sendXSwiftBusSettings();
|
||||||
|
bool receiveXSwiftBusSettings();
|
||||||
|
//! @}
|
||||||
|
|
||||||
DBusMode m_dbusMode;
|
DBusMode m_dbusMode;
|
||||||
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::Settings::TXSwiftBusServer> m_xswiftbusServerSetting { this };
|
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TXSwiftBusSettings> m_xSwiftBusServerSettings { this };
|
||||||
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 };
|
||||||
CXSwiftBusServiceProxy *m_serviceProxy { nullptr };
|
CXSwiftBusServiceProxy *m_serviceProxy { nullptr };
|
||||||
CXSwiftBusTrafficProxy *m_trafficProxy { nullptr };
|
CXSwiftBusTrafficProxy *m_trafficProxy { nullptr };
|
||||||
CXSwiftBusWeatherProxy *m_weatherProxy { nullptr };
|
CXSwiftBusWeatherProxy *m_weatherProxy { nullptr };
|
||||||
@@ -242,7 +248,7 @@ namespace BlackSimPlugin
|
|||||||
XPlaneData m_xplaneData; //!< XPlane data
|
XPlaneData m_xplaneData; //!< XPlane data
|
||||||
|
|
||||||
// statistics
|
// statistics
|
||||||
qint64 m_statsAddMaxTimeMs = -1;
|
qint64 m_statsAddMaxTimeMs = -1;
|
||||||
qint64 m_statsAddCurrentTimeMs = -1;
|
qint64 m_statsAddCurrentTimeMs = -1;
|
||||||
|
|
||||||
//! Reset the XPlane data
|
//! Reset the XPlane data
|
||||||
@@ -281,11 +287,12 @@ namespace BlackSimPlugin
|
|||||||
void checkConnectionCommon();
|
void checkConnectionCommon();
|
||||||
|
|
||||||
void serviceRegistered(const QString &serviceName);
|
void serviceRegistered(const QString &serviceName);
|
||||||
void xSwiftBusServerSettingChanged();
|
void onXSwiftBusServerSettingChanged();
|
||||||
|
|
||||||
QTimer m_timer { this };
|
QTimer m_timer { this };
|
||||||
QDBusConnection m_conn { "default" };
|
QDBusConnection m_DBusConnection { "default" };
|
||||||
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::Settings::TXSwiftBusServer> m_xswiftbusServerSetting { this, &CSimulatorXPlaneListener::xSwiftBusServerSettingChanged };
|
QString m_dBusServerAddress;
|
||||||
|
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::Settings::TXSwiftBusSettings> m_xSwiftBusServerSettings { this, &CSimulatorXPlaneListener::onXSwiftBusServerSettingChanged };
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Factory for creating CSimulatorXPlane instance
|
//! Factory for creating CSimulatorXPlane instance
|
||||||
|
|||||||
Reference in New Issue
Block a user