mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-06 02:16:04 +08:00
refs #423 Detect already running xbus
This commit is contained in:
@@ -454,9 +454,16 @@ namespace BlackSimPlugin
|
|||||||
if (m_watcher) // already started
|
if (m_watcher) // already started
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_conn = QDBusConnection::sessionBus(); // TODO make this configurable
|
if (isXBusRunning())
|
||||||
m_watcher = new QDBusServiceWatcher(xbusServiceName(), m_conn, QDBusServiceWatcher::WatchForRegistration, this);
|
{
|
||||||
connect(m_watcher, &QDBusServiceWatcher::serviceRegistered, this, &CSimulatorXPlaneListener::ps_serviceRegistered);
|
emit simulatorStarted();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_conn = QDBusConnection::sessionBus(); // TODO make this configurable
|
||||||
|
m_watcher = new QDBusServiceWatcher(xbusServiceName(), m_conn, QDBusServiceWatcher::WatchForRegistration, this);
|
||||||
|
connect(m_watcher, &QDBusServiceWatcher::serviceRegistered, this, &CSimulatorXPlaneListener::ps_serviceRegistered);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimulatorXPlaneListener::stop()
|
void CSimulatorXPlaneListener::stop()
|
||||||
@@ -468,6 +475,20 @@ namespace BlackSimPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CSimulatorXPlaneListener::isXBusRunning() const
|
||||||
|
{
|
||||||
|
QDBusConnection conn = QDBusConnection::sessionBus(); // TODO make this configurable
|
||||||
|
CXBusServiceProxy *service = new CXBusServiceProxy(conn);
|
||||||
|
CXBusTrafficProxy *traffic = new CXBusTrafficProxy(conn);
|
||||||
|
|
||||||
|
bool result = service->isValid() && traffic->isValid();
|
||||||
|
|
||||||
|
service->deleteLater();
|
||||||
|
traffic->deleteLater();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void CSimulatorXPlaneListener::ps_serviceRegistered(const QString &serviceName)
|
void CSimulatorXPlaneListener::ps_serviceRegistered(const QString &serviceName)
|
||||||
{
|
{
|
||||||
if (serviceName == xbusServiceName())
|
if (serviceName == xbusServiceName())
|
||||||
|
|||||||
@@ -198,6 +198,10 @@ namespace BlackSimPlugin
|
|||||||
//! \copydoc BlackCore::ISimulatorListener::stop
|
//! \copydoc BlackCore::ISimulatorListener::stop
|
||||||
virtual void stop() override;
|
virtual void stop() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
//! \brief Check if XBus service is already registered
|
||||||
|
bool isXBusRunning() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void ps_serviceRegistered(const QString &serviceName);
|
void ps_serviceRegistered(const QString &serviceName);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user