mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
refs #423 Detect already running xbus
This commit is contained in:
@@ -454,9 +454,16 @@ namespace BlackSimPlugin
|
||||
if (m_watcher) // already started
|
||||
return;
|
||||
|
||||
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);
|
||||
if (isXBusRunning())
|
||||
{
|
||||
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()
|
||||
@@ -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)
|
||||
{
|
||||
if (serviceName == xbusServiceName())
|
||||
|
||||
@@ -198,6 +198,10 @@ namespace BlackSimPlugin
|
||||
//! \copydoc BlackCore::ISimulatorListener::stop
|
||||
virtual void stop() override;
|
||||
|
||||
private:
|
||||
//! \brief Check if XBus service is already registered
|
||||
bool isXBusRunning() const;
|
||||
|
||||
private slots:
|
||||
void ps_serviceRegistered(const QString &serviceName);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user