refs #423 Detect already running xbus

This commit is contained in:
Michał Garapich
2015-05-24 12:14:54 +02:00
parent 76993ab394
commit 49a9b91258
2 changed files with 28 additions and 3 deletions

View File

@@ -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())

View File

@@ -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);